@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
|
@@ -9,18 +9,20 @@ import type { ChangeEvent } from 'react';
|
|
|
9
9
|
import {
|
|
10
10
|
Button,
|
|
11
11
|
privateApis as componentsPrivateApis,
|
|
12
|
+
__experimentalHStack as HStack,
|
|
12
13
|
} from '@wordpress/components';
|
|
13
|
-
import { __ } from '@wordpress/i18n';
|
|
14
|
-
import { memo } from '@wordpress/element';
|
|
15
|
-
import {
|
|
14
|
+
import { __, _x } from '@wordpress/i18n';
|
|
15
|
+
import { memo, useContext } from '@wordpress/element';
|
|
16
|
+
import { cog } from '@wordpress/icons';
|
|
16
17
|
|
|
17
18
|
/**
|
|
18
19
|
* Internal dependencies
|
|
19
20
|
*/
|
|
20
|
-
import { unlock } from '
|
|
21
|
-
import { SORTING_DIRECTIONS, sortLabels } from '
|
|
22
|
-
import { VIEW_LAYOUTS } from '
|
|
23
|
-
import type {
|
|
21
|
+
import { unlock } from '../../lock-unlock';
|
|
22
|
+
import { SORTING_DIRECTIONS, sortLabels } from '../../constants';
|
|
23
|
+
import { VIEW_LAYOUTS, getMandatoryFields } from '../../layouts';
|
|
24
|
+
import type { NormalizedField, View, SupportedLayouts } from '../../types';
|
|
25
|
+
import DataViewsContext from '../dataviews-context';
|
|
24
26
|
|
|
25
27
|
const {
|
|
26
28
|
DropdownMenuV2: DropdownMenu,
|
|
@@ -34,7 +36,7 @@ const {
|
|
|
34
36
|
interface ViewTypeMenuProps {
|
|
35
37
|
view: View;
|
|
36
38
|
onChangeView: ( view: View ) => void;
|
|
37
|
-
|
|
39
|
+
defaultLayouts?: SupportedLayouts;
|
|
38
40
|
}
|
|
39
41
|
|
|
40
42
|
interface PageSizeMenuProps {
|
|
@@ -42,84 +44,61 @@ interface PageSizeMenuProps {
|
|
|
42
44
|
onChangeView: ( view: View ) => void;
|
|
43
45
|
}
|
|
44
46
|
|
|
45
|
-
interface FieldsVisibilityMenuProps< Item
|
|
47
|
+
interface FieldsVisibilityMenuProps< Item > {
|
|
46
48
|
view: View;
|
|
47
49
|
onChangeView: ( view: View ) => void;
|
|
48
50
|
fields: NormalizedField< Item >[];
|
|
49
51
|
}
|
|
50
52
|
|
|
51
|
-
interface SortMenuProps< Item
|
|
53
|
+
interface SortMenuProps< Item > {
|
|
52
54
|
fields: NormalizedField< Item >[];
|
|
53
55
|
view: View;
|
|
54
56
|
onChangeView: ( view: View ) => void;
|
|
55
57
|
}
|
|
56
58
|
|
|
57
|
-
interface ViewActionsProps
|
|
58
|
-
|
|
59
|
-
view: View;
|
|
60
|
-
onChangeView: ( view: View ) => void;
|
|
61
|
-
supportedLayouts?: string[];
|
|
59
|
+
interface ViewActionsProps {
|
|
60
|
+
defaultLayouts?: SupportedLayouts;
|
|
62
61
|
}
|
|
63
62
|
|
|
64
63
|
function ViewTypeMenu( {
|
|
65
64
|
view,
|
|
66
65
|
onChangeView,
|
|
67
|
-
|
|
66
|
+
defaultLayouts = { list: {}, grid: {}, table: {} },
|
|
68
67
|
}: ViewTypeMenuProps ) {
|
|
69
|
-
|
|
70
|
-
if (
|
|
71
|
-
_availableViews = _availableViews.filter( ( _view ) =>
|
|
72
|
-
supportedLayouts.includes( _view.type )
|
|
73
|
-
);
|
|
74
|
-
}
|
|
75
|
-
if ( _availableViews.length === 1 ) {
|
|
68
|
+
const availableLayouts = Object.keys( defaultLayouts );
|
|
69
|
+
if ( availableLayouts.length <= 1 ) {
|
|
76
70
|
return null;
|
|
77
71
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
72
|
+
return availableLayouts.map( ( layout ) => {
|
|
73
|
+
const config = VIEW_LAYOUTS.find( ( v ) => v.type === layout );
|
|
74
|
+
if ( ! config ) {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
return (
|
|
78
|
+
<DropdownMenuRadioItem
|
|
79
|
+
key={ layout }
|
|
80
|
+
value={ layout }
|
|
81
|
+
name="view-actions-available-view"
|
|
82
|
+
checked={ layout === view.type }
|
|
83
|
+
hideOnClick
|
|
84
|
+
onChange={ ( e: ChangeEvent< HTMLInputElement > ) => {
|
|
85
|
+
switch ( e.target.value ) {
|
|
86
|
+
case 'list':
|
|
87
|
+
case 'grid':
|
|
88
|
+
case 'table':
|
|
89
|
+
return onChangeView( {
|
|
90
|
+
...view,
|
|
91
|
+
type: e.target.value,
|
|
92
|
+
...defaultLayouts[ e.target.value ],
|
|
93
|
+
} );
|
|
85
94
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
{ _availableViews.map( ( availableView ) => {
|
|
94
|
-
return (
|
|
95
|
-
<DropdownMenuRadioItem
|
|
96
|
-
key={ availableView.type }
|
|
97
|
-
value={ availableView.type }
|
|
98
|
-
name="view-actions-available-view"
|
|
99
|
-
checked={ availableView.type === view.type }
|
|
100
|
-
hideOnClick
|
|
101
|
-
onChange={ ( e: ChangeEvent< HTMLInputElement > ) => {
|
|
102
|
-
switch ( e.target.value ) {
|
|
103
|
-
case 'list':
|
|
104
|
-
case 'grid':
|
|
105
|
-
case 'table':
|
|
106
|
-
return onChangeView( {
|
|
107
|
-
...view,
|
|
108
|
-
type: e.target.value,
|
|
109
|
-
layout: {},
|
|
110
|
-
} );
|
|
111
|
-
}
|
|
112
|
-
throw new Error( 'Invalid dataview' );
|
|
113
|
-
} }
|
|
114
|
-
>
|
|
115
|
-
<DropdownMenuItemLabel>
|
|
116
|
-
{ availableView.label }
|
|
117
|
-
</DropdownMenuItemLabel>
|
|
118
|
-
</DropdownMenuRadioItem>
|
|
119
|
-
);
|
|
120
|
-
} ) }
|
|
121
|
-
</DropdownMenu>
|
|
122
|
-
);
|
|
95
|
+
throw new Error( 'Invalid dataview' );
|
|
96
|
+
} }
|
|
97
|
+
>
|
|
98
|
+
<DropdownMenuItemLabel>{ config.label }</DropdownMenuItemLabel>
|
|
99
|
+
</DropdownMenuRadioItem>
|
|
100
|
+
);
|
|
101
|
+
} );
|
|
123
102
|
}
|
|
124
103
|
|
|
125
104
|
const PAGE_SIZE_VALUES = [ 10, 20, 50, 100 ];
|
|
@@ -161,15 +140,18 @@ function PageSizeMenu( { view, onChangeView }: PageSizeMenuProps ) {
|
|
|
161
140
|
);
|
|
162
141
|
}
|
|
163
142
|
|
|
164
|
-
function FieldsVisibilityMenu< Item
|
|
143
|
+
function FieldsVisibilityMenu< Item >( {
|
|
165
144
|
view,
|
|
166
145
|
onChangeView,
|
|
167
146
|
fields,
|
|
168
147
|
}: FieldsVisibilityMenuProps< Item > ) {
|
|
148
|
+
const mandatoryFields = getMandatoryFields( view );
|
|
169
149
|
const hidableFields = fields.filter(
|
|
170
150
|
( field ) =>
|
|
171
|
-
field.enableHiding !== false &&
|
|
151
|
+
field.enableHiding !== false &&
|
|
152
|
+
! mandatoryFields.includes( field.id )
|
|
172
153
|
);
|
|
154
|
+
const viewFields = view.fields || fields.map( ( field ) => field.id );
|
|
173
155
|
if ( ! hidableFields?.length ) {
|
|
174
156
|
return null;
|
|
175
157
|
}
|
|
@@ -188,25 +170,20 @@ function FieldsVisibilityMenu< Item extends AnyItem >( {
|
|
|
188
170
|
<DropdownMenuCheckboxItem
|
|
189
171
|
key={ field.id }
|
|
190
172
|
value={ field.id }
|
|
191
|
-
checked={
|
|
173
|
+
checked={ viewFields.includes( field.id ) }
|
|
192
174
|
onChange={ () => {
|
|
193
175
|
onChangeView( {
|
|
194
176
|
...view,
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
)
|
|
198
|
-
? view.hiddenFields.filter(
|
|
177
|
+
fields: viewFields.includes( field.id )
|
|
178
|
+
? viewFields.filter(
|
|
199
179
|
( id ) => id !== field.id
|
|
200
180
|
)
|
|
201
|
-
: [
|
|
202
|
-
...( view.hiddenFields || [] ),
|
|
203
|
-
field.id,
|
|
204
|
-
],
|
|
181
|
+
: [ ...viewFields, field.id ],
|
|
205
182
|
} );
|
|
206
183
|
} }
|
|
207
184
|
>
|
|
208
185
|
<DropdownMenuItemLabel>
|
|
209
|
-
{ field.
|
|
186
|
+
{ field.label }
|
|
210
187
|
</DropdownMenuItemLabel>
|
|
211
188
|
</DropdownMenuCheckboxItem>
|
|
212
189
|
);
|
|
@@ -215,7 +192,7 @@ function FieldsVisibilityMenu< Item extends AnyItem >( {
|
|
|
215
192
|
);
|
|
216
193
|
}
|
|
217
194
|
|
|
218
|
-
function SortMenu< Item
|
|
195
|
+
function SortMenu< Item >( {
|
|
219
196
|
fields,
|
|
220
197
|
view,
|
|
221
198
|
onChangeView,
|
|
@@ -235,7 +212,7 @@ function SortMenu< Item extends AnyItem >( {
|
|
|
235
212
|
<DropdownMenuItem
|
|
236
213
|
suffix={
|
|
237
214
|
<span aria-hidden="true">
|
|
238
|
-
{ currentSortedField?.
|
|
215
|
+
{ currentSortedField?.label }
|
|
239
216
|
</span>
|
|
240
217
|
}
|
|
241
218
|
>
|
|
@@ -253,7 +230,7 @@ function SortMenu< Item extends AnyItem >( {
|
|
|
253
230
|
trigger={
|
|
254
231
|
<DropdownMenuItem>
|
|
255
232
|
<DropdownMenuItemLabel>
|
|
256
|
-
{ field.
|
|
233
|
+
{ field.label }
|
|
257
234
|
</DropdownMenuItemLabel>
|
|
258
235
|
</DropdownMenuItem>
|
|
259
236
|
}
|
|
@@ -303,45 +280,65 @@ function SortMenu< Item extends AnyItem >( {
|
|
|
303
280
|
);
|
|
304
281
|
}
|
|
305
282
|
|
|
306
|
-
function
|
|
307
|
-
fields,
|
|
308
|
-
view
|
|
309
|
-
onChangeView,
|
|
310
|
-
supportedLayouts,
|
|
311
|
-
}: ViewActionsProps< Item > ) {
|
|
283
|
+
function _DataViewsViewConfig( { defaultLayouts }: ViewActionsProps ) {
|
|
284
|
+
const { view, fields, onChangeView } = useContext( DataViewsContext );
|
|
285
|
+
const activeView = VIEW_LAYOUTS.find( ( v ) => view.type === v.type );
|
|
312
286
|
return (
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
287
|
+
<>
|
|
288
|
+
<HStack
|
|
289
|
+
spacing={ 1 }
|
|
290
|
+
expanded={ false }
|
|
291
|
+
style={ { flexShrink: 0 } }
|
|
292
|
+
>
|
|
293
|
+
<DropdownMenu
|
|
294
|
+
trigger={
|
|
295
|
+
<Button
|
|
296
|
+
size="compact"
|
|
297
|
+
icon={ activeView?.icon }
|
|
298
|
+
label={ __( 'Layout' ) }
|
|
299
|
+
/>
|
|
300
|
+
}
|
|
301
|
+
>
|
|
302
|
+
<ViewTypeMenu
|
|
303
|
+
view={ view }
|
|
304
|
+
onChangeView={ onChangeView }
|
|
305
|
+
defaultLayouts={ defaultLayouts }
|
|
306
|
+
/>
|
|
307
|
+
</DropdownMenu>
|
|
308
|
+
<DropdownMenu
|
|
309
|
+
trigger={
|
|
310
|
+
<Button
|
|
311
|
+
size="compact"
|
|
312
|
+
icon={ cog }
|
|
313
|
+
label={ _x(
|
|
314
|
+
'View options',
|
|
315
|
+
'View is used as a noun'
|
|
316
|
+
) }
|
|
317
|
+
/>
|
|
318
|
+
}
|
|
319
|
+
>
|
|
320
|
+
<DropdownMenuGroup>
|
|
321
|
+
<SortMenu
|
|
322
|
+
fields={ fields }
|
|
323
|
+
view={ view }
|
|
324
|
+
onChangeView={ onChangeView }
|
|
325
|
+
/>
|
|
326
|
+
<FieldsVisibilityMenu
|
|
327
|
+
fields={ fields }
|
|
328
|
+
view={ view }
|
|
329
|
+
onChangeView={ onChangeView }
|
|
330
|
+
/>
|
|
331
|
+
<PageSizeMenu
|
|
332
|
+
view={ view }
|
|
333
|
+
onChangeView={ onChangeView }
|
|
334
|
+
/>
|
|
335
|
+
</DropdownMenuGroup>
|
|
336
|
+
</DropdownMenu>
|
|
337
|
+
</HStack>
|
|
338
|
+
</>
|
|
341
339
|
);
|
|
342
340
|
}
|
|
343
341
|
|
|
344
|
-
|
|
345
|
-
const ViewActions = memo( _ViewActions ) as typeof _ViewActions;
|
|
342
|
+
const DataViewsViewConfig = memo( _DataViewsViewConfig );
|
|
346
343
|
|
|
347
|
-
export default
|
|
344
|
+
export default DataViewsViewConfig;
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
OPERATOR_IS_NOT_ALL,
|
|
16
16
|
} from './constants';
|
|
17
17
|
import { normalizeFields } from './normalize-fields';
|
|
18
|
-
import type { Field,
|
|
18
|
+
import type { Field, View } from './types';
|
|
19
19
|
|
|
20
20
|
function normalizeSearchInput( input = '' ) {
|
|
21
21
|
return removeAccents( input.trim().toLowerCase() );
|
|
@@ -32,7 +32,7 @@ const EMPTY_ARRAY: [] = [];
|
|
|
32
32
|
*
|
|
33
33
|
* @return Filtered, sorted and paginated data.
|
|
34
34
|
*/
|
|
35
|
-
export function filterSortAndPaginate< Item
|
|
35
|
+
export function filterSortAndPaginate< Item >(
|
|
36
36
|
data: Item[],
|
|
37
37
|
view: View,
|
|
38
38
|
fields: Field< Item >[]
|
|
@@ -61,7 +61,7 @@ export function filterSortAndPaginate< Item extends AnyItem >(
|
|
|
61
61
|
} );
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
if ( view.filters.length > 0 ) {
|
|
64
|
+
if ( view.filters && view.filters?.length > 0 ) {
|
|
65
65
|
view.filters.forEach( ( filter ) => {
|
|
66
66
|
const field = _fields.find(
|
|
67
67
|
( _field ) => _field.id === filter.field
|
|
@@ -142,6 +142,16 @@ export function filterSortAndPaginate< Item extends AnyItem >(
|
|
|
142
142
|
filteredData.sort( ( a, b ) => {
|
|
143
143
|
const valueA = fieldToSort.getValue( { item: a } ) ?? '';
|
|
144
144
|
const valueB = fieldToSort.getValue( { item: b } ) ?? '';
|
|
145
|
+
|
|
146
|
+
if (
|
|
147
|
+
typeof valueA === 'number' &&
|
|
148
|
+
typeof valueB === 'number'
|
|
149
|
+
) {
|
|
150
|
+
return view.sort?.direction === 'asc'
|
|
151
|
+
? valueA - valueB
|
|
152
|
+
: valueB - valueA;
|
|
153
|
+
}
|
|
154
|
+
|
|
145
155
|
return view.sort?.direction === 'asc'
|
|
146
156
|
? valueA.localeCompare( valueB )
|
|
147
157
|
: valueB.localeCompare( valueA );
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export { default as DataViews } from './dataviews';
|
|
1
|
+
export { default as DataViews } from './components/dataviews';
|
|
2
|
+
export { default as DataForm } from './components/dataform';
|
|
2
3
|
export { VIEW_LAYOUTS } from './layouts';
|
|
3
4
|
export { filterSortAndPaginate } from './filter-and-sort-data-view';
|
|
4
5
|
export type * from './types';
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { RangeControl, Button } from '@wordpress/components';
|
|
5
|
+
import { __ } from '@wordpress/i18n';
|
|
6
|
+
import { useViewportMatch } from '@wordpress/compose';
|
|
7
|
+
import { plus, lineSolid } from '@wordpress/icons';
|
|
8
|
+
import { useEffect } from '@wordpress/element';
|
|
9
|
+
|
|
10
|
+
const viewportBreaks = {
|
|
11
|
+
xhuge: { min: 3, max: 6, default: 5 },
|
|
12
|
+
huge: { min: 2, max: 4, default: 4 },
|
|
13
|
+
xlarge: { min: 2, max: 3, default: 3 },
|
|
14
|
+
large: { min: 1, max: 2, default: 2 },
|
|
15
|
+
mobile: { min: 1, max: 2, default: 2 },
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
function useViewPortBreakpoint() {
|
|
19
|
+
const isXHuge = useViewportMatch( 'xhuge', '>=' );
|
|
20
|
+
const isHuge = useViewportMatch( 'huge', '>=' );
|
|
21
|
+
const isXlarge = useViewportMatch( 'xlarge', '>=' );
|
|
22
|
+
const isLarge = useViewportMatch( 'large', '>=' );
|
|
23
|
+
const isMobile = useViewportMatch( 'mobile', '>=' );
|
|
24
|
+
|
|
25
|
+
if ( isXHuge ) {
|
|
26
|
+
return 'xhuge';
|
|
27
|
+
}
|
|
28
|
+
if ( isHuge ) {
|
|
29
|
+
return 'huge';
|
|
30
|
+
}
|
|
31
|
+
if ( isXlarge ) {
|
|
32
|
+
return 'xlarge';
|
|
33
|
+
}
|
|
34
|
+
if ( isLarge ) {
|
|
35
|
+
return 'large';
|
|
36
|
+
}
|
|
37
|
+
if ( isMobile ) {
|
|
38
|
+
return 'mobile';
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Value is number from 0 to 100 representing how big an item is in the grid
|
|
44
|
+
// 100 being the biggest and 0 being the smallest.
|
|
45
|
+
// The size is relative to the viewport size, if one a given viewport the
|
|
46
|
+
// number of allowed items in a grid is 3 to 6 a 0 ( the smallest ) will mean that the grid will
|
|
47
|
+
// have 6 items in a row, a 100 ( the biggest ) will mean that the grid will have 3 items in a row.
|
|
48
|
+
// A value of 75 will mean that the grid will have 4 items in a row.
|
|
49
|
+
function getRangeValue(
|
|
50
|
+
density: number,
|
|
51
|
+
breakValues: { min: number; max: number; default: number }
|
|
52
|
+
) {
|
|
53
|
+
const inverseDensity = breakValues.max - density;
|
|
54
|
+
const max = breakValues.max - breakValues.min;
|
|
55
|
+
return Math.round( ( inverseDensity * 100 ) / max );
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export default function DensityPicker( {
|
|
59
|
+
density,
|
|
60
|
+
setDensity,
|
|
61
|
+
}: {
|
|
62
|
+
density: number;
|
|
63
|
+
setDensity: React.Dispatch< React.SetStateAction< number > >;
|
|
64
|
+
} ) {
|
|
65
|
+
const viewport = useViewPortBreakpoint();
|
|
66
|
+
useEffect( () => {
|
|
67
|
+
setDensity( ( _density ) => {
|
|
68
|
+
if ( ! viewport || ! _density ) {
|
|
69
|
+
return 0;
|
|
70
|
+
}
|
|
71
|
+
const breakValues = viewportBreaks[ viewport ];
|
|
72
|
+
if ( _density < breakValues.min ) {
|
|
73
|
+
return breakValues.min;
|
|
74
|
+
}
|
|
75
|
+
if ( _density > breakValues.max ) {
|
|
76
|
+
return breakValues.max;
|
|
77
|
+
}
|
|
78
|
+
return _density;
|
|
79
|
+
} );
|
|
80
|
+
}, [ setDensity, viewport ] );
|
|
81
|
+
if ( ! viewport ) {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
const breakValues = viewportBreaks[ viewport ];
|
|
85
|
+
const densityToUse = density || breakValues.default;
|
|
86
|
+
const rangeValue = getRangeValue( densityToUse, breakValues );
|
|
87
|
+
|
|
88
|
+
const step = 100 / ( breakValues.max - breakValues.min + 1 );
|
|
89
|
+
return (
|
|
90
|
+
<>
|
|
91
|
+
<Button
|
|
92
|
+
size="compact"
|
|
93
|
+
icon={ lineSolid }
|
|
94
|
+
disabled={ rangeValue <= 0 }
|
|
95
|
+
accessibleWhenDisabled
|
|
96
|
+
label={ __( 'Decrease size' ) }
|
|
97
|
+
onClick={ () => {
|
|
98
|
+
setDensity( densityToUse + 1 );
|
|
99
|
+
} }
|
|
100
|
+
/>
|
|
101
|
+
<RangeControl
|
|
102
|
+
__nextHasNoMarginBottom
|
|
103
|
+
showTooltip={ false }
|
|
104
|
+
className="dataviews-density-picker__range-control"
|
|
105
|
+
label={ __( 'Item size' ) }
|
|
106
|
+
hideLabelFromVision
|
|
107
|
+
value={ rangeValue }
|
|
108
|
+
min={ 0 }
|
|
109
|
+
max={ 100 }
|
|
110
|
+
withInputField={ false }
|
|
111
|
+
onChange={ ( value = 0 ) => {
|
|
112
|
+
const inverseValue = 100 - value;
|
|
113
|
+
setDensity(
|
|
114
|
+
Math.round(
|
|
115
|
+
( inverseValue *
|
|
116
|
+
( breakValues.max - breakValues.min ) ) /
|
|
117
|
+
100 +
|
|
118
|
+
breakValues.min
|
|
119
|
+
)
|
|
120
|
+
);
|
|
121
|
+
} }
|
|
122
|
+
step={ step }
|
|
123
|
+
/>
|
|
124
|
+
<Button
|
|
125
|
+
size="compact"
|
|
126
|
+
icon={ plus }
|
|
127
|
+
disabled={ rangeValue >= 100 }
|
|
128
|
+
accessibleWhenDisabled
|
|
129
|
+
label={ __( 'Increase size' ) }
|
|
130
|
+
onClick={ () => {
|
|
131
|
+
setDensity( densityToUse - 1 );
|
|
132
|
+
} }
|
|
133
|
+
/>
|
|
134
|
+
</>
|
|
135
|
+
);
|
|
136
|
+
}
|