Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding (un)publish date info to List View #95

Open
freitasfa-bahag opened this issue Aug 2, 2023 · 6 comments
Open

Adding (un)publish date info to List View #95

freitasfa-bahag opened this issue Aug 2, 2023 · 6 comments

Comments

@freitasfa-bahag
Copy link

freitasfa-bahag commented Aug 2, 2023

I would like to add the date times for publish/unpublish to the List View as columns. How could that be possible? I saw Strapi offers a hook for that, but I didn't manage to find a way to set it.

Just to make it clear, the idea is to have a interface like this:
Screenshot 2023-08-02 at 16 37 53

@freitasfa-bahag
Copy link
Author

I saw there is an similar issue

@ComfortablyCoding
Copy link
Contributor

Interesting, I was not aware of this injection zone. I will have a look, if its allows for opting in from the configure the view I do not see why not.

@freitasfa-bahag
Copy link
Author

freitasfa-bahag commented Aug 3, 2023

Cool! Just to let you know, I've tried to add this hook on ./admin/src/index.js but it didn't work out. I'm aware that the key that brings the value from the plugin is name, so I'm not sure if should be publisher in that case or something else.

This code

import React from 'react';
import { prefixPluginTranslations } from '@strapi/helper-plugin';
import pluginPkg from 'strapi-plugin-publisher/package.json';
import { pluginId } from 'strapi-plugin-publisher/admin/src/pluginId';
import Initializer from 'strapi-plugin-publisher/admin/src/components/Initializer';
import { ActionLayout } from 'strapi-plugin-publisher/admin/src/components/ActionLayout';

const name = pluginPkg.strapi.name;

export default {
	register(app) {
		app.registerPlugin({
			id: pluginId,
			initializer: Initializer,
			isReady: false,
			name,
		});
	},

	bootstrap(app) {
		app.injectContentManagerComponent('editView', 'informations', {
			name: name,
			Component: ActionLayout,
		});

        app.registerHook(
            'Admin/CM/pages/ListView/inject-column-in-table',
            ({ displayedHeaders, layout }) => {
              return {
                layout,
                displayedHeaders: [
                  ...displayedHeaders,
                  {
                    key: '__publisher_key__',
                    fieldSchema: { type: 'string' },
                    metadatas: {
                        label: 'Publisher',
                        searchable: false,
                        sortable: false,
                    },
                    name: 'publisher',
                    cellFormatter: props => <p>{props}</p>
                  },
                ],
              };
            }
          );
	},

	async registerTrads({ locales }) {
		const importedTrads = [];

		for (const locale of locales) {
			try {
				const data = await import(`./translations/${locale}.json`);
				importedTrads.push({
					data: prefixPluginTranslations(data, pluginId),
					locale,
				});
			} catch (error) {
				importedTrads.push({ data: {}, locale });
			}
		}

		return importedTrads;
	},
};

Results:
Screenshot 2023-08-03 at 08 54 24

If I can help somehow, please let me know :) For now, I just don't know what else to do haha

@ComfortablyCoding
Copy link
Contributor

ComfortablyCoding commented Aug 4, 2023

Awesome! It still might not be possible as i18n injects the data into the content type itself as opposed to the way I am doing it which is a seperate content type.

I will try and have a look over the weekend to see if it's possible.

@freitasfa-bahag
Copy link
Author

Hey! Any updates on this? :)

@ComfortablyCoding
Copy link
Contributor

Unfortunately as the info is not actually on the schema aside from fetching it for each row in the table (which is not efficient) I do not see a way to do this.

So at this time it is not possible to do this. At some point I will probably migrate to using the injected fields like the i18n plugin does which will suport this behaviour but no ETA on that at this point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants