@wordpress/dataviews 14.0.0 → 14.1.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 +21 -0
- package/README.md +16 -5
- package/build/components/dataform-controls/array.cjs +2 -0
- package/build/components/dataform-controls/array.cjs.map +2 -2
- package/build/components/dataform-controls/checkbox.cjs +3 -1
- package/build/components/dataform-controls/checkbox.cjs.map +2 -2
- package/build/components/dataform-controls/color.cjs +8 -2
- package/build/components/dataform-controls/color.cjs.map +2 -2
- package/build/components/dataform-controls/date.cjs +31 -9
- package/build/components/dataform-controls/date.cjs.map +3 -3
- package/build/components/dataform-controls/datetime.cjs +9 -2
- package/build/components/dataform-controls/datetime.cjs.map +3 -3
- package/build/components/dataform-controls/password.cjs +4 -1
- package/build/components/dataform-controls/password.cjs.map +2 -2
- package/build/components/dataform-controls/radio.cjs +3 -1
- package/build/components/dataform-controls/radio.cjs.map +2 -2
- package/build/components/dataform-controls/select.cjs +3 -1
- package/build/components/dataform-controls/select.cjs.map +2 -2
- package/build/components/dataform-controls/textarea.cjs +2 -0
- package/build/components/dataform-controls/textarea.cjs.map +2 -2
- package/build/components/dataform-controls/toggle-group.cjs +3 -1
- package/build/components/dataform-controls/toggle-group.cjs.map +2 -2
- package/build/components/dataform-controls/toggle.cjs +3 -1
- package/build/components/dataform-controls/toggle.cjs.map +2 -2
- package/build/components/dataform-controls/utils/relative-date-control.cjs +5 -2
- package/build/components/dataform-controls/utils/relative-date-control.cjs.map +2 -2
- package/build/components/dataform-controls/utils/use-disabled-date-matchers.cjs +48 -0
- package/build/components/dataform-controls/utils/use-disabled-date-matchers.cjs.map +7 -0
- package/build/components/dataform-controls/utils/validated-input.cjs +2 -0
- package/build/components/dataform-controls/utils/validated-input.cjs.map +2 -2
- package/build/components/dataform-controls/utils/validated-number.cjs +3 -1
- package/build/components/dataform-controls/utils/validated-number.cjs.map +2 -2
- package/build/components/dataform-layouts/panel/summary-button.cjs +0 -1
- package/build/components/dataform-layouts/panel/summary-button.cjs.map +2 -2
- package/build/components/dataviews-context/index.cjs.map +1 -1
- package/build/components/dataviews-filters/input-widget.cjs +4 -0
- package/build/components/dataviews-filters/input-widget.cjs.map +2 -2
- package/build/components/dataviews-layouts/picker-grid/index.cjs +1 -4
- package/build/components/dataviews-layouts/picker-grid/index.cjs.map +2 -2
- package/build/components/dataviews-layouts/picker-table/index.cjs +15 -12
- package/build/components/dataviews-layouts/picker-table/index.cjs.map +2 -2
- package/build/components/dataviews-layouts/table/index.cjs +0 -1
- package/build/components/dataviews-layouts/table/index.cjs.map +2 -2
- package/build/components/dataviews-pagination/index.cjs +1 -0
- package/build/components/dataviews-pagination/index.cjs.map +2 -2
- package/build/dataviews/index.cjs +10 -8
- package/build/dataviews/index.cjs.map +2 -2
- package/build/dataviews-picker/index.cjs +16 -9
- package/build/dataviews-picker/index.cjs.map +2 -2
- package/build/field-types/date.cjs +4 -1
- package/build/field-types/date.cjs.map +2 -2
- package/build/field-types/datetime.cjs +4 -1
- package/build/field-types/datetime.cjs.map +2 -2
- package/build/field-types/index.cjs +1 -0
- package/build/field-types/index.cjs.map +2 -2
- package/build/field-types/utils/get-is-valid.cjs +29 -24
- package/build/field-types/utils/get-is-valid.cjs.map +2 -2
- package/build/field-types/utils/is-valid-date-boundary.cjs +64 -0
- package/build/field-types/utils/is-valid-date-boundary.cjs.map +7 -0
- package/build/types/dataviews.cjs.map +1 -1
- package/build/types/field-api.cjs.map +1 -1
- package/build-module/components/dataform-controls/array.mjs +2 -0
- package/build-module/components/dataform-controls/array.mjs.map +2 -2
- package/build-module/components/dataform-controls/checkbox.mjs +3 -1
- package/build-module/components/dataform-controls/checkbox.mjs.map +2 -2
- package/build-module/components/dataform-controls/color.mjs +8 -2
- package/build-module/components/dataform-controls/color.mjs.map +2 -2
- package/build-module/components/dataform-controls/date.mjs +31 -9
- package/build-module/components/dataform-controls/date.mjs.map +2 -2
- package/build-module/components/dataform-controls/datetime.mjs +9 -2
- package/build-module/components/dataform-controls/datetime.mjs.map +2 -2
- package/build-module/components/dataform-controls/password.mjs +4 -1
- package/build-module/components/dataform-controls/password.mjs.map +2 -2
- package/build-module/components/dataform-controls/radio.mjs +3 -1
- package/build-module/components/dataform-controls/radio.mjs.map +2 -2
- package/build-module/components/dataform-controls/select.mjs +3 -1
- package/build-module/components/dataform-controls/select.mjs.map +2 -2
- package/build-module/components/dataform-controls/textarea.mjs +2 -0
- package/build-module/components/dataform-controls/textarea.mjs.map +2 -2
- package/build-module/components/dataform-controls/toggle-group.mjs +3 -1
- package/build-module/components/dataform-controls/toggle-group.mjs.map +2 -2
- package/build-module/components/dataform-controls/toggle.mjs +3 -1
- package/build-module/components/dataform-controls/toggle.mjs.map +2 -2
- package/build-module/components/dataform-controls/utils/relative-date-control.mjs +5 -2
- package/build-module/components/dataform-controls/utils/relative-date-control.mjs.map +2 -2
- package/build-module/components/dataform-controls/utils/use-disabled-date-matchers.mjs +27 -0
- package/build-module/components/dataform-controls/utils/use-disabled-date-matchers.mjs.map +7 -0
- package/build-module/components/dataform-controls/utils/validated-input.mjs +2 -0
- package/build-module/components/dataform-controls/utils/validated-input.mjs.map +2 -2
- package/build-module/components/dataform-controls/utils/validated-number.mjs +3 -1
- package/build-module/components/dataform-controls/utils/validated-number.mjs.map +2 -2
- package/build-module/components/dataform-layouts/panel/summary-button.mjs +0 -1
- package/build-module/components/dataform-layouts/panel/summary-button.mjs.map +2 -2
- package/build-module/components/dataviews-context/index.mjs.map +1 -1
- package/build-module/components/dataviews-filters/input-widget.mjs +4 -0
- package/build-module/components/dataviews-filters/input-widget.mjs.map +2 -2
- package/build-module/components/dataviews-layouts/picker-grid/index.mjs +1 -4
- package/build-module/components/dataviews-layouts/picker-grid/index.mjs.map +2 -2
- package/build-module/components/dataviews-layouts/picker-table/index.mjs +15 -12
- package/build-module/components/dataviews-layouts/picker-table/index.mjs.map +2 -2
- package/build-module/components/dataviews-layouts/table/index.mjs +0 -1
- package/build-module/components/dataviews-layouts/table/index.mjs.map +2 -2
- package/build-module/components/dataviews-pagination/index.mjs +1 -0
- package/build-module/components/dataviews-pagination/index.mjs.map +2 -2
- package/build-module/dataviews/index.mjs +10 -8
- package/build-module/dataviews/index.mjs.map +2 -2
- package/build-module/dataviews-picker/index.mjs +16 -9
- package/build-module/dataviews-picker/index.mjs.map +2 -2
- package/build-module/field-types/date.mjs +4 -1
- package/build-module/field-types/date.mjs.map +2 -2
- package/build-module/field-types/datetime.mjs +4 -1
- package/build-module/field-types/datetime.mjs.map +2 -2
- package/build-module/field-types/index.mjs +1 -0
- package/build-module/field-types/index.mjs.map +2 -2
- package/build-module/field-types/utils/get-is-valid.mjs +29 -24
- package/build-module/field-types/utils/get-is-valid.mjs.map +2 -2
- package/build-module/field-types/utils/is-valid-date-boundary.mjs +38 -0
- package/build-module/field-types/utils/is-valid-date-boundary.mjs.map +7 -0
- package/build-style/style-rtl.css +14 -15
- package/build-style/style.css +14 -15
- package/build-types/components/dataform-controls/array.d.ts.map +1 -1
- package/build-types/components/dataform-controls/checkbox.d.ts.map +1 -1
- package/build-types/components/dataform-controls/color.d.ts.map +1 -1
- package/build-types/components/dataform-controls/date.d.ts.map +1 -1
- package/build-types/components/dataform-controls/datetime.d.ts.map +1 -1
- package/build-types/components/dataform-controls/password.d.ts.map +1 -1
- package/build-types/components/dataform-controls/radio.d.ts.map +1 -1
- package/build-types/components/dataform-controls/select.d.ts.map +1 -1
- package/build-types/components/dataform-controls/textarea.d.ts.map +1 -1
- package/build-types/components/dataform-controls/toggle-group.d.ts.map +1 -1
- package/build-types/components/dataform-controls/toggle.d.ts.map +1 -1
- package/build-types/components/dataform-controls/utils/relative-date-control.d.ts.map +1 -1
- package/build-types/components/dataform-controls/utils/use-disabled-date-matchers.d.ts +16 -0
- package/build-types/components/dataform-controls/utils/use-disabled-date-matchers.d.ts.map +1 -0
- package/build-types/components/dataform-controls/utils/validated-input.d.ts.map +1 -1
- package/build-types/components/dataform-controls/utils/validated-number.d.ts.map +1 -1
- package/build-types/components/dataform-layouts/panel/summary-button.d.ts.map +1 -1
- package/build-types/components/dataviews-context/index.d.ts +2 -2
- package/build-types/components/dataviews-context/index.d.ts.map +1 -1
- package/build-types/components/dataviews-filters/input-widget.d.ts.map +1 -1
- package/build-types/components/dataviews-layouts/index.d.ts +6 -6
- package/build-types/components/dataviews-layouts/picker-grid/index.d.ts.map +1 -1
- package/build-types/components/dataviews-layouts/picker-table/index.d.ts.map +1 -1
- package/build-types/components/dataviews-layouts/table/index.d.ts.map +1 -1
- package/build-types/components/dataviews-pagination/index.d.ts.map +1 -1
- package/build-types/components/dataviews-search/index.d.ts +1 -1
- package/build-types/components/dataviews-search/index.d.ts.map +1 -1
- package/build-types/constants.d.ts +2 -2
- package/build-types/dataform/stories/index.story.d.ts +11 -1
- package/build-types/dataform/stories/index.story.d.ts.map +1 -1
- package/build-types/dataform/stories/layout-regular.d.ts +2 -1
- package/build-types/dataform/stories/layout-regular.d.ts.map +1 -1
- package/build-types/dataform/stories/validation.d.ts.map +1 -1
- package/build-types/dataviews/index.d.ts +1 -1
- package/build-types/dataviews/index.d.ts.map +1 -1
- package/build-types/dataviews-picker/index.d.ts +3 -2
- package/build-types/dataviews-picker/index.d.ts.map +1 -1
- package/build-types/dataviews-picker/stories/index.story.d.ts.map +1 -1
- package/build-types/field-types/array.d.ts +1 -1
- package/build-types/field-types/array.d.ts.map +1 -1
- package/build-types/field-types/boolean.d.ts +1 -1
- package/build-types/field-types/boolean.d.ts.map +1 -1
- package/build-types/field-types/color.d.ts +1 -1
- package/build-types/field-types/color.d.ts.map +1 -1
- package/build-types/field-types/date.d.ts +3 -0
- package/build-types/field-types/date.d.ts.map +1 -1
- package/build-types/field-types/datetime.d.ts +3 -0
- package/build-types/field-types/datetime.d.ts.map +1 -1
- package/build-types/field-types/email.d.ts +1 -1
- package/build-types/field-types/email.d.ts.map +1 -1
- package/build-types/field-types/index.d.ts.map +1 -1
- package/build-types/field-types/integer.d.ts +1 -1
- package/build-types/field-types/integer.d.ts.map +1 -1
- package/build-types/field-types/number.d.ts +1 -1
- package/build-types/field-types/number.d.ts.map +1 -1
- package/build-types/field-types/stories/index.story.d.ts +37 -15
- package/build-types/field-types/stories/index.story.d.ts.map +1 -1
- package/build-types/field-types/utils/get-is-valid.d.ts.map +1 -1
- package/build-types/field-types/utils/is-valid-date-boundary.d.ts +7 -0
- package/build-types/field-types/utils/is-valid-date-boundary.d.ts.map +1 -0
- package/build-types/types/dataviews.d.ts +8 -0
- package/build-types/types/dataviews.d.ts.map +1 -1
- package/build-types/types/field-api.d.ts +24 -9
- package/build-types/types/field-api.d.ts.map +1 -1
- package/build-wp/index.js +1141 -990
- package/package.json +16 -16
- package/src/components/dataform-controls/array.tsx +2 -0
- package/src/components/dataform-controls/checkbox.tsx +2 -0
- package/src/components/dataform-controls/color.tsx +7 -0
- package/src/components/dataform-controls/date.tsx +30 -4
- package/src/components/dataform-controls/datetime.tsx +17 -0
- package/src/components/dataform-controls/password.tsx +3 -0
- package/src/components/dataform-controls/radio.tsx +2 -0
- package/src/components/dataform-controls/select.tsx +2 -0
- package/src/components/dataform-controls/textarea.tsx +2 -0
- package/src/components/dataform-controls/toggle-group.tsx +2 -0
- package/src/components/dataform-controls/toggle.tsx +2 -0
- package/src/components/dataform-controls/utils/relative-date-control.tsx +3 -0
- package/src/components/dataform-controls/utils/use-disabled-date-matchers.ts +48 -0
- package/src/components/dataform-controls/utils/validated-input.tsx +2 -0
- package/src/components/dataform-controls/utils/validated-number.tsx +2 -0
- package/src/components/dataform-layouts/panel/style.scss +4 -5
- package/src/components/dataform-layouts/panel/summary-button.tsx +0 -1
- package/src/components/dataviews-context/index.ts +2 -2
- package/src/components/dataviews-filters/input-widget.tsx +4 -0
- package/src/components/dataviews-filters/style.scss +2 -2
- package/src/components/dataviews-layouts/activity/style.scss +3 -3
- package/src/components/dataviews-layouts/grid/style.scss +1 -1
- package/src/components/dataviews-layouts/list/style.scss +1 -1
- package/src/components/dataviews-layouts/picker-grid/index.tsx +2 -6
- package/src/components/dataviews-layouts/picker-grid/style.scss +1 -1
- package/src/components/dataviews-layouts/picker-table/index.tsx +9 -7
- package/src/components/dataviews-layouts/picker-table/style.scss +1 -1
- package/src/components/dataviews-layouts/table/index.tsx +0 -2
- package/src/components/dataviews-pagination/index.tsx +1 -0
- package/src/dataform/stories/content.story.tsx +1 -1
- package/src/dataform/stories/data-adapter.tsx +6 -6
- package/src/dataform/stories/index.story.tsx +7 -0
- package/src/dataform/stories/layout-card.tsx +5 -5
- package/src/dataform/stories/layout-details.tsx +5 -5
- package/src/dataform/stories/layout-panel.tsx +9 -9
- package/src/dataform/stories/layout-regular.tsx +31 -10
- package/src/dataform/stories/layout-row.tsx +9 -9
- package/src/dataform/stories/validation.tsx +25 -10
- package/src/dataviews/index.tsx +11 -7
- package/src/dataviews/stories/empty.tsx +4 -4
- package/src/dataviews/stories/free-composition.tsx +2 -2
- package/src/dataviews/stories/infinite-scroll.tsx +4 -4
- package/src/dataviews/stories/layout-custom.tsx +1 -1
- package/src/dataviews/stories/layout-grid.tsx +1 -1
- package/src/dataviews/stories/layout-list.tsx +1 -1
- package/src/dataviews/stories/layout-table.tsx +1 -1
- package/src/dataviews/stories/minimal-ui.tsx +1 -1
- package/src/dataviews/stories/with-card.tsx +4 -4
- package/src/dataviews/style.scss +1 -1
- package/src/dataviews/test/dataviews.tsx +73 -6
- package/src/dataviews-picker/index.tsx +17 -7
- package/src/dataviews-picker/stories/index.story.tsx +1 -5
- package/src/dataviews-picker/test/dataviews-picker.tsx +79 -2
- package/src/field-types/date.tsx +3 -0
- package/src/field-types/datetime.tsx +3 -0
- package/src/field-types/index.tsx +4 -0
- package/src/field-types/stories/index.story.tsx +67 -6
- package/src/field-types/test/normalize-fields.ts +44 -0
- package/src/field-types/utils/get-is-valid.ts +44 -31
- package/src/field-types/utils/is-valid-date-boundary.ts +80 -0
- package/src/hooks/test/use-form-validity.ts +479 -0
- package/src/types/dataviews.ts +9 -0
- package/src/types/field-api.ts +27 -9
package/src/dataviews/index.tsx
CHANGED
|
@@ -57,7 +57,7 @@ type DataViewsProps< Item > = {
|
|
|
57
57
|
totalItems: number;
|
|
58
58
|
totalPages: number;
|
|
59
59
|
};
|
|
60
|
-
defaultLayouts
|
|
60
|
+
defaultLayouts?: SupportedLayouts;
|
|
61
61
|
selection?: string[];
|
|
62
62
|
onChangeSelection?: ( items: string[] ) => void;
|
|
63
63
|
onClickItem?: ( item: Item ) => void;
|
|
@@ -82,6 +82,7 @@ type DataViewsProps< Item > = {
|
|
|
82
82
|
const defaultGetItemId = ( item: ItemWithId ) => item.id;
|
|
83
83
|
const defaultIsItemClickable = () => true;
|
|
84
84
|
const EMPTY_ARRAY: any[] = [];
|
|
85
|
+
const DEFAULT_LAYOUTS: SupportedLayouts = { table: {}, grid: {}, list: {} };
|
|
85
86
|
|
|
86
87
|
const dataViewsLayouts = VIEW_LAYOUTS.filter(
|
|
87
88
|
( viewLayout ) => ! viewLayout.isPicker
|
|
@@ -144,7 +145,7 @@ function DataViews< Item >( {
|
|
|
144
145
|
getItemLevel,
|
|
145
146
|
isLoading = false,
|
|
146
147
|
paginationInfo,
|
|
147
|
-
defaultLayouts: defaultLayoutsProperty,
|
|
148
|
+
defaultLayouts: defaultLayoutsProperty = DEFAULT_LAYOUTS,
|
|
148
149
|
selection: selectionProperty,
|
|
149
150
|
onChangeSelection,
|
|
150
151
|
onClickItem,
|
|
@@ -241,17 +242,20 @@ function DataViews< Item >( {
|
|
|
241
242
|
}
|
|
242
243
|
}, [ hasPrimaryOrLockedFilters, isShowingFilter ] );
|
|
243
244
|
|
|
244
|
-
// Filter out DataViewsPicker layouts
|
|
245
|
+
// Filter out DataViewsPicker layouts and normalize `true` to `{}`.
|
|
245
246
|
const defaultLayouts = useMemo(
|
|
246
247
|
() =>
|
|
247
248
|
Object.fromEntries(
|
|
248
|
-
Object.entries( defaultLayoutsProperty )
|
|
249
|
-
( [ layoutType ] ) => {
|
|
249
|
+
Object.entries( defaultLayoutsProperty )
|
|
250
|
+
.filter( ( [ layoutType ] ) => {
|
|
250
251
|
return dataViewsLayouts.some(
|
|
251
252
|
( viewLayout ) => viewLayout.type === layoutType
|
|
252
253
|
);
|
|
253
|
-
}
|
|
254
|
-
|
|
254
|
+
} )
|
|
255
|
+
.map( ( [ key, value ] ) => [
|
|
256
|
+
key,
|
|
257
|
+
value === true ? {} : value,
|
|
258
|
+
] )
|
|
255
259
|
),
|
|
256
260
|
[ defaultLayoutsProperty ]
|
|
257
261
|
);
|
|
@@ -79,10 +79,10 @@ const EmptyComponent = ( {
|
|
|
79
79
|
onChangeView={ setView }
|
|
80
80
|
actions={ actions }
|
|
81
81
|
defaultLayouts={ {
|
|
82
|
-
[ LAYOUT_TABLE ]:
|
|
83
|
-
[ LAYOUT_GRID ]:
|
|
84
|
-
[ LAYOUT_LIST ]:
|
|
85
|
-
[ LAYOUT_ACTIVITY ]:
|
|
82
|
+
[ LAYOUT_TABLE ]: true,
|
|
83
|
+
[ LAYOUT_GRID ]: true,
|
|
84
|
+
[ LAYOUT_LIST ]: true,
|
|
85
|
+
[ LAYOUT_ACTIVITY ]: true,
|
|
86
86
|
} }
|
|
87
87
|
isLoading={ isLoading }
|
|
88
88
|
empty={ customEmpty ? <CustomEmptyComponent /> : undefined }
|
|
@@ -50,10 +50,10 @@ const InfiniteScroll = () => {
|
|
|
50
50
|
onChangeView={ setView }
|
|
51
51
|
actions={ actions }
|
|
52
52
|
defaultLayouts={ {
|
|
53
|
-
[ LAYOUT_TABLE ]:
|
|
54
|
-
[ LAYOUT_GRID ]:
|
|
55
|
-
[ LAYOUT_LIST ]:
|
|
56
|
-
[ LAYOUT_ACTIVITY ]:
|
|
53
|
+
[ LAYOUT_TABLE ]: true,
|
|
54
|
+
[ LAYOUT_GRID ]: true,
|
|
55
|
+
[ LAYOUT_LIST ]: true,
|
|
56
|
+
[ LAYOUT_ACTIVITY ]: true,
|
|
57
57
|
} }
|
|
58
58
|
/>
|
|
59
59
|
</>
|
|
@@ -130,7 +130,7 @@ export const LayoutCustomComponent = ( {
|
|
|
130
130
|
view={ view }
|
|
131
131
|
fields={ fields }
|
|
132
132
|
onChangeView={ setView }
|
|
133
|
-
defaultLayouts={ { table:
|
|
133
|
+
defaultLayouts={ { table: true } }
|
|
134
134
|
>
|
|
135
135
|
<div style={ { padding: '2px', height: containerHeight } }>
|
|
136
136
|
<DataViews.Search />
|
|
@@ -59,10 +59,10 @@ const WithCardComponent = ( {
|
|
|
59
59
|
( action ) => ! action.supportsBulk
|
|
60
60
|
) }
|
|
61
61
|
defaultLayouts={ {
|
|
62
|
-
[ LAYOUT_TABLE ]:
|
|
63
|
-
[ LAYOUT_GRID ]:
|
|
64
|
-
[ LAYOUT_LIST ]:
|
|
65
|
-
[ LAYOUT_ACTIVITY ]:
|
|
62
|
+
[ LAYOUT_TABLE ]: true,
|
|
63
|
+
[ LAYOUT_GRID ]: true,
|
|
64
|
+
[ LAYOUT_LIST ]: true,
|
|
65
|
+
[ LAYOUT_ACTIVITY ]: true,
|
|
66
66
|
} }
|
|
67
67
|
/>
|
|
68
68
|
</Card.FullBleed>
|
package/src/dataviews/style.scss
CHANGED
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
LAYOUT_LIST,
|
|
20
20
|
LAYOUT_TABLE,
|
|
21
21
|
} from '../../constants';
|
|
22
|
-
import type { Action, View } from '../../types';
|
|
22
|
+
import type { Action, SupportedLayouts, View } from '../../types';
|
|
23
23
|
import filterSortAndPaginate from '../../utils/filter-sort-and-paginate';
|
|
24
24
|
|
|
25
25
|
type Data = {
|
|
@@ -38,11 +38,11 @@ const DEFAULT_VIEW = {
|
|
|
38
38
|
filters: [],
|
|
39
39
|
};
|
|
40
40
|
|
|
41
|
-
const defaultLayouts = {
|
|
42
|
-
[ LAYOUT_TABLE ]:
|
|
43
|
-
[ LAYOUT_GRID ]:
|
|
44
|
-
[ LAYOUT_LIST ]:
|
|
45
|
-
[ LAYOUT_ACTIVITY ]:
|
|
41
|
+
const defaultLayouts: SupportedLayouts = {
|
|
42
|
+
[ LAYOUT_TABLE ]: true,
|
|
43
|
+
[ LAYOUT_GRID ]: true,
|
|
44
|
+
[ LAYOUT_LIST ]: true,
|
|
45
|
+
[ LAYOUT_ACTIVITY ]: true,
|
|
46
46
|
};
|
|
47
47
|
|
|
48
48
|
const fields = [
|
|
@@ -737,4 +737,71 @@ describe( 'DataViews component', () => {
|
|
|
737
737
|
).toEqual( 3 );
|
|
738
738
|
} );
|
|
739
739
|
} );
|
|
740
|
+
describe( 'Default layouts', () => {
|
|
741
|
+
/**
|
|
742
|
+
* A minimal wrapper that intentionally omits the `defaultLayouts` prop so
|
|
743
|
+
* DataViews falls back to its internal DEFAULT_LAYOUTS constant
|
|
744
|
+
* ({ table: true, grid: true, list: true }).
|
|
745
|
+
*/
|
|
746
|
+
function DataViewWrapperWithoutDefaultLayouts() {
|
|
747
|
+
const [ view, setView ] = useState< View >( {
|
|
748
|
+
...DEFAULT_VIEW,
|
|
749
|
+
fields: [ 'title', 'order', 'author' ],
|
|
750
|
+
} );
|
|
751
|
+
|
|
752
|
+
const { data: shownData, paginationInfo } = useMemo( () => {
|
|
753
|
+
return filterSortAndPaginate( data, view, fields );
|
|
754
|
+
}, [ view ] );
|
|
755
|
+
|
|
756
|
+
return (
|
|
757
|
+
<DataViews
|
|
758
|
+
getItemId={ ( item: Data ) => item.id.toString() }
|
|
759
|
+
paginationInfo={ paginationInfo }
|
|
760
|
+
data={ shownData }
|
|
761
|
+
view={ view }
|
|
762
|
+
fields={ fields }
|
|
763
|
+
onChangeView={ setView }
|
|
764
|
+
// No `defaultLayouts` prop — falls back to DEFAULT_LAYOUTS
|
|
765
|
+
/>
|
|
766
|
+
);
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
it( 'renders Table, Grid, and List layout options when defaultLayouts is not provided', async () => {
|
|
770
|
+
render( <DataViewWrapperWithoutDefaultLayouts /> );
|
|
771
|
+
|
|
772
|
+
const user = userEvent.setup();
|
|
773
|
+
|
|
774
|
+
// All three default layouts are available, so the Layout switcher
|
|
775
|
+
// button (rendered by ViewTypeMenu) must be present.
|
|
776
|
+
const layoutButton = screen.getByRole( 'button', {
|
|
777
|
+
name: 'Layout',
|
|
778
|
+
} );
|
|
779
|
+
expect( layoutButton ).toBeInTheDocument();
|
|
780
|
+
|
|
781
|
+
// Open the layout menu.
|
|
782
|
+
await user.click( layoutButton );
|
|
783
|
+
|
|
784
|
+
// Table, Grid, and List options must all appear.
|
|
785
|
+
expect(
|
|
786
|
+
screen.getByRole( 'menuitemradio', { name: 'Table' } )
|
|
787
|
+
).toBeInTheDocument();
|
|
788
|
+
expect(
|
|
789
|
+
screen.getByRole( 'menuitemradio', { name: 'Grid' } )
|
|
790
|
+
).toBeInTheDocument();
|
|
791
|
+
expect(
|
|
792
|
+
screen.getByRole( 'menuitemradio', { name: 'List' } )
|
|
793
|
+
).toBeInTheDocument();
|
|
794
|
+
|
|
795
|
+
// Table is the default active layout.
|
|
796
|
+
expect(
|
|
797
|
+
screen.getByRole( 'menuitemradio', { name: 'Table' } )
|
|
798
|
+
).toBeChecked();
|
|
799
|
+
expect(
|
|
800
|
+
screen.getByRole( 'menuitemradio', { name: 'Grid' } )
|
|
801
|
+
).not.toBeChecked();
|
|
802
|
+
expect(
|
|
803
|
+
screen.getByRole( 'menuitemradio', { name: 'List' } )
|
|
804
|
+
).not.toBeChecked();
|
|
805
|
+
} );
|
|
806
|
+
} );
|
|
740
807
|
} );
|
|
@@ -62,7 +62,7 @@ type DataViewsPickerProps< Item > = {
|
|
|
62
62
|
totalItems: number;
|
|
63
63
|
totalPages: number;
|
|
64
64
|
};
|
|
65
|
-
defaultLayouts
|
|
65
|
+
defaultLayouts?: SupportedLayouts;
|
|
66
66
|
selection: string[];
|
|
67
67
|
onChangeSelection: ( items: string[] ) => void;
|
|
68
68
|
children?: ReactNode;
|
|
@@ -71,12 +71,17 @@ type DataViewsPickerProps< Item > = {
|
|
|
71
71
|
};
|
|
72
72
|
itemListLabel?: string;
|
|
73
73
|
empty?: ReactNode;
|
|
74
|
+
onReset?: ( () => void ) | false;
|
|
74
75
|
} & ( Item extends ItemWithId
|
|
75
76
|
? { getItemId?: ( item: Item ) => string }
|
|
76
77
|
: { getItemId: ( item: Item ) => string } );
|
|
77
78
|
|
|
78
79
|
const defaultGetItemId = ( item: ItemWithId ) => item.id;
|
|
79
80
|
const EMPTY_ARRAY: any[] = [];
|
|
81
|
+
const DEFAULT_PICKER_LAYOUTS: SupportedLayouts = {
|
|
82
|
+
pickerGrid: true,
|
|
83
|
+
pickerTable: true,
|
|
84
|
+
};
|
|
80
85
|
|
|
81
86
|
type DefaultUIProps = Pick<
|
|
82
87
|
DataViewsPickerProps< any >,
|
|
@@ -132,13 +137,14 @@ function DataViewsPicker< Item >( {
|
|
|
132
137
|
getItemId = defaultGetItemId,
|
|
133
138
|
isLoading = false,
|
|
134
139
|
paginationInfo,
|
|
135
|
-
defaultLayouts: defaultLayoutsProperty,
|
|
140
|
+
defaultLayouts: defaultLayoutsProperty = DEFAULT_PICKER_LAYOUTS,
|
|
136
141
|
selection,
|
|
137
142
|
onChangeSelection,
|
|
138
143
|
children,
|
|
139
144
|
config = { perPageSizes: [ 10, 20, 50, 100 ] },
|
|
140
145
|
itemListLabel,
|
|
141
146
|
empty,
|
|
147
|
+
onReset,
|
|
142
148
|
}: DataViewsPickerProps< Item > ) {
|
|
143
149
|
// useData ensures data loading is correct whether infinite scroll is enabled or pagination is used.
|
|
144
150
|
const { data: displayData, setVisibleEntries } = useData( {
|
|
@@ -198,17 +204,20 @@ function DataViewsPicker< Item >( {
|
|
|
198
204
|
}
|
|
199
205
|
}, [ hasPrimaryOrLockedFilters, isShowingFilter ] );
|
|
200
206
|
|
|
201
|
-
// Filter out
|
|
207
|
+
// Filter out non-picker layouts and normalize `true` to `{}`.
|
|
202
208
|
const defaultLayouts = useMemo(
|
|
203
209
|
() =>
|
|
204
210
|
Object.fromEntries(
|
|
205
|
-
Object.entries( defaultLayoutsProperty )
|
|
206
|
-
( [ layoutType ] ) => {
|
|
211
|
+
Object.entries( defaultLayoutsProperty )
|
|
212
|
+
.filter( ( [ layoutType ] ) => {
|
|
207
213
|
return dataViewsPickerLayouts.some(
|
|
208
214
|
( viewLayout ) => viewLayout.type === layoutType
|
|
209
215
|
);
|
|
210
|
-
}
|
|
211
|
-
|
|
216
|
+
} )
|
|
217
|
+
.map( ( [ key, value ] ) => [
|
|
218
|
+
key,
|
|
219
|
+
value === true ? {} : value,
|
|
220
|
+
] )
|
|
212
221
|
),
|
|
213
222
|
[ defaultLayoutsProperty ]
|
|
214
223
|
);
|
|
@@ -243,6 +252,7 @@ function DataViewsPicker< Item >( {
|
|
|
243
252
|
config,
|
|
244
253
|
itemListLabel,
|
|
245
254
|
empty,
|
|
255
|
+
onReset,
|
|
246
256
|
hasInitiallyLoaded: true,
|
|
247
257
|
intersectionObserver,
|
|
248
258
|
} }
|
|
@@ -14,7 +14,7 @@ import { Stack } from '@wordpress/ui';
|
|
|
14
14
|
* Internal dependencies
|
|
15
15
|
*/
|
|
16
16
|
import DataViewsPicker from '../index';
|
|
17
|
-
import { LAYOUT_PICKER_GRID
|
|
17
|
+
import { LAYOUT_PICKER_GRID } from '../../constants';
|
|
18
18
|
import filterSortAndPaginate from '../../utils/filter-sort-and-paginate';
|
|
19
19
|
import type { ActionButton, View } from '../../types';
|
|
20
20
|
import { data, fields, type SpaceObject } from './fixtures';
|
|
@@ -187,10 +187,6 @@ const DataViewsPickerContent = ( {
|
|
|
187
187
|
onChangeView={ setView }
|
|
188
188
|
config={ { perPageSizes } }
|
|
189
189
|
itemListLabel="Galactic Bodies"
|
|
190
|
-
defaultLayouts={ {
|
|
191
|
-
[ LAYOUT_PICKER_GRID ]: {},
|
|
192
|
-
[ LAYOUT_PICKER_TABLE ]: {},
|
|
193
|
-
} }
|
|
194
190
|
/>
|
|
195
191
|
</>
|
|
196
192
|
);
|
|
@@ -14,7 +14,12 @@ import { useMemo, useState } from '@wordpress/element';
|
|
|
14
14
|
*/
|
|
15
15
|
import DataViewsPicker from '../index';
|
|
16
16
|
import { LAYOUT_PICKER_GRID } from '../../constants';
|
|
17
|
-
import type {
|
|
17
|
+
import type {
|
|
18
|
+
ActionButton,
|
|
19
|
+
SupportedLayouts,
|
|
20
|
+
View,
|
|
21
|
+
ViewPickerGrid,
|
|
22
|
+
} from '../../types';
|
|
18
23
|
import filterSortAndPaginate from '../../utils/filter-sort-and-paginate';
|
|
19
24
|
|
|
20
25
|
type Data = {
|
|
@@ -107,7 +112,7 @@ function Picker( {
|
|
|
107
112
|
paginationInfo,
|
|
108
113
|
data: shownData,
|
|
109
114
|
view,
|
|
110
|
-
defaultLayouts: { [ LAYOUT_PICKER_GRID ]:
|
|
115
|
+
defaultLayouts: { [ LAYOUT_PICKER_GRID ]: true } as SupportedLayouts,
|
|
111
116
|
fields: [],
|
|
112
117
|
onChangeView: setView,
|
|
113
118
|
multiselect,
|
|
@@ -475,4 +480,76 @@ describe( 'DataViews Picker', () => {
|
|
|
475
480
|
} );
|
|
476
481
|
} );
|
|
477
482
|
} );
|
|
483
|
+
|
|
484
|
+
describe( 'Default layouts', () => {
|
|
485
|
+
/**
|
|
486
|
+
* A minimal Picker that intentionally omits the `defaultLayouts` prop so
|
|
487
|
+
* that DataViewsPicker falls back to its internal DEFAULT_PICKER_LAYOUTS
|
|
488
|
+
* constant ({ pickerGrid: true, pickerTable: true }).
|
|
489
|
+
*/
|
|
490
|
+
function PickerWithoutDefaultLayouts() {
|
|
491
|
+
const [ view, setView ] = useState< View >( {
|
|
492
|
+
type: LAYOUT_PICKER_GRID,
|
|
493
|
+
fields: [],
|
|
494
|
+
titleField: 'title',
|
|
495
|
+
mediaField: 'image',
|
|
496
|
+
search: '',
|
|
497
|
+
page: 1,
|
|
498
|
+
perPage: 10,
|
|
499
|
+
filters: [],
|
|
500
|
+
} satisfies ViewPickerGrid );
|
|
501
|
+
|
|
502
|
+
const [ selection, setSelection ] = useState< string[] >( [] );
|
|
503
|
+
|
|
504
|
+
const { data: shownData, paginationInfo } = useMemo( () => {
|
|
505
|
+
return filterSortAndPaginate( data, view, [] );
|
|
506
|
+
}, [ view ] );
|
|
507
|
+
|
|
508
|
+
return (
|
|
509
|
+
<DataViewsPicker
|
|
510
|
+
getItemId={ ( item: Data ) => item.id.toString() }
|
|
511
|
+
paginationInfo={ paginationInfo }
|
|
512
|
+
data={ shownData }
|
|
513
|
+
view={ view }
|
|
514
|
+
fields={ [] }
|
|
515
|
+
onChangeView={ setView }
|
|
516
|
+
selection={ selection }
|
|
517
|
+
onChangeSelection={ setSelection }
|
|
518
|
+
// No `defaultLayouts` prop falls back to DEFAULT_PICKER_LAYOUTS
|
|
519
|
+
/>
|
|
520
|
+
);
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
it( 'renders both picker layout options when defaultLayouts is not provided', async () => {
|
|
524
|
+
render( <PickerWithoutDefaultLayouts /> );
|
|
525
|
+
|
|
526
|
+
const user = userEvent.setup();
|
|
527
|
+
|
|
528
|
+
// Both picker layouts are available, so the Layout switcher button
|
|
529
|
+
// (rendered by ViewTypeMenu) must be present.
|
|
530
|
+
const layoutButton = screen.getByRole( 'button', {
|
|
531
|
+
name: 'Layout',
|
|
532
|
+
} );
|
|
533
|
+
expect( layoutButton ).toBeInTheDocument();
|
|
534
|
+
|
|
535
|
+
// Open the layout menu.
|
|
536
|
+
await user.click( layoutButton );
|
|
537
|
+
|
|
538
|
+
// Both "Grid" and "Table" picker layout options must appear in the menu.
|
|
539
|
+
expect(
|
|
540
|
+
screen.getByRole( 'menuitemradio', { name: 'Grid' } )
|
|
541
|
+
).toBeInTheDocument();
|
|
542
|
+
expect(
|
|
543
|
+
screen.getByRole( 'menuitemradio', { name: 'Table' } )
|
|
544
|
+
).toBeInTheDocument();
|
|
545
|
+
|
|
546
|
+
// The grid layout is active by default.
|
|
547
|
+
expect(
|
|
548
|
+
screen.getByRole( 'menuitemradio', { name: 'Grid' } )
|
|
549
|
+
).toBeChecked();
|
|
550
|
+
expect(
|
|
551
|
+
screen.getByRole( 'menuitemradio', { name: 'Table' } )
|
|
552
|
+
).not.toBeChecked();
|
|
553
|
+
} );
|
|
554
|
+
} );
|
|
478
555
|
} );
|
package/src/field-types/date.tsx
CHANGED
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
OPERATOR_BETWEEN,
|
|
22
22
|
} from '../constants';
|
|
23
23
|
import isValidRequired from './utils/is-valid-required';
|
|
24
|
+
import { isValidMaxDate, isValidMinDate } from './utils/is-valid-date-boundary';
|
|
24
25
|
import render from './utils/render-default';
|
|
25
26
|
|
|
26
27
|
const format = {
|
|
@@ -91,5 +92,7 @@ export default {
|
|
|
91
92
|
validate: {
|
|
92
93
|
required: isValidRequired,
|
|
93
94
|
elements: isValidElements,
|
|
95
|
+
min: isValidMinDate,
|
|
96
|
+
max: isValidMaxDate,
|
|
94
97
|
},
|
|
95
98
|
} satisfies FieldType< any >;
|
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
OPERATOR_OVER,
|
|
21
21
|
} from '../constants';
|
|
22
22
|
import isValidRequired from './utils/is-valid-required';
|
|
23
|
+
import { isValidMaxDate, isValidMinDate } from './utils/is-valid-date-boundary';
|
|
23
24
|
import render from './utils/render-default';
|
|
24
25
|
|
|
25
26
|
const format = {
|
|
@@ -88,5 +89,7 @@ export default {
|
|
|
88
89
|
validate: {
|
|
89
90
|
required: isValidRequired,
|
|
90
91
|
elements: isValidElements,
|
|
92
|
+
min: isValidMinDate,
|
|
93
|
+
max: isValidMaxDate,
|
|
91
94
|
},
|
|
92
95
|
} satisfies FieldType< any >;
|
|
@@ -96,6 +96,10 @@ export default function normalizeFields< Item >(
|
|
|
96
96
|
getElements: field.getElements,
|
|
97
97
|
hasElements: hasElements( field ),
|
|
98
98
|
isVisible: field.isVisible,
|
|
99
|
+
isDisabled:
|
|
100
|
+
typeof field.isDisabled === 'function'
|
|
101
|
+
? field.isDisabled
|
|
102
|
+
: () => !! field.isDisabled,
|
|
99
103
|
enableHiding: field.enableHiding ?? true,
|
|
100
104
|
readOnly: field.readOnly ?? false,
|
|
101
105
|
// The type provides defaults for the following props
|