@wordpress/dataviews 2.2.0 → 4.0.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 +23 -0
- package/README.md +23 -8
- package/build/components/dataform/index.js +78 -0
- package/build/components/dataform/index.js.map +1 -0
- package/build/components/dataviews/index.js +115 -0
- package/build/components/dataviews/index.js.map +1 -0
- package/build/{bulk-actions.js → components/dataviews-bulk-actions/index.js} +39 -16
- package/build/components/dataviews-bulk-actions/index.js.map +1 -0
- package/build/{bulk-actions-toolbar.js → components/dataviews-bulk-actions-toolbar/index.js} +36 -20
- package/build/components/dataviews-bulk-actions-toolbar/index.js.map +1 -0
- package/build/components/dataviews-context/index.js +36 -0
- package/build/components/dataviews-context/index.js.map +1 -0
- package/build/{add-filter.js → components/dataviews-filters/add-filter.js} +3 -3
- package/build/components/dataviews-filters/add-filter.js.map +1 -0
- package/build/{filter-summary.js → components/dataviews-filters/filter-summary.js} +15 -14
- package/build/components/dataviews-filters/filter-summary.js.map +1 -0
- package/build/{filters.js → components/dataviews-filters/index.js} +15 -16
- package/build/components/dataviews-filters/index.js.map +1 -0
- package/build/{reset-filters.js → components/dataviews-filters/reset-filters.js} +1 -1
- package/build/components/dataviews-filters/reset-filters.js.map +1 -0
- package/build/{search-widget.js → components/dataviews-filters/search-widget.js} +21 -19
- package/build/components/dataviews-filters/search-widget.js.map +1 -0
- package/build/{item-actions.js → components/dataviews-item-actions/index.js} +3 -3
- package/build/components/dataviews-item-actions/index.js.map +1 -0
- package/build/components/dataviews-layout/index.js +53 -0
- package/build/components/dataviews-layout/index.js.map +1 -0
- package/build/{pagination.js → components/dataviews-pagination/index.js} +18 -15
- package/build/components/dataviews-pagination/index.js.map +1 -0
- package/build/{search.js → components/dataviews-search/index.js} +10 -6
- package/build/components/dataviews-search/index.js.map +1 -0
- package/build/components/dataviews-selection-checkbox/index.js +52 -0
- package/build/components/dataviews-selection-checkbox/index.js.map +1 -0
- package/build/{view-actions.js → components/dataviews-view-config/index.js} +94 -80
- package/build/components/dataviews-view-config/index.js.map +1 -0
- package/build/filter-and-sort-data-view.js +4 -1
- package/build/filter-and-sort-data-view.js.map +1 -1
- package/build/index.js +8 -1
- package/build/index.js.map +1 -1
- package/build/layouts/grid/density-picker.js +143 -0
- package/build/layouts/grid/density-picker.js.map +1 -0
- package/build/{view-grid.js → layouts/grid/index.js} +40 -53
- package/build/layouts/grid/index.js.map +1 -0
- package/build/layouts/index.js +52 -0
- package/build/layouts/index.js.map +1 -0
- package/build/{view-list.js → layouts/list/index.js} +31 -27
- package/build/layouts/list/index.js.map +1 -0
- package/build/layouts/table/column-header-menu.js +196 -0
- package/build/layouts/table/column-header-menu.js.map +1 -0
- package/build/layouts/table/index.js +350 -0
- package/build/layouts/table/index.js.map +1 -0
- package/build/normalize-fields.js +1 -1
- package/build/normalize-fields.js.map +1 -1
- package/build/private-types.js +6 -0
- package/build/private-types.js.map +1 -0
- package/build/types.js.map +1 -1
- package/build/utils.js.map +1 -1
- package/build-module/components/dataform/index.js +72 -0
- package/build-module/components/dataform/index.js.map +1 -0
- package/build-module/components/dataviews/index.js +108 -0
- package/build-module/components/dataviews/index.js.map +1 -0
- package/build-module/{bulk-actions.js → components/dataviews-bulk-actions/index.js} +39 -17
- package/build-module/components/dataviews-bulk-actions/index.js.map +1 -0
- package/build-module/{bulk-actions-toolbar.js → components/dataviews-bulk-actions-toolbar/index.js} +35 -20
- package/build-module/components/dataviews-bulk-actions-toolbar/index.js.map +1 -0
- package/build-module/components/dataviews-context/index.js +30 -0
- package/build-module/components/dataviews-context/index.js.map +1 -0
- package/build-module/{add-filter.js → components/dataviews-filters/add-filter.js} +3 -3
- package/build-module/components/dataviews-filters/add-filter.js.map +1 -0
- package/build-module/{filter-summary.js → components/dataviews-filters/filter-summary.js} +15 -14
- package/build-module/components/dataviews-filters/filter-summary.js.map +1 -0
- package/build-module/{filters.js → components/dataviews-filters/index.js} +16 -17
- package/build-module/components/dataviews-filters/index.js.map +1 -0
- package/build-module/{reset-filters.js → components/dataviews-filters/reset-filters.js} +1 -1
- package/build-module/components/dataviews-filters/reset-filters.js.map +1 -0
- package/build-module/{search-widget.js → components/dataviews-filters/search-widget.js} +21 -19
- package/build-module/components/dataviews-filters/search-widget.js.map +1 -0
- package/build-module/{item-actions.js → components/dataviews-item-actions/index.js} +3 -3
- package/build-module/components/dataviews-item-actions/index.js.map +1 -0
- package/build-module/components/dataviews-layout/index.js +45 -0
- package/build-module/components/dataviews-layout/index.js.map +1 -0
- package/build-module/{pagination.js → components/dataviews-pagination/index.js} +19 -17
- package/build-module/components/dataviews-pagination/index.js.map +1 -0
- package/build-module/{search.js → components/dataviews-search/index.js} +10 -7
- package/build-module/components/dataviews-search/index.js.map +1 -0
- package/build-module/components/dataviews-selection-checkbox/index.js +45 -0
- package/build-module/components/dataviews-selection-checkbox/index.js.map +1 -0
- package/build-module/{view-actions.js → components/dataviews-view-config/index.js} +98 -84
- package/build-module/components/dataviews-view-config/index.js.map +1 -0
- package/build-module/filter-and-sort-data-view.js +4 -1
- package/build-module/filter-and-sort-data-view.js.map +1 -1
- package/build-module/index.js +2 -1
- package/build-module/index.js.map +1 -1
- package/build-module/layouts/grid/density-picker.js +138 -0
- package/build-module/layouts/grid/density-picker.js.map +1 -0
- package/build-module/{view-grid.js → layouts/grid/index.js} +37 -50
- package/build-module/layouts/grid/index.js.map +1 -0
- package/build-module/layouts/index.js +43 -0
- package/build-module/layouts/index.js.map +1 -0
- package/build-module/{view-list.js → layouts/list/index.js} +29 -25
- package/build-module/layouts/list/index.js.map +1 -0
- package/build-module/layouts/table/column-header-menu.js +190 -0
- package/build-module/layouts/table/column-header-menu.js.map +1 -0
- package/build-module/layouts/table/index.js +344 -0
- package/build-module/layouts/table/index.js.map +1 -0
- package/build-module/normalize-fields.js +1 -1
- package/build-module/normalize-fields.js.map +1 -1
- package/build-module/private-types.js +2 -0
- package/build-module/private-types.js.map +1 -0
- package/build-module/types.js.map +1 -1
- package/build-module/utils.js.map +1 -1
- package/build-style/style-rtl.css +607 -561
- package/build-style/style.css +607 -561
- package/build-types/components/dataform/index.d.ts +17 -0
- package/build-types/components/dataform/index.d.ts.map +1 -0
- package/build-types/components/dataform/stories/index.story.d.ts +11 -0
- package/build-types/components/dataform/stories/index.story.d.ts.map +1 -0
- package/build-types/components/dataviews/index.d.ts +33 -0
- package/build-types/components/dataviews/index.d.ts.map +1 -0
- package/build-types/{stories → components/dataviews/stories}/fixtures.d.ts +18 -17
- package/build-types/components/dataviews/stories/fixtures.d.ts.map +1 -0
- package/build-types/components/dataviews/stories/index.story.d.ts +46 -0
- package/build-types/components/dataviews/stories/index.story.d.ts.map +1 -0
- package/build-types/components/dataviews-bulk-actions/index.d.ts +5 -0
- package/build-types/components/dataviews-bulk-actions/index.d.ts.map +1 -0
- package/build-types/components/dataviews-bulk-actions-toolbar/index.d.ts +2 -0
- package/build-types/components/dataviews-bulk-actions-toolbar/index.d.ts.map +1 -0
- package/build-types/components/dataviews-context/index.d.ts +26 -0
- package/build-types/components/dataviews-context/index.d.ts.map +1 -0
- package/build-types/{add-filter.d.ts → components/dataviews-filters/add-filter.d.ts} +1 -2
- package/build-types/components/dataviews-filters/add-filter.d.ts.map +1 -0
- package/build-types/{filter-summary.d.ts → components/dataviews-filters/filter-summary.d.ts} +1 -1
- package/build-types/components/dataviews-filters/filter-summary.d.ts.map +1 -0
- package/build-types/components/dataviews-filters/index.d.ts +4 -0
- package/build-types/components/dataviews-filters/index.d.ts.map +1 -0
- package/build-types/{reset-filters.d.ts → components/dataviews-filters/reset-filters.d.ts} +1 -2
- package/build-types/components/dataviews-filters/reset-filters.d.ts.map +1 -0
- package/build-types/{search-widget.d.ts → components/dataviews-filters/search-widget.d.ts} +1 -2
- package/build-types/components/dataviews-filters/search-widget.d.ts.map +1 -0
- package/build-types/components/dataviews-item-actions/index.d.ts +35 -0
- package/build-types/components/dataviews-item-actions/index.d.ts.map +1 -0
- package/build-types/components/dataviews-layout/index.d.ts +2 -0
- package/build-types/components/dataviews-layout/index.d.ts.map +1 -0
- package/build-types/components/dataviews-pagination/index.d.ts +4 -0
- package/build-types/components/dataviews-pagination/index.d.ts.map +1 -0
- package/build-types/components/dataviews-search/index.d.ts +6 -0
- package/build-types/components/dataviews-search/index.d.ts.map +1 -0
- package/build-types/components/dataviews-selection-checkbox/index.d.ts +16 -0
- package/build-types/components/dataviews-selection-checkbox/index.d.ts.map +1 -0
- package/build-types/components/dataviews-view-config/index.d.ts +8 -0
- package/build-types/components/dataviews-view-config/index.d.ts.map +1 -0
- package/build-types/filter-and-sort-data-view.d.ts +2 -2
- package/build-types/filter-and-sort-data-view.d.ts.map +1 -1
- package/build-types/index.d.ts +2 -1
- package/build-types/index.d.ts.map +1 -1
- package/build-types/layouts/grid/density-picker.d.ts +5 -0
- package/build-types/layouts/grid/density-picker.d.ts.map +1 -0
- package/build-types/layouts/grid/index.d.ts +3 -0
- package/build-types/layouts/grid/index.d.ts.map +1 -0
- package/build-types/{layouts.d.ts → layouts/index.d.ts} +6 -5
- package/build-types/layouts/index.d.ts.map +1 -0
- package/build-types/layouts/list/index.d.ts +3 -0
- package/build-types/layouts/list/index.d.ts.map +1 -0
- package/build-types/layouts/table/column-header-menu.d.ts +17 -0
- package/build-types/layouts/table/column-header-menu.d.ts.map +1 -0
- package/build-types/layouts/table/index.d.ts +4 -0
- package/build-types/layouts/table/index.d.ts.map +1 -0
- package/build-types/normalize-fields.d.ts +2 -2
- package/build-types/normalize-fields.d.ts.map +1 -1
- package/build-types/private-types.d.ts +3 -0
- package/build-types/private-types.d.ts.map +1 -0
- package/build-types/types.d.ts +106 -46
- package/build-types/types.d.ts.map +1 -1
- package/build-types/utils.d.ts +2 -2
- package/build-types/utils.d.ts.map +1 -1
- package/package.json +10 -10
- package/src/components/dataform/index.tsx +106 -0
- package/src/components/dataform/stories/index.story.tsx +42 -0
- package/src/components/dataviews/index.tsx +149 -0
- package/src/{stories → components/dataviews/stories}/fixtures.js +23 -11
- package/src/components/dataviews/stories/index.story.js +65 -0
- package/src/components/dataviews/style.scss +97 -0
- package/src/{bulk-actions.tsx → components/dataviews-bulk-actions/index.tsx} +58 -36
- package/src/components/dataviews-bulk-actions/style.scss +7 -0
- package/src/{bulk-actions-toolbar.tsx → components/dataviews-bulk-actions-toolbar/index.tsx} +48 -36
- package/src/components/dataviews-bulk-actions-toolbar/style.scss +45 -0
- package/src/components/dataviews-context/index.ts +49 -0
- package/src/{add-filter.tsx → components/dataviews-filters/add-filter.tsx} +4 -4
- package/src/{filter-summary.tsx → components/dataviews-filters/filter-summary.tsx} +36 -22
- package/src/{filters.tsx → components/dataviews-filters/index.tsx} +11 -25
- package/src/{reset-filters.tsx → components/dataviews-filters/reset-filters.tsx} +2 -2
- package/src/{search-widget.tsx → components/dataviews-filters/search-widget.tsx} +20 -20
- package/src/components/dataviews-filters/style.scss +252 -0
- package/src/{item-actions.tsx → components/dataviews-item-actions/index.tsx} +16 -17
- package/src/components/dataviews-item-actions/style.scss +3 -0
- package/src/components/dataviews-layout/index.tsx +51 -0
- package/src/{pagination.tsx → components/dataviews-pagination/index.tsx} +15 -23
- package/src/components/dataviews-pagination/style.scss +26 -0
- package/src/{search.tsx → components/dataviews-search/index.tsx} +5 -10
- package/src/components/dataviews-selection-checkbox/index.tsx +65 -0
- package/src/components/dataviews-selection-checkbox/style.scss +14 -0
- package/src/{view-actions.tsx → components/dataviews-view-config/index.tsx} +116 -119
- package/src/filter-and-sort-data-view.ts +13 -3
- package/src/index.ts +2 -1
- package/src/layouts/grid/density-picker.tsx +136 -0
- package/src/{view-grid.tsx → layouts/grid/index.tsx} +45 -63
- package/src/layouts/grid/style.scss +140 -0
- package/src/layouts/index.ts +66 -0
- package/src/{view-list.tsx → layouts/list/index.tsx} +40 -30
- package/src/layouts/list/style.scss +189 -0
- package/src/layouts/table/column-header-menu.tsx +268 -0
- package/src/layouts/table/index.tsx +471 -0
- package/src/layouts/table/style.scss +201 -0
- package/src/normalize-fields.ts +6 -4
- package/src/private-types.tsx +2 -0
- package/src/style.scss +11 -919
- package/src/test/filter-and-sort-data-view.js +17 -2
- package/src/types.ts +113 -55
- package/src/utils.ts +2 -4
- package/tsconfig.tsbuildinfo +1 -1
- package/build/add-filter.js.map +0 -1
- package/build/bulk-actions-toolbar.js.map +0 -1
- package/build/bulk-actions.js.map +0 -1
- package/build/dataviews.js +0 -136
- package/build/dataviews.js.map +0 -1
- package/build/filter-summary.js.map +0 -1
- package/build/filters.js.map +0 -1
- package/build/item-actions.js.map +0 -1
- package/build/layouts.js +0 -38
- package/build/layouts.js.map +0 -1
- package/build/pagination.js.map +0 -1
- package/build/reset-filters.js.map +0 -1
- package/build/search-widget.js.map +0 -1
- package/build/search.js.map +0 -1
- package/build/single-selection-checkbox.js +0 -63
- package/build/single-selection-checkbox.js.map +0 -1
- package/build/view-actions.js.map +0 -1
- package/build/view-grid.js.map +0 -1
- package/build/view-list.js.map +0 -1
- package/build/view-table.js +0 -409
- package/build/view-table.js.map +0 -1
- package/build-module/add-filter.js.map +0 -1
- package/build-module/bulk-actions-toolbar.js.map +0 -1
- package/build-module/bulk-actions.js.map +0 -1
- package/build-module/dataviews.js +0 -129
- package/build-module/dataviews.js.map +0 -1
- package/build-module/filter-summary.js.map +0 -1
- package/build-module/filters.js.map +0 -1
- package/build-module/item-actions.js.map +0 -1
- package/build-module/layouts.js +0 -30
- package/build-module/layouts.js.map +0 -1
- package/build-module/pagination.js.map +0 -1
- package/build-module/reset-filters.js.map +0 -1
- package/build-module/search-widget.js.map +0 -1
- package/build-module/search.js.map +0 -1
- package/build-module/single-selection-checkbox.js +0 -56
- package/build-module/single-selection-checkbox.js.map +0 -1
- package/build-module/view-actions.js.map +0 -1
- package/build-module/view-grid.js.map +0 -1
- package/build-module/view-list.js.map +0 -1
- package/build-module/view-table.js +0 -402
- package/build-module/view-table.js.map +0 -1
- package/build-types/add-filter.d.ts.map +0 -1
- package/build-types/bulk-actions-toolbar.d.ts +0 -12
- package/build-types/bulk-actions-toolbar.d.ts.map +0 -1
- package/build-types/bulk-actions.d.ts +0 -14
- package/build-types/bulk-actions.d.ts.map +0 -1
- package/build-types/dataviews.d.ts +0 -24
- package/build-types/dataviews.d.ts.map +0 -1
- package/build-types/filter-summary.d.ts.map +0 -1
- package/build-types/filters.d.ts +0 -13
- package/build-types/filters.d.ts.map +0 -1
- package/build-types/item-actions.d.ts +0 -35
- package/build-types/item-actions.d.ts.map +0 -1
- package/build-types/layouts.d.ts.map +0 -1
- package/build-types/pagination.d.ts +0 -16
- package/build-types/pagination.d.ts.map +0 -1
- package/build-types/reset-filters.d.ts.map +0 -1
- package/build-types/search-widget.d.ts.map +0 -1
- package/build-types/search.d.ts +0 -13
- package/build-types/search.d.ts.map +0 -1
- package/build-types/single-selection-checkbox.d.ts +0 -17
- package/build-types/single-selection-checkbox.d.ts.map +0 -1
- package/build-types/stories/fixtures.d.ts.map +0 -1
- package/build-types/stories/index.story.d.ts +0 -15
- package/build-types/stories/index.story.d.ts.map +0 -1
- package/build-types/view-actions.d.ts +0 -12
- package/build-types/view-actions.d.ts.map +0 -1
- package/build-types/view-grid.d.ts +0 -4
- package/build-types/view-grid.d.ts.map +0 -1
- package/build-types/view-list.d.ts +0 -4
- package/build-types/view-list.d.ts.map +0 -1
- package/build-types/view-table.d.ts +0 -5
- package/build-types/view-table.d.ts.map +0 -1
- package/src/dataviews.tsx +0 -189
- package/src/layouts.ts +0 -39
- package/src/single-selection-checkbox.tsx +0 -80
- package/src/stories/index.story.js +0 -64
- package/src/view-table.tsx +0 -603
package/build-types/types.d.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import type { ReactElement,
|
|
4
|
+
import type { ReactElement, ComponentType } from 'react';
|
|
5
|
+
/**
|
|
6
|
+
* Internal dependencies
|
|
7
|
+
*/
|
|
8
|
+
import type { SetSelection } from './private-types';
|
|
5
9
|
export type SortDirection = 'asc' | 'desc';
|
|
6
10
|
/**
|
|
7
11
|
* Generic option type.
|
|
@@ -25,11 +29,16 @@ interface FilterByConfig {
|
|
|
25
29
|
isPrimary?: boolean;
|
|
26
30
|
}
|
|
27
31
|
export type Operator = 'is' | 'isNot' | 'isAny' | 'isNone' | 'isAll' | 'isNotAll';
|
|
28
|
-
export type
|
|
32
|
+
export type ItemRecord = Record<string, unknown>;
|
|
33
|
+
export type FieldType = 'text';
|
|
29
34
|
/**
|
|
30
35
|
* A dataview field for a specific property of a data type.
|
|
31
36
|
*/
|
|
32
|
-
export
|
|
37
|
+
export type Field<Item> = {
|
|
38
|
+
/**
|
|
39
|
+
* Type of the fields.
|
|
40
|
+
*/
|
|
41
|
+
type?: FieldType;
|
|
33
42
|
/**
|
|
34
43
|
* The unique identifier of the field.
|
|
35
44
|
*/
|
|
@@ -37,32 +46,17 @@ export interface Field<Item extends AnyItem> {
|
|
|
37
46
|
/**
|
|
38
47
|
* The label of the field. Defaults to the id.
|
|
39
48
|
*/
|
|
40
|
-
|
|
49
|
+
label?: string;
|
|
41
50
|
/**
|
|
42
|
-
*
|
|
43
|
-
* Defaults to `item[ field.id ]`.
|
|
51
|
+
* Placeholder for the field.
|
|
44
52
|
*/
|
|
45
|
-
|
|
46
|
-
item: Item;
|
|
47
|
-
}) => any;
|
|
53
|
+
placeholder?: string;
|
|
48
54
|
/**
|
|
49
55
|
* Callback used to render the field. Defaults to `field.getValue`.
|
|
50
56
|
*/
|
|
51
|
-
render?:
|
|
57
|
+
render?: ComponentType<{
|
|
52
58
|
item: Item;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* The width of the field column.
|
|
56
|
-
*/
|
|
57
|
-
width?: string | number;
|
|
58
|
-
/**
|
|
59
|
-
* The minimum width of the field column.
|
|
60
|
-
*/
|
|
61
|
-
maxWidth?: string | number;
|
|
62
|
-
/**
|
|
63
|
-
* The maximum width of the field column.
|
|
64
|
-
*/
|
|
65
|
-
minWidth?: string | number;
|
|
59
|
+
}>;
|
|
66
60
|
/**
|
|
67
61
|
* Whether the field is sortable.
|
|
68
62
|
*/
|
|
@@ -83,13 +77,43 @@ export interface Field<Item extends AnyItem> {
|
|
|
83
77
|
* Filter config for the field.
|
|
84
78
|
*/
|
|
85
79
|
filterBy?: FilterByConfig | undefined;
|
|
86
|
-
}
|
|
87
|
-
|
|
80
|
+
} & (Item extends ItemRecord ? {
|
|
81
|
+
/**
|
|
82
|
+
* Callback used to retrieve the value of the field from the item.
|
|
83
|
+
* Defaults to `item[ field.id ]`.
|
|
84
|
+
*/
|
|
85
|
+
getValue?: (args: {
|
|
86
|
+
item: Item;
|
|
87
|
+
}) => any;
|
|
88
|
+
} : {
|
|
89
|
+
/**
|
|
90
|
+
* Callback used to retrieve the value of the field from the item.
|
|
91
|
+
* Defaults to `item[ field.id ]`.
|
|
92
|
+
*/
|
|
93
|
+
getValue: (args: {
|
|
94
|
+
item: Item;
|
|
95
|
+
}) => any;
|
|
96
|
+
});
|
|
97
|
+
export type NormalizedField<Item> = Field<Item> & {
|
|
98
|
+
label: string;
|
|
99
|
+
getValue: (args: {
|
|
100
|
+
item: Item;
|
|
101
|
+
}) => any;
|
|
102
|
+
render: ComponentType<{
|
|
103
|
+
item: Item;
|
|
104
|
+
}>;
|
|
105
|
+
};
|
|
88
106
|
/**
|
|
89
107
|
* A collection of dataview fields for a data type.
|
|
90
108
|
*/
|
|
91
|
-
export type Fields<Item
|
|
92
|
-
export type Data<Item
|
|
109
|
+
export type Fields<Item> = Field<Item>[];
|
|
110
|
+
export type Data<Item> = Item[];
|
|
111
|
+
/**
|
|
112
|
+
* The form configuration.
|
|
113
|
+
*/
|
|
114
|
+
export type Form = {
|
|
115
|
+
visibleFields?: string[];
|
|
116
|
+
};
|
|
93
117
|
/**
|
|
94
118
|
* The filters applied to the dataset.
|
|
95
119
|
*/
|
|
@@ -149,7 +173,7 @@ interface ViewBase {
|
|
|
149
173
|
/**
|
|
150
174
|
* The filters to apply.
|
|
151
175
|
*/
|
|
152
|
-
filters
|
|
176
|
+
filters?: Filter[];
|
|
153
177
|
/**
|
|
154
178
|
* The sorting configuration.
|
|
155
179
|
*/
|
|
@@ -172,26 +196,56 @@ interface ViewBase {
|
|
|
172
196
|
*/
|
|
173
197
|
perPage?: number;
|
|
174
198
|
/**
|
|
175
|
-
* The
|
|
199
|
+
* The fields to render
|
|
176
200
|
*/
|
|
177
|
-
|
|
201
|
+
fields?: string[];
|
|
202
|
+
}
|
|
203
|
+
export interface CombinedField {
|
|
204
|
+
id: string;
|
|
205
|
+
label: string;
|
|
206
|
+
/**
|
|
207
|
+
* The fields to use as columns.
|
|
208
|
+
*/
|
|
209
|
+
children: string[];
|
|
210
|
+
/**
|
|
211
|
+
* The direction of the stack.
|
|
212
|
+
*/
|
|
213
|
+
direction: 'horizontal' | 'vertical';
|
|
214
|
+
}
|
|
215
|
+
export interface ColumnStyle {
|
|
216
|
+
/**
|
|
217
|
+
* The width of the field column.
|
|
218
|
+
*/
|
|
219
|
+
width?: string | number;
|
|
220
|
+
/**
|
|
221
|
+
* The minimum width of the field column.
|
|
222
|
+
*/
|
|
223
|
+
maxWidth?: string | number;
|
|
224
|
+
/**
|
|
225
|
+
* The maximum width of the field column.
|
|
226
|
+
*/
|
|
227
|
+
minWidth?: string | number;
|
|
178
228
|
}
|
|
179
229
|
export interface ViewTable extends ViewBase {
|
|
180
230
|
type: 'table';
|
|
181
|
-
layout
|
|
231
|
+
layout?: {
|
|
182
232
|
/**
|
|
183
233
|
* The field to use as the primary field.
|
|
184
234
|
*/
|
|
185
235
|
primaryField?: string;
|
|
186
236
|
/**
|
|
187
|
-
* The
|
|
237
|
+
* The fields to use as columns.
|
|
188
238
|
*/
|
|
189
|
-
|
|
239
|
+
combinedFields?: CombinedField[];
|
|
240
|
+
/**
|
|
241
|
+
* The styles for the columns.
|
|
242
|
+
*/
|
|
243
|
+
styles?: Record<string, ColumnStyle>;
|
|
190
244
|
};
|
|
191
245
|
}
|
|
192
246
|
export interface ViewList extends ViewBase {
|
|
193
247
|
type: 'list';
|
|
194
|
-
layout
|
|
248
|
+
layout?: {
|
|
195
249
|
/**
|
|
196
250
|
* The field to use as the primary field.
|
|
197
251
|
*/
|
|
@@ -204,7 +258,7 @@ export interface ViewList extends ViewBase {
|
|
|
204
258
|
}
|
|
205
259
|
export interface ViewGrid extends ViewBase {
|
|
206
260
|
type: 'grid';
|
|
207
|
-
layout
|
|
261
|
+
layout?: {
|
|
208
262
|
/**
|
|
209
263
|
* The field to use as the primary field.
|
|
210
264
|
*/
|
|
@@ -224,7 +278,7 @@ export interface ViewGrid extends ViewBase {
|
|
|
224
278
|
};
|
|
225
279
|
}
|
|
226
280
|
export type View = ViewList | ViewGrid | ViewTable;
|
|
227
|
-
interface ActionBase<Item
|
|
281
|
+
interface ActionBase<Item> {
|
|
228
282
|
/**
|
|
229
283
|
* The unique identifier of the action.
|
|
230
284
|
*/
|
|
@@ -262,7 +316,7 @@ interface ActionBase<Item extends AnyItem> {
|
|
|
262
316
|
*/
|
|
263
317
|
supportsBulk?: boolean;
|
|
264
318
|
}
|
|
265
|
-
export interface ActionModal<Item
|
|
319
|
+
export interface ActionModal<Item> extends ActionBase<Item> {
|
|
266
320
|
/**
|
|
267
321
|
* Modal to render when the action is triggered.
|
|
268
322
|
*/
|
|
@@ -280,7 +334,7 @@ export interface ActionModal<Item extends AnyItem> extends ActionBase<Item> {
|
|
|
280
334
|
*/
|
|
281
335
|
modalHeader?: string;
|
|
282
336
|
}
|
|
283
|
-
export interface ActionButton<Item
|
|
337
|
+
export interface ActionButton<Item> extends ActionBase<Item> {
|
|
284
338
|
/**
|
|
285
339
|
* The callback to execute when the action is triggered.
|
|
286
340
|
*/
|
|
@@ -289,28 +343,34 @@ export interface ActionButton<Item extends AnyItem> extends ActionBase<AnyItem>
|
|
|
289
343
|
onActionPerformed?: (items: Item[]) => void;
|
|
290
344
|
}) => void;
|
|
291
345
|
}
|
|
292
|
-
export type Action<Item
|
|
293
|
-
export interface ViewBaseProps<Item
|
|
346
|
+
export type Action<Item> = ActionModal<Item> | ActionButton<Item>;
|
|
347
|
+
export interface ViewBaseProps<Item> {
|
|
294
348
|
actions: Action<Item>[];
|
|
295
349
|
data: Item[];
|
|
296
350
|
fields: NormalizedField<Item>[];
|
|
297
351
|
getItemId: (item: Item) => string;
|
|
298
352
|
isLoading?: boolean;
|
|
299
|
-
onChangeView(view: View)
|
|
300
|
-
|
|
353
|
+
onChangeView: (view: View) => void;
|
|
354
|
+
onChangeSelection: SetSelection;
|
|
301
355
|
selection: string[];
|
|
302
356
|
setOpenedFilter: (fieldId: string) => void;
|
|
303
357
|
view: View;
|
|
358
|
+
density: number;
|
|
304
359
|
}
|
|
305
|
-
export interface ViewTableProps<Item
|
|
360
|
+
export interface ViewTableProps<Item> extends ViewBaseProps<Item> {
|
|
306
361
|
view: ViewTable;
|
|
307
362
|
}
|
|
308
|
-
export interface ViewListProps<Item
|
|
363
|
+
export interface ViewListProps<Item> extends ViewBaseProps<Item> {
|
|
309
364
|
view: ViewList;
|
|
310
365
|
}
|
|
311
|
-
export interface ViewGridProps<Item
|
|
366
|
+
export interface ViewGridProps<Item> extends ViewBaseProps<Item> {
|
|
312
367
|
view: ViewGrid;
|
|
313
368
|
}
|
|
314
|
-
export type ViewProps<Item
|
|
369
|
+
export type ViewProps<Item> = ViewTableProps<Item> | ViewGridProps<Item> | ViewListProps<Item>;
|
|
370
|
+
export interface SupportedLayouts {
|
|
371
|
+
list?: Omit<ViewList, 'type'>;
|
|
372
|
+
grid?: Omit<ViewGrid, 'type'>;
|
|
373
|
+
table?: Omit<ViewTable, 'type'>;
|
|
374
|
+
}
|
|
315
375
|
export {};
|
|
316
376
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,
|
|
1
|
+
{"version":3,"file":"types.d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AAS,EAAE,MAAM,EAAE,CAAC;IACpB,eAAe,EAAE,CAAE,OAAO,EAAE,MAAM,KAAM,IAAI,CAAC;IAC7C,IAAI,EAAE,IAAI,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,cAAc,CAAE,IAAI,CAAG,SAAQ,aAAa,CAAE,IAAI,CAAE;IACpE,IAAI,EAAE,SAAS,CAAC;CAChB;AAED,MAAM,WAAW,aAAa,CAAE,IAAI,CAAG,SAAQ,aAAa,CAAE,IAAI,CAAE;IACnE,IAAI,EAAE,QAAQ,CAAC;CACf;AAED,MAAM,WAAW,aAAa,CAAE,IAAI,CAAG,SAAQ,aAAa,CAAE,IAAI,CAAE;IACnE,IAAI,EAAE,QAAQ,CAAC;CACf;AAED,MAAM,MAAM,SAAS,CAAE,IAAI,IACxB,cAAc,CAAE,IAAI,CAAE,GACtB,aAAa,CAAE,IAAI,CAAE,GACrB,aAAa,CAAE,IAAI,CAAE,CAAC;AAEzB,MAAM,WAAW,gBAAgB;IAChC,IAAI,CAAC,EAAE,IAAI,CAAE,QAAQ,EAAE,MAAM,CAAE,CAAC;IAChC,IAAI,CAAC,EAAE,IAAI,CAAE,QAAQ,EAAE,MAAM,CAAE,CAAC;IAChC,KAAK,CAAC,EAAE,IAAI,CAAE,SAAS,EAAE,MAAM,CAAE,CAAC;CAClC"}
|
package/build-types/utils.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare function sanitizeOperators<Item
|
|
1
|
+
import type { NormalizedField } from './types';
|
|
2
|
+
export declare function sanitizeOperators<Item>(field: NormalizedField<Item>): import("./types").Operator[];
|
|
3
3
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE/C,wBAAgB,iBAAiB,CAAE,IAAI,EAAI,KAAK,EAAE,eAAe,CAAE,IAAI,CAAE,gCAyBxE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/dataviews",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "DataViews is a component that provides an API to render datasets using different types of layouts (table, grid, list, etc.).",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -30,14 +30,14 @@
|
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@ariakit/react": "^0.3.12",
|
|
32
32
|
"@babel/runtime": "^7.16.0",
|
|
33
|
-
"@wordpress/components": "^28.
|
|
34
|
-
"@wordpress/compose": "^7.
|
|
35
|
-
"@wordpress/data": "^10.
|
|
36
|
-
"@wordpress/element": "^6.
|
|
37
|
-
"@wordpress/i18n": "^5.
|
|
38
|
-
"@wordpress/icons": "^10.
|
|
39
|
-
"@wordpress/primitives": "^4.
|
|
40
|
-
"@wordpress/private-apis": "^1.
|
|
33
|
+
"@wordpress/components": "^28.4.0",
|
|
34
|
+
"@wordpress/compose": "^7.4.0",
|
|
35
|
+
"@wordpress/data": "^10.4.0",
|
|
36
|
+
"@wordpress/element": "^6.4.0",
|
|
37
|
+
"@wordpress/i18n": "^5.4.0",
|
|
38
|
+
"@wordpress/icons": "^10.4.0",
|
|
39
|
+
"@wordpress/primitives": "^4.4.0",
|
|
40
|
+
"@wordpress/private-apis": "^1.4.0",
|
|
41
41
|
"clsx": "^2.1.1",
|
|
42
42
|
"remove-accents": "^0.5.0"
|
|
43
43
|
},
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"publishConfig": {
|
|
48
48
|
"access": "public"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "363edb39b8dda8727f652e42cbb8497732693ed2"
|
|
51
51
|
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import type { Dispatch, SetStateAction } from 'react';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* WordPress dependencies
|
|
8
|
+
*/
|
|
9
|
+
import { TextControl } from '@wordpress/components';
|
|
10
|
+
import { useCallback, useMemo } from '@wordpress/element';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Internal dependencies
|
|
14
|
+
*/
|
|
15
|
+
import type { Form, Field, NormalizedField } from '../../types';
|
|
16
|
+
import { normalizeFields } from '../../normalize-fields';
|
|
17
|
+
|
|
18
|
+
type DataFormProps< Item > = {
|
|
19
|
+
data: Item;
|
|
20
|
+
fields: Field< Item >[];
|
|
21
|
+
form: Form;
|
|
22
|
+
onChange: Dispatch< SetStateAction< Item > >;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
type DataFormControlProps< Item > = {
|
|
26
|
+
data: Item;
|
|
27
|
+
field: NormalizedField< Item >;
|
|
28
|
+
onChange: Dispatch< SetStateAction< Item > >;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
function DataFormTextControl< Item >( {
|
|
32
|
+
data,
|
|
33
|
+
field,
|
|
34
|
+
onChange,
|
|
35
|
+
}: DataFormControlProps< Item > ) {
|
|
36
|
+
const { id, label, placeholder } = field;
|
|
37
|
+
const value = field.getValue( { item: data } );
|
|
38
|
+
|
|
39
|
+
const onChangeControl = useCallback(
|
|
40
|
+
( newValue: string ) =>
|
|
41
|
+
onChange( ( prevItem: Item ) => ( {
|
|
42
|
+
...prevItem,
|
|
43
|
+
[ id ]: newValue,
|
|
44
|
+
} ) ),
|
|
45
|
+
[ id, onChange ]
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<TextControl
|
|
50
|
+
label={ label }
|
|
51
|
+
placeholder={ placeholder }
|
|
52
|
+
value={ value ?? '' }
|
|
53
|
+
onChange={ onChangeControl }
|
|
54
|
+
__next40pxDefaultSize
|
|
55
|
+
/>
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const controls: {
|
|
60
|
+
[ key: string ]: < Item >(
|
|
61
|
+
props: DataFormControlProps< Item >
|
|
62
|
+
) => JSX.Element;
|
|
63
|
+
} = {
|
|
64
|
+
text: DataFormTextControl,
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
function getControlForField< Item >( field: NormalizedField< Item > ) {
|
|
68
|
+
if ( ! field.type ) {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if ( ! Object.keys( controls ).includes( field.type ) ) {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return controls[ field.type ];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export default function DataForm< Item >( {
|
|
80
|
+
data,
|
|
81
|
+
fields,
|
|
82
|
+
form,
|
|
83
|
+
onChange,
|
|
84
|
+
}: DataFormProps< Item > ) {
|
|
85
|
+
const visibleFields = useMemo(
|
|
86
|
+
() =>
|
|
87
|
+
normalizeFields(
|
|
88
|
+
fields.filter(
|
|
89
|
+
( { id } ) => !! form.visibleFields?.includes( id )
|
|
90
|
+
)
|
|
91
|
+
),
|
|
92
|
+
[ fields, form.visibleFields ]
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
return visibleFields.map( ( field ) => {
|
|
96
|
+
const DataFormControl = getControlForField( field );
|
|
97
|
+
return DataFormControl ? (
|
|
98
|
+
<DataFormControl
|
|
99
|
+
key={ field.id }
|
|
100
|
+
data={ data }
|
|
101
|
+
field={ field }
|
|
102
|
+
onChange={ onChange }
|
|
103
|
+
/>
|
|
104
|
+
) : null;
|
|
105
|
+
} );
|
|
106
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useState } from '@wordpress/element';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Internal dependencies
|
|
8
|
+
*/
|
|
9
|
+
import DataForm from '../index';
|
|
10
|
+
|
|
11
|
+
const meta = {
|
|
12
|
+
title: 'DataViews/DataForm',
|
|
13
|
+
component: DataForm,
|
|
14
|
+
};
|
|
15
|
+
export default meta;
|
|
16
|
+
|
|
17
|
+
const fields = [
|
|
18
|
+
{
|
|
19
|
+
id: 'title',
|
|
20
|
+
label: 'Title',
|
|
21
|
+
type: 'text' as const,
|
|
22
|
+
},
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
export const Default = () => {
|
|
26
|
+
const [ post, setPost ] = useState( {
|
|
27
|
+
title: 'Hello, World!',
|
|
28
|
+
} );
|
|
29
|
+
|
|
30
|
+
const form = {
|
|
31
|
+
visibleFields: [ 'title' ],
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<DataForm
|
|
36
|
+
data={ post }
|
|
37
|
+
fields={ fields }
|
|
38
|
+
form={ form }
|
|
39
|
+
onChange={ setPost }
|
|
40
|
+
/>
|
|
41
|
+
);
|
|
42
|
+
};
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import type { ReactNode } from 'react';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* WordPress dependencies
|
|
8
|
+
*/
|
|
9
|
+
import { __experimentalHStack as HStack } from '@wordpress/components';
|
|
10
|
+
import { useMemo, useState } from '@wordpress/element';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Internal dependencies
|
|
14
|
+
*/
|
|
15
|
+
import { default as DataViewsBulkActions } from '../dataviews-bulk-actions';
|
|
16
|
+
import DataViewsBulkActionsToolbar from '../dataviews-bulk-actions-toolbar';
|
|
17
|
+
import DataViewsContext from '../dataviews-context';
|
|
18
|
+
import DataViewsFilters from '../dataviews-filters';
|
|
19
|
+
import DataViewsLayout from '../dataviews-layout';
|
|
20
|
+
import DataviewsPagination from '../dataviews-pagination';
|
|
21
|
+
import DataViewsSearch from '../dataviews-search';
|
|
22
|
+
import DataViewsViewConfig from '../dataviews-view-config';
|
|
23
|
+
import { normalizeFields } from '../../normalize-fields';
|
|
24
|
+
import type { Action, Field, View, SupportedLayouts } from '../../types';
|
|
25
|
+
import type { SelectionOrUpdater } from '../../private-types';
|
|
26
|
+
import DensityPicker from '../../layouts/grid/density-picker';
|
|
27
|
+
import { LAYOUT_GRID } from '../../constants';
|
|
28
|
+
|
|
29
|
+
type ItemWithId = { id: string };
|
|
30
|
+
|
|
31
|
+
type DataViewsProps< Item > = {
|
|
32
|
+
view: View;
|
|
33
|
+
onChangeView: ( view: View ) => void;
|
|
34
|
+
fields: Field< Item >[];
|
|
35
|
+
search?: boolean;
|
|
36
|
+
searchLabel?: string;
|
|
37
|
+
actions?: Action< Item >[];
|
|
38
|
+
data: Item[];
|
|
39
|
+
isLoading?: boolean;
|
|
40
|
+
paginationInfo: {
|
|
41
|
+
totalItems: number;
|
|
42
|
+
totalPages: number;
|
|
43
|
+
};
|
|
44
|
+
defaultLayouts: SupportedLayouts;
|
|
45
|
+
selection?: string[];
|
|
46
|
+
onChangeSelection?: ( items: string[] ) => void;
|
|
47
|
+
header?: ReactNode;
|
|
48
|
+
} & ( Item extends ItemWithId
|
|
49
|
+
? { getItemId?: ( item: Item ) => string }
|
|
50
|
+
: { getItemId: ( item: Item ) => string } );
|
|
51
|
+
|
|
52
|
+
const defaultGetItemId = ( item: ItemWithId ) => item.id;
|
|
53
|
+
|
|
54
|
+
export default function DataViews< Item >( {
|
|
55
|
+
view,
|
|
56
|
+
onChangeView,
|
|
57
|
+
fields,
|
|
58
|
+
search = true,
|
|
59
|
+
searchLabel = undefined,
|
|
60
|
+
actions = [],
|
|
61
|
+
data,
|
|
62
|
+
getItemId = defaultGetItemId,
|
|
63
|
+
isLoading = false,
|
|
64
|
+
paginationInfo,
|
|
65
|
+
defaultLayouts,
|
|
66
|
+
selection: selectionProperty,
|
|
67
|
+
onChangeSelection,
|
|
68
|
+
header,
|
|
69
|
+
}: DataViewsProps< Item > ) {
|
|
70
|
+
const [ selectionState, setSelectionState ] = useState< string[] >( [] );
|
|
71
|
+
const [ density, setDensity ] = useState< number >( 0 );
|
|
72
|
+
const isUncontrolled =
|
|
73
|
+
selectionProperty === undefined || onChangeSelection === undefined;
|
|
74
|
+
const selection = isUncontrolled ? selectionState : selectionProperty;
|
|
75
|
+
const [ openedFilter, setOpenedFilter ] = useState< string | null >( null );
|
|
76
|
+
function setSelectionWithChange( value: SelectionOrUpdater ) {
|
|
77
|
+
const newValue =
|
|
78
|
+
typeof value === 'function' ? value( selection ) : value;
|
|
79
|
+
if ( isUncontrolled ) {
|
|
80
|
+
setSelectionState( newValue );
|
|
81
|
+
}
|
|
82
|
+
if ( onChangeSelection ) {
|
|
83
|
+
onChangeSelection( newValue );
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
const _fields = useMemo( () => normalizeFields( fields ), [ fields ] );
|
|
87
|
+
const _selection = useMemo( () => {
|
|
88
|
+
return selection.filter( ( id ) =>
|
|
89
|
+
data.some( ( item ) => getItemId( item ) === id )
|
|
90
|
+
);
|
|
91
|
+
}, [ selection, data, getItemId ] );
|
|
92
|
+
|
|
93
|
+
return (
|
|
94
|
+
<DataViewsContext.Provider
|
|
95
|
+
value={ {
|
|
96
|
+
view,
|
|
97
|
+
onChangeView,
|
|
98
|
+
fields: _fields,
|
|
99
|
+
actions,
|
|
100
|
+
data,
|
|
101
|
+
isLoading,
|
|
102
|
+
paginationInfo,
|
|
103
|
+
selection: _selection,
|
|
104
|
+
onChangeSelection: setSelectionWithChange,
|
|
105
|
+
openedFilter,
|
|
106
|
+
setOpenedFilter,
|
|
107
|
+
getItemId,
|
|
108
|
+
density,
|
|
109
|
+
} }
|
|
110
|
+
>
|
|
111
|
+
<div className="dataviews-wrapper">
|
|
112
|
+
<HStack
|
|
113
|
+
alignment="top"
|
|
114
|
+
justify="start"
|
|
115
|
+
className="dataviews__view-actions"
|
|
116
|
+
>
|
|
117
|
+
<HStack
|
|
118
|
+
justify="start"
|
|
119
|
+
className="dataviews-filters__container"
|
|
120
|
+
wrap
|
|
121
|
+
>
|
|
122
|
+
{ search && <DataViewsSearch label={ searchLabel } /> }
|
|
123
|
+
<DataViewsFilters />
|
|
124
|
+
</HStack>
|
|
125
|
+
{ view.type === LAYOUT_GRID && (
|
|
126
|
+
<DensityPicker
|
|
127
|
+
density={ density }
|
|
128
|
+
setDensity={ setDensity }
|
|
129
|
+
/>
|
|
130
|
+
) }
|
|
131
|
+
<DataViewsBulkActions />
|
|
132
|
+
<HStack
|
|
133
|
+
spacing={ 1 }
|
|
134
|
+
expanded={ false }
|
|
135
|
+
style={ { flexShrink: 0 } }
|
|
136
|
+
>
|
|
137
|
+
<DataViewsViewConfig
|
|
138
|
+
defaultLayouts={ defaultLayouts }
|
|
139
|
+
/>
|
|
140
|
+
{ header }
|
|
141
|
+
</HStack>
|
|
142
|
+
</HStack>
|
|
143
|
+
<DataViewsLayout />
|
|
144
|
+
<DataviewsPagination />
|
|
145
|
+
<DataViewsBulkActionsToolbar />
|
|
146
|
+
</div>
|
|
147
|
+
</DataViewsContext.Provider>
|
|
148
|
+
);
|
|
149
|
+
}
|