@wordpress/dataviews 4.9.1-next.cd6172eb0.0 → 4.11.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 +28 -1
- package/LICENSE.md +1 -1
- package/README.md +337 -228
- package/build/components/dataviews/index.js +13 -1
- package/build/components/dataviews/index.js.map +1 -1
- package/build/components/dataviews-bulk-actions/index.js +30 -2
- package/build/components/dataviews-bulk-actions/index.js.map +1 -1
- package/build/components/dataviews-context/index.js +2 -1
- package/build/components/dataviews-context/index.js.map +1 -1
- package/build/components/dataviews-filters/add-filter.js +36 -30
- package/build/components/dataviews-filters/add-filter.js.map +1 -1
- package/build/components/dataviews-filters/filter-summary.js +1 -0
- package/build/components/dataviews-filters/filter-summary.js.map +1 -1
- package/build/components/dataviews-filters/index.js +4 -1
- package/build/components/dataviews-filters/index.js.map +1 -1
- package/build/components/dataviews-filters/reset-filters.js +1 -0
- package/build/components/dataviews-filters/reset-filters.js.map +1 -1
- package/build/components/dataviews-filters/search-widget.js +1 -0
- package/build/components/dataviews-filters/search-widget.js.map +1 -1
- package/build/components/dataviews-item-actions/index.js +68 -79
- package/build/components/dataviews-item-actions/index.js.map +1 -1
- package/build/components/dataviews-layout/index.js +3 -0
- package/build/components/dataviews-layout/index.js.map +1 -1
- package/build/components/dataviews-pagination/index.js +1 -0
- package/build/components/dataviews-pagination/index.js.map +1 -1
- package/build/components/dataviews-selection-checkbox/index.js +4 -3
- package/build/components/dataviews-selection-checkbox/index.js.map +1 -1
- package/build/components/dataviews-view-config/index.js +235 -161
- package/build/components/dataviews-view-config/index.js.map +1 -1
- package/build/dataforms-layouts/data-form-layout.js +1 -0
- package/build/dataforms-layouts/data-form-layout.js.map +1 -1
- package/build/dataforms-layouts/index.js +1 -0
- package/build/dataforms-layouts/index.js.map +1 -1
- package/build/dataforms-layouts/panel/index.js +1 -0
- package/build/dataforms-layouts/panel/index.js.map +1 -1
- package/build/dataforms-layouts/regular/index.js +1 -0
- package/build/dataforms-layouts/regular/index.js.map +1 -1
- package/build/dataviews-layouts/grid/index.js +108 -65
- package/build/dataviews-layouts/grid/index.js.map +1 -1
- package/build/dataviews-layouts/grid/preview-size-picker.js +22 -25
- package/build/dataviews-layouts/grid/preview-size-picker.js.map +1 -1
- package/build/dataviews-layouts/index.js +0 -60
- package/build/dataviews-layouts/index.js.map +1 -1
- package/build/dataviews-layouts/list/index.js +67 -33
- package/build/dataviews-layouts/list/index.js.map +1 -1
- package/build/dataviews-layouts/table/column-header-menu.js +119 -120
- package/build/dataviews-layouts/table/column-header-menu.js.map +1 -1
- package/build/dataviews-layouts/table/column-primary.js +59 -0
- package/build/dataviews-layouts/table/column-primary.js.map +1 -0
- package/build/dataviews-layouts/table/index.js +78 -88
- package/build/dataviews-layouts/table/index.js.map +1 -1
- package/build/dataviews-layouts/utils/get-clickable-item-props.js +2 -2
- package/build/dataviews-layouts/utils/get-clickable-item-props.js.map +1 -1
- package/build/filter-and-sort-data-view.js +1 -0
- package/build/filter-and-sort-data-view.js.map +1 -1
- package/build/normalize-fields.js +1 -0
- package/build/normalize-fields.js.map +1 -1
- package/build/normalize-form-fields.js +1 -0
- package/build/normalize-form-fields.js.map +1 -1
- package/build/types.js.map +1 -1
- package/build/utils.js +1 -0
- package/build/utils.js.map +1 -1
- package/build/validation.js +1 -0
- package/build/validation.js.map +1 -1
- package/build-module/components/dataviews/index.js +13 -1
- package/build-module/components/dataviews/index.js.map +1 -1
- package/build-module/components/dataviews-bulk-actions/index.js +31 -3
- package/build-module/components/dataviews-bulk-actions/index.js.map +1 -1
- package/build-module/components/dataviews-context/index.js +2 -1
- package/build-module/components/dataviews-context/index.js.map +1 -1
- package/build-module/components/dataviews-filters/add-filter.js +37 -31
- package/build-module/components/dataviews-filters/add-filter.js.map +1 -1
- package/build-module/components/dataviews-filters/filter-summary.js +1 -0
- package/build-module/components/dataviews-filters/filter-summary.js.map +1 -1
- package/build-module/components/dataviews-filters/index.js +4 -1
- package/build-module/components/dataviews-filters/index.js.map +1 -1
- package/build-module/components/dataviews-filters/reset-filters.js +1 -0
- package/build-module/components/dataviews-filters/reset-filters.js.map +1 -1
- package/build-module/components/dataviews-filters/search-widget.js +1 -0
- package/build-module/components/dataviews-filters/search-widget.js.map +1 -1
- package/build-module/components/dataviews-item-actions/index.js +69 -79
- package/build-module/components/dataviews-item-actions/index.js.map +1 -1
- package/build-module/components/dataviews-layout/index.js +3 -0
- package/build-module/components/dataviews-layout/index.js.map +1 -1
- package/build-module/components/dataviews-pagination/index.js +1 -0
- package/build-module/components/dataviews-pagination/index.js.map +1 -1
- package/build-module/components/dataviews-selection-checkbox/index.js +4 -3
- package/build-module/components/dataviews-selection-checkbox/index.js.map +1 -1
- package/build-module/components/dataviews-view-config/index.js +240 -166
- package/build-module/components/dataviews-view-config/index.js.map +1 -1
- package/build-module/dataforms-layouts/data-form-layout.js +1 -0
- package/build-module/dataforms-layouts/data-form-layout.js.map +1 -1
- package/build-module/dataforms-layouts/index.js +1 -0
- package/build-module/dataforms-layouts/index.js.map +1 -1
- package/build-module/dataforms-layouts/panel/index.js +1 -0
- package/build-module/dataforms-layouts/panel/index.js.map +1 -1
- package/build-module/dataforms-layouts/regular/index.js +1 -0
- package/build-module/dataforms-layouts/regular/index.js.map +1 -1
- package/build-module/dataviews-layouts/grid/index.js +111 -68
- package/build-module/dataviews-layouts/grid/index.js.map +1 -1
- package/build-module/dataviews-layouts/grid/preview-size-picker.js +22 -25
- package/build-module/dataviews-layouts/grid/preview-size-picker.js.map +1 -1
- package/build-module/dataviews-layouts/index.js +0 -57
- package/build-module/dataviews-layouts/index.js.map +1 -1
- package/build-module/dataviews-layouts/list/index.js +67 -33
- package/build-module/dataviews-layouts/list/index.js.map +1 -1
- package/build-module/dataviews-layouts/table/column-header-menu.js +119 -120
- package/build-module/dataviews-layouts/table/column-header-menu.js.map +1 -1
- package/build-module/dataviews-layouts/table/column-primary.js +52 -0
- package/build-module/dataviews-layouts/table/column-primary.js.map +1 -0
- package/build-module/dataviews-layouts/table/index.js +81 -91
- package/build-module/dataviews-layouts/table/index.js.map +1 -1
- package/build-module/dataviews-layouts/utils/get-clickable-item-props.js +2 -2
- package/build-module/dataviews-layouts/utils/get-clickable-item-props.js.map +1 -1
- package/build-module/filter-and-sort-data-view.js +1 -0
- package/build-module/filter-and-sort-data-view.js.map +1 -1
- package/build-module/normalize-fields.js +1 -0
- package/build-module/normalize-fields.js.map +1 -1
- package/build-module/normalize-form-fields.js +1 -0
- package/build-module/normalize-form-fields.js.map +1 -1
- package/build-module/types.js.map +1 -1
- package/build-module/utils.js +1 -0
- package/build-module/utils.js.map +1 -1
- package/build-module/validation.js +1 -0
- package/build-module/validation.js.map +1 -1
- package/build-style/style-rtl.css +123 -121
- package/build-style/style.css +123 -121
- package/build-types/components/dataviews/index.d.ts +2 -1
- package/build-types/components/dataviews/index.d.ts.map +1 -1
- package/build-types/components/dataviews/stories/fixtures.d.ts.map +1 -1
- package/build-types/components/dataviews/stories/index.story.d.ts +0 -1
- package/build-types/components/dataviews/stories/index.story.d.ts.map +1 -1
- package/build-types/components/dataviews-bulk-actions/index.d.ts.map +1 -1
- package/build-types/components/dataviews-context/index.d.ts +2 -0
- package/build-types/components/dataviews-context/index.d.ts.map +1 -1
- package/build-types/components/dataviews-filters/add-filter.d.ts +3 -2
- package/build-types/components/dataviews-filters/add-filter.d.ts.map +1 -1
- package/build-types/components/dataviews-item-actions/index.d.ts +7 -9
- package/build-types/components/dataviews-item-actions/index.d.ts.map +1 -1
- package/build-types/components/dataviews-layout/index.d.ts.map +1 -1
- package/build-types/components/dataviews-selection-checkbox/index.d.ts +2 -2
- package/build-types/components/dataviews-selection-checkbox/index.d.ts.map +1 -1
- package/build-types/components/dataviews-view-config/index.d.ts.map +1 -1
- package/build-types/dataviews-layouts/grid/index.d.ts.map +1 -1
- package/build-types/dataviews-layouts/grid/preview-size-picker.d.ts.map +1 -1
- package/build-types/dataviews-layouts/index.d.ts +0 -4
- package/build-types/dataviews-layouts/index.d.ts.map +1 -1
- package/build-types/dataviews-layouts/list/index.d.ts.map +1 -1
- package/build-types/dataviews-layouts/table/column-header-menu.d.ts +1 -0
- package/build-types/dataviews-layouts/table/column-header-menu.d.ts.map +1 -1
- package/build-types/dataviews-layouts/table/column-primary.d.ts +15 -0
- package/build-types/dataviews-layouts/table/column-primary.d.ts.map +1 -0
- package/build-types/dataviews-layouts/table/index.d.ts +1 -1
- package/build-types/dataviews-layouts/table/index.d.ts.map +1 -1
- package/build-types/dataviews-layouts/utils/get-clickable-item-props.d.ts +3 -3
- package/build-types/dataviews-layouts/utils/get-clickable-item-props.d.ts.map +1 -1
- package/build-types/test/dataform.d.ts +2 -0
- package/build-types/test/dataform.d.ts.map +1 -0
- package/build-types/test/dataviews.d.ts +2 -0
- package/build-types/test/dataviews.d.ts.map +1 -0
- package/build-types/test/normalize-fields.d.ts +2 -0
- package/build-types/test/normalize-fields.d.ts.map +1 -0
- package/build-types/test/validation.d.ts +2 -0
- package/build-types/test/validation.d.ts.map +1 -0
- package/build-types/types.d.ts +25 -39
- package/build-types/types.d.ts.map +1 -1
- package/build-wp/index.js +1892 -1814
- package/build.js +1 -1
- package/package.json +13 -12
- package/src/components/dataviews/index.tsx +15 -1
- package/src/components/dataviews/stories/fixtures.tsx +0 -3
- package/src/components/dataviews/stories/index.story.tsx +14 -106
- package/src/components/dataviews/style.scss +32 -33
- package/src/components/dataviews-bulk-actions/index.tsx +43 -3
- package/src/components/dataviews-context/index.ts +3 -0
- package/src/components/dataviews-filters/add-filter.tsx +43 -39
- package/src/components/dataviews-filters/index.tsx +1 -1
- package/src/components/dataviews-footer/style.scss +0 -3
- package/src/components/dataviews-item-actions/index.tsx +90 -107
- package/src/components/dataviews-layout/index.tsx +2 -0
- package/src/components/dataviews-selection-checkbox/index.tsx +4 -4
- package/src/components/dataviews-view-config/index.tsx +347 -232
- package/src/components/dataviews-view-config/style.scss +17 -1
- package/src/dataviews-layouts/grid/index.tsx +150 -103
- package/src/dataviews-layouts/grid/preview-size-picker.tsx +25 -30
- package/src/dataviews-layouts/grid/style.scss +38 -56
- package/src/dataviews-layouts/index.ts +0 -88
- package/src/dataviews-layouts/list/index.tsx +95 -57
- package/src/dataviews-layouts/list/style.scss +10 -9
- package/src/dataviews-layouts/table/column-header-menu.tsx +183 -171
- package/src/dataviews-layouts/table/column-primary.tsx +65 -0
- package/src/dataviews-layouts/table/index.tsx +98 -133
- package/src/dataviews-layouts/table/style.scss +4 -1
- package/src/dataviews-layouts/utils/get-clickable-item-props.ts +9 -3
- package/src/test/dataform.tsx +348 -0
- package/src/test/dataviews.tsx +380 -0
- package/src/types.ts +27 -46
- package/tsconfig.json +14 -4
- package/tsconfig.tsbuildinfo +1 -1
- package/build/components/form-field-visibility/index.js +0 -32
- package/build/components/form-field-visibility/index.js.map +0 -1
- package/build-module/components/form-field-visibility/index.js +0 -26
- package/build-module/components/form-field-visibility/index.js.map +0 -1
- package/build-types/components/form-field-visibility/index.d.ts +0 -11
- package/build-types/components/form-field-visibility/index.d.ts.map +0 -1
- package/src/components/form-field-visibility/index.tsx +0 -32
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import type { MouseEventHandler
|
|
4
|
+
import type { MouseEventHandler } from 'react';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* WordPress dependencies
|
|
@@ -32,20 +32,17 @@ export interface ActionTriggerProps< Item > {
|
|
|
32
32
|
items: Item[];
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
interface ActionModalProps< Item > {
|
|
35
|
+
export interface ActionModalProps< Item > {
|
|
36
36
|
action: ActionModalType< Item >;
|
|
37
37
|
items: Item[];
|
|
38
|
-
closeModal
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
interface ActionWithModalProps< Item > extends ActionModalProps< Item > {
|
|
42
|
-
ActionTrigger: ( props: ActionTriggerProps< Item > ) => ReactElement;
|
|
43
|
-
isBusy?: boolean;
|
|
38
|
+
closeModal: () => void;
|
|
44
39
|
}
|
|
45
40
|
|
|
46
41
|
interface ActionsMenuGroupProps< Item > {
|
|
47
42
|
actions: Action< Item >[];
|
|
48
43
|
item: Item;
|
|
44
|
+
registry: ReturnType< typeof useRegistry >;
|
|
45
|
+
setActiveModalAction: ( action: ActionModalType< Item > | null ) => void;
|
|
49
46
|
}
|
|
50
47
|
|
|
51
48
|
interface ItemActionsProps< Item > {
|
|
@@ -58,6 +55,7 @@ interface CompactItemActionsProps< Item > {
|
|
|
58
55
|
item: Item;
|
|
59
56
|
actions: Action< Item >[];
|
|
60
57
|
isSmall?: boolean;
|
|
58
|
+
registry: ReturnType< typeof useRegistry >;
|
|
61
59
|
}
|
|
62
60
|
|
|
63
61
|
interface PrimaryActionsProps< Item > {
|
|
@@ -77,6 +75,8 @@ function ButtonTrigger< Item >( {
|
|
|
77
75
|
<Button
|
|
78
76
|
label={ label }
|
|
79
77
|
icon={ action.icon }
|
|
78
|
+
disabled={ !! action.disabled }
|
|
79
|
+
accessibleWhenDisabled
|
|
80
80
|
isDestructive={ action.isDestructive }
|
|
81
81
|
size="compact"
|
|
82
82
|
onClick={ onClick }
|
|
@@ -92,10 +92,7 @@ function MenuItemTrigger< Item >( {
|
|
|
92
92
|
const label =
|
|
93
93
|
typeof action.label === 'string' ? action.label : action.label( items );
|
|
94
94
|
return (
|
|
95
|
-
<Menu.Item
|
|
96
|
-
onClick={ onClick }
|
|
97
|
-
hideOnClick={ ! ( 'RenderModal' in action ) }
|
|
98
|
-
>
|
|
95
|
+
<Menu.Item disabled={ action.disabled } onClick={ onClick }>
|
|
99
96
|
<Menu.ItemLabel>{ label }</Menu.ItemLabel>
|
|
100
97
|
</Menu.Item>
|
|
101
98
|
);
|
|
@@ -112,7 +109,7 @@ export function ActionModal< Item >( {
|
|
|
112
109
|
<Modal
|
|
113
110
|
title={ action.modalHeader || label }
|
|
114
111
|
__experimentalHideHeader={ !! action.hideModalHeader }
|
|
115
|
-
onRequestClose={ closeModal
|
|
112
|
+
onRequestClose={ closeModal }
|
|
116
113
|
focusOnMount="firstContentElement"
|
|
117
114
|
size="medium"
|
|
118
115
|
overlayClassName={ `dataviews-action-modal dataviews-action-modal__${ kebabCase(
|
|
@@ -124,75 +121,32 @@ export function ActionModal< Item >( {
|
|
|
124
121
|
);
|
|
125
122
|
}
|
|
126
123
|
|
|
127
|
-
export function ActionWithModal< Item >( {
|
|
128
|
-
action,
|
|
129
|
-
items,
|
|
130
|
-
ActionTrigger,
|
|
131
|
-
isBusy,
|
|
132
|
-
}: ActionWithModalProps< Item > ) {
|
|
133
|
-
const [ isModalOpen, setIsModalOpen ] = useState( false );
|
|
134
|
-
const actionTriggerProps = {
|
|
135
|
-
action,
|
|
136
|
-
onClick: () => {
|
|
137
|
-
setIsModalOpen( true );
|
|
138
|
-
},
|
|
139
|
-
items,
|
|
140
|
-
isBusy,
|
|
141
|
-
};
|
|
142
|
-
return (
|
|
143
|
-
<>
|
|
144
|
-
<ActionTrigger { ...actionTriggerProps } />
|
|
145
|
-
{ isModalOpen && (
|
|
146
|
-
<ActionModal
|
|
147
|
-
action={ action }
|
|
148
|
-
items={ items }
|
|
149
|
-
closeModal={ () => setIsModalOpen( false ) }
|
|
150
|
-
/>
|
|
151
|
-
) }
|
|
152
|
-
</>
|
|
153
|
-
);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
124
|
export function ActionsMenuGroup< Item >( {
|
|
157
125
|
actions,
|
|
158
126
|
item,
|
|
127
|
+
registry,
|
|
128
|
+
setActiveModalAction,
|
|
159
129
|
}: ActionsMenuGroupProps< Item > ) {
|
|
160
|
-
const registry = useRegistry();
|
|
161
130
|
return (
|
|
162
131
|
<Menu.Group>
|
|
163
|
-
{ actions.map( ( action ) =>
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
action={ action }
|
|
178
|
-
onClick={ () => {
|
|
179
|
-
action.callback( [ item ], { registry } );
|
|
180
|
-
} }
|
|
181
|
-
items={ [ item ] }
|
|
182
|
-
/>
|
|
183
|
-
);
|
|
184
|
-
} ) }
|
|
132
|
+
{ actions.map( ( action ) => (
|
|
133
|
+
<MenuItemTrigger
|
|
134
|
+
key={ action.id }
|
|
135
|
+
action={ action }
|
|
136
|
+
onClick={ () => {
|
|
137
|
+
if ( 'RenderModal' in action ) {
|
|
138
|
+
setActiveModalAction( action );
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
action.callback( [ item ], { registry } );
|
|
142
|
+
} }
|
|
143
|
+
items={ [ item ] }
|
|
144
|
+
/>
|
|
145
|
+
) ) }
|
|
185
146
|
</Menu.Group>
|
|
186
147
|
);
|
|
187
148
|
}
|
|
188
149
|
|
|
189
|
-
function hasOnlyOneActionAndIsPrimary< Item >(
|
|
190
|
-
primaryActions: Action< Item >[],
|
|
191
|
-
actions: Action< Item >[]
|
|
192
|
-
) {
|
|
193
|
-
return primaryActions.length === 1 && actions.length === 1;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
150
|
export default function ItemActions< Item >( {
|
|
197
151
|
item,
|
|
198
152
|
actions,
|
|
@@ -220,11 +174,13 @@ export default function ItemActions< Item >( {
|
|
|
220
174
|
item={ item }
|
|
221
175
|
actions={ eligibleActions }
|
|
222
176
|
isSmall
|
|
177
|
+
registry={ registry }
|
|
223
178
|
/>
|
|
224
179
|
);
|
|
225
180
|
}
|
|
226
181
|
|
|
227
|
-
|
|
182
|
+
// If all actions are primary, there is no need to render the dropdown.
|
|
183
|
+
if ( primaryActions.length === eligibleActions.length ) {
|
|
228
184
|
return (
|
|
229
185
|
<PrimaryActions
|
|
230
186
|
item={ item }
|
|
@@ -249,7 +205,11 @@ export default function ItemActions< Item >( {
|
|
|
249
205
|
actions={ primaryActions }
|
|
250
206
|
registry={ registry }
|
|
251
207
|
/>
|
|
252
|
-
<CompactItemActions
|
|
208
|
+
<CompactItemActions
|
|
209
|
+
item={ item }
|
|
210
|
+
actions={ eligibleActions }
|
|
211
|
+
registry={ registry }
|
|
212
|
+
/>
|
|
253
213
|
</HStack>
|
|
254
214
|
);
|
|
255
215
|
}
|
|
@@ -258,23 +218,43 @@ function CompactItemActions< Item >( {
|
|
|
258
218
|
item,
|
|
259
219
|
actions,
|
|
260
220
|
isSmall,
|
|
221
|
+
registry,
|
|
261
222
|
}: CompactItemActionsProps< Item > ) {
|
|
223
|
+
const [ activeModalAction, setActiveModalAction ] = useState(
|
|
224
|
+
null as ActionModalType< Item > | null
|
|
225
|
+
);
|
|
262
226
|
return (
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
<
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
227
|
+
<>
|
|
228
|
+
<Menu placement="bottom-end">
|
|
229
|
+
<Menu.TriggerButton
|
|
230
|
+
render={
|
|
231
|
+
<Button
|
|
232
|
+
size={ isSmall ? 'small' : 'compact' }
|
|
233
|
+
icon={ moreVertical }
|
|
234
|
+
label={ __( 'Actions' ) }
|
|
235
|
+
accessibleWhenDisabled
|
|
236
|
+
disabled={ ! actions.length }
|
|
237
|
+
className="dataviews-all-actions-button"
|
|
238
|
+
/>
|
|
239
|
+
}
|
|
272
240
|
/>
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
241
|
+
<Menu.Popover>
|
|
242
|
+
<ActionsMenuGroup
|
|
243
|
+
actions={ actions }
|
|
244
|
+
item={ item }
|
|
245
|
+
registry={ registry }
|
|
246
|
+
setActiveModalAction={ setActiveModalAction }
|
|
247
|
+
/>
|
|
248
|
+
</Menu.Popover>
|
|
249
|
+
</Menu>
|
|
250
|
+
{ !! activeModalAction && (
|
|
251
|
+
<ActionModal
|
|
252
|
+
action={ activeModalAction }
|
|
253
|
+
items={ [ item ] }
|
|
254
|
+
closeModal={ () => setActiveModalAction( null ) }
|
|
255
|
+
/>
|
|
256
|
+
) }
|
|
257
|
+
</>
|
|
278
258
|
);
|
|
279
259
|
}
|
|
280
260
|
|
|
@@ -283,30 +263,33 @@ function PrimaryActions< Item >( {
|
|
|
283
263
|
actions,
|
|
284
264
|
registry,
|
|
285
265
|
}: PrimaryActionsProps< Item > ) {
|
|
266
|
+
const [ activeModalAction, setActiveModalAction ] = useState( null as any );
|
|
286
267
|
if ( ! Array.isArray( actions ) || actions.length === 0 ) {
|
|
287
268
|
return null;
|
|
288
269
|
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
<ActionWithModal
|
|
270
|
+
return (
|
|
271
|
+
<>
|
|
272
|
+
{ actions.map( ( action ) => (
|
|
273
|
+
<ButtonTrigger
|
|
294
274
|
key={ action.id }
|
|
295
275
|
action={ action }
|
|
276
|
+
onClick={ () => {
|
|
277
|
+
if ( 'RenderModal' in action ) {
|
|
278
|
+
setActiveModalAction( action );
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
action.callback( [ item ], { registry } );
|
|
282
|
+
} }
|
|
296
283
|
items={ [ item ] }
|
|
297
|
-
ActionTrigger={ ButtonTrigger }
|
|
298
284
|
/>
|
|
299
|
-
)
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
/>
|
|
310
|
-
);
|
|
311
|
-
} );
|
|
285
|
+
) ) }
|
|
286
|
+
{ !! activeModalAction && (
|
|
287
|
+
<ActionModal
|
|
288
|
+
action={ activeModalAction }
|
|
289
|
+
items={ [ item ] }
|
|
290
|
+
closeModal={ () => setActiveModalAction( null ) }
|
|
291
|
+
/>
|
|
292
|
+
) }
|
|
293
|
+
</>
|
|
294
|
+
);
|
|
312
295
|
}
|
|
@@ -21,6 +21,7 @@ export default function DataViewsLayout() {
|
|
|
21
21
|
data,
|
|
22
22
|
fields,
|
|
23
23
|
getItemId,
|
|
24
|
+
getItemLevel,
|
|
24
25
|
isLoading,
|
|
25
26
|
view,
|
|
26
27
|
onChangeView,
|
|
@@ -40,6 +41,7 @@ export default function DataViewsLayout() {
|
|
|
40
41
|
data={ data }
|
|
41
42
|
fields={ fields }
|
|
42
43
|
getItemId={ getItemId }
|
|
44
|
+
getItemLevel={ getItemLevel }
|
|
43
45
|
isLoading={ isLoading }
|
|
44
46
|
onChangeView={ onChangeView }
|
|
45
47
|
onChangeSelection={ onChangeSelection }
|
|
@@ -15,7 +15,7 @@ interface DataViewsSelectionCheckboxProps< Item > {
|
|
|
15
15
|
onChangeSelection: SetSelection;
|
|
16
16
|
item: Item;
|
|
17
17
|
getItemId: ( item: Item ) => string;
|
|
18
|
-
|
|
18
|
+
titleField?: Field< Item >;
|
|
19
19
|
disabled: boolean;
|
|
20
20
|
}
|
|
21
21
|
|
|
@@ -24,19 +24,19 @@ export default function DataViewsSelectionCheckbox< Item >( {
|
|
|
24
24
|
onChangeSelection,
|
|
25
25
|
item,
|
|
26
26
|
getItemId,
|
|
27
|
-
|
|
27
|
+
titleField,
|
|
28
28
|
disabled,
|
|
29
29
|
}: DataViewsSelectionCheckboxProps< Item > ) {
|
|
30
30
|
const id = getItemId( item );
|
|
31
31
|
const checked = ! disabled && selection.includes( id );
|
|
32
32
|
let selectionLabel;
|
|
33
|
-
if (
|
|
33
|
+
if ( titleField?.getValue && item ) {
|
|
34
34
|
// eslint-disable-next-line @wordpress/valid-sprintf
|
|
35
35
|
selectionLabel = sprintf(
|
|
36
36
|
checked
|
|
37
37
|
? /* translators: %s: item title. */ __( 'Deselect item: %s' )
|
|
38
38
|
: /* translators: %s: item title. */ __( 'Select item: %s' ),
|
|
39
|
-
|
|
39
|
+
titleField.getValue( { item } )
|
|
40
40
|
);
|
|
41
41
|
} else {
|
|
42
42
|
selectionLabel = checked
|