@@ -21,74 +21,65 @@ type Props = {
2121}
2222
2323const ActionManagerComponent = ( { document, entity, locale } : Props ) => {
24- const { formatMessage } = useIntl ( ) ;
25- const [ showActions , setShowActions ] = useState ( false ) ;
26- const { getSettings } = useSettings ( ) ;
27- const { isLoading, data, isRefetching } = getSettings ( ) ;
28-
29- useEffect ( ( ) => {
30- if ( ! isLoading && ! isRefetching ) {
31- if ( ! data . contentTypes ?. length || data . contentTypes ?. find ( ( uid ) => uid === entity . slug ) ) {
32- setShowActions ( true ) ;
33- }
34- }
35- } , [ isLoading , isRefetching ] ) ;
36-
37- if ( ! showActions ) {
38- return null ;
39- }
40-
41- return (
42- < >
43- { actionModes . map ( ( mode , index ) => (
44- < div className = "actionButton" key = { index } >
45- < Action
46- mode = { mode }
47- key = { mode + index }
48- documentId = { document . documentId }
49- entitySlug = { entity . model }
50- locale = { locale }
51- />
52- </ div >
53- ) ) }
54- < style >
55- { `
56- .actionButton {
57- width: 100%;
58- }
59- ` }
60- </ style >
61- </ >
62- ) ;
24+ return (
25+ < >
26+ { actionModes . map ( ( mode , index ) => (
27+ < div className = "actionButton" key = { index } >
28+ < Action
29+ mode = { mode }
30+ key = { mode + index }
31+ documentId = { document . documentId }
32+ entitySlug = { entity . model }
33+ locale = { locale }
34+ />
35+ </ div >
36+ ) ) }
37+ < style >
38+ { `
39+ .actionButton {
40+ width: 100%;
41+ }
42+ ` }
43+ </ style >
44+ </ >
45+ ) ;
6346} ;
6447
6548const ActionManager : PanelComponent = ( ) => {
66- const entity = useContentManagerContext ( ) ;
67- const location = useLocation ( ) ;
68- const params = new URLSearchParams ( location . search ) ;
69- const currentLocale = params . get ( 'plugins[i18n][locale]' ) ;
49+ const entity = useContentManagerContext ( ) ;
50+ const location = useLocation ( ) ;
51+ const params = new URLSearchParams ( location . search ) ;
52+ const currentLocale = params . get ( 'plugins[i18n][locale]' ) ;
53+
54+ const { document } = useDocument ( {
55+ documentId : entity ?. id ,
56+ model : entity ?. model ,
57+ collectionType : entity ?. collectionType ,
58+ params : {
59+ locale : currentLocale ,
60+ } ,
61+ } ) ;
62+
63+ const { getSettings } = useSettings ( ) ;
64+ const { isLoading, data, isRefetching } = getSettings ( ) ;
7065
71- const { document } = useDocument ( {
72- documentId : entity ?. id ,
73- model : entity ?. model ,
74- collectionType : entity ?. collectionType ,
75- params : {
76- locale : currentLocale ,
77- }
78- } ) ;
66+ if ( ! entity . hasDraftAndPublish || entity . isCreatingEntry ) return null ;
67+ if ( ! document || ! entity ) return null ;
7968
80- if ( ! entity . hasDraftAndPublish || entity . isCreatingEntry ) {
81- return null ;
82- }
69+ const isEnabled =
70+ ! isLoading &&
71+ ! isRefetching &&
72+ (
73+ ! data . contentTypes ?. length ||
74+ data . contentTypes ?. includes ( entity . slug )
75+ ) ;
8376
84- if ( ! document || ! entity ) {
85- return null ;
86- }
77+ if ( ! isEnabled ) return null ;
8778
88- return {
89- title : "Publisher" ,
90- content : < ActionManagerComponent document = { document } entity = { entity } locale = { currentLocale } /> ,
91- }
79+ return {
80+ title : "Publisher" ,
81+ content : < ActionManagerComponent document = { document } entity = { entity } locale = { currentLocale } /> ,
82+ } ;
9283} ;
9384
94- export default ActionManager ;
85+ export default ActionManager ;
0 commit comments