@wordpress/editor 14.0.3 → 14.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -12
- package/README.md +189 -24
- package/build/components/create-template-part-modal/index.js +2 -0
- package/build/components/create-template-part-modal/index.js.map +1 -1
- package/build/components/document-bar/index.js +11 -4
- package/build/components/document-bar/index.js.map +1 -1
- package/build/components/editor/index.js +18 -24
- package/build/components/editor/index.js.map +1 -1
- package/build/components/editor-interface/index.js +3 -1
- package/build/components/editor-interface/index.js.map +1 -1
- package/build/components/entities-saved-states/hooks/use-is-dirty.js +9 -0
- package/build/components/entities-saved-states/hooks/use-is-dirty.js.map +1 -1
- package/build/components/entities-saved-states/index.js +28 -0
- package/build/components/entities-saved-states/index.js.map +1 -1
- package/build/components/global-keyboard-shortcuts/index.js +1 -1
- package/build/components/global-keyboard-shortcuts/index.js.map +1 -1
- package/build/components/header/index.js +6 -2
- package/build/components/header/index.js.map +1 -1
- package/build/components/index.js +15 -0
- package/build/components/index.js.map +1 -1
- package/build/components/post-actions/actions.js +286 -263
- package/build/components/post-actions/actions.js.map +1 -1
- package/build/components/post-actions/index.js +2 -0
- package/build/components/post-actions/index.js.map +1 -1
- package/build/components/post-publish-button/index.js +4 -0
- package/build/components/post-publish-button/index.js.map +1 -1
- package/build/components/post-publish-button/label.js +5 -0
- package/build/components/post-publish-button/label.js.map +1 -1
- package/build/components/post-publish-panel/index.js +4 -0
- package/build/components/post-publish-panel/index.js.map +1 -1
- package/build/components/post-slug/check.js +8 -1
- package/build/components/post-slug/check.js.map +1 -1
- package/build/components/post-slug/index.js +6 -0
- package/build/components/post-slug/index.js.map +1 -1
- package/build/components/post-status/index.js +2 -1
- package/build/components/post-status/index.js.map +1 -1
- package/build/components/post-sticky/check.js +8 -0
- package/build/components/post-sticky/check.js.map +1 -1
- package/build/components/post-sticky/index.js +13 -13
- package/build/components/post-sticky/index.js.map +1 -1
- package/build/components/post-switch-to-draft-button/index.js +11 -2
- package/build/components/post-switch-to-draft-button/index.js.map +1 -1
- package/build/components/post-sync-status/index.js +5 -1
- package/build/components/post-sync-status/index.js.map +1 -1
- package/build/components/post-taxonomies/check.js +8 -0
- package/build/components/post-taxonomies/check.js.map +1 -1
- package/build/components/post-taxonomies/flat-term-selector.js +14 -2
- package/build/components/post-taxonomies/flat-term-selector.js.map +1 -1
- package/build/components/post-taxonomies/index.js +9 -0
- package/build/components/post-taxonomies/index.js.map +1 -1
- package/build/components/post-taxonomies/panel.js +10 -0
- package/build/components/post-taxonomies/panel.js.map +1 -1
- package/build/components/post-template/create-new-template-modal.js +2 -0
- package/build/components/post-template/create-new-template-modal.js.map +1 -1
- package/build/components/post-title/index.js +4 -8
- package/build/components/post-title/index.js.map +1 -1
- package/build/components/post-title/post-title-raw.js +3 -7
- package/build/components/post-title/post-title-raw.js.map +1 -1
- package/build/components/post-trash/check.js +8 -0
- package/build/components/post-trash/check.js.map +1 -1
- package/build/components/post-trash/index.js +5 -1
- package/build/components/post-trash/index.js.map +1 -1
- package/build/components/provider/index.js +18 -15
- package/build/components/provider/index.js.map +1 -1
- package/build/components/sidebar/index.js +2 -1
- package/build/components/sidebar/index.js.map +1 -1
- package/build/components/sidebar/post-summary.js +2 -3
- package/build/components/sidebar/post-summary.js.map +1 -1
- package/build/components/table-of-contents/index.js +11 -0
- package/build/components/table-of-contents/index.js.map +1 -1
- package/build/components/template-part-content-panel/index.js +70 -0
- package/build/components/template-part-content-panel/index.js.map +1 -0
- package/build/components/template-part-menu-items/convert-to-regular.js +38 -0
- package/build/components/template-part-menu-items/convert-to-regular.js.map +1 -0
- package/build/components/template-part-menu-items/convert-to-template-part.js +77 -0
- package/build/components/template-part-menu-items/convert-to-template-part.js.map +1 -0
- package/build/components/template-part-menu-items/index.js +67 -0
- package/build/components/template-part-menu-items/index.js.map +1 -0
- package/build/components/template-part-menu-items/index.native.js +10 -0
- package/build/components/template-part-menu-items/index.native.js.map +1 -0
- package/build/components/theme-support-check/index.js +9 -0
- package/build/components/theme-support-check/index.js.map +1 -1
- package/build/components/time-to-read/index.js +6 -0
- package/build/components/time-to-read/index.js.map +1 -1
- package/build/components/word-count/index.js +5 -1
- package/build/components/word-count/index.js.map +1 -1
- package/build/dataviews/api.js +61 -0
- package/build/dataviews/api.js.map +1 -0
- package/build/dataviews/store/private-actions.js +28 -0
- package/build/dataviews/store/private-actions.js.map +1 -0
- package/build/dataviews/store/private-selectors.js +20 -0
- package/build/dataviews/store/private-selectors.js.map +1 -0
- package/build/dataviews/store/reducer.js +36 -0
- package/build/dataviews/store/reducer.js.map +1 -0
- package/build/index.js +12 -0
- package/build/index.js.map +1 -1
- package/build/private-apis.js +0 -6
- package/build/private-apis.js.map +1 -1
- package/build/private-apis.native.js +0 -2
- package/build/private-apis.native.js.map +1 -1
- package/build/store/private-actions.js +21 -0
- package/build/store/private-actions.js.map +1 -1
- package/build/store/private-selectors.js +5 -0
- package/build/store/private-selectors.js.map +1 -1
- package/build/store/reducer.js +4 -1
- package/build/store/reducer.js.map +1 -1
- package/build-module/components/create-template-part-modal/index.js +2 -0
- package/build-module/components/create-template-part-modal/index.js.map +1 -1
- package/build-module/components/document-bar/index.js +11 -4
- package/build-module/components/document-bar/index.js.map +1 -1
- package/build-module/components/editor/index.js +19 -24
- package/build-module/components/editor/index.js.map +1 -1
- package/build-module/components/editor-interface/index.js +3 -1
- package/build-module/components/editor-interface/index.js.map +1 -1
- package/build-module/components/entities-saved-states/hooks/use-is-dirty.js +10 -0
- package/build-module/components/entities-saved-states/hooks/use-is-dirty.js.map +1 -1
- package/build-module/components/entities-saved-states/index.js +28 -0
- package/build-module/components/entities-saved-states/index.js.map +1 -1
- package/build-module/components/global-keyboard-shortcuts/index.js +1 -1
- package/build-module/components/global-keyboard-shortcuts/index.js.map +1 -1
- package/build-module/components/header/index.js +6 -2
- package/build-module/components/header/index.js.map +1 -1
- package/build-module/components/index.js +16 -0
- package/build-module/components/index.js.map +1 -1
- package/build-module/components/post-actions/actions.js +286 -263
- package/build-module/components/post-actions/actions.js.map +1 -1
- package/build-module/components/post-actions/index.js +2 -0
- package/build-module/components/post-actions/index.js.map +1 -1
- package/build-module/components/post-publish-button/index.js +4 -0
- package/build-module/components/post-publish-button/index.js.map +1 -1
- package/build-module/components/post-publish-button/label.js +6 -0
- package/build-module/components/post-publish-button/label.js.map +1 -1
- package/build-module/components/post-publish-panel/index.js +4 -0
- package/build-module/components/post-publish-panel/index.js.map +1 -1
- package/build-module/components/post-slug/check.js +9 -0
- package/build-module/components/post-slug/check.js.map +1 -1
- package/build-module/components/post-slug/index.js +6 -0
- package/build-module/components/post-slug/index.js.map +1 -1
- package/build-module/components/post-status/index.js +2 -1
- package/build-module/components/post-status/index.js.map +1 -1
- package/build-module/components/post-sticky/check.js +9 -0
- package/build-module/components/post-sticky/check.js.map +1 -1
- package/build-module/components/post-sticky/index.js +15 -13
- package/build-module/components/post-sticky/index.js.map +1 -1
- package/build-module/components/post-switch-to-draft-button/index.js +10 -1
- package/build-module/components/post-switch-to-draft-button/index.js.map +1 -1
- package/build-module/components/post-sync-status/index.js +6 -0
- package/build-module/components/post-sync-status/index.js.map +1 -1
- package/build-module/components/post-taxonomies/check.js +9 -0
- package/build-module/components/post-taxonomies/check.js.map +1 -1
- package/build-module/components/post-taxonomies/flat-term-selector.js +14 -2
- package/build-module/components/post-taxonomies/flat-term-selector.js.map +1 -1
- package/build-module/components/post-taxonomies/index.js +9 -0
- package/build-module/components/post-taxonomies/index.js.map +1 -1
- package/build-module/components/post-taxonomies/panel.js +10 -0
- package/build-module/components/post-taxonomies/panel.js.map +1 -1
- package/build-module/components/post-template/create-new-template-modal.js +2 -0
- package/build-module/components/post-template/create-new-template-modal.js.map +1 -1
- package/build-module/components/post-title/index.js +4 -8
- package/build-module/components/post-title/index.js.map +1 -1
- package/build-module/components/post-title/post-title-raw.js +3 -7
- package/build-module/components/post-title/post-title-raw.js.map +1 -1
- package/build-module/components/post-trash/check.js +9 -0
- package/build-module/components/post-trash/check.js.map +1 -1
- package/build-module/components/post-trash/index.js +6 -0
- package/build-module/components/post-trash/index.js.map +1 -1
- package/build-module/components/provider/index.js +18 -15
- package/build-module/components/provider/index.js.map +1 -1
- package/build-module/components/sidebar/index.js +2 -1
- package/build-module/components/sidebar/index.js.map +1 -1
- package/build-module/components/sidebar/post-summary.js +2 -3
- package/build-module/components/sidebar/post-summary.js.map +1 -1
- package/build-module/components/table-of-contents/index.js +11 -0
- package/build-module/components/table-of-contents/index.js.map +1 -1
- package/build-module/components/template-part-content-panel/index.js +63 -0
- package/build-module/components/template-part-content-panel/index.js.map +1 -0
- package/build-module/components/template-part-menu-items/convert-to-regular.js +31 -0
- package/build-module/components/template-part-menu-items/convert-to-regular.js.map +1 -0
- package/build-module/components/template-part-menu-items/convert-to-template-part.js +71 -0
- package/build-module/components/template-part-menu-items/convert-to-template-part.js.map +1 -0
- package/build-module/components/template-part-menu-items/index.js +59 -0
- package/build-module/components/template-part-menu-items/index.js.map +1 -0
- package/build-module/components/template-part-menu-items/index.native.js +4 -0
- package/build-module/components/template-part-menu-items/index.native.js.map +1 -0
- package/build-module/components/theme-support-check/index.js +10 -0
- package/build-module/components/theme-support-check/index.js.map +1 -1
- package/build-module/components/time-to-read/index.js +6 -0
- package/build-module/components/time-to-read/index.js.map +1 -1
- package/build-module/components/word-count/index.js +6 -0
- package/build-module/components/word-count/index.js.map +1 -1
- package/build-module/dataviews/api.js +54 -0
- package/build-module/dataviews/api.js.map +1 -0
- package/build-module/dataviews/store/private-actions.js +21 -0
- package/build-module/dataviews/store/private-actions.js.map +1 -0
- package/build-module/dataviews/store/private-selectors.js +14 -0
- package/build-module/dataviews/store/private-selectors.js.map +1 -0
- package/build-module/dataviews/store/reducer.js +29 -0
- package/build-module/dataviews/store/reducer.js.map +1 -0
- package/build-module/index.js +1 -0
- package/build-module/index.js.map +1 -1
- package/build-module/private-apis.js +0 -6
- package/build-module/private-apis.js.map +1 -1
- package/build-module/private-apis.native.js +0 -2
- package/build-module/private-apis.native.js.map +1 -1
- package/build-module/store/private-actions.js +1 -0
- package/build-module/store/private-actions.js.map +1 -1
- package/build-module/store/private-selectors.js +4 -0
- package/build-module/store/private-selectors.js.map +1 -1
- package/build-module/store/reducer.js +3 -1
- package/build-module/store/reducer.js.map +1 -1
- package/build-style/style-rtl.css +10 -9
- package/build-style/style.css +10 -9
- package/build-types/dataviews/store/private-actions.d.ts +17 -0
- package/build-types/dataviews/store/private-actions.d.ts.map +1 -0
- package/build-types/dataviews/store/private-selectors.d.ts +10 -0
- package/build-types/dataviews/store/private-selectors.d.ts.map +1 -0
- package/build-types/dataviews/store/reducer.d.ts +11 -0
- package/build-types/dataviews/store/reducer.d.ts.map +1 -0
- package/package.json +35 -35
- package/src/components/create-template-part-modal/index.js +2 -0
- package/src/components/create-template-part-modal/style.scss +0 -6
- package/src/components/document-bar/index.js +11 -4
- package/src/components/editor/index.js +23 -28
- package/src/components/editor-interface/index.js +2 -0
- package/src/components/entities-saved-states/hooks/use-is-dirty.js +9 -0
- package/src/components/entities-saved-states/index.js +26 -0
- package/src/components/global-keyboard-shortcuts/index.js +1 -1
- package/src/components/header/index.js +2 -1
- package/src/components/index.js +16 -0
- package/src/components/keyboard-shortcut-help-modal/style.scss +0 -3
- package/src/components/post-actions/actions.js +376 -387
- package/src/components/post-actions/index.js +2 -0
- package/src/components/post-card-panel/style.scss +4 -0
- package/src/components/post-panel-row/style.scss +1 -1
- package/src/components/post-publish-button/index.js +3 -0
- package/src/components/post-publish-button/label.js +5 -0
- package/src/components/post-publish-panel/index.js +3 -0
- package/src/components/post-slug/check.js +8 -0
- package/src/components/post-slug/index.js +5 -0
- package/src/components/post-status/index.js +2 -0
- package/src/components/post-status/style.scss +5 -0
- package/src/components/post-sticky/check.js +8 -0
- package/src/components/post-sticky/index.js +14 -12
- package/src/components/post-sticky/style.scss +3 -2
- package/src/components/post-switch-to-draft-button/index.js +10 -1
- package/src/components/post-sync-status/index.js +5 -0
- package/src/components/post-taxonomies/check.js +8 -0
- package/src/components/post-taxonomies/flat-term-selector.js +13 -2
- package/src/components/post-taxonomies/index.js +8 -0
- package/src/components/post-taxonomies/panel.js +9 -0
- package/src/components/post-template/create-new-template-modal.js +2 -0
- package/src/components/post-title/index.js +2 -5
- package/src/components/post-title/post-title-raw.js +2 -5
- package/src/components/post-trash/check.js +8 -0
- package/src/components/post-trash/index.js +5 -0
- package/src/components/provider/index.js +17 -17
- package/src/components/sidebar/index.js +2 -0
- package/src/components/sidebar/post-summary.js +1 -3
- package/src/components/table-of-contents/index.js +10 -0
- package/src/components/template-part-content-panel/index.js +62 -0
- package/src/components/template-part-menu-items/convert-to-regular.js +32 -0
- package/src/components/template-part-menu-items/convert-to-template-part.js +75 -0
- package/src/components/template-part-menu-items/index.js +59 -0
- package/src/components/template-part-menu-items/index.native.js +3 -0
- package/src/components/theme-support-check/index.js +9 -0
- package/src/components/time-to-read/index.js +5 -0
- package/src/components/word-count/index.js +5 -0
- package/src/dataviews/api.js +55 -0
- package/src/dataviews/store/private-actions.ts +30 -0
- package/src/dataviews/store/private-selectors.ts +15 -0
- package/src/dataviews/store/reducer.ts +44 -0
- package/src/index.js +1 -0
- package/src/private-apis.js +0 -6
- package/src/private-apis.native.js +0 -2
- package/src/store/private-actions.js +1 -0
- package/src/store/private-selectors.js +5 -0
- package/src/store/reducer.js +2 -0
- package/tsconfig.json +36 -0
- package/tsconfig.tsbuildinfo +1 -0
|
@@ -93,12 +93,7 @@ const deletePostAction = {
|
|
|
93
93
|
},
|
|
94
94
|
supportsBulk: true,
|
|
95
95
|
hideModalHeader: true,
|
|
96
|
-
RenderModal: ( {
|
|
97
|
-
items,
|
|
98
|
-
closeModal,
|
|
99
|
-
onActionStart,
|
|
100
|
-
onActionPerformed,
|
|
101
|
-
} ) => {
|
|
96
|
+
RenderModal: ( { items, closeModal, onActionPerformed } ) => {
|
|
102
97
|
const [ isBusy, setIsBusy ] = useState( false );
|
|
103
98
|
const { removeTemplates } = unlock( useDispatch( editorStore ) );
|
|
104
99
|
return (
|
|
@@ -133,9 +128,6 @@ const deletePostAction = {
|
|
|
133
128
|
variant="primary"
|
|
134
129
|
onClick={ async () => {
|
|
135
130
|
setIsBusy( true );
|
|
136
|
-
if ( onActionStart ) {
|
|
137
|
-
onActionStart( items );
|
|
138
|
-
}
|
|
139
131
|
await removeTemplates( items, {
|
|
140
132
|
allowUndo: false,
|
|
141
133
|
} );
|
|
@@ -155,24 +147,6 @@ const deletePostAction = {
|
|
|
155
147
|
},
|
|
156
148
|
};
|
|
157
149
|
|
|
158
|
-
function useCanUserEligibilityCheckPostType( capability, resource, action ) {
|
|
159
|
-
const registry = useRegistry();
|
|
160
|
-
return useMemo(
|
|
161
|
-
() => ( {
|
|
162
|
-
...action,
|
|
163
|
-
isEligible( item ) {
|
|
164
|
-
return (
|
|
165
|
-
action.isEligible( item ) &&
|
|
166
|
-
registry
|
|
167
|
-
.select( coreStore )
|
|
168
|
-
.canUser( capability, resource, item.id )
|
|
169
|
-
);
|
|
170
|
-
},
|
|
171
|
-
} ),
|
|
172
|
-
[ action, registry, capability, resource ]
|
|
173
|
-
);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
150
|
const trashPostAction = {
|
|
177
151
|
id: 'move-to-trash',
|
|
178
152
|
label: __( 'Move to Trash' ),
|
|
@@ -183,12 +157,7 @@ const trashPostAction = {
|
|
|
183
157
|
},
|
|
184
158
|
supportsBulk: true,
|
|
185
159
|
hideModalHeader: true,
|
|
186
|
-
RenderModal: ( {
|
|
187
|
-
items,
|
|
188
|
-
closeModal,
|
|
189
|
-
onActionStart,
|
|
190
|
-
onActionPerformed,
|
|
191
|
-
} ) => {
|
|
160
|
+
RenderModal: ( { items, closeModal, onActionPerformed } ) => {
|
|
192
161
|
const [ isBusy, setIsBusy ] = useState( false );
|
|
193
162
|
const { createSuccessNotice, createErrorNotice } =
|
|
194
163
|
useDispatch( noticesStore );
|
|
@@ -227,9 +196,6 @@ const trashPostAction = {
|
|
|
227
196
|
variant="primary"
|
|
228
197
|
onClick={ async () => {
|
|
229
198
|
setIsBusy( true );
|
|
230
|
-
if ( onActionStart ) {
|
|
231
|
-
onActionStart( items );
|
|
232
|
-
}
|
|
233
199
|
const promiseResult = await Promise.allSettled(
|
|
234
200
|
items.map( ( item ) =>
|
|
235
201
|
deleteEntityRecord(
|
|
@@ -341,6 +307,24 @@ const trashPostAction = {
|
|
|
341
307
|
},
|
|
342
308
|
};
|
|
343
309
|
|
|
310
|
+
function useCanUserEligibilityCheckPostType( capability, resource, action ) {
|
|
311
|
+
const registry = useRegistry();
|
|
312
|
+
return useMemo(
|
|
313
|
+
() => ( {
|
|
314
|
+
...action,
|
|
315
|
+
isEligible( item ) {
|
|
316
|
+
return (
|
|
317
|
+
action.isEligible( item ) &&
|
|
318
|
+
registry
|
|
319
|
+
.select( coreStore )
|
|
320
|
+
.canUser( capability, resource, item.id )
|
|
321
|
+
);
|
|
322
|
+
},
|
|
323
|
+
} ),
|
|
324
|
+
[ action, registry, capability, resource ]
|
|
325
|
+
);
|
|
326
|
+
}
|
|
327
|
+
|
|
344
328
|
function useTrashPostAction( resource ) {
|
|
345
329
|
return useCanUserEligibilityCheckPostType(
|
|
346
330
|
'delete',
|
|
@@ -349,111 +333,97 @@ function useTrashPostAction( resource ) {
|
|
|
349
333
|
);
|
|
350
334
|
}
|
|
351
335
|
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
post.id,
|
|
372
|
-
{ force: true },
|
|
373
|
-
{ throwOnError: true }
|
|
374
|
-
);
|
|
375
|
-
} )
|
|
336
|
+
const permanentlyDeletePostAction = {
|
|
337
|
+
id: 'permanently-delete',
|
|
338
|
+
label: __( 'Permanently delete' ),
|
|
339
|
+
supportsBulk: true,
|
|
340
|
+
isEligible( { status } ) {
|
|
341
|
+
return status === 'trash';
|
|
342
|
+
},
|
|
343
|
+
async callback( posts, { registry } ) {
|
|
344
|
+
const { createSuccessNotice, createErrorNotice } =
|
|
345
|
+
registry.dispatch( noticesStore );
|
|
346
|
+
const { deleteEntityRecord } = registry.dispatch( coreStore );
|
|
347
|
+
const promiseResult = await Promise.allSettled(
|
|
348
|
+
posts.map( ( post ) => {
|
|
349
|
+
return deleteEntityRecord(
|
|
350
|
+
'postType',
|
|
351
|
+
post.type,
|
|
352
|
+
post.id,
|
|
353
|
+
{ force: true },
|
|
354
|
+
{ throwOnError: true }
|
|
376
355
|
);
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
356
|
+
} )
|
|
357
|
+
);
|
|
358
|
+
// If all the promises were fulfilled with success.
|
|
359
|
+
if ( promiseResult.every( ( { status } ) => status === 'fulfilled' ) ) {
|
|
360
|
+
let successMessage;
|
|
361
|
+
if ( promiseResult.length === 1 ) {
|
|
362
|
+
successMessage = sprintf(
|
|
363
|
+
/* translators: The posts's title. */
|
|
364
|
+
__( '"%s" permanently deleted.' ),
|
|
365
|
+
getItemTitle( posts[ 0 ] )
|
|
366
|
+
);
|
|
367
|
+
} else {
|
|
368
|
+
successMessage = __( 'The posts were permanently deleted.' );
|
|
369
|
+
}
|
|
370
|
+
createSuccessNotice( successMessage, {
|
|
371
|
+
type: 'snackbar',
|
|
372
|
+
id: 'permanently-delete-post-action',
|
|
373
|
+
} );
|
|
374
|
+
} else {
|
|
375
|
+
// If there was at lease one failure.
|
|
376
|
+
let errorMessage;
|
|
377
|
+
// If we were trying to permanently delete a single post.
|
|
378
|
+
if ( promiseResult.length === 1 ) {
|
|
379
|
+
if ( promiseResult[ 0 ].reason?.message ) {
|
|
380
|
+
errorMessage = promiseResult[ 0 ].reason.message;
|
|
402
381
|
} else {
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
const errorMessages = new Set();
|
|
417
|
-
const failedPromises = promiseResult.filter(
|
|
418
|
-
( { status } ) => status === 'rejected'
|
|
419
|
-
);
|
|
420
|
-
for ( const failedPromise of failedPromises ) {
|
|
421
|
-
if ( failedPromise.reason?.message ) {
|
|
422
|
-
errorMessages.add(
|
|
423
|
-
failedPromise.reason.message
|
|
424
|
-
);
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
if ( errorMessages.size === 0 ) {
|
|
428
|
-
errorMessage = __(
|
|
429
|
-
'An error occurred while permanently deleting the posts.'
|
|
430
|
-
);
|
|
431
|
-
} else if ( errorMessages.size === 1 ) {
|
|
432
|
-
errorMessage = sprintf(
|
|
433
|
-
/* translators: %s: an error message */
|
|
434
|
-
__(
|
|
435
|
-
'An error occurred while permanently deleting the posts: %s'
|
|
436
|
-
),
|
|
437
|
-
[ ...errorMessages ][ 0 ]
|
|
438
|
-
);
|
|
439
|
-
} else {
|
|
440
|
-
errorMessage = sprintf(
|
|
441
|
-
/* translators: %s: a list of comma separated error messages */
|
|
442
|
-
__(
|
|
443
|
-
'Some errors occurred while permanently deleting the posts: %s'
|
|
444
|
-
),
|
|
445
|
-
[ ...errorMessages ].join( ',' )
|
|
446
|
-
);
|
|
447
|
-
}
|
|
382
|
+
errorMessage = __(
|
|
383
|
+
'An error occurred while permanently deleting the post.'
|
|
384
|
+
);
|
|
385
|
+
}
|
|
386
|
+
// If we were trying to permanently delete multiple posts
|
|
387
|
+
} else {
|
|
388
|
+
const errorMessages = new Set();
|
|
389
|
+
const failedPromises = promiseResult.filter(
|
|
390
|
+
( { status } ) => status === 'rejected'
|
|
391
|
+
);
|
|
392
|
+
for ( const failedPromise of failedPromises ) {
|
|
393
|
+
if ( failedPromise.reason?.message ) {
|
|
394
|
+
errorMessages.add( failedPromise.reason.message );
|
|
448
395
|
}
|
|
449
|
-
createErrorNotice( errorMessage, {
|
|
450
|
-
type: 'snackbar',
|
|
451
|
-
} );
|
|
452
396
|
}
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
397
|
+
if ( errorMessages.size === 0 ) {
|
|
398
|
+
errorMessage = __(
|
|
399
|
+
'An error occurred while permanently deleting the posts.'
|
|
400
|
+
);
|
|
401
|
+
} else if ( errorMessages.size === 1 ) {
|
|
402
|
+
errorMessage = sprintf(
|
|
403
|
+
/* translators: %s: an error message */
|
|
404
|
+
__(
|
|
405
|
+
'An error occurred while permanently deleting the posts: %s'
|
|
406
|
+
),
|
|
407
|
+
[ ...errorMessages ][ 0 ]
|
|
408
|
+
);
|
|
409
|
+
} else {
|
|
410
|
+
errorMessage = sprintf(
|
|
411
|
+
/* translators: %s: a list of comma separated error messages */
|
|
412
|
+
__(
|
|
413
|
+
'Some errors occurred while permanently deleting the posts: %s'
|
|
414
|
+
),
|
|
415
|
+
[ ...errorMessages ].join( ',' )
|
|
416
|
+
);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
createErrorNotice( errorMessage, {
|
|
420
|
+
type: 'snackbar',
|
|
421
|
+
} );
|
|
422
|
+
}
|
|
423
|
+
},
|
|
424
|
+
};
|
|
425
|
+
|
|
426
|
+
function usePermanentlyDeletePostAction( resource ) {
|
|
457
427
|
return useCanUserEligibilityCheckPostType(
|
|
458
428
|
'delete',
|
|
459
429
|
resource,
|
|
@@ -461,138 +431,114 @@ function usePermanentlyDeletePostAction( resource ) {
|
|
|
461
431
|
);
|
|
462
432
|
}
|
|
463
433
|
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
434
|
+
const restorePostAction = {
|
|
435
|
+
id: 'restore',
|
|
436
|
+
label: __( 'Restore' ),
|
|
437
|
+
isPrimary: true,
|
|
438
|
+
icon: backup,
|
|
439
|
+
supportsBulk: true,
|
|
440
|
+
isEligible( { status } ) {
|
|
441
|
+
return status === 'trash';
|
|
442
|
+
},
|
|
443
|
+
async callback( posts, { registry, onActionPerformed } ) {
|
|
444
|
+
const { createSuccessNotice, createErrorNotice } =
|
|
445
|
+
registry.dispatch( noticesStore );
|
|
446
|
+
const { editEntityRecord, saveEditedEntityRecord } =
|
|
447
|
+
registry.dispatch( coreStore );
|
|
448
|
+
await Promise.allSettled(
|
|
449
|
+
posts.map( ( post ) => {
|
|
450
|
+
return editEntityRecord( 'postType', post.type, post.id, {
|
|
451
|
+
status: 'draft',
|
|
452
|
+
} );
|
|
453
|
+
} )
|
|
454
|
+
);
|
|
455
|
+
const promiseResult = await Promise.allSettled(
|
|
456
|
+
posts.map( ( post ) => {
|
|
457
|
+
return saveEditedEntityRecord( 'postType', post.type, post.id, {
|
|
458
|
+
throwOnError: true,
|
|
459
|
+
} );
|
|
460
|
+
} )
|
|
461
|
+
);
|
|
469
462
|
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
isEligible( { status } ) {
|
|
478
|
-
return status === 'trash';
|
|
479
|
-
},
|
|
480
|
-
async callback( posts, onActionPerformed ) {
|
|
481
|
-
await Promise.allSettled(
|
|
482
|
-
posts.map( ( post ) => {
|
|
483
|
-
return editEntityRecord(
|
|
484
|
-
'postType',
|
|
485
|
-
post.type,
|
|
486
|
-
post.id,
|
|
487
|
-
{
|
|
488
|
-
status: 'draft',
|
|
489
|
-
}
|
|
490
|
-
);
|
|
491
|
-
} )
|
|
463
|
+
if ( promiseResult.every( ( { status } ) => status === 'fulfilled' ) ) {
|
|
464
|
+
let successMessage;
|
|
465
|
+
if ( posts.length === 1 ) {
|
|
466
|
+
successMessage = sprintf(
|
|
467
|
+
/* translators: The number of posts. */
|
|
468
|
+
__( '"%s" has been restored.' ),
|
|
469
|
+
getItemTitle( posts[ 0 ] )
|
|
492
470
|
);
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
post.id,
|
|
499
|
-
{ throwOnError: true }
|
|
500
|
-
);
|
|
501
|
-
} )
|
|
471
|
+
} else if ( posts[ 0 ].type === 'page' ) {
|
|
472
|
+
successMessage = sprintf(
|
|
473
|
+
/* translators: The number of posts. */
|
|
474
|
+
__( '%d pages have been restored.' ),
|
|
475
|
+
posts.length
|
|
502
476
|
);
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
)
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
/* translators: The number of posts. */
|
|
525
|
-
__( '%d posts have been restored.' ),
|
|
526
|
-
posts.length
|
|
527
|
-
);
|
|
528
|
-
}
|
|
529
|
-
createSuccessNotice( successMessage, {
|
|
530
|
-
type: 'snackbar',
|
|
531
|
-
id: 'restore-post-action',
|
|
532
|
-
} );
|
|
533
|
-
if ( onActionPerformed ) {
|
|
534
|
-
onActionPerformed( posts );
|
|
535
|
-
}
|
|
477
|
+
} else {
|
|
478
|
+
successMessage = sprintf(
|
|
479
|
+
/* translators: The number of posts. */
|
|
480
|
+
__( '%d posts have been restored.' ),
|
|
481
|
+
posts.length
|
|
482
|
+
);
|
|
483
|
+
}
|
|
484
|
+
createSuccessNotice( successMessage, {
|
|
485
|
+
type: 'snackbar',
|
|
486
|
+
id: 'restore-post-action',
|
|
487
|
+
} );
|
|
488
|
+
if ( onActionPerformed ) {
|
|
489
|
+
onActionPerformed( posts );
|
|
490
|
+
}
|
|
491
|
+
} else {
|
|
492
|
+
// If there was at lease one failure.
|
|
493
|
+
let errorMessage;
|
|
494
|
+
// If we were trying to move a single post to the trash.
|
|
495
|
+
if ( promiseResult.length === 1 ) {
|
|
496
|
+
if ( promiseResult[ 0 ].reason?.message ) {
|
|
497
|
+
errorMessage = promiseResult[ 0 ].reason.message;
|
|
536
498
|
} else {
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
const errorMessages = new Set();
|
|
551
|
-
const failedPromises = promiseResult.filter(
|
|
552
|
-
( { status } ) => status === 'rejected'
|
|
553
|
-
);
|
|
554
|
-
for ( const failedPromise of failedPromises ) {
|
|
555
|
-
if ( failedPromise.reason?.message ) {
|
|
556
|
-
errorMessages.add(
|
|
557
|
-
failedPromise.reason.message
|
|
558
|
-
);
|
|
559
|
-
}
|
|
560
|
-
}
|
|
561
|
-
if ( errorMessages.size === 0 ) {
|
|
562
|
-
errorMessage = __(
|
|
563
|
-
'An error occurred while restoring the posts.'
|
|
564
|
-
);
|
|
565
|
-
} else if ( errorMessages.size === 1 ) {
|
|
566
|
-
errorMessage = sprintf(
|
|
567
|
-
/* translators: %s: an error message */
|
|
568
|
-
__(
|
|
569
|
-
'An error occurred while restoring the posts: %s'
|
|
570
|
-
),
|
|
571
|
-
[ ...errorMessages ][ 0 ]
|
|
572
|
-
);
|
|
573
|
-
} else {
|
|
574
|
-
errorMessage = sprintf(
|
|
575
|
-
/* translators: %s: a list of comma separated error messages */
|
|
576
|
-
__(
|
|
577
|
-
'Some errors occurred while restoring the posts: %s'
|
|
578
|
-
),
|
|
579
|
-
[ ...errorMessages ].join( ',' )
|
|
580
|
-
);
|
|
581
|
-
}
|
|
499
|
+
errorMessage = __(
|
|
500
|
+
'An error occurred while restoring the post.'
|
|
501
|
+
);
|
|
502
|
+
}
|
|
503
|
+
// If we were trying to move multiple posts to the trash
|
|
504
|
+
} else {
|
|
505
|
+
const errorMessages = new Set();
|
|
506
|
+
const failedPromises = promiseResult.filter(
|
|
507
|
+
( { status } ) => status === 'rejected'
|
|
508
|
+
);
|
|
509
|
+
for ( const failedPromise of failedPromises ) {
|
|
510
|
+
if ( failedPromise.reason?.message ) {
|
|
511
|
+
errorMessages.add( failedPromise.reason.message );
|
|
582
512
|
}
|
|
583
|
-
createErrorNotice( errorMessage, {
|
|
584
|
-
type: 'snackbar',
|
|
585
|
-
} );
|
|
586
513
|
}
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
514
|
+
if ( errorMessages.size === 0 ) {
|
|
515
|
+
errorMessage = __(
|
|
516
|
+
'An error occurred while restoring the posts.'
|
|
517
|
+
);
|
|
518
|
+
} else if ( errorMessages.size === 1 ) {
|
|
519
|
+
errorMessage = sprintf(
|
|
520
|
+
/* translators: %s: an error message */
|
|
521
|
+
__( 'An error occurred while restoring the posts: %s' ),
|
|
522
|
+
[ ...errorMessages ][ 0 ]
|
|
523
|
+
);
|
|
524
|
+
} else {
|
|
525
|
+
errorMessage = sprintf(
|
|
526
|
+
/* translators: %s: a list of comma separated error messages */
|
|
527
|
+
__(
|
|
528
|
+
'Some errors occurred while restoring the posts: %s'
|
|
529
|
+
),
|
|
530
|
+
[ ...errorMessages ].join( ',' )
|
|
531
|
+
);
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
createErrorNotice( errorMessage, {
|
|
535
|
+
type: 'snackbar',
|
|
536
|
+
} );
|
|
537
|
+
}
|
|
538
|
+
},
|
|
539
|
+
};
|
|
540
|
+
|
|
541
|
+
function useRestorePostAction( resource ) {
|
|
596
542
|
return useCanUserEligibilityCheckPostType(
|
|
597
543
|
'update',
|
|
598
544
|
resource,
|
|
@@ -608,7 +554,7 @@ const viewPostAction = {
|
|
|
608
554
|
isEligible( post ) {
|
|
609
555
|
return post.status !== 'trash';
|
|
610
556
|
},
|
|
611
|
-
callback( posts, onActionPerformed ) {
|
|
557
|
+
callback( posts, { onActionPerformed } ) {
|
|
612
558
|
const post = posts[ 0 ];
|
|
613
559
|
window.open( post.link, '_blank' );
|
|
614
560
|
if ( onActionPerformed ) {
|
|
@@ -639,7 +585,7 @@ const postRevisionsAction = {
|
|
|
639
585
|
post?._links?.[ 'version-history' ]?.[ 0 ]?.count ?? 0;
|
|
640
586
|
return lastRevisionId && revisionsCount > 1;
|
|
641
587
|
},
|
|
642
|
-
callback( posts, onActionPerformed ) {
|
|
588
|
+
callback( posts, { onActionPerformed } ) {
|
|
643
589
|
const post = posts[ 0 ];
|
|
644
590
|
const href = addQueryArgs( 'revision.php', {
|
|
645
591
|
revision: post?._links?.[ 'predecessor-version' ]?.[ 0 ]?.id,
|
|
@@ -767,118 +713,162 @@ function useRenamePostAction( resource ) {
|
|
|
767
713
|
);
|
|
768
714
|
}
|
|
769
715
|
|
|
770
|
-
const
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
716
|
+
const useDuplicatePostAction = ( postType ) => {
|
|
717
|
+
const { userCanCreatePost } = useSelect(
|
|
718
|
+
( select ) => {
|
|
719
|
+
const { getPostType, canUser } = select( coreStore );
|
|
720
|
+
const resource = getPostType( postType )?.rest_base || '';
|
|
721
|
+
return {
|
|
722
|
+
userCanCreatePost: canUser( 'create', resource ),
|
|
723
|
+
};
|
|
724
|
+
},
|
|
725
|
+
[ postType ]
|
|
726
|
+
);
|
|
727
|
+
return useMemo(
|
|
728
|
+
() =>
|
|
729
|
+
userCanCreatePost && {
|
|
730
|
+
id: 'duplicate-post',
|
|
731
|
+
label: _x( 'Duplicate', 'action label' ),
|
|
732
|
+
isEligible( { status } ) {
|
|
733
|
+
return status !== 'trash';
|
|
734
|
+
},
|
|
735
|
+
RenderModal: ( { items, closeModal, onActionPerformed } ) => {
|
|
736
|
+
const [ item ] = items;
|
|
737
|
+
const [ isCreatingPage, setIsCreatingPage ] =
|
|
738
|
+
useState( false );
|
|
739
|
+
const [ title, setTitle ] = useState(
|
|
740
|
+
sprintf(
|
|
741
|
+
/* translators: %s: Existing item title */
|
|
742
|
+
__( '%s (Copy)' ),
|
|
743
|
+
getItemTitle( item )
|
|
744
|
+
)
|
|
745
|
+
);
|
|
786
746
|
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
747
|
+
const { saveEntityRecord } = useDispatch( coreStore );
|
|
748
|
+
const { createSuccessNotice, createErrorNotice } =
|
|
749
|
+
useDispatch( noticesStore );
|
|
790
750
|
|
|
791
|
-
|
|
792
|
-
|
|
751
|
+
async function createPage( event ) {
|
|
752
|
+
event.preventDefault();
|
|
793
753
|
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
setIsCreatingPage( true );
|
|
798
|
-
try {
|
|
799
|
-
const newItem = await saveEntityRecord(
|
|
800
|
-
'postType',
|
|
801
|
-
item.type,
|
|
802
|
-
{
|
|
803
|
-
status: 'draft',
|
|
804
|
-
title,
|
|
805
|
-
slug: title || __( 'No title' ),
|
|
806
|
-
author: item.author,
|
|
807
|
-
comment_status: item.comment_status,
|
|
808
|
-
content:
|
|
809
|
-
typeof item.content === 'string'
|
|
810
|
-
? item.content
|
|
811
|
-
: item.content.raw,
|
|
812
|
-
excerpt: item.excerpt.raw,
|
|
813
|
-
meta: item.meta,
|
|
814
|
-
parent: item.parent,
|
|
815
|
-
password: item.password,
|
|
816
|
-
template: item.template,
|
|
817
|
-
format: item.format,
|
|
818
|
-
featured_media: item.featured_media,
|
|
819
|
-
menu_order: item.menu_order,
|
|
820
|
-
ping_status: item.ping_status,
|
|
821
|
-
categories: item.categories,
|
|
822
|
-
tags: item.tags,
|
|
823
|
-
},
|
|
824
|
-
{ throwOnError: true }
|
|
825
|
-
);
|
|
754
|
+
if ( isCreatingPage ) {
|
|
755
|
+
return;
|
|
756
|
+
}
|
|
826
757
|
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
758
|
+
const newItemOject = {
|
|
759
|
+
status: 'draft',
|
|
760
|
+
title,
|
|
761
|
+
slug: title || __( 'No title' ),
|
|
762
|
+
comment_status: item.comment_status,
|
|
763
|
+
content:
|
|
764
|
+
typeof item.content === 'string'
|
|
765
|
+
? item.content
|
|
766
|
+
: item.content.raw,
|
|
767
|
+
excerpt: item.excerpt.raw,
|
|
768
|
+
meta: item.meta,
|
|
769
|
+
parent: item.parent,
|
|
770
|
+
password: item.password,
|
|
771
|
+
template: item.template,
|
|
772
|
+
format: item.format,
|
|
773
|
+
featured_media: item.featured_media,
|
|
774
|
+
menu_order: item.menu_order,
|
|
775
|
+
ping_status: item.ping_status,
|
|
776
|
+
};
|
|
777
|
+
const assignablePropertiesPrefix = 'wp:action-assign-';
|
|
778
|
+
// Get all the properties that the current user is able to assign normally author, categories, tags,
|
|
779
|
+
// and custom taxonomies.
|
|
780
|
+
const assignableProperties = Object.keys(
|
|
781
|
+
item?._links || {}
|
|
782
|
+
)
|
|
783
|
+
.filter( ( property ) =>
|
|
784
|
+
property.startsWith(
|
|
785
|
+
assignablePropertiesPrefix
|
|
786
|
+
)
|
|
787
|
+
)
|
|
788
|
+
.map( ( property ) =>
|
|
789
|
+
property.slice(
|
|
790
|
+
assignablePropertiesPrefix.length
|
|
791
|
+
)
|
|
792
|
+
);
|
|
793
|
+
assignableProperties.forEach( ( property ) => {
|
|
794
|
+
if ( item[ property ] ) {
|
|
795
|
+
newItemOject[ property ] = item[ property ];
|
|
796
|
+
}
|
|
797
|
+
} );
|
|
798
|
+
setIsCreatingPage( true );
|
|
799
|
+
try {
|
|
800
|
+
const newItem = await saveEntityRecord(
|
|
801
|
+
'postType',
|
|
802
|
+
item.type,
|
|
803
|
+
newItemOject,
|
|
804
|
+
{ throwOnError: true }
|
|
805
|
+
);
|
|
838
806
|
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
807
|
+
createSuccessNotice(
|
|
808
|
+
sprintf(
|
|
809
|
+
// translators: %s: Title of the created template e.g: "Category".
|
|
810
|
+
__( '"%s" successfully created.' ),
|
|
811
|
+
decodeEntities(
|
|
812
|
+
newItem.title?.rendered || title
|
|
813
|
+
)
|
|
814
|
+
),
|
|
815
|
+
{
|
|
816
|
+
id: 'duplicate-post-action',
|
|
817
|
+
type: 'snackbar',
|
|
818
|
+
}
|
|
819
|
+
);
|
|
847
820
|
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
821
|
+
if ( onActionPerformed ) {
|
|
822
|
+
onActionPerformed( [ newItem ] );
|
|
823
|
+
}
|
|
824
|
+
} catch ( error ) {
|
|
825
|
+
const errorMessage =
|
|
826
|
+
error.message && error.code !== 'unknown_error'
|
|
827
|
+
? error.message
|
|
828
|
+
: __(
|
|
829
|
+
'An error occurred while duplicating the page.'
|
|
830
|
+
);
|
|
831
|
+
|
|
832
|
+
createErrorNotice( errorMessage, {
|
|
833
|
+
type: 'snackbar',
|
|
834
|
+
} );
|
|
835
|
+
} finally {
|
|
836
|
+
setIsCreatingPage( false );
|
|
837
|
+
closeModal();
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
return (
|
|
841
|
+
<form onSubmit={ createPage }>
|
|
842
|
+
<VStack spacing={ 3 }>
|
|
843
|
+
<TextControl
|
|
844
|
+
label={ __( 'Title' ) }
|
|
845
|
+
onChange={ setTitle }
|
|
846
|
+
placeholder={ __( 'No title' ) }
|
|
847
|
+
value={ title }
|
|
848
|
+
/>
|
|
849
|
+
<HStack spacing={ 2 } justify="end">
|
|
850
|
+
<Button
|
|
851
|
+
variant="tertiary"
|
|
852
|
+
onClick={ closeModal }
|
|
853
|
+
>
|
|
854
|
+
{ __( 'Cancel' ) }
|
|
855
|
+
</Button>
|
|
856
|
+
<Button
|
|
857
|
+
variant="primary"
|
|
858
|
+
type="submit"
|
|
859
|
+
isBusy={ isCreatingPage }
|
|
860
|
+
aria-disabled={ isCreatingPage }
|
|
861
|
+
>
|
|
862
|
+
{ _x( 'Duplicate', 'action label' ) }
|
|
863
|
+
</Button>
|
|
864
|
+
</HStack>
|
|
865
|
+
</VStack>
|
|
866
|
+
</form>
|
|
867
|
+
);
|
|
868
|
+
},
|
|
869
|
+
},
|
|
870
|
+
[ userCanCreatePost ]
|
|
871
|
+
);
|
|
882
872
|
};
|
|
883
873
|
|
|
884
874
|
const isTemplatePartRevertable = ( item ) => {
|
|
@@ -900,12 +890,7 @@ const resetTemplateAction = {
|
|
|
900
890
|
icon: backup,
|
|
901
891
|
supportsBulk: true,
|
|
902
892
|
hideModalHeader: true,
|
|
903
|
-
RenderModal: ( {
|
|
904
|
-
items,
|
|
905
|
-
closeModal,
|
|
906
|
-
onActionStart,
|
|
907
|
-
onActionPerformed,
|
|
908
|
-
} ) => {
|
|
893
|
+
RenderModal: ( { items, closeModal, onActionPerformed } ) => {
|
|
909
894
|
const [ isBusy, setIsBusy ] = useState( false );
|
|
910
895
|
const { revertTemplate, removeTemplates } = unlock(
|
|
911
896
|
useDispatch( editorStore )
|
|
@@ -995,9 +980,6 @@ const resetTemplateAction = {
|
|
|
995
980
|
variant="primary"
|
|
996
981
|
onClick={ async () => {
|
|
997
982
|
setIsBusy( true );
|
|
998
|
-
if ( onActionStart ) {
|
|
999
|
-
onActionStart( items );
|
|
1000
|
-
}
|
|
1001
983
|
await onConfirm( items );
|
|
1002
984
|
onActionPerformed?.( items );
|
|
1003
985
|
setIsBusy( false );
|
|
@@ -1076,26 +1058,30 @@ export const duplicateTemplatePartAction = {
|
|
|
1076
1058
|
|
|
1077
1059
|
export function usePostActions( { postType, onActionPerformed, context } ) {
|
|
1078
1060
|
const {
|
|
1061
|
+
defaultActions,
|
|
1079
1062
|
postTypeObject,
|
|
1063
|
+
userCanCreatePostType,
|
|
1080
1064
|
resource,
|
|
1081
1065
|
cachedCanUserResolvers,
|
|
1082
|
-
userCanCreatePostType,
|
|
1083
1066
|
} = useSelect(
|
|
1084
1067
|
( select ) => {
|
|
1085
|
-
const { getPostType,
|
|
1068
|
+
const { getPostType, canUser, getCachedResolvers } =
|
|
1086
1069
|
select( coreStore );
|
|
1070
|
+
const { getEntityActions } = unlock( select( editorStore ) );
|
|
1087
1071
|
const _postTypeObject = getPostType( postType );
|
|
1088
1072
|
const _resource = _postTypeObject?.rest_base || '';
|
|
1089
1073
|
return {
|
|
1090
1074
|
postTypeObject: _postTypeObject,
|
|
1075
|
+
defaultActions: getEntityActions( 'postType', postType ),
|
|
1076
|
+
userCanCreatePostType: canUser( 'create', _resource ),
|
|
1091
1077
|
resource: _resource,
|
|
1092
1078
|
cachedCanUserResolvers: getCachedResolvers()?.canUser,
|
|
1093
|
-
userCanCreatePostType: canUser( 'create', _resource ),
|
|
1094
1079
|
};
|
|
1095
1080
|
},
|
|
1096
1081
|
[ postType ]
|
|
1097
1082
|
);
|
|
1098
1083
|
|
|
1084
|
+
const duplicatePostAction = useDuplicatePostAction( postType );
|
|
1099
1085
|
const trashPostActionForPostType = useTrashPostAction( resource );
|
|
1100
1086
|
const permanentlyDeletePostActionForPostType =
|
|
1101
1087
|
usePermanentlyDeletePostAction( resource );
|
|
@@ -1136,6 +1122,7 @@ export function usePostActions( { postType, onActionPerformed, context } ) {
|
|
|
1136
1122
|
: trashPostActionForPostType,
|
|
1137
1123
|
! isTemplateOrTemplatePart &&
|
|
1138
1124
|
permanentlyDeletePostActionForPostType,
|
|
1125
|
+
...defaultActions,
|
|
1139
1126
|
].filter( Boolean );
|
|
1140
1127
|
// Filter actions based on provided context. If not provided
|
|
1141
1128
|
// all actions are returned. We'll have a single entry for getting the actions
|
|
@@ -1156,7 +1143,7 @@ export function usePostActions( { postType, onActionPerformed, context } ) {
|
|
|
1156
1143
|
const existingCallback = actions[ i ].callback;
|
|
1157
1144
|
actions[ i ] = {
|
|
1158
1145
|
...actions[ i ],
|
|
1159
|
-
callback: ( items, _onActionPerformed ) => {
|
|
1146
|
+
callback: ( items, { _onActionPerformed } ) => {
|
|
1160
1147
|
existingCallback( items, ( _items ) => {
|
|
1161
1148
|
if ( _onActionPerformed ) {
|
|
1162
1149
|
_onActionPerformed( _items );
|
|
@@ -1196,19 +1183,21 @@ export function usePostActions( { postType, onActionPerformed, context } ) {
|
|
|
1196
1183
|
// when user capabilities are resolved. This makes sure the isEligible functions of actions dependent on capabilities are re-evaluated.
|
|
1197
1184
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1198
1185
|
}, [
|
|
1186
|
+
defaultActions,
|
|
1187
|
+
userCanCreatePostType,
|
|
1199
1188
|
isTemplateOrTemplatePart,
|
|
1200
1189
|
isPattern,
|
|
1201
1190
|
postTypeObject?.viewable,
|
|
1202
|
-
|
|
1191
|
+
duplicatePostAction,
|
|
1192
|
+
trashPostActionForPostType,
|
|
1203
1193
|
restorePostActionForPostType,
|
|
1204
1194
|
renamePostActionForPostType,
|
|
1205
|
-
|
|
1195
|
+
permanentlyDeletePostActionForPostType,
|
|
1206
1196
|
onActionPerformed,
|
|
1207
1197
|
isLoaded,
|
|
1208
1198
|
supportsRevisions,
|
|
1209
1199
|
supportsTitle,
|
|
1210
1200
|
context,
|
|
1211
|
-
userCanCreatePostType,
|
|
1212
1201
|
cachedCanUserResolvers,
|
|
1213
1202
|
] );
|
|
1214
1203
|
}
|