@wordpress/edit-site 6.4.0 → 6.5.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 +2 -0
- package/build/components/add-new-pattern/index.js +6 -1
- package/build/components/add-new-pattern/index.js.map +1 -1
- package/build/components/add-new-post/index.js +2 -1
- package/build/components/add-new-post/index.js.map +1 -1
- package/build/components/add-new-template/utils.js +2 -2
- package/build/components/add-new-template/utils.js.map +1 -1
- package/build/components/editor/index.js +71 -20
- package/build/components/editor/index.js.map +1 -1
- package/build/components/global-styles/font-families.js +3 -4
- package/build/components/global-styles/font-families.js.map +1 -1
- package/build/components/global-styles/font-library-modal/context.js +0 -5
- package/build/components/global-styles/font-library-modal/context.js.map +1 -1
- package/build/components/global-styles/font-library-modal/font-collection.js +25 -5
- package/build/components/global-styles/font-library-modal/font-collection.js.map +1 -1
- package/build/components/global-styles/font-library-modal/index.js +1 -8
- package/build/components/global-styles/font-library-modal/index.js.map +1 -1
- package/build/components/global-styles/font-library-modal/installed-fonts.js +21 -6
- package/build/components/global-styles/font-library-modal/installed-fonts.js.map +1 -1
- package/build/components/global-styles/font-library-modal/upload-fonts.js +2 -3
- package/build/components/global-styles/font-library-modal/upload-fonts.js.map +1 -1
- package/build/components/global-styles/screen-typeset.js +40 -0
- package/build/components/global-styles/screen-typeset.js.map +1 -0
- package/build/components/global-styles/screen-typography-element.js +14 -0
- package/build/components/global-styles/screen-typography-element.js.map +1 -1
- package/build/components/global-styles/screen-typography.js +4 -6
- package/build/components/global-styles/screen-typography.js.map +1 -1
- package/build/components/global-styles/shadows-edit-panel.js +50 -59
- package/build/components/global-styles/shadows-edit-panel.js.map +1 -1
- package/build/components/global-styles/typeset-button.js +97 -0
- package/build/components/global-styles/typeset-button.js.map +1 -0
- package/build/components/global-styles/typeset.js +80 -0
- package/build/components/global-styles/typeset.js.map +1 -0
- package/build/components/global-styles/ui.js +4 -0
- package/build/components/global-styles/ui.js.map +1 -1
- package/build/components/global-styles/utils.js +10 -1
- package/build/components/global-styles/utils.js.map +1 -1
- package/build/components/page-patterns/fields.js +230 -0
- package/build/components/page-patterns/fields.js.map +1 -0
- package/build/components/page-patterns/index.js +8 -226
- package/build/components/page-patterns/index.js.map +1 -1
- package/build/components/page-patterns/use-patterns.js +26 -1
- package/build/components/page-patterns/use-patterns.js.map +1 -1
- package/build/components/page-templates/fields.js +169 -0
- package/build/components/page-templates/fields.js.map +1 -0
- package/build/components/page-templates/index.js +10 -177
- package/build/components/page-templates/index.js.map +1 -1
- package/build/components/post-edit/index.js +18 -6
- package/build/components/post-edit/index.js.map +1 -1
- package/build/components/post-fields/index.js +19 -15
- package/build/components/post-fields/index.js.map +1 -1
- package/build/components/post-list/index.js +125 -67
- package/build/components/post-list/index.js.map +1 -1
- package/build/components/sidebar-dataviews/add-new-view.js +2 -2
- package/build/components/sidebar-dataviews/add-new-view.js.map +1 -1
- package/build/components/sidebar-dataviews/dataview-item.js +2 -3
- package/build/components/sidebar-dataviews/dataview-item.js.map +1 -1
- package/build/components/sidebar-dataviews/default-views.js +81 -81
- package/build/components/sidebar-dataviews/default-views.js.map +1 -1
- package/build/components/sidebar-dataviews/index.js +3 -42
- package/build/components/sidebar-dataviews/index.js.map +1 -1
- package/build/components/site-hub/index.js +6 -3
- package/build/components/site-hub/index.js.map +1 -1
- package/build/components/style-book/index.js +22 -25
- package/build/components/style-book/index.js.map +1 -1
- package/build/components/sync-state-with-url/use-init-edited-entity-from-url.js +5 -0
- package/build/components/sync-state-with-url/use-init-edited-entity-from-url.js.map +1 -1
- package/build/hooks/push-changes-to-global-styles/index.js +2 -3
- package/build/hooks/push-changes-to-global-styles/index.js.map +1 -1
- package/build/hooks/use-theme-style-variations/use-theme-style-variations-by-property.js +2 -4
- package/build/hooks/use-theme-style-variations/use-theme-style-variations-by-property.js.map +1 -1
- package/build/index.js +0 -2
- package/build/index.js.map +1 -1
- package/build-module/components/add-new-pattern/index.js +6 -1
- package/build-module/components/add-new-pattern/index.js.map +1 -1
- package/build-module/components/add-new-post/index.js +2 -1
- package/build-module/components/add-new-post/index.js.map +1 -1
- package/build-module/components/add-new-template/utils.js +2 -2
- package/build-module/components/add-new-template/utils.js.map +1 -1
- package/build-module/components/editor/index.js +73 -22
- package/build-module/components/editor/index.js.map +1 -1
- package/build-module/components/global-styles/font-families.js +3 -4
- package/build-module/components/global-styles/font-families.js.map +1 -1
- package/build-module/components/global-styles/font-library-modal/context.js +0 -5
- package/build-module/components/global-styles/font-library-modal/context.js.map +1 -1
- package/build-module/components/global-styles/font-library-modal/font-collection.js +26 -6
- package/build-module/components/global-styles/font-library-modal/font-collection.js.map +1 -1
- package/build-module/components/global-styles/font-library-modal/index.js +1 -8
- package/build-module/components/global-styles/font-library-modal/index.js.map +1 -1
- package/build-module/components/global-styles/font-library-modal/installed-fonts.js +21 -6
- package/build-module/components/global-styles/font-library-modal/installed-fonts.js.map +1 -1
- package/build-module/components/global-styles/font-library-modal/upload-fonts.js +2 -3
- package/build-module/components/global-styles/font-library-modal/upload-fonts.js.map +1 -1
- package/build-module/components/global-styles/screen-typeset.js +34 -0
- package/build-module/components/global-styles/screen-typeset.js.map +1 -0
- package/build-module/components/global-styles/screen-typography-element.js +14 -0
- package/build-module/components/global-styles/screen-typography-element.js.map +1 -1
- package/build-module/components/global-styles/screen-typography.js +4 -6
- package/build-module/components/global-styles/screen-typography.js.map +1 -1
- package/build-module/components/global-styles/shadows-edit-panel.js +51 -60
- package/build-module/components/global-styles/shadows-edit-panel.js.map +1 -1
- package/build-module/components/global-styles/typeset-button.js +89 -0
- package/build-module/components/global-styles/typeset-button.js.map +1 -0
- package/build-module/components/global-styles/typeset.js +71 -0
- package/build-module/components/global-styles/typeset.js.map +1 -0
- package/build-module/components/global-styles/ui.js +4 -0
- package/build-module/components/global-styles/ui.js.map +1 -1
- package/build-module/components/global-styles/utils.js +10 -1
- package/build-module/components/global-styles/utils.js.map +1 -1
- package/build-module/components/page-patterns/fields.js +223 -0
- package/build-module/components/page-patterns/fields.js.map +1 -0
- package/build-module/components/page-patterns/index.js +11 -229
- package/build-module/components/page-patterns/index.js.map +1 -1
- package/build-module/components/page-patterns/use-patterns.js +26 -1
- package/build-module/components/page-patterns/use-patterns.js.map +1 -1
- package/build-module/components/page-templates/fields.js +160 -0
- package/build-module/components/page-templates/fields.js.map +1 -0
- package/build-module/components/page-templates/index.js +12 -178
- package/build-module/components/page-templates/index.js.map +1 -1
- package/build-module/components/post-edit/index.js +20 -8
- package/build-module/components/post-edit/index.js.map +1 -1
- package/build-module/components/post-fields/index.js +19 -15
- package/build-module/components/post-fields/index.js.map +1 -1
- package/build-module/components/post-list/index.js +127 -69
- package/build-module/components/post-list/index.js.map +1 -1
- package/build-module/components/sidebar-dataviews/add-new-view.js +2 -2
- package/build-module/components/sidebar-dataviews/add-new-view.js.map +1 -1
- package/build-module/components/sidebar-dataviews/dataview-item.js +2 -3
- package/build-module/components/sidebar-dataviews/dataview-item.js.map +1 -1
- package/build-module/components/sidebar-dataviews/default-views.js +81 -81
- package/build-module/components/sidebar-dataviews/default-views.js.map +1 -1
- package/build-module/components/sidebar-dataviews/index.js +3 -42
- package/build-module/components/sidebar-dataviews/index.js.map +1 -1
- package/build-module/components/site-hub/index.js +7 -4
- package/build-module/components/site-hub/index.js.map +1 -1
- package/build-module/components/style-book/index.js +23 -26
- package/build-module/components/style-book/index.js.map +1 -1
- package/build-module/components/sync-state-with-url/use-init-edited-entity-from-url.js +5 -0
- package/build-module/components/sync-state-with-url/use-init-edited-entity-from-url.js.map +1 -1
- package/build-module/hooks/push-changes-to-global-styles/index.js +2 -3
- package/build-module/hooks/push-changes-to-global-styles/index.js.map +1 -1
- package/build-module/hooks/use-theme-style-variations/use-theme-style-variations-by-property.js +2 -3
- package/build-module/hooks/use-theme-style-variations/use-theme-style-variations-by-property.js.map +1 -1
- package/build-module/index.js +0 -2
- package/build-module/index.js.map +1 -1
- package/build-style/posts-rtl.css +190 -11
- package/build-style/posts.css +190 -11
- package/build-style/style-rtl.css +296 -55
- package/build-style/style.css +296 -55
- package/package.json +41 -41
- package/src/components/add-new-pattern/index.js +8 -3
- package/src/components/add-new-post/index.js +2 -1
- package/src/components/add-new-template/utils.js +10 -6
- package/src/components/editor/index.js +80 -22
- package/src/components/editor/style.scss +59 -1
- package/src/components/global-styles/font-families.js +3 -5
- package/src/components/global-styles/font-library-modal/context.js +0 -5
- package/src/components/global-styles/font-library-modal/font-collection.js +34 -10
- package/src/components/global-styles/font-library-modal/index.js +2 -7
- package/src/components/global-styles/font-library-modal/installed-fonts.js +23 -5
- package/src/components/global-styles/font-library-modal/style.scss +1 -1
- package/src/components/global-styles/font-library-modal/upload-fonts.js +2 -2
- package/src/components/global-styles/screen-typeset.js +42 -0
- package/src/components/global-styles/screen-typography-element.js +14 -0
- package/src/components/global-styles/screen-typography.js +4 -4
- package/src/components/global-styles/shadows-edit-panel.js +66 -73
- package/src/components/global-styles/style.scss +4 -7
- package/src/components/global-styles/typeset-button.js +93 -0
- package/src/components/global-styles/typeset.js +73 -0
- package/src/components/global-styles/ui.js +5 -0
- package/src/components/global-styles/utils.js +13 -1
- package/src/components/layout/style.scss +8 -0
- package/src/components/page-patterns/fields.js +251 -0
- package/src/components/page-patterns/index.js +15 -244
- package/src/components/page-patterns/style.scss +82 -85
- package/src/components/page-patterns/use-patterns.js +31 -1
- package/src/components/page-templates/fields.js +157 -0
- package/src/components/page-templates/index.js +19 -170
- package/src/components/page-templates/style.scss +14 -5
- package/src/components/post-edit/index.js +27 -8
- package/src/components/post-fields/index.js +29 -17
- package/src/components/post-list/index.js +134 -74
- package/src/components/sidebar-dataviews/add-new-view.js +2 -4
- package/src/components/sidebar-dataviews/dataview-item.js +2 -2
- package/src/components/sidebar-dataviews/default-views.js +95 -95
- package/src/components/sidebar-dataviews/index.js +3 -37
- package/src/components/site-hub/index.js +11 -2
- package/src/components/site-icon/style.scss +4 -1
- package/src/components/style-book/index.js +27 -32
- package/src/components/sync-state-with-url/use-init-edited-entity-from-url.js +5 -0
- package/src/hooks/push-changes-to-global-styles/index.js +2 -3
- package/src/hooks/use-theme-style-variations/use-theme-style-variations-by-property.js +2 -3
- package/src/index.js +0 -2
- package/build/utils/clone-deep.js +0 -15
- package/build/utils/clone-deep.js.map +0 -1
- package/build-module/utils/clone-deep.js +0 -9
- package/build-module/utils/clone-deep.js.map +0 -1
- package/src/utils/clone-deep.js +0 -8
|
@@ -2,11 +2,14 @@
|
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { Button } from '@wordpress/components';
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
store as coreStore,
|
|
7
|
+
privateApis as coreDataPrivateApis,
|
|
8
|
+
} from '@wordpress/core-data';
|
|
6
9
|
import { useState, useMemo, useCallback, useEffect } from '@wordpress/element';
|
|
7
10
|
import { privateApis as routerPrivateApis } from '@wordpress/router';
|
|
8
11
|
import { useSelect, useDispatch } from '@wordpress/data';
|
|
9
|
-
import { DataViews } from '@wordpress/dataviews';
|
|
12
|
+
import { DataViews, filterSortAndPaginate } from '@wordpress/dataviews';
|
|
10
13
|
import { privateApis as editorPrivateApis } from '@wordpress/editor';
|
|
11
14
|
import { __ } from '@wordpress/i18n';
|
|
12
15
|
import { drawerRight } from '@wordpress/icons';
|
|
@@ -33,102 +36,139 @@ import usePostFields from '../post-fields';
|
|
|
33
36
|
|
|
34
37
|
const { usePostActions } = unlock( editorPrivateApis );
|
|
35
38
|
const { useLocation, useHistory } = unlock( routerPrivateApis );
|
|
39
|
+
const { useEntityRecordsWithPermissions } = unlock( coreDataPrivateApis );
|
|
36
40
|
const EMPTY_ARRAY = [];
|
|
37
41
|
|
|
42
|
+
const getDefaultView = ( defaultViews, activeView ) => {
|
|
43
|
+
return defaultViews.find( ( { slug } ) => slug === activeView )?.view;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const getCustomView = ( editedEntityRecord ) => {
|
|
47
|
+
if ( ! editedEntityRecord?.content ) {
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const content = JSON.parse( editedEntityRecord.content );
|
|
52
|
+
if ( ! content ) {
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return {
|
|
57
|
+
...content,
|
|
58
|
+
layout: defaultLayouts[ content.type ]?.layout,
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* This function abstracts working with default & custom views by
|
|
64
|
+
* providing a [ state, setState ] tuple based on the URL parameters.
|
|
65
|
+
*
|
|
66
|
+
* Consumers use the provided tuple to work with state
|
|
67
|
+
* and don't have to deal with the specifics of default & custom views.
|
|
68
|
+
*
|
|
69
|
+
* @param {string} postType Post type to retrieve default views for.
|
|
70
|
+
* @return {Array} The [ state, setState ] tuple.
|
|
71
|
+
*/
|
|
38
72
|
function useView( postType ) {
|
|
39
73
|
const {
|
|
40
74
|
params: { activeView = 'all', isCustom = 'false', layout },
|
|
41
75
|
} = useLocation();
|
|
42
76
|
const history = useHistory();
|
|
43
|
-
const DEFAULT_VIEWS = useDefaultViews( { postType } );
|
|
44
|
-
const selectedDefaultView = useMemo( () => {
|
|
45
|
-
const defaultView =
|
|
46
|
-
isCustom === 'false' &&
|
|
47
|
-
DEFAULT_VIEWS[ postType ].find(
|
|
48
|
-
( { slug } ) => slug === activeView
|
|
49
|
-
)?.view;
|
|
50
|
-
if ( isCustom === 'false' && layout ) {
|
|
51
|
-
return {
|
|
52
|
-
...defaultView,
|
|
53
|
-
type: layout,
|
|
54
|
-
layout: defaultLayouts[ layout ]?.layout,
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
return defaultView;
|
|
58
|
-
}, [ isCustom, activeView, layout, postType, DEFAULT_VIEWS ] );
|
|
59
|
-
const [ view, setView ] = useState( selectedDefaultView );
|
|
60
77
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
}, [ selectedDefaultView ] );
|
|
66
|
-
const editedViewRecord = useSelect(
|
|
78
|
+
const defaultViews = useDefaultViews( { postType } );
|
|
79
|
+
const { editEntityRecord } = useDispatch( coreStore );
|
|
80
|
+
const editedEntityRecord = useSelect(
|
|
67
81
|
( select ) => {
|
|
68
82
|
if ( isCustom !== 'true' ) {
|
|
69
|
-
return;
|
|
83
|
+
return undefined;
|
|
70
84
|
}
|
|
85
|
+
|
|
71
86
|
const { getEditedEntityRecord } = select( coreStore );
|
|
72
|
-
|
|
87
|
+
return getEditedEntityRecord(
|
|
73
88
|
'postType',
|
|
74
89
|
'wp_dataviews',
|
|
75
90
|
Number( activeView )
|
|
76
91
|
);
|
|
77
|
-
return dataviewRecord;
|
|
78
92
|
},
|
|
79
93
|
[ activeView, isCustom ]
|
|
80
94
|
);
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
95
|
+
const [ view, setView ] = useState( () => {
|
|
96
|
+
let initialView;
|
|
97
|
+
if ( isCustom === 'true' ) {
|
|
98
|
+
initialView = getCustomView( editedEntityRecord ) ?? {
|
|
99
|
+
type: layout ?? LAYOUT_LIST,
|
|
100
|
+
};
|
|
101
|
+
} else {
|
|
102
|
+
initialView = getDefaultView( defaultViews, activeView ) ?? {
|
|
103
|
+
type: layout ?? LAYOUT_LIST,
|
|
104
|
+
};
|
|
89
105
|
}
|
|
90
106
|
|
|
107
|
+
const type = layout ?? initialView.type;
|
|
91
108
|
return {
|
|
92
|
-
...
|
|
93
|
-
|
|
109
|
+
...initialView,
|
|
110
|
+
type,
|
|
94
111
|
};
|
|
95
|
-
}
|
|
112
|
+
} );
|
|
96
113
|
|
|
97
|
-
const
|
|
98
|
-
(
|
|
99
|
-
|
|
100
|
-
'postType',
|
|
101
|
-
'wp_dataviews',
|
|
102
|
-
editedViewRecord?.id,
|
|
103
|
-
{
|
|
104
|
-
content: JSON.stringify( viewToSet ),
|
|
105
|
-
}
|
|
106
|
-
);
|
|
107
|
-
},
|
|
108
|
-
[ editEntityRecord, editedViewRecord?.id ]
|
|
109
|
-
);
|
|
114
|
+
const setViewWithUrlUpdate = useCallback(
|
|
115
|
+
( newView ) => {
|
|
116
|
+
const { params } = history.getLocationWithParams();
|
|
110
117
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
118
|
+
if ( newView.type === LAYOUT_LIST && ! params?.layout ) {
|
|
119
|
+
// Skip updating the layout URL param if
|
|
120
|
+
// it is not present and the newView.type is LAYOUT_LIST.
|
|
121
|
+
} else if ( newView.type !== params?.layout ) {
|
|
115
122
|
history.push( {
|
|
116
123
|
...params,
|
|
117
|
-
layout:
|
|
124
|
+
layout: newView.type,
|
|
118
125
|
} );
|
|
119
126
|
}
|
|
120
|
-
|
|
127
|
+
|
|
128
|
+
setView( newView );
|
|
129
|
+
|
|
130
|
+
if ( isCustom === 'true' && editedEntityRecord?.id ) {
|
|
131
|
+
editEntityRecord(
|
|
132
|
+
'postType',
|
|
133
|
+
'wp_dataviews',
|
|
134
|
+
editedEntityRecord?.id,
|
|
135
|
+
{
|
|
136
|
+
content: JSON.stringify( newView ),
|
|
137
|
+
}
|
|
138
|
+
);
|
|
139
|
+
}
|
|
121
140
|
},
|
|
122
|
-
[ history,
|
|
141
|
+
[ history, isCustom, editEntityRecord, editedEntityRecord?.id ]
|
|
123
142
|
);
|
|
124
143
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
144
|
+
// When layout URL param changes, update the view type
|
|
145
|
+
// without affecting any other config.
|
|
146
|
+
useEffect( () => {
|
|
147
|
+
setView( ( prevView ) => ( {
|
|
148
|
+
...prevView,
|
|
149
|
+
type: layout ?? LAYOUT_LIST,
|
|
150
|
+
} ) );
|
|
151
|
+
}, [ layout ] );
|
|
152
|
+
|
|
153
|
+
// When activeView or isCustom URL parameters change, reset the view.
|
|
154
|
+
useEffect( () => {
|
|
155
|
+
let newView;
|
|
156
|
+
if ( isCustom === 'true' ) {
|
|
157
|
+
newView = getCustomView( editedEntityRecord );
|
|
158
|
+
} else {
|
|
159
|
+
newView = getDefaultView( defaultViews, activeView );
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if ( newView ) {
|
|
163
|
+
const type = layout ?? newView.type;
|
|
164
|
+
setView( {
|
|
165
|
+
...newView,
|
|
166
|
+
type,
|
|
167
|
+
} );
|
|
168
|
+
}
|
|
169
|
+
}, [ activeView, isCustom, layout, defaultViews, editedEntityRecord ] );
|
|
170
|
+
|
|
171
|
+
return [ view, setViewWithUrlUpdate, setViewWithUrlUpdate ];
|
|
132
172
|
}
|
|
133
173
|
|
|
134
174
|
const DEFAULT_STATUSES = 'draft,future,pending,private,publish'; // All but 'trash'.
|
|
@@ -141,7 +181,12 @@ export default function PostList( { postType } ) {
|
|
|
141
181
|
const [ view, setView ] = useView( postType );
|
|
142
182
|
const history = useHistory();
|
|
143
183
|
const location = useLocation();
|
|
144
|
-
const {
|
|
184
|
+
const {
|
|
185
|
+
postId,
|
|
186
|
+
quickEdit = false,
|
|
187
|
+
isCustom,
|
|
188
|
+
activeView = 'all',
|
|
189
|
+
} = location.params;
|
|
145
190
|
const [ selection, setSelection ] = useState( postId?.split( ',' ) ?? [] );
|
|
146
191
|
const onChangeSelection = useCallback(
|
|
147
192
|
( items ) => {
|
|
@@ -157,9 +202,11 @@ export default function PostList( { postType } ) {
|
|
|
157
202
|
[ history ]
|
|
158
203
|
);
|
|
159
204
|
|
|
205
|
+
const { isLoading: isLoadingFields, fields } = usePostFields( view.type );
|
|
206
|
+
|
|
160
207
|
const queryArgs = useMemo( () => {
|
|
161
208
|
const filters = {};
|
|
162
|
-
view.filters
|
|
209
|
+
view.filters?.forEach( ( filter ) => {
|
|
163
210
|
if (
|
|
164
211
|
filter.field === 'status' &&
|
|
165
212
|
filter.operator === OPERATOR_IS_ANY
|
|
@@ -196,12 +243,25 @@ export default function PostList( { postType } ) {
|
|
|
196
243
|
}, [ view ] );
|
|
197
244
|
const {
|
|
198
245
|
records,
|
|
199
|
-
isResolving:
|
|
246
|
+
isResolving: isLoadingData,
|
|
200
247
|
totalItems,
|
|
201
248
|
totalPages,
|
|
202
|
-
} =
|
|
249
|
+
} = useEntityRecordsWithPermissions( 'postType', postType, queryArgs );
|
|
250
|
+
|
|
251
|
+
// The REST API sort the authors by ID, but we want to sort them by name.
|
|
252
|
+
const data = useMemo( () => {
|
|
253
|
+
if ( ! isLoadingFields && view?.sort?.field === 'author' ) {
|
|
254
|
+
return filterSortAndPaginate(
|
|
255
|
+
records,
|
|
256
|
+
{ sort: { ...view.sort } },
|
|
257
|
+
fields
|
|
258
|
+
).data;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
return records;
|
|
262
|
+
}, [ records, fields, isLoadingFields, view?.sort ] );
|
|
203
263
|
|
|
204
|
-
const ids =
|
|
264
|
+
const ids = data?.map( ( record ) => getItemId( record ) ) ?? [];
|
|
205
265
|
const prevIds = usePrevious( ids ) ?? [];
|
|
206
266
|
const deletedIds = prevIds.filter( ( id ) => ! ids.includes( id ) );
|
|
207
267
|
const postIdWasDeleted = deletedIds.includes( postId );
|
|
@@ -259,7 +319,6 @@ export default function PostList( { postType } ) {
|
|
|
259
319
|
} );
|
|
260
320
|
closeModal();
|
|
261
321
|
};
|
|
262
|
-
const { isLoading: isLoadingFields, fields } = usePostFields( view.type );
|
|
263
322
|
|
|
264
323
|
return (
|
|
265
324
|
<Page
|
|
@@ -287,11 +346,12 @@ export default function PostList( { postType } ) {
|
|
|
287
346
|
}
|
|
288
347
|
>
|
|
289
348
|
<DataViews
|
|
349
|
+
key={ activeView + isCustom }
|
|
290
350
|
paginationInfo={ paginationInfo }
|
|
291
351
|
fields={ fields }
|
|
292
352
|
actions={ actions }
|
|
293
|
-
data={
|
|
294
|
-
isLoading={
|
|
353
|
+
data={ data || EMPTY_ARRAY }
|
|
354
|
+
isLoading={ isLoadingData || isLoadingFields }
|
|
295
355
|
view={ view }
|
|
296
356
|
onChangeView={ setView }
|
|
297
357
|
selection={ selection }
|
|
@@ -29,7 +29,7 @@ function AddNewItemModalContent( { type, setIsAdding } ) {
|
|
|
29
29
|
const { saveEntityRecord } = useDispatch( coreStore );
|
|
30
30
|
const [ title, setTitle ] = useState( '' );
|
|
31
31
|
const [ isSaving, setIsSaving ] = useState( false );
|
|
32
|
-
const
|
|
32
|
+
const defaultViews = useDefaultViews( { postType: type } );
|
|
33
33
|
return (
|
|
34
34
|
<form
|
|
35
35
|
onSubmit={ async ( event ) => {
|
|
@@ -61,9 +61,7 @@ function AddNewItemModalContent( { type, setIsAdding } ) {
|
|
|
61
61
|
title,
|
|
62
62
|
status: 'publish',
|
|
63
63
|
wp_dataviews_type: dataViewTaxonomyId,
|
|
64
|
-
content: JSON.stringify(
|
|
65
|
-
DEFAULT_VIEWS[ type ][ 0 ].view
|
|
66
|
-
),
|
|
64
|
+
content: JSON.stringify( defaultViews[ 0 ].view ),
|
|
67
65
|
}
|
|
68
66
|
);
|
|
69
67
|
const {
|
|
@@ -29,7 +29,7 @@ export default function DataViewItem( {
|
|
|
29
29
|
suffix,
|
|
30
30
|
} ) {
|
|
31
31
|
const {
|
|
32
|
-
params: { postType
|
|
32
|
+
params: { postType },
|
|
33
33
|
} = useLocation();
|
|
34
34
|
|
|
35
35
|
const iconToUse =
|
|
@@ -41,7 +41,7 @@ export default function DataViewItem( {
|
|
|
41
41
|
}
|
|
42
42
|
const linkInfo = useLink( {
|
|
43
43
|
postType,
|
|
44
|
-
layout,
|
|
44
|
+
layout: type,
|
|
45
45
|
activeView,
|
|
46
46
|
isCustom: isCustom ? 'true' : undefined,
|
|
47
47
|
} );
|
|
@@ -77,105 +77,105 @@ export function useDefaultViews( { postType } ) {
|
|
|
77
77
|
[ postType ]
|
|
78
78
|
);
|
|
79
79
|
return useMemo( () => {
|
|
80
|
-
return
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
],
|
|
101
|
-
},
|
|
80
|
+
return [
|
|
81
|
+
{
|
|
82
|
+
title: labels?.all_items || __( 'All items' ),
|
|
83
|
+
slug: 'all',
|
|
84
|
+
icon: pages,
|
|
85
|
+
view: DEFAULT_POST_BASE,
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
title: __( 'Published' ),
|
|
89
|
+
slug: 'published',
|
|
90
|
+
icon: published,
|
|
91
|
+
view: {
|
|
92
|
+
...DEFAULT_POST_BASE,
|
|
93
|
+
filters: [
|
|
94
|
+
{
|
|
95
|
+
field: 'status',
|
|
96
|
+
operator: OPERATOR_IS_ANY,
|
|
97
|
+
value: 'publish',
|
|
98
|
+
},
|
|
99
|
+
],
|
|
102
100
|
},
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
title: __( 'Scheduled' ),
|
|
104
|
+
slug: 'future',
|
|
105
|
+
icon: scheduled,
|
|
106
|
+
view: {
|
|
107
|
+
...DEFAULT_POST_BASE,
|
|
108
|
+
filters: [
|
|
109
|
+
{
|
|
110
|
+
field: 'status',
|
|
111
|
+
operator: OPERATOR_IS_ANY,
|
|
112
|
+
value: 'future',
|
|
113
|
+
},
|
|
114
|
+
],
|
|
117
115
|
},
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
title: __( 'Drafts' ),
|
|
119
|
+
slug: 'drafts',
|
|
120
|
+
icon: drafts,
|
|
121
|
+
view: {
|
|
122
|
+
...DEFAULT_POST_BASE,
|
|
123
|
+
filters: [
|
|
124
|
+
{
|
|
125
|
+
field: 'status',
|
|
126
|
+
operator: OPERATOR_IS_ANY,
|
|
127
|
+
value: 'draft',
|
|
128
|
+
},
|
|
129
|
+
],
|
|
132
130
|
},
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
title: __( 'Pending' ),
|
|
134
|
+
slug: 'pending',
|
|
135
|
+
icon: pending,
|
|
136
|
+
view: {
|
|
137
|
+
...DEFAULT_POST_BASE,
|
|
138
|
+
filters: [
|
|
139
|
+
{
|
|
140
|
+
field: 'status',
|
|
141
|
+
operator: OPERATOR_IS_ANY,
|
|
142
|
+
value: 'pending',
|
|
143
|
+
},
|
|
144
|
+
],
|
|
147
145
|
},
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
title: __( 'Private' ),
|
|
149
|
+
slug: 'private',
|
|
150
|
+
icon: notAllowed,
|
|
151
|
+
view: {
|
|
152
|
+
...DEFAULT_POST_BASE,
|
|
153
|
+
filters: [
|
|
154
|
+
{
|
|
155
|
+
field: 'status',
|
|
156
|
+
operator: OPERATOR_IS_ANY,
|
|
157
|
+
value: 'private',
|
|
158
|
+
},
|
|
159
|
+
],
|
|
162
160
|
},
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
title: __( 'Trash' ),
|
|
164
|
+
slug: 'trash',
|
|
165
|
+
icon: trash,
|
|
166
|
+
view: {
|
|
167
|
+
...DEFAULT_POST_BASE,
|
|
168
|
+
type: LAYOUT_TABLE,
|
|
169
|
+
layout: defaultLayouts[ LAYOUT_TABLE ].layout,
|
|
170
|
+
filters: [
|
|
171
|
+
{
|
|
172
|
+
field: 'status',
|
|
173
|
+
operator: OPERATOR_IS_ANY,
|
|
174
|
+
value: 'trash',
|
|
175
|
+
},
|
|
176
|
+
],
|
|
177
177
|
},
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
}, [ labels
|
|
178
|
+
},
|
|
179
|
+
];
|
|
180
|
+
}, [ labels ] );
|
|
181
181
|
}
|
|
@@ -3,8 +3,6 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { __experimentalItemGroup as ItemGroup } from '@wordpress/components';
|
|
5
5
|
import { privateApis as routerPrivateApis } from '@wordpress/router';
|
|
6
|
-
import { useRef, useEffect } from '@wordpress/element';
|
|
7
|
-
import { usePrevious } from '@wordpress/compose';
|
|
8
6
|
|
|
9
7
|
/**
|
|
10
8
|
* Internal dependencies
|
|
@@ -14,45 +12,13 @@ import { unlock } from '../../lock-unlock';
|
|
|
14
12
|
import DataViewItem from './dataview-item';
|
|
15
13
|
import CustomDataViewsList from './custom-dataviews-list';
|
|
16
14
|
|
|
17
|
-
const { useLocation
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Hook to switch to table layout when switching to the trash view.
|
|
21
|
-
* When going out of the trash view, it switches back to the previous layout if
|
|
22
|
-
* there was an automatic switch to table layout.
|
|
23
|
-
*/
|
|
24
|
-
function useSwitchToTableOnTrash() {
|
|
25
|
-
const {
|
|
26
|
-
params: { activeView, layout, ...restParams },
|
|
27
|
-
} = useLocation();
|
|
28
|
-
const history = useHistory();
|
|
29
|
-
const viewToSwitchOutOfTrash = useRef( undefined );
|
|
30
|
-
const previousActiveView = usePrevious( activeView );
|
|
31
|
-
useEffect( () => {
|
|
32
|
-
if ( activeView === 'trash' && previousActiveView !== 'trash' ) {
|
|
33
|
-
viewToSwitchOutOfTrash.current = layout || 'list';
|
|
34
|
-
history.push( { ...restParams, layout: 'table', activeView } );
|
|
35
|
-
} else if (
|
|
36
|
-
previousActiveView === 'trash' &&
|
|
37
|
-
activeView !== 'trash' &&
|
|
38
|
-
viewToSwitchOutOfTrash.current
|
|
39
|
-
) {
|
|
40
|
-
history.push( {
|
|
41
|
-
...restParams,
|
|
42
|
-
layout: viewToSwitchOutOfTrash.current,
|
|
43
|
-
activeView,
|
|
44
|
-
} );
|
|
45
|
-
viewToSwitchOutOfTrash.current = undefined;
|
|
46
|
-
}
|
|
47
|
-
}, [ previousActiveView, activeView, layout, history, restParams ] );
|
|
48
|
-
}
|
|
15
|
+
const { useLocation } = unlock( routerPrivateApis );
|
|
49
16
|
|
|
50
17
|
export default function DataViewsSidebarContent() {
|
|
51
18
|
const {
|
|
52
19
|
params: { postType, activeView = 'all', isCustom = 'false' },
|
|
53
20
|
} = useLocation();
|
|
54
|
-
|
|
55
|
-
const DEFAULT_VIEWS = useDefaultViews( { postType } );
|
|
21
|
+
const defaultViews = useDefaultViews( { postType } );
|
|
56
22
|
if ( ! postType ) {
|
|
57
23
|
return null;
|
|
58
24
|
}
|
|
@@ -61,7 +27,7 @@ export default function DataViewsSidebarContent() {
|
|
|
61
27
|
return (
|
|
62
28
|
<>
|
|
63
29
|
<ItemGroup>
|
|
64
|
-
{
|
|
30
|
+
{ defaultViews.map( ( dataview ) => {
|
|
65
31
|
return (
|
|
66
32
|
<DataViewItem
|
|
67
33
|
key={ dataview.slug }
|
|
@@ -7,7 +7,11 @@ import clsx from 'clsx';
|
|
|
7
7
|
* WordPress dependencies
|
|
8
8
|
*/
|
|
9
9
|
import { useSelect, useDispatch } from '@wordpress/data';
|
|
10
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
Button,
|
|
12
|
+
__experimentalHStack as HStack,
|
|
13
|
+
VisuallyHidden,
|
|
14
|
+
} from '@wordpress/components';
|
|
11
15
|
import { __ } from '@wordpress/i18n';
|
|
12
16
|
import { store as coreStore } from '@wordpress/core-data';
|
|
13
17
|
import { decodeEntities } from '@wordpress/html-entities';
|
|
@@ -80,9 +84,14 @@ const SiteHub = memo(
|
|
|
80
84
|
variant="link"
|
|
81
85
|
href={ homeUrl }
|
|
82
86
|
target="_blank"
|
|
83
|
-
label={ __( 'View site (opens in a new tab)' ) }
|
|
84
87
|
>
|
|
85
88
|
{ decodeEntities( siteTitle ) }
|
|
89
|
+
<VisuallyHidden as="span">
|
|
90
|
+
{
|
|
91
|
+
/* translators: accessibility text */
|
|
92
|
+
__( '(opens in a new tab)' )
|
|
93
|
+
}
|
|
94
|
+
</VisuallyHidden>
|
|
86
95
|
</Button>
|
|
87
96
|
</div>
|
|
88
97
|
<HStack
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
.edit-site-site-icon__icon {
|
|
2
2
|
fill: currentColor;
|
|
3
|
+
width: 100%;
|
|
4
|
+
height: 100%;
|
|
3
5
|
|
|
4
6
|
.edit-site-layout.is-full-canvas & {
|
|
5
7
|
// Make the WordPress icon not so big in full canvas.
|
|
6
|
-
padding: $grid-unit-15
|
|
8
|
+
padding: $grid-unit-15;
|
|
7
9
|
}
|
|
8
10
|
}
|
|
9
11
|
|
|
@@ -12,6 +14,7 @@
|
|
|
12
14
|
height: 100%;
|
|
13
15
|
object-fit: cover;
|
|
14
16
|
background: #333;
|
|
17
|
+
aspect-ratio: 1 / 1;
|
|
15
18
|
|
|
16
19
|
.edit-site-layout.is-full-canvas & {
|
|
17
20
|
border-radius: 0;
|