@wordpress/dataviews 4.22.0 → 5.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 +39 -0
- package/README.md +147 -32
- package/build/components/dataviews/index.js +71 -37
- package/build/components/dataviews/index.js.map +1 -1
- package/build/components/dataviews-context/index.js +15 -1
- package/build/components/dataviews-context/index.js.map +1 -1
- package/build/components/dataviews-filters/{filter-summary.js → filter.js} +108 -17
- package/build/components/dataviews-filters/filter.js.map +1 -0
- package/build/components/dataviews-filters/index.js +21 -20
- package/build/components/dataviews-filters/index.js.map +1 -1
- package/build/components/dataviews-filters/input-widget.js +76 -0
- package/build/components/dataviews-filters/input-widget.js.map +1 -0
- package/build/components/dataviews-filters/search-widget.js +33 -39
- package/build/components/dataviews-filters/search-widget.js.map +1 -1
- package/build/components/dataviews-filters/utils.js +25 -0
- package/build/components/dataviews-filters/utils.js.map +1 -0
- package/build/components/dataviews-item-actions/index.js +1 -1
- package/build/components/dataviews-item-actions/index.js.map +1 -1
- package/build/components/dataviews-layout/index.js +7 -2
- package/build/components/dataviews-layout/index.js.map +1 -1
- package/build/components/dataviews-pagination/index.js +4 -3
- package/build/components/dataviews-pagination/index.js.map +1 -1
- package/build/components/dataviews-selection-checkbox/index.js.map +1 -1
- package/build/components/dataviews-view-config/index.js +10 -19
- package/build/components/dataviews-view-config/index.js.map +1 -1
- package/build/constants.js +83 -2
- package/build/constants.js.map +1 -1
- package/build/dataform-controls/boolean.js +42 -0
- package/build/dataform-controls/boolean.js.map +1 -0
- package/build/dataform-controls/checkbox.js +44 -0
- package/build/dataform-controls/checkbox.js.map +1 -0
- package/build/dataform-controls/datetime.js +96 -2
- package/build/dataform-controls/datetime.js.map +1 -1
- package/build/dataform-controls/email.js +48 -0
- package/build/dataform-controls/email.js.map +1 -0
- package/build/dataform-controls/index.js +9 -1
- package/build/dataform-controls/index.js.map +1 -1
- package/build/dataform-controls/integer.js +49 -1
- package/build/dataform-controls/integer.js.map +1 -1
- package/build/dataform-controls/select.js +1 -0
- package/build/dataform-controls/select.js.map +1 -1
- package/build/dataform-controls/text.js +3 -1
- package/build/dataform-controls/text.js.map +1 -1
- package/build/dataform-controls/toggle-group.js +52 -0
- package/build/dataform-controls/toggle-group.js.map +1 -0
- package/build/dataforms-layouts/data-form-layout.js +1 -1
- package/build/dataforms-layouts/data-form-layout.js.map +1 -1
- package/build/dataforms-layouts/panel/index.js +14 -5
- package/build/dataforms-layouts/panel/index.js.map +1 -1
- package/build/dataforms-layouts/regular/index.js +23 -4
- package/build/dataforms-layouts/regular/index.js.map +1 -1
- package/build/dataviews-layouts/grid/index.js +89 -27
- package/build/dataviews-layouts/grid/index.js.map +1 -1
- package/build/dataviews-layouts/list/index.js +11 -6
- package/build/dataviews-layouts/list/index.js.map +1 -1
- package/build/dataviews-layouts/table/column-header-menu.js +9 -7
- package/build/dataviews-layouts/table/column-header-menu.js.map +1 -1
- package/build/dataviews-layouts/table/column-primary.js +18 -13
- package/build/dataviews-layouts/table/column-primary.js.map +1 -1
- package/build/dataviews-layouts/table/index.js +46 -14
- package/build/dataviews-layouts/table/index.js.map +1 -1
- package/build/dataviews-layouts/table/use-is-horizontal-scroll-end.js +65 -0
- package/build/dataviews-layouts/table/use-is-horizontal-scroll-end.js.map +1 -0
- package/build/dataviews-layouts/utils/item-click-wrapper.js +77 -0
- package/build/dataviews-layouts/utils/item-click-wrapper.js.map +1 -0
- package/build/field-types/array.js +62 -0
- package/build/field-types/array.js.map +1 -0
- package/build/field-types/boolean.js +71 -0
- package/build/field-types/boolean.js.map +1 -0
- package/build/field-types/date.js +57 -0
- package/build/field-types/date.js.map +1 -0
- package/build/field-types/datetime.js +19 -1
- package/build/field-types/datetime.js.map +1 -1
- package/build/field-types/email.js +60 -0
- package/build/field-types/email.js.map +1 -0
- package/build/field-types/index.js +42 -1
- package/build/field-types/index.js.map +1 -1
- package/build/field-types/integer.js +23 -1
- package/build/field-types/integer.js.map +1 -1
- package/build/field-types/media.js +31 -0
- package/build/field-types/media.js.map +1 -0
- package/build/field-types/text.js +23 -1
- package/build/field-types/text.js.map +1 -1
- package/build/filter-and-sort-data-view.js +174 -11
- package/build/filter-and-sort-data-view.js.map +1 -1
- package/build/normalize-fields.js +72 -11
- package/build/normalize-fields.js.map +1 -1
- package/build/types.js.map +1 -1
- package/build/utils.js +11 -19
- package/build/utils.js.map +1 -1
- package/build-module/components/dataviews/index.js +74 -40
- package/build-module/components/dataviews/index.js.map +1 -1
- package/build-module/components/dataviews-context/index.js +16 -2
- package/build-module/components/dataviews-context/index.js.map +1 -1
- package/build-module/components/dataviews-filters/filter.js +309 -0
- package/build-module/components/dataviews-filters/filter.js.map +1 -0
- package/build-module/components/dataviews-filters/index.js +22 -21
- package/build-module/components/dataviews-filters/index.js.map +1 -1
- package/build-module/components/dataviews-filters/input-widget.js +69 -0
- package/build-module/components/dataviews-filters/input-widget.js.map +1 -0
- package/build-module/components/dataviews-filters/search-widget.js +31 -37
- package/build-module/components/dataviews-filters/search-widget.js.map +1 -1
- package/build-module/components/dataviews-filters/utils.js +18 -0
- package/build-module/components/dataviews-filters/utils.js.map +1 -0
- package/build-module/components/dataviews-item-actions/index.js +1 -1
- package/build-module/components/dataviews-item-actions/index.js.map +1 -1
- package/build-module/components/dataviews-layout/index.js +7 -2
- package/build-module/components/dataviews-layout/index.js.map +1 -1
- package/build-module/components/dataviews-pagination/index.js +4 -4
- package/build-module/components/dataviews-pagination/index.js.map +1 -1
- package/build-module/components/dataviews-selection-checkbox/index.js.map +1 -1
- package/build-module/components/dataviews-view-config/index.js +9 -20
- package/build-module/components/dataviews-view-config/index.js.map +1 -1
- package/build-module/constants.js +82 -1
- package/build-module/constants.js.map +1 -1
- package/build-module/dataform-controls/boolean.js +35 -0
- package/build-module/dataform-controls/boolean.js.map +1 -0
- package/build-module/dataform-controls/checkbox.js +37 -0
- package/build-module/dataform-controls/checkbox.js.map +1 -0
- package/build-module/dataform-controls/datetime.js +98 -3
- package/build-module/dataform-controls/datetime.js.map +1 -1
- package/build-module/dataform-controls/email.js +41 -0
- package/build-module/dataform-controls/email.js.map +1 -0
- package/build-module/dataform-controls/index.js +9 -1
- package/build-module/dataform-controls/index.js.map +1 -1
- package/build-module/dataform-controls/integer.js +51 -3
- package/build-module/dataform-controls/integer.js.map +1 -1
- package/build-module/dataform-controls/select.js +1 -0
- package/build-module/dataform-controls/select.js.map +1 -1
- package/build-module/dataform-controls/text.js +3 -1
- package/build-module/dataform-controls/text.js.map +1 -1
- package/build-module/dataform-controls/toggle-group.js +45 -0
- package/build-module/dataform-controls/toggle-group.js.map +1 -0
- package/build-module/dataforms-layouts/data-form-layout.js +1 -1
- package/build-module/dataforms-layouts/data-form-layout.js.map +1 -1
- package/build-module/dataforms-layouts/panel/index.js +14 -5
- package/build-module/dataforms-layouts/panel/index.js.map +1 -1
- package/build-module/dataforms-layouts/regular/index.js +23 -4
- package/build-module/dataforms-layouts/regular/index.js.map +1 -1
- package/build-module/dataviews-layouts/grid/index.js +90 -29
- package/build-module/dataviews-layouts/grid/index.js.map +1 -1
- package/build-module/dataviews-layouts/list/index.js +11 -6
- package/build-module/dataviews-layouts/list/index.js.map +1 -1
- package/build-module/dataviews-layouts/table/column-header-menu.js +9 -7
- package/build-module/dataviews-layouts/table/column-header-menu.js.map +1 -1
- package/build-module/dataviews-layouts/table/column-primary.js +18 -12
- package/build-module/dataviews-layouts/table/column-primary.js.map +1 -1
- package/build-module/dataviews-layouts/table/index.js +47 -16
- package/build-module/dataviews-layouts/table/index.js.map +1 -1
- package/build-module/dataviews-layouts/table/use-is-horizontal-scroll-end.js +58 -0
- package/build-module/dataviews-layouts/table/use-is-horizontal-scroll-end.js.map +1 -0
- package/build-module/dataviews-layouts/utils/item-click-wrapper.js +71 -0
- package/build-module/dataviews-layouts/utils/item-click-wrapper.js.map +1 -0
- package/build-module/field-types/array.js +57 -0
- package/build-module/field-types/array.js.map +1 -0
- package/build-module/field-types/boolean.js +65 -0
- package/build-module/field-types/boolean.js.map +1 -0
- package/build-module/field-types/date.js +51 -0
- package/build-module/field-types/date.js.map +1 -0
- package/build-module/field-types/datetime.js +19 -1
- package/build-module/field-types/datetime.js.map +1 -1
- package/build-module/field-types/email.js +54 -0
- package/build-module/field-types/email.js.map +1 -0
- package/build-module/field-types/index.js +42 -1
- package/build-module/field-types/index.js.map +1 -1
- package/build-module/field-types/integer.js +23 -1
- package/build-module/field-types/integer.js.map +1 -1
- package/build-module/field-types/media.js +25 -0
- package/build-module/field-types/media.js.map +1 -0
- package/build-module/field-types/text.js +23 -1
- package/build-module/field-types/text.js.map +1 -1
- package/build-module/filter-and-sort-data-view.js +175 -12
- package/build-module/filter-and-sort-data-view.js.map +1 -1
- package/build-module/normalize-fields.js +72 -11
- package/build-module/normalize-fields.js.map +1 -1
- package/build-module/types.js.map +1 -1
- package/build-module/utils.js +10 -17
- package/build-module/utils.js.map +1 -1
- package/build-style/style-rtl.css +315 -13
- package/build-style/style.css +315 -13
- package/build-types/components/dataform/stories/index.story.d.ts.map +1 -1
- package/build-types/components/dataviews/index.d.ts +24 -3
- package/build-types/components/dataviews/index.d.ts.map +1 -1
- package/build-types/components/dataviews/stories/fixtures.d.ts +10 -1
- package/build-types/components/dataviews/stories/fixtures.d.ts.map +1 -1
- package/build-types/components/dataviews/stories/index.story.d.ts +23 -4
- package/build-types/components/dataviews/stories/index.story.d.ts.map +1 -1
- package/build-types/components/dataviews-context/index.d.ts +14 -1
- package/build-types/components/dataviews-context/index.d.ts.map +1 -1
- package/build-types/components/dataviews-filters/filter.d.ts +15 -0
- package/build-types/components/dataviews-filters/filter.d.ts.map +1 -0
- package/build-types/components/dataviews-filters/index.d.ts +3 -8
- package/build-types/components/dataviews-filters/index.d.ts.map +1 -1
- package/build-types/components/dataviews-filters/input-widget.d.ts +13 -0
- package/build-types/components/dataviews-filters/input-widget.d.ts.map +1 -0
- package/build-types/components/dataviews-filters/search-widget.d.ts +4 -5
- package/build-types/components/dataviews-filters/search-widget.d.ts.map +1 -1
- package/build-types/components/dataviews-filters/utils.d.ts +6 -0
- package/build-types/components/dataviews-filters/utils.d.ts.map +1 -0
- package/build-types/components/dataviews-layout/index.d.ts +5 -1
- package/build-types/components/dataviews-layout/index.d.ts.map +1 -1
- package/build-types/components/dataviews-pagination/index.d.ts +1 -1
- package/build-types/components/dataviews-pagination/index.d.ts.map +1 -1
- package/build-types/components/dataviews-selection-checkbox/index.d.ts +2 -2
- package/build-types/components/dataviews-selection-checkbox/index.d.ts.map +1 -1
- package/build-types/components/dataviews-view-config/index.d.ts +3 -4
- package/build-types/components/dataviews-view-config/index.d.ts.map +1 -1
- package/build-types/components/stories/index.story.d.ts +63 -0
- package/build-types/components/stories/index.story.d.ts.map +1 -0
- package/build-types/constants.d.ts +20 -3
- package/build-types/constants.d.ts.map +1 -1
- package/build-types/dataform-controls/boolean.d.ts +6 -0
- package/build-types/dataform-controls/boolean.d.ts.map +1 -0
- package/build-types/dataform-controls/checkbox.d.ts +6 -0
- package/build-types/dataform-controls/checkbox.d.ts.map +1 -0
- package/build-types/dataform-controls/datetime.d.ts +1 -1
- package/build-types/dataform-controls/datetime.d.ts.map +1 -1
- package/build-types/dataform-controls/email.d.ts +6 -0
- package/build-types/dataform-controls/email.d.ts.map +1 -0
- package/build-types/dataform-controls/index.d.ts +1 -1
- package/build-types/dataform-controls/index.d.ts.map +1 -1
- package/build-types/dataform-controls/integer.d.ts +1 -4
- package/build-types/dataform-controls/integer.d.ts.map +1 -1
- package/build-types/dataform-controls/select.d.ts.map +1 -1
- package/build-types/dataform-controls/text.d.ts.map +1 -1
- package/build-types/dataform-controls/toggle-group.d.ts +6 -0
- package/build-types/dataform-controls/toggle-group.d.ts.map +1 -0
- package/build-types/dataforms-layouts/panel/index.d.ts.map +1 -1
- package/build-types/dataforms-layouts/regular/index.d.ts.map +1 -1
- package/build-types/dataviews-layouts/grid/index.d.ts +2 -1
- package/build-types/dataviews-layouts/grid/index.d.ts.map +1 -1
- package/build-types/dataviews-layouts/index.d.ts +3 -3
- package/build-types/dataviews-layouts/list/index.d.ts.map +1 -1
- package/build-types/dataviews-layouts/table/column-header-menu.d.ts.map +1 -1
- package/build-types/dataviews-layouts/table/column-primary.d.ts +8 -1
- package/build-types/dataviews-layouts/table/column-primary.d.ts.map +1 -1
- package/build-types/dataviews-layouts/table/index.d.ts +1 -1
- package/build-types/dataviews-layouts/table/index.d.ts.map +1 -1
- package/build-types/dataviews-layouts/table/use-is-horizontal-scroll-end.d.ts +19 -0
- package/build-types/dataviews-layouts/table/use-is-horizontal-scroll-end.d.ts.map +1 -0
- package/build-types/dataviews-layouts/utils/item-click-wrapper.d.ts +15 -0
- package/build-types/dataviews-layouts/utils/item-click-wrapper.d.ts.map +1 -0
- package/build-types/field-types/array.d.ts +7 -0
- package/build-types/field-types/array.d.ts.map +1 -0
- package/build-types/field-types/boolean.d.ts +19 -0
- package/build-types/field-types/boolean.d.ts.map +1 -0
- package/build-types/field-types/date.d.ts +16 -0
- package/build-types/field-types/date.d.ts.map +1 -0
- package/build-types/field-types/datetime.d.ts +7 -1
- package/build-types/field-types/datetime.d.ts.map +1 -1
- package/build-types/field-types/email.d.ts +19 -0
- package/build-types/field-types/email.d.ts.map +1 -0
- package/build-types/field-types/index.d.ts +2 -10
- package/build-types/field-types/index.d.ts.map +1 -1
- package/build-types/field-types/integer.d.ts +7 -1
- package/build-types/field-types/integer.d.ts.map +1 -1
- package/build-types/field-types/media.d.ts +16 -0
- package/build-types/field-types/media.d.ts.map +1 -0
- package/build-types/field-types/text.d.ts +7 -1
- package/build-types/field-types/text.d.ts.map +1 -1
- package/build-types/filter-and-sort-data-view.d.ts.map +1 -1
- package/build-types/normalize-fields.d.ts.map +1 -1
- package/build-types/types.d.ts +74 -8
- package/build-types/types.d.ts.map +1 -1
- package/build-types/utils.d.ts +5 -2
- package/build-types/utils.d.ts.map +1 -1
- package/build-wp/index.js +3299 -1182
- package/package.json +18 -12
- package/src/components/dataform/stories/index.story.tsx +41 -20
- package/src/components/dataviews/index.tsx +108 -43
- package/src/components/dataviews/stories/fixtures.tsx +135 -69
- package/src/components/dataviews/stories/index.story.tsx +265 -7
- package/src/components/dataviews/stories/style.css +24 -3
- package/src/components/dataviews/style.scss +27 -0
- package/src/components/dataviews-context/index.ts +30 -2
- package/src/components/dataviews-filters/filter.tsx +603 -0
- package/src/components/dataviews-filters/index.tsx +23 -29
- package/src/components/dataviews-filters/input-widget.tsx +91 -0
- package/src/components/dataviews-filters/search-widget.tsx +51 -48
- package/src/components/dataviews-filters/style.scss +117 -14
- package/src/components/dataviews-filters/utils.ts +25 -0
- package/src/components/dataviews-item-actions/index.tsx +1 -1
- package/src/components/dataviews-layout/index.tsx +8 -1
- package/src/components/dataviews-pagination/index.tsx +4 -4
- package/src/components/dataviews-selection-checkbox/index.tsx +2 -2
- package/src/components/dataviews-view-config/index.tsx +10 -18
- package/src/components/stories/index.story.tsx +372 -0
- package/src/constants.ts +116 -1
- package/src/dataform-controls/boolean.tsx +30 -0
- package/src/dataform-controls/checkbox.tsx +31 -0
- package/src/dataform-controls/datetime.tsx +106 -2
- package/src/dataform-controls/email.tsx +42 -0
- package/src/dataform-controls/index.tsx +8 -0
- package/src/dataform-controls/integer.tsx +75 -1
- package/src/dataform-controls/select.tsx +1 -0
- package/src/dataform-controls/style.scss +5 -0
- package/src/dataform-controls/text.tsx +2 -1
- package/src/dataform-controls/toggle-group.tsx +59 -0
- package/src/dataforms-layouts/data-form-layout.tsx +1 -1
- package/src/dataforms-layouts/panel/index.tsx +19 -7
- package/src/dataforms-layouts/panel/style.scss +8 -1
- package/src/dataforms-layouts/regular/index.tsx +50 -17
- package/src/dataforms-layouts/regular/style.scss +4 -1
- package/src/dataviews-layouts/grid/index.tsx +180 -68
- package/src/dataviews-layouts/grid/style.scss +8 -0
- package/src/dataviews-layouts/list/index.tsx +12 -5
- package/src/dataviews-layouts/table/column-header-menu.tsx +10 -8
- package/src/dataviews-layouts/table/column-primary.tsx +26 -13
- package/src/dataviews-layouts/table/index.tsx +74 -10
- package/src/dataviews-layouts/table/style.scss +37 -1
- package/src/dataviews-layouts/table/use-is-horizontal-scroll-end.ts +82 -0
- package/src/dataviews-layouts/utils/item-click-wrapper.tsx +93 -0
- package/src/field-types/array.tsx +75 -0
- package/src/field-types/boolean.tsx +66 -0
- package/src/field-types/date.ts +56 -0
- package/src/field-types/datetime.tsx +46 -2
- package/src/field-types/email.tsx +79 -0
- package/src/field-types/index.tsx +50 -3
- package/src/field-types/integer.tsx +53 -2
- package/src/field-types/media.tsx +28 -0
- package/src/field-types/text.tsx +41 -2
- package/src/filter-and-sort-data-view.ts +270 -10
- package/src/normalize-fields.ts +116 -13
- package/src/test/dataviews.tsx +20 -2
- package/src/test/filter-and-sort-data-view.js +601 -25
- package/src/test/normalize-fields.ts +155 -0
- package/src/types.ts +112 -9
- package/src/utils.ts +10 -33
- package/tsconfig.json +2 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/build/components/dataviews-filters/filter-summary.js.map +0 -1
- package/build/dataviews-layouts/utils/get-clickable-item-props.js +0 -36
- package/build/dataviews-layouts/utils/get-clickable-item-props.js.map +0 -1
- package/build-module/components/dataviews-filters/filter-summary.js +0 -218
- package/build-module/components/dataviews-filters/filter-summary.js.map +0 -1
- package/build-module/dataviews-layouts/utils/get-clickable-item-props.js +0 -30
- package/build-module/dataviews-layouts/utils/get-clickable-item-props.js.map +0 -1
- package/build-types/components/dataviews-filters/filter-summary.d.ts +0 -14
- package/build-types/components/dataviews-filters/filter-summary.d.ts.map +0 -1
- package/build-types/dataviews-layouts/utils/get-clickable-item-props.d.ts +0 -19
- package/build-types/dataviews-layouts/utils/get-clickable-item-props.d.ts.map +0 -1
- package/src/components/dataviews-filters/filter-summary.tsx +0 -338
- package/src/dataviews-layouts/utils/get-clickable-item-props.ts +0 -39
|
@@ -6,12 +6,18 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.filterSortAndPaginate = filterSortAndPaginate;
|
|
8
8
|
var _removeAccents = _interopRequireDefault(require("remove-accents"));
|
|
9
|
+
var _dateFns = require("date-fns");
|
|
10
|
+
var _date = require("@wordpress/date");
|
|
9
11
|
var _constants = require("./constants");
|
|
10
12
|
var _normalizeFields = require("./normalize-fields");
|
|
11
13
|
/**
|
|
12
14
|
* External dependencies
|
|
13
15
|
*/
|
|
14
16
|
|
|
17
|
+
/**
|
|
18
|
+
* WordPress dependencies
|
|
19
|
+
*/
|
|
20
|
+
|
|
15
21
|
/**
|
|
16
22
|
* Internal dependencies
|
|
17
23
|
*/
|
|
@@ -21,6 +27,28 @@ function normalizeSearchInput(input = '') {
|
|
|
21
27
|
}
|
|
22
28
|
const EMPTY_ARRAY = [];
|
|
23
29
|
|
|
30
|
+
/**
|
|
31
|
+
* Calculates a date offset from now.
|
|
32
|
+
*
|
|
33
|
+
* @param value Number of units to offset.
|
|
34
|
+
* @param unit Unit of time to offset.
|
|
35
|
+
* @return Date offset from now.
|
|
36
|
+
*/
|
|
37
|
+
function getRelativeDate(value, unit) {
|
|
38
|
+
switch (unit) {
|
|
39
|
+
case 'days':
|
|
40
|
+
return (0, _dateFns.subDays)(new Date(), value);
|
|
41
|
+
case 'weeks':
|
|
42
|
+
return (0, _dateFns.subWeeks)(new Date(), value);
|
|
43
|
+
case 'months':
|
|
44
|
+
return (0, _dateFns.subMonths)(new Date(), value);
|
|
45
|
+
case 'years':
|
|
46
|
+
return (0, _dateFns.subYears)(new Date(), value);
|
|
47
|
+
default:
|
|
48
|
+
return new Date();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
24
52
|
/**
|
|
25
53
|
* Applies the filtering, sorting and pagination to the raw data based on the view configuration.
|
|
26
54
|
*
|
|
@@ -101,7 +129,7 @@ function filterSortAndPaginate(data, view, fields) {
|
|
|
101
129
|
filteredData = filteredData.filter(item => {
|
|
102
130
|
return filter.value === field.getValue({
|
|
103
131
|
item
|
|
104
|
-
});
|
|
132
|
+
}) || filter.value === undefined;
|
|
105
133
|
});
|
|
106
134
|
} else if (filter.operator === _constants.OPERATOR_IS_NOT) {
|
|
107
135
|
filteredData = filteredData.filter(item => {
|
|
@@ -109,23 +137,158 @@ function filterSortAndPaginate(data, view, fields) {
|
|
|
109
137
|
item
|
|
110
138
|
});
|
|
111
139
|
});
|
|
140
|
+
} else if (filter.operator === _constants.OPERATOR_ON && filter.value !== undefined) {
|
|
141
|
+
const filterDate = (0, _date.getDate)(filter.value);
|
|
142
|
+
filteredData = filteredData.filter(item => {
|
|
143
|
+
const fieldDate = (0, _date.getDate)(field.getValue({
|
|
144
|
+
item
|
|
145
|
+
}));
|
|
146
|
+
return filterDate.getTime() === fieldDate.getTime();
|
|
147
|
+
});
|
|
148
|
+
} else if (filter.operator === _constants.OPERATOR_NOT_ON && filter.value !== undefined) {
|
|
149
|
+
const filterDate = (0, _date.getDate)(filter.value);
|
|
150
|
+
filteredData = filteredData.filter(item => {
|
|
151
|
+
const fieldDate = (0, _date.getDate)(field.getValue({
|
|
152
|
+
item
|
|
153
|
+
}));
|
|
154
|
+
return filterDate.getTime() !== fieldDate.getTime();
|
|
155
|
+
});
|
|
156
|
+
} else if (filter.operator === _constants.OPERATOR_LESS_THAN && filter.value !== undefined) {
|
|
157
|
+
filteredData = filteredData.filter(item => {
|
|
158
|
+
const fieldValue = field.getValue({
|
|
159
|
+
item
|
|
160
|
+
});
|
|
161
|
+
return fieldValue < filter.value;
|
|
162
|
+
});
|
|
163
|
+
} else if (filter.operator === _constants.OPERATOR_GREATER_THAN && filter.value !== undefined) {
|
|
164
|
+
filteredData = filteredData.filter(item => {
|
|
165
|
+
const fieldValue = field.getValue({
|
|
166
|
+
item
|
|
167
|
+
});
|
|
168
|
+
return fieldValue > filter.value;
|
|
169
|
+
});
|
|
170
|
+
} else if (filter.operator === _constants.OPERATOR_LESS_THAN_OR_EQUAL && filter.value !== undefined) {
|
|
171
|
+
filteredData = filteredData.filter(item => {
|
|
172
|
+
const fieldValue = field.getValue({
|
|
173
|
+
item
|
|
174
|
+
});
|
|
175
|
+
return fieldValue <= filter.value;
|
|
176
|
+
});
|
|
177
|
+
} else if (filter.operator === _constants.OPERATOR_GREATER_THAN_OR_EQUAL && filter.value !== undefined) {
|
|
178
|
+
filteredData = filteredData.filter(item => {
|
|
179
|
+
const fieldValue = field.getValue({
|
|
180
|
+
item
|
|
181
|
+
});
|
|
182
|
+
return fieldValue >= filter.value;
|
|
183
|
+
});
|
|
184
|
+
} else if (filter.operator === _constants.OPERATOR_CONTAINS && filter?.value !== undefined) {
|
|
185
|
+
filteredData = filteredData.filter(item => {
|
|
186
|
+
const fieldValue = field.getValue({
|
|
187
|
+
item
|
|
188
|
+
});
|
|
189
|
+
return typeof fieldValue === 'string' && filter.value && fieldValue.toLowerCase().includes(String(filter.value).toLowerCase());
|
|
190
|
+
});
|
|
191
|
+
} else if (filter.operator === _constants.OPERATOR_NOT_CONTAINS && filter?.value !== undefined) {
|
|
192
|
+
filteredData = filteredData.filter(item => {
|
|
193
|
+
const fieldValue = field.getValue({
|
|
194
|
+
item
|
|
195
|
+
});
|
|
196
|
+
return typeof fieldValue === 'string' && filter.value && !fieldValue.toLowerCase().includes(String(filter.value).toLowerCase());
|
|
197
|
+
});
|
|
198
|
+
} else if (filter.operator === _constants.OPERATOR_STARTS_WITH && filter?.value !== undefined) {
|
|
199
|
+
filteredData = filteredData.filter(item => {
|
|
200
|
+
const fieldValue = field.getValue({
|
|
201
|
+
item
|
|
202
|
+
});
|
|
203
|
+
return typeof fieldValue === 'string' && filter.value && fieldValue.toLowerCase().startsWith(String(filter.value).toLowerCase());
|
|
204
|
+
});
|
|
205
|
+
} else if (filter.operator === _constants.OPERATOR_BEFORE && filter.value !== undefined) {
|
|
206
|
+
const filterValue = (0, _date.getDate)(filter.value);
|
|
207
|
+
filteredData = filteredData.filter(item => {
|
|
208
|
+
const fieldValue = (0, _date.getDate)(field.getValue({
|
|
209
|
+
item
|
|
210
|
+
}));
|
|
211
|
+
return fieldValue < filterValue;
|
|
212
|
+
});
|
|
213
|
+
} else if (filter.operator === _constants.OPERATOR_AFTER && filter.value !== undefined) {
|
|
214
|
+
const filterValue = (0, _date.getDate)(filter.value);
|
|
215
|
+
filteredData = filteredData.filter(item => {
|
|
216
|
+
const fieldValue = (0, _date.getDate)(field.getValue({
|
|
217
|
+
item
|
|
218
|
+
}));
|
|
219
|
+
return fieldValue > filterValue;
|
|
220
|
+
});
|
|
221
|
+
} else if (filter.operator === _constants.OPERATOR_BEFORE_INC && filter.value !== undefined) {
|
|
222
|
+
const filterValue = (0, _date.getDate)(filter.value);
|
|
223
|
+
filteredData = filteredData.filter(item => {
|
|
224
|
+
const fieldValue = (0, _date.getDate)(field.getValue({
|
|
225
|
+
item
|
|
226
|
+
}));
|
|
227
|
+
return fieldValue <= filterValue;
|
|
228
|
+
});
|
|
229
|
+
} else if (filter.operator === _constants.OPERATOR_AFTER_INC && filter.value !== undefined) {
|
|
230
|
+
const filterValue = (0, _date.getDate)(filter.value);
|
|
231
|
+
filteredData = filteredData.filter(item => {
|
|
232
|
+
const fieldValue = (0, _date.getDate)(field.getValue({
|
|
233
|
+
item
|
|
234
|
+
}));
|
|
235
|
+
return fieldValue >= filterValue;
|
|
236
|
+
});
|
|
237
|
+
} else if (filter.operator === _constants.OPERATOR_BETWEEN && Array.isArray(filter.value) && filter.value.length === 2 && filter.value[0] !== undefined && filter.value[1] !== undefined) {
|
|
238
|
+
filteredData = filteredData.filter(item => {
|
|
239
|
+
const fieldValue = field.getValue({
|
|
240
|
+
item
|
|
241
|
+
});
|
|
242
|
+
if (typeof fieldValue === 'number' || fieldValue instanceof Date || typeof fieldValue === 'string') {
|
|
243
|
+
return fieldValue >= filter.value[0] && fieldValue <= filter.value[1];
|
|
244
|
+
}
|
|
245
|
+
return false;
|
|
246
|
+
});
|
|
247
|
+
} else if (filter.operator === _constants.OPERATOR_IN_THE_PAST && filter.value?.value !== undefined && filter.value?.unit !== undefined) {
|
|
248
|
+
const targetDate = getRelativeDate(filter.value.value, filter.value.unit);
|
|
249
|
+
filteredData = filteredData.filter(item => {
|
|
250
|
+
const fieldValue = (0, _date.getDate)(field.getValue({
|
|
251
|
+
item
|
|
252
|
+
}));
|
|
253
|
+
return fieldValue >= targetDate && fieldValue <= new Date();
|
|
254
|
+
});
|
|
255
|
+
} else if (filter.operator === _constants.OPERATOR_OVER && filter.value?.value !== undefined && filter.value?.unit !== undefined) {
|
|
256
|
+
const targetDate = getRelativeDate(filter.value.value, filter.value.unit);
|
|
257
|
+
filteredData = filteredData.filter(item => {
|
|
258
|
+
const fieldValue = (0, _date.getDate)(field.getValue({
|
|
259
|
+
item
|
|
260
|
+
}));
|
|
261
|
+
return fieldValue < targetDate;
|
|
262
|
+
});
|
|
112
263
|
}
|
|
113
264
|
}
|
|
114
265
|
});
|
|
115
266
|
}
|
|
116
267
|
|
|
117
268
|
// Handle sorting.
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
269
|
+
const sortByField = view.sort?.field ? _fields.find(field => {
|
|
270
|
+
return field.id === view.sort?.field;
|
|
271
|
+
}) : null;
|
|
272
|
+
const groupByField = view.groupByField ? _fields.find(field => {
|
|
273
|
+
return field.id === view.groupByField;
|
|
274
|
+
}) : null;
|
|
275
|
+
if (sortByField || groupByField) {
|
|
276
|
+
filteredData.sort((a, b) => {
|
|
277
|
+
if (groupByField) {
|
|
278
|
+
const groupCompare = groupByField.sort(a, b, 'asc');
|
|
279
|
+
|
|
280
|
+
// If items are in different groups, return the group comparison result.
|
|
281
|
+
// Otherwise, fall back to sorting by the sort field.
|
|
282
|
+
if (groupCompare !== 0) {
|
|
283
|
+
return groupCompare;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
if (sortByField) {
|
|
125
287
|
var _view$sort$direction;
|
|
126
|
-
return
|
|
127
|
-
}
|
|
128
|
-
|
|
288
|
+
return sortByField.sort(a, b, (_view$sort$direction = view.sort?.direction) !== null && _view$sort$direction !== void 0 ? _view$sort$direction : 'desc');
|
|
289
|
+
}
|
|
290
|
+
return 0;
|
|
291
|
+
});
|
|
129
292
|
}
|
|
130
293
|
|
|
131
294
|
// Handle pagination.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_removeAccents","_interopRequireDefault","require","_constants","_normalizeFields","normalizeSearchInput","input","removeAccents","trim","toLowerCase","EMPTY_ARRAY","filterSortAndPaginate","data","view","fields","paginationInfo","totalItems","totalPages","_fields","normalizeFields","filteredData","search","normalizedSearch","filter","item","field","enableGlobalSearch","map","getValue","some","includes","filters","length","forEach","find","_field","id","operator","OPERATOR_IS_ANY","value","fieldValue","Array","isArray","filterValue","OPERATOR_IS_NONE","OPERATOR_IS_ALL","every","OPERATOR_IS_NOT_ALL","OPERATOR_IS","OPERATOR_IS_NOT","sort","fieldId","fieldToSort","a","b","_view$sort$direction","direction","page","undefined","perPage","start","Math","ceil","slice"],"sources":["@wordpress/dataviews/src/filter-and-sort-data-view.ts"],"sourcesContent":["/**\n * External dependencies\n */\nimport removeAccents from 'remove-accents';\n\n/**\n * Internal dependencies\n */\nimport {\n\tOPERATOR_IS,\n\tOPERATOR_IS_NOT,\n\tOPERATOR_IS_NONE,\n\tOPERATOR_IS_ANY,\n\tOPERATOR_IS_ALL,\n\tOPERATOR_IS_NOT_ALL,\n} from './constants';\nimport { normalizeFields } from './normalize-fields';\nimport type { Field, View } from './types';\n\nfunction normalizeSearchInput( input = '' ) {\n\treturn removeAccents( input.trim().toLowerCase() );\n}\n\nconst EMPTY_ARRAY: [] = [];\n\n/**\n * Applies the filtering, sorting and pagination to the raw data based on the view configuration.\n *\n * @param data Raw data.\n * @param view View config.\n * @param fields Fields config.\n *\n * @return Filtered, sorted and paginated data.\n */\nexport function filterSortAndPaginate< Item >(\n\tdata: Item[],\n\tview: View,\n\tfields: Field< Item >[]\n): {\n\tdata: Item[];\n\tpaginationInfo: { totalItems: number; totalPages: number };\n} {\n\tif ( ! data ) {\n\t\treturn {\n\t\t\tdata: EMPTY_ARRAY,\n\t\t\tpaginationInfo: { totalItems: 0, totalPages: 0 },\n\t\t};\n\t}\n\tconst _fields = normalizeFields( fields );\n\tlet filteredData = [ ...data ];\n\t// Handle global search.\n\tif ( view.search ) {\n\t\tconst normalizedSearch = normalizeSearchInput( view.search );\n\t\tfilteredData = filteredData.filter( ( item ) => {\n\t\t\treturn _fields\n\t\t\t\t.filter( ( field ) => field.enableGlobalSearch )\n\t\t\t\t.map( ( field ) => {\n\t\t\t\t\treturn normalizeSearchInput( field.getValue( { item } ) );\n\t\t\t\t} )\n\t\t\t\t.some( ( field ) => field.includes( normalizedSearch ) );\n\t\t} );\n\t}\n\n\tif ( view.filters && view.filters?.length > 0 ) {\n\t\tview.filters.forEach( ( filter ) => {\n\t\t\tconst field = _fields.find(\n\t\t\t\t( _field ) => _field.id === filter.field\n\t\t\t);\n\t\t\tif ( field ) {\n\t\t\t\tif (\n\t\t\t\t\tfilter.operator === OPERATOR_IS_ANY &&\n\t\t\t\t\tfilter?.value?.length > 0\n\t\t\t\t) {\n\t\t\t\t\tfilteredData = filteredData.filter( ( item ) => {\n\t\t\t\t\t\tconst fieldValue = field.getValue( { item } );\n\t\t\t\t\t\tif ( Array.isArray( fieldValue ) ) {\n\t\t\t\t\t\t\treturn filter.value.some( ( filterValue: any ) =>\n\t\t\t\t\t\t\t\tfieldValue.includes( filterValue )\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} else if ( typeof fieldValue === 'string' ) {\n\t\t\t\t\t\t\treturn filter.value.includes( fieldValue );\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t} );\n\t\t\t\t} else if (\n\t\t\t\t\tfilter.operator === OPERATOR_IS_NONE &&\n\t\t\t\t\tfilter?.value?.length > 0\n\t\t\t\t) {\n\t\t\t\t\tfilteredData = filteredData.filter( ( item ) => {\n\t\t\t\t\t\tconst fieldValue = field.getValue( { item } );\n\t\t\t\t\t\tif ( Array.isArray( fieldValue ) ) {\n\t\t\t\t\t\t\treturn ! filter.value.some( ( filterValue: any ) =>\n\t\t\t\t\t\t\t\tfieldValue.includes( filterValue )\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} else if ( typeof fieldValue === 'string' ) {\n\t\t\t\t\t\t\treturn ! filter.value.includes( fieldValue );\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t} );\n\t\t\t\t} else if (\n\t\t\t\t\tfilter.operator === OPERATOR_IS_ALL &&\n\t\t\t\t\tfilter?.value?.length > 0\n\t\t\t\t) {\n\t\t\t\t\tfilteredData = filteredData.filter( ( item ) => {\n\t\t\t\t\t\treturn filter.value.every( ( value: any ) => {\n\t\t\t\t\t\t\treturn field\n\t\t\t\t\t\t\t\t.getValue( { item } )\n\t\t\t\t\t\t\t\t?.includes( value );\n\t\t\t\t\t\t} );\n\t\t\t\t\t} );\n\t\t\t\t} else if (\n\t\t\t\t\tfilter.operator === OPERATOR_IS_NOT_ALL &&\n\t\t\t\t\tfilter?.value?.length > 0\n\t\t\t\t) {\n\t\t\t\t\tfilteredData = filteredData.filter( ( item ) => {\n\t\t\t\t\t\treturn filter.value.every( ( value: any ) => {\n\t\t\t\t\t\t\treturn ! field\n\t\t\t\t\t\t\t\t.getValue( { item } )\n\t\t\t\t\t\t\t\t?.includes( value );\n\t\t\t\t\t\t} );\n\t\t\t\t\t} );\n\t\t\t\t} else if ( filter.operator === OPERATOR_IS ) {\n\t\t\t\t\tfilteredData = filteredData.filter( ( item ) => {\n\t\t\t\t\t\treturn filter.value === field.getValue( { item } );\n\t\t\t\t\t} );\n\t\t\t\t} else if ( filter.operator === OPERATOR_IS_NOT ) {\n\t\t\t\t\tfilteredData = filteredData.filter( ( item ) => {\n\t\t\t\t\t\treturn filter.value !== field.getValue( { item } );\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t}\n\t\t} );\n\t}\n\n\t// Handle sorting.\n\tif ( view.sort ) {\n\t\tconst fieldId = view.sort.field;\n\t\tconst fieldToSort = _fields.find( ( field ) => {\n\t\t\treturn field.id === fieldId;\n\t\t} );\n\t\tif ( fieldToSort ) {\n\t\t\tfilteredData.sort( ( a, b ) => {\n\t\t\t\treturn fieldToSort.sort( a, b, view.sort?.direction ?? 'desc' );\n\t\t\t} );\n\t\t}\n\t}\n\n\t// Handle pagination.\n\tlet totalItems = filteredData.length;\n\tlet totalPages = 1;\n\tif ( view.page !== undefined && view.perPage !== undefined ) {\n\t\tconst start = ( view.page - 1 ) * view.perPage;\n\t\ttotalItems = filteredData?.length || 0;\n\t\ttotalPages = Math.ceil( totalItems / view.perPage );\n\t\tfilteredData = filteredData?.slice( start, start + view.perPage );\n\t}\n\n\treturn {\n\t\tdata: filteredData,\n\t\tpaginationInfo: {\n\t\t\ttotalItems,\n\t\t\ttotalPages,\n\t\t},\n\t};\n}\n"],"mappings":";;;;;;;AAGA,IAAAA,cAAA,GAAAC,sBAAA,CAAAC,OAAA;AAKA,IAAAC,UAAA,GAAAD,OAAA;AAQA,IAAAE,gBAAA,GAAAF,OAAA;AAhBA;AACA;AACA;;AAGA;AACA;AACA;;AAYA,SAASG,oBAAoBA,CAAEC,KAAK,GAAG,EAAE,EAAG;EAC3C,OAAO,IAAAC,sBAAa,EAAED,KAAK,CAACE,IAAI,CAAC,CAAC,CAACC,WAAW,CAAC,CAAE,CAAC;AACnD;AAEA,MAAMC,WAAe,GAAG,EAAE;;AAE1B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,qBAAqBA,CACpCC,IAAY,EACZC,IAAU,EACVC,MAAuB,EAItB;EACD,IAAK,CAAEF,IAAI,EAAG;IACb,OAAO;MACNA,IAAI,EAAEF,WAAW;MACjBK,cAAc,EAAE;QAAEC,UAAU,EAAE,CAAC;QAAEC,UAAU,EAAE;MAAE;IAChD,CAAC;EACF;EACA,MAAMC,OAAO,GAAG,IAAAC,gCAAe,EAAEL,MAAO,CAAC;EACzC,IAAIM,YAAY,GAAG,CA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1C,IAAI,CAACqC,IAAI,EAAEM,SAAS,cAAAD,oBAAA,cAAAA,oBAAA,GAAI,MAAO,CAAC;MAChE,CAAE,CAAC;IACJ;EACD;;EAEA;EACA,IAAIvC,UAAU,GAAGI,YAAY,CAACY,MAAM;EACpC,IAAIf,UAAU,GAAG,CAAC;EAClB,IAAKJ,IAAI,CAAC4C,IAAI,KAAKC,SAAS,IAAI7C,IAAI,CAAC8C,OAAO,KAAKD,SAAS,EAAG;IAC5D,MAAME,KAAK,GAAG,CAAE/C,IAAI,CAAC4C,IAAI,GAAG,CAAC,IAAK5C,IAAI,CAAC8C,OAAO;IAC9C3C,UAAU,GAAGI,YAAY,EAAEY,MAAM,IAAI,CAAC;IACtCf,UAAU,GAAG4C,IAAI,CAACC,IAAI,CAAE9C,UAAU,GAAGH,IAAI,CAAC8C,OAAQ,CAAC;IACnDvC,YAAY,GAAGA,YAAY,EAAE2C,KAAK,CAAEH,KAAK,EAAEA,KAAK,GAAG/C,IAAI,CAAC8C,OAAQ,CAAC;EAClE;EAEA,OAAO;IACN/C,IAAI,EAAEQ,YAAY;IAClBL,cAAc,EAAE;MACfC,UAAU;MACVC;IACD;EACD,CAAC;AACF","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_removeAccents","_interopRequireDefault","require","_dateFns","_date","_constants","_normalizeFields","normalizeSearchInput","input","removeAccents","trim","toLowerCase","EMPTY_ARRAY","getRelativeDate","value","unit","subDays","Date","subWeeks","subMonths","subYears","filterSortAndPaginate","data","view","fields","paginationInfo","totalItems","totalPages","_fields","normalizeFields","filteredData","search","normalizedSearch","filter","item","field","enableGlobalSearch","map","getValue","some","includes","filters","length","forEach","find","_field","id","operator","OPERATOR_IS_ANY","fieldValue","Array","isArray","filterValue","OPERATOR_IS_NONE","OPERATOR_IS_ALL","every","OPERATOR_IS_NOT_ALL","OPERATOR_IS","undefined","OPERATOR_IS_NOT","OPERATOR_ON","filterDate","getDate","fieldDate","getTime","OPERATOR_NOT_ON","OPERATOR_LESS_THAN","OPERATOR_GREATER_THAN","OPERATOR_LESS_THAN_OR_EQUAL","OPERATOR_GREATER_THAN_OR_EQUAL","OPERATOR_CONTAINS","String","OPERATOR_NOT_CONTAINS","OPERATOR_STARTS_WITH","startsWith","OPERATOR_BEFORE","OPERATOR_AFTER","OPERATOR_BEFORE_INC","OPERATOR_AFTER_INC","OPERATOR_BETWEEN","OPERATOR_IN_THE_PAST","targetDate","OPERATOR_OVER","sortByField","sort","groupByField","a","b","groupCompare","_view$sort$direction","direction","page","perPage","start","Math","ceil","slice"],"sources":["@wordpress/dataviews/src/filter-and-sort-data-view.ts"],"sourcesContent":["/**\n * External dependencies\n */\nimport removeAccents from 'remove-accents';\nimport { subDays, subWeeks, subMonths, subYears } from 'date-fns';\n\n/**\n * WordPress dependencies\n */\nimport { getDate } from '@wordpress/date';\n\n/**\n * Internal dependencies\n */\nimport {\n\tOPERATOR_IS,\n\tOPERATOR_IS_NOT,\n\tOPERATOR_IS_NONE,\n\tOPERATOR_IS_ANY,\n\tOPERATOR_IS_ALL,\n\tOPERATOR_IS_NOT_ALL,\n\tOPERATOR_LESS_THAN,\n\tOPERATOR_GREATER_THAN,\n\tOPERATOR_LESS_THAN_OR_EQUAL,\n\tOPERATOR_GREATER_THAN_OR_EQUAL,\n\tOPERATOR_BEFORE,\n\tOPERATOR_AFTER,\n\tOPERATOR_BEFORE_INC,\n\tOPERATOR_AFTER_INC,\n\tOPERATOR_CONTAINS,\n\tOPERATOR_NOT_CONTAINS,\n\tOPERATOR_STARTS_WITH,\n\tOPERATOR_BETWEEN,\n\tOPERATOR_ON,\n\tOPERATOR_NOT_ON,\n\tOPERATOR_IN_THE_PAST,\n\tOPERATOR_OVER,\n} from './constants';\nimport { normalizeFields } from './normalize-fields';\nimport type { Field, View } from './types';\n\nfunction normalizeSearchInput( input = '' ) {\n\treturn removeAccents( input.trim().toLowerCase() );\n}\n\nconst EMPTY_ARRAY: [] = [];\n\n/**\n * Calculates a date offset from now.\n *\n * @param value Number of units to offset.\n * @param unit Unit of time to offset.\n * @return Date offset from now.\n */\nfunction getRelativeDate( value: number, unit: string ): Date {\n\tswitch ( unit ) {\n\t\tcase 'days':\n\t\t\treturn subDays( new Date(), value );\n\t\tcase 'weeks':\n\t\t\treturn subWeeks( new Date(), value );\n\t\tcase 'months':\n\t\t\treturn subMonths( new Date(), value );\n\t\tcase 'years':\n\t\t\treturn subYears( new Date(), value );\n\t\tdefault:\n\t\t\treturn new Date();\n\t}\n}\n\n/**\n * Applies the filtering, sorting and pagination to the raw data based on the view configuration.\n *\n * @param data Raw data.\n * @param view View config.\n * @param fields Fields config.\n *\n * @return Filtered, sorted and paginated data.\n */\nexport function filterSortAndPaginate< Item >(\n\tdata: Item[],\n\tview: View,\n\tfields: Field< Item >[]\n): {\n\tdata: Item[];\n\tpaginationInfo: { totalItems: number; totalPages: number };\n} {\n\tif ( ! data ) {\n\t\treturn {\n\t\t\tdata: EMPTY_ARRAY,\n\t\t\tpaginationInfo: { totalItems: 0, totalPages: 0 },\n\t\t};\n\t}\n\tconst _fields = normalizeFields( fields );\n\tlet filteredData = [ ...data ];\n\t// Handle global search.\n\tif ( view.search ) {\n\t\tconst normalizedSearch = normalizeSearchInput( view.search );\n\t\tfilteredData = filteredData.filter( ( item ) => {\n\t\t\treturn _fields\n\t\t\t\t.filter( ( field ) => field.enableGlobalSearch )\n\t\t\t\t.map( ( field ) => {\n\t\t\t\t\treturn normalizeSearchInput( field.getValue( { item } ) );\n\t\t\t\t} )\n\t\t\t\t.some( ( field ) => field.includes( normalizedSearch ) );\n\t\t} );\n\t}\n\n\tif ( view.filters && view.filters?.length > 0 ) {\n\t\tview.filters.forEach( ( filter ) => {\n\t\t\tconst field = _fields.find(\n\t\t\t\t( _field ) => _field.id === filter.field\n\t\t\t);\n\t\t\tif ( field ) {\n\t\t\t\tif (\n\t\t\t\t\tfilter.operator === OPERATOR_IS_ANY &&\n\t\t\t\t\tfilter?.value?.length > 0\n\t\t\t\t) {\n\t\t\t\t\tfilteredData = filteredData.filter( ( item ) => {\n\t\t\t\t\t\tconst fieldValue = field.getValue( { item } );\n\t\t\t\t\t\tif ( Array.isArray( fieldValue ) ) {\n\t\t\t\t\t\t\treturn filter.value.some( ( filterValue: any ) =>\n\t\t\t\t\t\t\t\tfieldValue.includes( filterValue )\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} else if ( typeof fieldValue === 'string' ) {\n\t\t\t\t\t\t\treturn filter.value.includes( fieldValue );\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t} );\n\t\t\t\t} else if (\n\t\t\t\t\tfilter.operator === OPERATOR_IS_NONE &&\n\t\t\t\t\tfilter?.value?.length > 0\n\t\t\t\t) {\n\t\t\t\t\tfilteredData = filteredData.filter( ( item ) => {\n\t\t\t\t\t\tconst fieldValue = field.getValue( { item } );\n\t\t\t\t\t\tif ( Array.isArray( fieldValue ) ) {\n\t\t\t\t\t\t\treturn ! filter.value.some( ( filterValue: any ) =>\n\t\t\t\t\t\t\t\tfieldValue.includes( filterValue )\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t} else if ( typeof fieldValue === 'string' ) {\n\t\t\t\t\t\t\treturn ! filter.value.includes( fieldValue );\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t} );\n\t\t\t\t} else if (\n\t\t\t\t\tfilter.operator === OPERATOR_IS_ALL &&\n\t\t\t\t\tfilter?.value?.length > 0\n\t\t\t\t) {\n\t\t\t\t\tfilteredData = filteredData.filter( ( item ) => {\n\t\t\t\t\t\treturn filter.value.every( ( value: any ) => {\n\t\t\t\t\t\t\treturn field\n\t\t\t\t\t\t\t\t.getValue( { item } )\n\t\t\t\t\t\t\t\t?.includes( value );\n\t\t\t\t\t\t} );\n\t\t\t\t\t} );\n\t\t\t\t} else if (\n\t\t\t\t\tfilter.operator === OPERATOR_IS_NOT_ALL &&\n\t\t\t\t\tfilter?.value?.length > 0\n\t\t\t\t) {\n\t\t\t\t\tfilteredData = filteredData.filter( ( item ) => {\n\t\t\t\t\t\treturn filter.value.every( ( value: any ) => {\n\t\t\t\t\t\t\treturn ! field\n\t\t\t\t\t\t\t\t.getValue( { item } )\n\t\t\t\t\t\t\t\t?.includes( value );\n\t\t\t\t\t\t} );\n\t\t\t\t\t} );\n\t\t\t\t} else if ( filter.operator === OPERATOR_IS ) {\n\t\t\t\t\tfilteredData = filteredData.filter( ( item ) => {\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\tfilter.value === field.getValue( { item } ) ||\n\t\t\t\t\t\t\tfilter.value === undefined\n\t\t\t\t\t\t);\n\t\t\t\t\t} );\n\t\t\t\t} else if ( filter.operator === OPERATOR_IS_NOT ) {\n\t\t\t\t\tfilteredData = filteredData.filter( ( item ) => {\n\t\t\t\t\t\treturn filter.value !== field.getValue( { item } );\n\t\t\t\t\t} );\n\t\t\t\t} else if (\n\t\t\t\t\tfilter.operator === OPERATOR_ON &&\n\t\t\t\t\tfilter.value !== undefined\n\t\t\t\t) {\n\t\t\t\t\tconst filterDate = getDate( filter.value );\n\t\t\t\t\tfilteredData = filteredData.filter( ( item ) => {\n\t\t\t\t\t\tconst fieldDate = getDate( field.getValue( { item } ) );\n\t\t\t\t\t\treturn filterDate.getTime() === fieldDate.getTime();\n\t\t\t\t\t} );\n\t\t\t\t} else if (\n\t\t\t\t\tfilter.operator === OPERATOR_NOT_ON &&\n\t\t\t\t\tfilter.value !== undefined\n\t\t\t\t) {\n\t\t\t\t\tconst filterDate = getDate( filter.value );\n\t\t\t\t\tfilteredData = filteredData.filter( ( item ) => {\n\t\t\t\t\t\tconst fieldDate = getDate( field.getValue( { item } ) );\n\t\t\t\t\t\treturn filterDate.getTime() !== fieldDate.getTime();\n\t\t\t\t\t} );\n\t\t\t\t} else if (\n\t\t\t\t\tfilter.operator === OPERATOR_LESS_THAN &&\n\t\t\t\t\tfilter.value !== undefined\n\t\t\t\t) {\n\t\t\t\t\tfilteredData = filteredData.filter( ( item ) => {\n\t\t\t\t\t\tconst fieldValue = field.getValue( { item } );\n\t\t\t\t\t\treturn fieldValue < filter.value;\n\t\t\t\t\t} );\n\t\t\t\t} else if (\n\t\t\t\t\tfilter.operator === OPERATOR_GREATER_THAN &&\n\t\t\t\t\tfilter.value !== undefined\n\t\t\t\t) {\n\t\t\t\t\tfilteredData = filteredData.filter( ( item ) => {\n\t\t\t\t\t\tconst fieldValue = field.getValue( { item } );\n\t\t\t\t\t\treturn fieldValue > filter.value;\n\t\t\t\t\t} );\n\t\t\t\t} else if (\n\t\t\t\t\tfilter.operator === OPERATOR_LESS_THAN_OR_EQUAL &&\n\t\t\t\t\tfilter.value !== undefined\n\t\t\t\t) {\n\t\t\t\t\tfilteredData = filteredData.filter( ( item ) => {\n\t\t\t\t\t\tconst fieldValue = field.getValue( { item } );\n\t\t\t\t\t\treturn fieldValue <= filter.value;\n\t\t\t\t\t} );\n\t\t\t\t} else if (\n\t\t\t\t\tfilter.operator === OPERATOR_GREATER_THAN_OR_EQUAL &&\n\t\t\t\t\tfilter.value !== undefined\n\t\t\t\t) {\n\t\t\t\t\tfilteredData = filteredData.filter( ( item ) => {\n\t\t\t\t\t\tconst fieldValue = field.getValue( { item } );\n\t\t\t\t\t\treturn fieldValue >= filter.value;\n\t\t\t\t\t} );\n\t\t\t\t} else if (\n\t\t\t\t\tfilter.operator === OPERATOR_CONTAINS &&\n\t\t\t\t\tfilter?.value !== undefined\n\t\t\t\t) {\n\t\t\t\t\tfilteredData = filteredData.filter( ( item ) => {\n\t\t\t\t\t\tconst fieldValue = field.getValue( { item } );\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\ttypeof fieldValue === 'string' &&\n\t\t\t\t\t\t\tfilter.value &&\n\t\t\t\t\t\t\tfieldValue\n\t\t\t\t\t\t\t\t.toLowerCase()\n\t\t\t\t\t\t\t\t.includes(\n\t\t\t\t\t\t\t\t\tString( filter.value ).toLowerCase()\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t);\n\t\t\t\t\t} );\n\t\t\t\t} else if (\n\t\t\t\t\tfilter.operator === OPERATOR_NOT_CONTAINS &&\n\t\t\t\t\tfilter?.value !== undefined\n\t\t\t\t) {\n\t\t\t\t\tfilteredData = filteredData.filter( ( item ) => {\n\t\t\t\t\t\tconst fieldValue = field.getValue( { item } );\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\ttypeof fieldValue === 'string' &&\n\t\t\t\t\t\t\tfilter.value &&\n\t\t\t\t\t\t\t! fieldValue\n\t\t\t\t\t\t\t\t.toLowerCase()\n\t\t\t\t\t\t\t\t.includes(\n\t\t\t\t\t\t\t\t\tString( filter.value ).toLowerCase()\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t);\n\t\t\t\t\t} );\n\t\t\t\t} else if (\n\t\t\t\t\tfilter.operator === OPERATOR_STARTS_WITH &&\n\t\t\t\t\tfilter?.value !== undefined\n\t\t\t\t) {\n\t\t\t\t\tfilteredData = filteredData.filter( ( item ) => {\n\t\t\t\t\t\tconst fieldValue = field.getValue( { item } );\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\ttypeof fieldValue === 'string' &&\n\t\t\t\t\t\t\tfilter.value &&\n\t\t\t\t\t\t\tfieldValue\n\t\t\t\t\t\t\t\t.toLowerCase()\n\t\t\t\t\t\t\t\t.startsWith(\n\t\t\t\t\t\t\t\t\tString( filter.value ).toLowerCase()\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t);\n\t\t\t\t\t} );\n\t\t\t\t} else if (\n\t\t\t\t\tfilter.operator === OPERATOR_BEFORE &&\n\t\t\t\t\tfilter.value !== undefined\n\t\t\t\t) {\n\t\t\t\t\tconst filterValue = getDate( filter.value );\n\t\t\t\t\tfilteredData = filteredData.filter( ( item ) => {\n\t\t\t\t\t\tconst fieldValue = getDate(\n\t\t\t\t\t\t\tfield.getValue( { item } )\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn fieldValue < filterValue;\n\t\t\t\t\t} );\n\t\t\t\t} else if (\n\t\t\t\t\tfilter.operator === OPERATOR_AFTER &&\n\t\t\t\t\tfilter.value !== undefined\n\t\t\t\t) {\n\t\t\t\t\tconst filterValue = getDate( filter.value );\n\t\t\t\t\tfilteredData = filteredData.filter( ( item ) => {\n\t\t\t\t\t\tconst fieldValue = getDate(\n\t\t\t\t\t\t\tfield.getValue( { item } )\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn fieldValue > filterValue;\n\t\t\t\t\t} );\n\t\t\t\t} else if (\n\t\t\t\t\tfilter.operator === OPERATOR_BEFORE_INC &&\n\t\t\t\t\tfilter.value !== undefined\n\t\t\t\t) {\n\t\t\t\t\tconst filterValue = getDate( filter.value );\n\t\t\t\t\tfilteredData = filteredData.filter( ( item ) => {\n\t\t\t\t\t\tconst fieldValue = getDate(\n\t\t\t\t\t\t\tfield.getValue( { item } )\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn fieldValue <= filterValue;\n\t\t\t\t\t} );\n\t\t\t\t} else if (\n\t\t\t\t\tfilter.operator === OPERATOR_AFTER_INC &&\n\t\t\t\t\tfilter.value !== undefined\n\t\t\t\t) {\n\t\t\t\t\tconst filterValue = getDate( filter.value );\n\t\t\t\t\tfilteredData = filteredData.filter( ( item ) => {\n\t\t\t\t\t\tconst fieldValue = getDate(\n\t\t\t\t\t\t\tfield.getValue( { item } )\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn fieldValue >= filterValue;\n\t\t\t\t\t} );\n\t\t\t\t} else if (\n\t\t\t\t\tfilter.operator === OPERATOR_BETWEEN &&\n\t\t\t\t\tArray.isArray( filter.value ) &&\n\t\t\t\t\tfilter.value.length === 2 &&\n\t\t\t\t\tfilter.value[ 0 ] !== undefined &&\n\t\t\t\t\tfilter.value[ 1 ] !== undefined\n\t\t\t\t) {\n\t\t\t\t\tfilteredData = filteredData.filter( ( item ) => {\n\t\t\t\t\t\tconst fieldValue = field.getValue( { item } );\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\ttypeof fieldValue === 'number' ||\n\t\t\t\t\t\t\tfieldValue instanceof Date ||\n\t\t\t\t\t\t\ttypeof fieldValue === 'string'\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\tfieldValue >= filter.value[ 0 ] &&\n\t\t\t\t\t\t\t\tfieldValue <= filter.value[ 1 ]\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t} );\n\t\t\t\t} else if (\n\t\t\t\t\tfilter.operator === OPERATOR_IN_THE_PAST &&\n\t\t\t\t\tfilter.value?.value !== undefined &&\n\t\t\t\t\tfilter.value?.unit !== undefined\n\t\t\t\t) {\n\t\t\t\t\tconst targetDate = getRelativeDate(\n\t\t\t\t\t\tfilter.value.value,\n\t\t\t\t\t\tfilter.value.unit\n\t\t\t\t\t);\n\t\t\t\t\tfilteredData = filteredData.filter( ( item ) => {\n\t\t\t\t\t\tconst fieldValue = getDate(\n\t\t\t\t\t\t\tfield.getValue( { item } )\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\tfieldValue >= targetDate && fieldValue <= new Date()\n\t\t\t\t\t\t);\n\t\t\t\t\t} );\n\t\t\t\t} else if (\n\t\t\t\t\tfilter.operator === OPERATOR_OVER &&\n\t\t\t\t\tfilter.value?.value !== undefined &&\n\t\t\t\t\tfilter.value?.unit !== undefined\n\t\t\t\t) {\n\t\t\t\t\tconst targetDate = getRelativeDate(\n\t\t\t\t\t\tfilter.value.value,\n\t\t\t\t\t\tfilter.value.unit\n\t\t\t\t\t);\n\t\t\t\t\tfilteredData = filteredData.filter( ( item ) => {\n\t\t\t\t\t\tconst fieldValue = getDate(\n\t\t\t\t\t\t\tfield.getValue( { item } )\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn fieldValue < targetDate;\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t}\n\t\t} );\n\t}\n\n\t// Handle sorting.\n\tconst sortByField = view.sort?.field\n\t\t? _fields.find( ( field ) => {\n\t\t\t\treturn field.id === view.sort?.field;\n\t\t } )\n\t\t: null;\n\tconst groupByField = view.groupByField\n\t\t? _fields.find( ( field ) => {\n\t\t\t\treturn field.id === view.groupByField;\n\t\t } )\n\t\t: null;\n\tif ( sortByField || groupByField ) {\n\t\tfilteredData.sort( ( a, b ) => {\n\t\t\tif ( groupByField ) {\n\t\t\t\tconst groupCompare = groupByField.sort( a, b, 'asc' );\n\n\t\t\t\t// If items are in different groups, return the group comparison result.\n\t\t\t\t// Otherwise, fall back to sorting by the sort field.\n\t\t\t\tif ( groupCompare !== 0 ) {\n\t\t\t\t\treturn groupCompare;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif ( sortByField ) {\n\t\t\t\treturn sortByField.sort( a, b, view.sort?.direction ?? 'desc' );\n\t\t\t}\n\n\t\t\treturn 0;\n\t\t} );\n\t}\n\n\t// Handle pagination.\n\tlet totalItems = filteredData.length;\n\tlet totalPages = 1;\n\tif ( view.page !== undefined && view.perPage !== undefined ) {\n\t\tconst start = ( view.page - 1 ) * view.perPage;\n\t\ttotalItems = filteredData?.length || 0;\n\t\ttotalPages = Math.ceil( totalItems / view.perPage );\n\t\tfilteredData = filteredData?.slice( start, start + view.perPage );\n\t}\n\n\treturn {\n\t\tdata: filteredData,\n\t\tpaginationInfo: {\n\t\t\ttotalItems,\n\t\t\ttotalPages,\n\t\t},\n\t};\n}\n"],"mappings":";;;;;;;AAGA,IAAAA,cAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AAKA,IAAAE,KAAA,GAAAF,OAAA;AAKA,IAAAG,UAAA,GAAAH,OAAA;AAwBA,IAAAI,gBAAA,GAAAJ,OAAA;AAtCA;AACA;AACA;;AAIA;AACA;AACA;;AAGA;AACA;AACA;;AA4BA,SAASK,oBAAoBA,CAAEC,KAAK,GAAG,EAAE,EAAG;EAC3C,OAAO,IAAAC,sBAAa,EAAED,KAAK,CAACE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,OAAO,KAAKlC,SAAS,EAAG;IAC5D,MAAMmC,KAAK,GAAG,CAAEtE,IAAI,CAACoE,IAAI,GAAG,CAAC,IAAKpE,IAAI,CAACqE,OAAO;IAC9ClE,UAAU,GAAGI,YAAY,EAAEY,MAAM,IAAI,CAAC;IACtCf,UAAU,GAAGmE,IAAI,CAACC,IAAI,CAAErE,UAAU,GAAGH,IAAI,CAACqE,OAAQ,CAAC;IACnD9D,YAAY,GAAGA,YAAY,EAAEkE,KAAK,CAAEH,KAAK,EAAEA,KAAK,GAAGtE,IAAI,CAACqE,OAAQ,CAAC;EAClE;EAEA,OAAO;IACNtE,IAAI,EAAEQ,YAAY;IAClBL,cAAc,EAAE;MACfC,UAAU;MACVC;IACD;EACD,CAAC;AACF","ignoreList":[]}
|
|
@@ -7,6 +7,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.normalizeFields = normalizeFields;
|
|
8
8
|
var _fieldTypes = _interopRequireDefault(require("./field-types"));
|
|
9
9
|
var _dataformControls = require("./dataform-controls");
|
|
10
|
+
var _constants = require("./constants");
|
|
11
|
+
/**
|
|
12
|
+
* External dependencies
|
|
13
|
+
*/
|
|
14
|
+
|
|
10
15
|
/**
|
|
11
16
|
* Internal dependencies
|
|
12
17
|
*/
|
|
@@ -25,6 +30,61 @@ const getValueFromId = id => ({
|
|
|
25
30
|
}
|
|
26
31
|
return value;
|
|
27
32
|
};
|
|
33
|
+
function getFilterBy(field, fieldTypeDefinition) {
|
|
34
|
+
if (field.filterBy === false) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
if (typeof field.filterBy === 'object') {
|
|
38
|
+
let operators = field.filterBy.operators;
|
|
39
|
+
|
|
40
|
+
// Assign default values if no operator was provided.
|
|
41
|
+
if (!operators || !Array.isArray(operators)) {
|
|
42
|
+
operators = !!fieldTypeDefinition.filterBy ? fieldTypeDefinition.filterBy.defaultOperators : [];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Make sure only valid operators are included.
|
|
46
|
+
let validOperators = _constants.ALL_OPERATORS;
|
|
47
|
+
if (typeof fieldTypeDefinition.filterBy === 'object') {
|
|
48
|
+
validOperators = fieldTypeDefinition.filterBy.validOperators;
|
|
49
|
+
}
|
|
50
|
+
operators = operators.filter(operator => validOperators.includes(operator));
|
|
51
|
+
|
|
52
|
+
// The `between` operator is not supported when elements are provided.
|
|
53
|
+
if (field.elements && operators.includes(_constants.OPERATOR_BETWEEN)) {
|
|
54
|
+
operators = operators.filter(operator => operator !== _constants.OPERATOR_BETWEEN);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Do not allow mixing single & multiselection operators.
|
|
58
|
+
// Remove multiselection operators if any of the single selection ones is present.
|
|
59
|
+
const hasSingleSelectionOperator = operators.some(operator => _constants.SINGLE_SELECTION_OPERATORS.includes(operator));
|
|
60
|
+
if (hasSingleSelectionOperator) {
|
|
61
|
+
operators = operators.filter(operator =>
|
|
62
|
+
// The 'Between' operator is unique as it can be combined with single selection operators.
|
|
63
|
+
[..._constants.SINGLE_SELECTION_OPERATORS, _constants.OPERATOR_BETWEEN].includes(operator));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// If no operators are left at this point,
|
|
67
|
+
// the filters should be disabled.
|
|
68
|
+
if (operators.length === 0) {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
isPrimary: !!field.filterBy.isPrimary,
|
|
73
|
+
operators
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
if (fieldTypeDefinition.filterBy === false) {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
let defaultOperators = fieldTypeDefinition.filterBy.defaultOperators;
|
|
80
|
+
// The `between` operator is not supported when elements are provided.
|
|
81
|
+
if (field.elements && defaultOperators.includes(_constants.OPERATOR_BETWEEN)) {
|
|
82
|
+
defaultOperators = defaultOperators.filter(operator => operator !== _constants.OPERATOR_BETWEEN);
|
|
83
|
+
}
|
|
84
|
+
return {
|
|
85
|
+
operators: defaultOperators
|
|
86
|
+
};
|
|
87
|
+
}
|
|
28
88
|
|
|
29
89
|
/**
|
|
30
90
|
* Apply default values and normalize the fields config.
|
|
@@ -34,7 +94,7 @@ const getValueFromId = id => ({
|
|
|
34
94
|
*/
|
|
35
95
|
function normalizeFields(fields) {
|
|
36
96
|
return fields.map(field => {
|
|
37
|
-
var _field$sort, _field$isValid, _field$enableHiding, _field$enableSorting;
|
|
97
|
+
var _field$sort, _field$isValid, _field$render, _field$enableHiding, _ref, _field$enableSorting, _ref2, _field$readOnly;
|
|
38
98
|
const fieldTypeDefinition = (0, _fieldTypes.default)(field.type);
|
|
39
99
|
const getValue = field.getValue || getValueFromId(field.id);
|
|
40
100
|
const sort = (_field$sort = field.sort) !== null && _field$sort !== void 0 ? _field$sort : function sort(a, b, direction) {
|
|
@@ -50,17 +110,16 @@ function normalizeFields(fields) {
|
|
|
50
110
|
}), context);
|
|
51
111
|
};
|
|
52
112
|
const Edit = (0, _dataformControls.getControl)(field, fieldTypeDefinition);
|
|
53
|
-
const
|
|
54
|
-
item
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
item
|
|
113
|
+
const render = (_field$render = field.render) !== null && _field$render !== void 0 ? _field$render : function render({
|
|
114
|
+
item,
|
|
115
|
+
field: renderedField
|
|
116
|
+
}) {
|
|
117
|
+
return fieldTypeDefinition.render({
|
|
118
|
+
item,
|
|
119
|
+
field: renderedField
|
|
61
120
|
});
|
|
62
121
|
};
|
|
63
|
-
const
|
|
122
|
+
const filterBy = getFilterBy(field, fieldTypeDefinition);
|
|
64
123
|
return {
|
|
65
124
|
...field,
|
|
66
125
|
label: field.label || field.id,
|
|
@@ -71,7 +130,9 @@ function normalizeFields(fields) {
|
|
|
71
130
|
isValid,
|
|
72
131
|
Edit,
|
|
73
132
|
enableHiding: (_field$enableHiding = field.enableHiding) !== null && _field$enableHiding !== void 0 ? _field$enableHiding : true,
|
|
74
|
-
enableSorting: (_field$enableSorting = field.enableSorting) !== null && _field$enableSorting !== void 0 ? _field$enableSorting : true
|
|
133
|
+
enableSorting: (_ref = (_field$enableSorting = field.enableSorting) !== null && _field$enableSorting !== void 0 ? _field$enableSorting : fieldTypeDefinition.enableSorting) !== null && _ref !== void 0 ? _ref : true,
|
|
134
|
+
filterBy,
|
|
135
|
+
readOnly: (_ref2 = (_field$readOnly = field.readOnly) !== null && _field$readOnly !== void 0 ? _field$readOnly : fieldTypeDefinition.readOnly) !== null && _ref2 !== void 0 ? _ref2 : false
|
|
75
136
|
};
|
|
76
137
|
});
|
|
77
138
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_fieldTypes","_interopRequireDefault","require","_dataformControls","getValueFromId","id","item","path","split","value","segment","hasOwnProperty","undefined","normalizeFields","fields","map","
|
|
1
|
+
{"version":3,"names":["_fieldTypes","_interopRequireDefault","require","_dataformControls","_constants","getValueFromId","id","item","path","split","value","segment","hasOwnProperty","undefined","getFilterBy","field","fieldTypeDefinition","filterBy","operators","Array","isArray","defaultOperators","validOperators","ALL_OPERATORS","filter","operator","includes","elements","OPERATOR_BETWEEN","hasSingleSelectionOperator","some","SINGLE_SELECTION_OPERATORS","length","isPrimary","normalizeFields","fields","map","_field$sort","_field$isValid","_field$render","_field$enableHiding","_ref","_field$enableSorting","_ref2","_field$readOnly","getFieldTypeDefinition","type","getValue","sort","a","b","direction","isValid","context","Edit","getControl","render","renderedField","label","header","enableHiding","enableSorting","readOnly"],"sources":["@wordpress/dataviews/src/normalize-fields.ts"],"sourcesContent":["/**\n * External dependencies\n */\nimport type { FunctionComponent } from 'react';\n\n/**\n * Internal dependencies\n */\nimport getFieldTypeDefinition from './field-types';\nimport type {\n\tDataViewRenderFieldProps,\n\tField,\n\tFieldTypeDefinition,\n\tNormalizedFilterByConfig,\n\tNormalizedField,\n} from './types';\nimport { getControl } from './dataform-controls';\nimport {\n\tALL_OPERATORS,\n\tOPERATOR_BETWEEN,\n\tSINGLE_SELECTION_OPERATORS,\n} from './constants';\n\nconst getValueFromId =\n\t( id: string ) =>\n\t( { item }: { item: any } ) => {\n\t\tconst path = id.split( '.' );\n\t\tlet value = item;\n\t\tfor ( const segment of path ) {\n\t\t\tif ( value.hasOwnProperty( segment ) ) {\n\t\t\t\tvalue = value[ segment ];\n\t\t\t} else {\n\t\t\t\tvalue = undefined;\n\t\t\t}\n\t\t}\n\n\t\treturn value;\n\t};\n\nfunction getFilterBy< Item >(\n\tfield: Field< Item >,\n\tfieldTypeDefinition: FieldTypeDefinition< Item >\n): NormalizedFilterByConfig | false {\n\tif ( field.filterBy === false ) {\n\t\treturn false;\n\t}\n\n\tif ( typeof field.filterBy === 'object' ) {\n\t\tlet operators = field.filterBy.operators;\n\n\t\t// Assign default values if no operator was provided.\n\t\tif ( ! operators || ! Array.isArray( operators ) ) {\n\t\t\toperators = !! fieldTypeDefinition.filterBy\n\t\t\t\t? fieldTypeDefinition.filterBy.defaultOperators\n\t\t\t\t: [];\n\t\t}\n\n\t\t// Make sure only valid operators are included.\n\t\tlet validOperators = ALL_OPERATORS;\n\t\tif ( typeof fieldTypeDefinition.filterBy === 'object' ) {\n\t\t\tvalidOperators = fieldTypeDefinition.filterBy.validOperators;\n\t\t}\n\t\toperators = operators.filter( ( operator ) =>\n\t\t\tvalidOperators.includes( operator )\n\t\t);\n\n\t\t// The `between` operator is not supported when elements are provided.\n\t\tif ( field.elements && operators.includes( OPERATOR_BETWEEN ) ) {\n\t\t\toperators = operators.filter(\n\t\t\t\t( operator ) => operator !== OPERATOR_BETWEEN\n\t\t\t);\n\t\t}\n\n\t\t// Do not allow mixing single & multiselection operators.\n\t\t// Remove multiselection operators if any of the single selection ones is present.\n\t\tconst hasSingleSelectionOperator = operators.some( ( operator ) =>\n\t\t\tSINGLE_SELECTION_OPERATORS.includes( operator )\n\t\t);\n\t\tif ( hasSingleSelectionOperator ) {\n\t\t\toperators = operators.filter( ( operator ) =>\n\t\t\t\t// The 'Between' operator is unique as it can be combined with single selection operators.\n\t\t\t\t[ ...SINGLE_SELECTION_OPERATORS, OPERATOR_BETWEEN ].includes(\n\t\t\t\t\toperator\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\n\t\t// If no operators are left at this point,\n\t\t// the filters should be disabled.\n\t\tif ( operators.length === 0 ) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn {\n\t\t\tisPrimary: !! field.filterBy.isPrimary,\n\t\t\toperators,\n\t\t};\n\t}\n\n\tif ( fieldTypeDefinition.filterBy === false ) {\n\t\treturn false;\n\t}\n\n\tlet defaultOperators = fieldTypeDefinition.filterBy.defaultOperators;\n\t// The `between` operator is not supported when elements are provided.\n\tif ( field.elements && defaultOperators.includes( OPERATOR_BETWEEN ) ) {\n\t\tdefaultOperators = defaultOperators.filter(\n\t\t\t( operator ) => operator !== OPERATOR_BETWEEN\n\t\t);\n\t}\n\n\treturn {\n\t\toperators: defaultOperators,\n\t};\n}\n\n/**\n * Apply default values and normalize the fields config.\n *\n * @param fields Fields config.\n * @return Normalized fields config.\n */\nexport function normalizeFields< Item >(\n\tfields: Field< Item >[]\n): NormalizedField< Item >[] {\n\treturn fields.map( ( field ) => {\n\t\tconst fieldTypeDefinition = getFieldTypeDefinition< Item >(\n\t\t\tfield.type\n\t\t);\n\t\tconst getValue = field.getValue || getValueFromId( field.id );\n\n\t\tconst sort =\n\t\t\tfield.sort ??\n\t\t\tfunction sort( a, b, direction ) {\n\t\t\t\treturn fieldTypeDefinition.sort(\n\t\t\t\t\tgetValue( { item: a } ),\n\t\t\t\t\tgetValue( { item: b } ),\n\t\t\t\t\tdirection\n\t\t\t\t);\n\t\t\t};\n\n\t\tconst isValid =\n\t\t\tfield.isValid ??\n\t\t\tfunction isValid( item, context ) {\n\t\t\t\treturn fieldTypeDefinition.isValid(\n\t\t\t\t\tgetValue( { item } ),\n\t\t\t\t\tcontext\n\t\t\t\t);\n\t\t\t};\n\n\t\tconst Edit = getControl( field, fieldTypeDefinition );\n\n\t\tconst render =\n\t\t\tfield.render ??\n\t\t\tfunction render( {\n\t\t\t\titem,\n\t\t\t\tfield: renderedField,\n\t\t\t}: DataViewRenderFieldProps< Item > ) {\n\t\t\t\treturn (\n\t\t\t\t\tfieldTypeDefinition.render as FunctionComponent<\n\t\t\t\t\t\tDataViewRenderFieldProps< Item >\n\t\t\t\t\t>\n\t\t\t\t )( { item, field: renderedField } );\n\t\t\t};\n\n\t\tconst filterBy = getFilterBy( field, fieldTypeDefinition );\n\n\t\treturn {\n\t\t\t...field,\n\t\t\tlabel: field.label || field.id,\n\t\t\theader: field.header || field.label || field.id,\n\t\t\tgetValue,\n\t\t\trender,\n\t\t\tsort,\n\t\t\tisValid,\n\t\t\tEdit,\n\t\t\tenableHiding: field.enableHiding ?? true,\n\t\t\tenableSorting:\n\t\t\t\tfield.enableSorting ??\n\t\t\t\tfieldTypeDefinition.enableSorting ??\n\t\t\t\ttrue,\n\t\t\tfilterBy,\n\t\t\treadOnly: field.readOnly ?? fieldTypeDefinition.readOnly ?? false,\n\t\t};\n\t} );\n}\n"],"mappings":";;;;;;;AAQA,IAAAA,WAAA,GAAAC,sBAAA,CAAAC,OAAA;AAQA,IAAAC,iBAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAF,OAAA;AAjBA;AACA;AACA;;AAGA;AACA;AACA;;AAgBA,MAAMG,cAAc,GACjBC,EAAU,IACZ,CAAE;EAAEC;AAAoB,CAAC,KAAM;EAC9B,MAAMC,IAAI,GAAGF,EAAE,CAACG,KAAK,CAAE,GAAI,CAAC;EAC5B,IAAIC,KAAK,GAAGH,IAAI;EAChB,KAAM,MAAMI,OAAO,IAAIH,IAAI,EAAG;IAC7B,IAAKE,KAAK,CAACE,cAAc,CAAED,OAAQ,CAAC,EAAG;MACtCD,KAAK,GAAGA,KAAK,CAAEC,OAAO,CAAE;IACzB,CAAC,MAAM;MACND,KAAK,GAAGG,SAAS;IAClB;EACD;EAEA,OAAOH,KAAK;AACb,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ApB,IAAA,cAAAA,IAAA,GACjC,IAAI;MACLxB,QAAQ;MACR6C,QAAQ,GAAAnB,KAAA,IAAAC,eAAA,GAAE7B,KAAK,CAAC+C,QAAQ,cAAAlB,eAAA,cAAAA,eAAA,GAAI5B,mBAAmB,CAAC8C,QAAQ,cAAAnB,KAAA,cAAAA,KAAA,GAAI;IAC7D,CAAC;EACF,CAAE,CAAC;AACJ","ignoreList":[]}
|
package/build/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["@wordpress/dataviews/src/types.ts"],"sourcesContent":["/**\n * External dependencies\n */\nimport type { ReactElement, ComponentType } from 'react';\n\n/**\n * Internal dependencies\n */\nimport type { SetSelection } from './private-types';\n\n/**\n * WordPress dependencies\n */\nimport type { useFocusOnMount } from '@wordpress/compose';\n\nexport type SortDirection = 'asc' | 'desc';\n\n/**\n * Generic option type.\n */\nexport interface Option< Value extends any = any > {\n\tvalue: Value;\n\tlabel: string;\n\tdescription?: string;\n}\n\ninterface FilterByConfig {\n\t/**\n\t * The list of operators supported by the field.\n\t */\n\toperators?: Operator[];\n\n\t/**\n\t * Whether it is a primary filter.\n\t *\n\t * A primary filter is always visible and is not listed in the \"Add filter\" component,\n\t * except for the list layout where it behaves like a secondary filter.\n\t */\n\tisPrimary?: boolean;\n}\n\nexport type Operator =\n\t| 'is'\n\t| 'isNot'\n\t| 'isAny'\n\t| 'isNone'\n\t| 'isAll'\n\t| 'isNotAll';\n\nexport type FieldType = 'text' | 'integer' | 'datetime' | 'media';\n\nexport type ValidationContext = {\n\telements?: Option[];\n};\n\n/**\n * An abstract interface for Field based on the field type.\n */\nexport type FieldTypeDefinition< Item > = {\n\t/**\n\t * Callback used to sort the field.\n\t */\n\tsort: ( a: Item, b: Item, direction: SortDirection ) => number;\n\n\t/**\n\t * Callback used to validate the field.\n\t */\n\tisValid: ( item: Item, context?: ValidationContext ) => boolean;\n\n\t/**\n\t * Callback used to render an edit control for the field or control name.\n\t */\n\tEdit: ComponentType< DataFormControlProps< Item > > | string;\n};\n\n/**\n * A dataview field for a specific property of a data type.\n */\nexport type Field< Item > = {\n\t/**\n\t * Type of the fields.\n\t */\n\ttype?: FieldType;\n\n\t/**\n\t * The unique identifier of the field.\n\t */\n\tid: string;\n\n\t/**\n\t * The label of the field. Defaults to the id.\n\t */\n\tlabel?: string;\n\n\t/**\n\t * The header of the field. Defaults to the label.\n\t * It allows the usage of a React Element to render the field labels.\n\t */\n\theader?: string | ReactElement;\n\n\t/**\n\t * A description of the field.\n\t */\n\tdescription?: string;\n\n\t/**\n\t * Placeholder for the field.\n\t */\n\tplaceholder?: string;\n\n\t/**\n\t * Callback used to render the field. Defaults to `field.getValue`.\n\t */\n\trender?: ComponentType< DataViewRenderFieldProps< Item > >;\n\n\t/**\n\t * Callback used to render an edit control for the field.\n\t */\n\tEdit?: ComponentType< DataFormControlProps< Item > > | string;\n\n\t/**\n\t * Callback used to sort the field.\n\t */\n\tsort?: ( a: Item, b: Item, direction: SortDirection ) => number;\n\n\t/**\n\t * Callback used to validate the field.\n\t */\n\tisValid?: ( item: Item, context?: ValidationContext ) => boolean;\n\n\t/**\n\t * Callback used to decide if a field should be displayed.\n\t */\n\tisVisible?: ( item: Item ) => boolean;\n\n\t/**\n\t * Whether the field is sortable.\n\t */\n\tenableSorting?: boolean;\n\n\t/**\n\t * Whether the field is searchable.\n\t */\n\tenableGlobalSearch?: boolean;\n\n\t/**\n\t * Whether the field is filterable.\n\t */\n\tenableHiding?: boolean;\n\n\t/**\n\t * The list of options to pick from when using the field as a filter.\n\t */\n\telements?: Option[];\n\n\t/**\n\t * Filter config for the field.\n\t */\n\tfilterBy?: FilterByConfig | undefined;\n\n\t/**\n\t * Callback used to retrieve the value of the field from the item.\n\t * Defaults to `item[ field.id ]`.\n\t */\n\tgetValue?: ( args: { item: Item } ) => any;\n};\n\nexport type NormalizedField< Item > = Field< Item > & {\n\tlabel: string;\n\theader: string | ReactElement;\n\tgetValue: ( args: { item: Item } ) => any;\n\trender: ComponentType< DataViewRenderFieldProps< Item > >;\n\tEdit: ComponentType< DataFormControlProps< Item > >;\n\tsort: ( a: Item, b: Item, direction: SortDirection ) => number;\n\tisValid: ( item: Item, context?: ValidationContext ) => boolean;\n\tenableHiding: boolean;\n\tenableSorting: boolean;\n};\n\n/**\n * A collection of dataview fields for a data type.\n */\nexport type Fields< Item > = Field< Item >[];\n\nexport type Data< Item > = Item[];\n\nexport type DataFormControlProps< Item > = {\n\tdata: Item;\n\tfield: NormalizedField< Item >;\n\tonChange: ( value: Record< string, any > ) => void;\n\thideLabelFromVision?: boolean;\n};\n\nexport type DataViewRenderFieldProps< Item > = {\n\titem: Item;\n};\n\n/**\n * The filters applied to the dataset.\n */\nexport interface Filter {\n\t/**\n\t * The field to filter by.\n\t */\n\tfield: string;\n\n\t/**\n\t * The operator to use.\n\t */\n\toperator: Operator;\n\n\t/**\n\t * The value to filter by.\n\t */\n\tvalue: any;\n}\n\nexport interface NormalizedFilter {\n\t/**\n\t * The field to filter by.\n\t */\n\tfield: string;\n\n\t/**\n\t * The field name.\n\t */\n\tname: string;\n\n\t/**\n\t * The list of options to pick from when using the field as a filter.\n\t */\n\telements: Option[];\n\n\t/**\n\t * Is a single selection filter.\n\t */\n\tsingleSelection: boolean;\n\n\t/**\n\t * The list of operators supported by the field.\n\t */\n\toperators: Operator[];\n\n\t/**\n\t * Whether the filter is visible.\n\t */\n\tisVisible: boolean;\n\n\t/**\n\t * Whether it is a primary filter.\n\t */\n\tisPrimary: boolean;\n}\n\ninterface ViewBase {\n\t/**\n\t * The layout of the view.\n\t */\n\ttype: string;\n\n\t/**\n\t * The global search term.\n\t */\n\tsearch?: string;\n\n\t/**\n\t * The filters to apply.\n\t */\n\tfilters?: Filter[];\n\n\t/**\n\t * The sorting configuration.\n\t */\n\tsort?: {\n\t\t/**\n\t\t * The field to sort by.\n\t\t */\n\t\tfield: string;\n\n\t\t/**\n\t\t * The direction to sort by.\n\t\t */\n\t\tdirection: SortDirection;\n\t};\n\n\t/**\n\t * The active page\n\t */\n\tpage?: number;\n\n\t/**\n\t * The number of items per page\n\t */\n\tperPage?: number;\n\n\t/**\n\t * The fields to render\n\t */\n\tfields?: string[];\n\n\t/**\n\t * Title field\n\t */\n\ttitleField?: string;\n\n\t/**\n\t * Media field\n\t */\n\tmediaField?: string;\n\n\t/**\n\t * Description field\n\t */\n\tdescriptionField?: string;\n\n\t/**\n\t * Whether to show the title\n\t */\n\tshowTitle?: boolean;\n\n\t/**\n\t * Whether to show the media\n\t */\n\tshowMedia?: boolean;\n\n\t/**\n\t * Whether to show the description\n\t */\n\tshowDescription?: boolean;\n\n\t/**\n\t * Whether to show the hierarchical levels.\n\t */\n\tshowLevels?: boolean;\n}\n\nexport interface ColumnStyle {\n\t/**\n\t * The width of the field column.\n\t */\n\twidth?: string | number;\n\n\t/**\n\t * The minimum width of the field column.\n\t */\n\tmaxWidth?: string | number;\n\n\t/**\n\t * The maximum width of the field column.\n\t */\n\tminWidth?: string | number;\n}\n\nexport type Density = 'compact' | 'balanced' | 'comfortable';\n\nexport interface ViewTable extends ViewBase {\n\ttype: 'table';\n\n\tlayout?: {\n\t\t/**\n\t\t * The styles for the columns.\n\t\t */\n\t\tstyles?: Record< string, ColumnStyle >;\n\n\t\t/**\n\t\t * The density of the view.\n\t\t */\n\t\tdensity?: Density;\n\t};\n}\n\nexport interface ViewList extends ViewBase {\n\ttype: 'list';\n}\n\nexport interface ViewGrid extends ViewBase {\n\ttype: 'grid';\n\n\tlayout?: {\n\t\t/**\n\t\t * The fields to use as badge fields.\n\t\t */\n\t\tbadgeFields?: string[];\n\n\t\t/**\n\t\t * The preview size of the grid.\n\t\t */\n\t\tpreviewSize?: number;\n\t};\n}\n\nexport type View = ViewList | ViewGrid | ViewTable;\n\ninterface ActionBase< Item > {\n\t/**\n\t * The unique identifier of the action.\n\t */\n\tid: string;\n\n\t/**\n\t * The label of the action.\n\t * In case we want to adjust the label based on the selected items,\n\t * a function can be provided.\n\t */\n\tlabel: string | ( ( items: Item[] ) => string );\n\n\t/**\n\t * The icon of the action. (Either a string or an SVG element)\n\t * This should be IconType from the components package\n\t * but that import is breaking typescript build for the moment.\n\t */\n\ticon?: any;\n\n\t/**\n\t * Whether the action is disabled.\n\t */\n\tdisabled?: boolean;\n\n\t/**\n\t * Whether the action is destructive.\n\t */\n\tisDestructive?: boolean;\n\n\t/**\n\t * Whether the action is a primary action.\n\t */\n\tisPrimary?: boolean;\n\n\t/**\n\t * Whether the item passed as an argument supports the current action.\n\t */\n\tisEligible?: ( item: Item ) => boolean;\n\n\t/**\n\t * Whether the action can be used as a bulk action.\n\t */\n\tsupportsBulk?: boolean;\n\n\t/**\n\t * The context in which the action is visible.\n\t * This is only a \"meta\" information for now.\n\t */\n\tcontext?: 'list' | 'single';\n}\n\nexport interface RenderModalProps< Item > {\n\titems: Item[];\n\tcloseModal?: () => void;\n\tonActionPerformed?: ( items: Item[] ) => void;\n}\n\nexport interface ActionModal< Item > extends ActionBase< Item > {\n\t/**\n\t * Modal to render when the action is triggered.\n\t */\n\tRenderModal: ( {\n\t\titems,\n\t\tcloseModal,\n\t\tonActionPerformed,\n\t}: RenderModalProps< Item > ) => ReactElement;\n\n\t/**\n\t * Whether to hide the modal header.\n\t */\n\thideModalHeader?: boolean;\n\n\t/**\n\t * The header of the modal.\n\t */\n\tmodalHeader?: string;\n\n\t/**\n\t * The size of the modal.\n\t *\n\t * @default 'medium'\n\t */\n\tmodalSize?: 'small' | 'medium' | 'large' | 'fill';\n\n\t/**\n\t * The focus on mount property of the modal.\n\t */\n\tmodalFocusOnMount?:\n\t\t| Parameters< typeof useFocusOnMount >[ 0 ]\n\t\t| 'firstContentElement';\n}\n\nexport interface ActionButton< Item > extends ActionBase< Item > {\n\t/**\n\t * The callback to execute when the action is triggered.\n\t */\n\tcallback: (\n\t\titems: Item[],\n\t\tcontext: {\n\t\t\tregistry: any;\n\t\t\tonActionPerformed?: ( items: Item[] ) => void;\n\t\t}\n\t) => void;\n}\n\nexport type Action< Item > = ActionModal< Item > | ActionButton< Item >;\n\nexport interface ViewBaseProps< Item > {\n\tactions: Action< Item >[];\n\tdata: Item[];\n\tfields: NormalizedField< Item >[];\n\tgetItemId: ( item: Item ) => string;\n\tgetItemLevel?: ( item: Item ) => number;\n\tisLoading?: boolean;\n\tonChangeView: ( view: View ) => void;\n\tonChangeSelection: SetSelection;\n\tselection: string[];\n\tsetOpenedFilter: ( fieldId: string ) => void;\n\tonClickItem?: ( item: Item ) => void;\n\tisItemClickable: ( item: Item ) => boolean;\n\tview: View;\n}\n\nexport interface ViewTableProps< Item > extends ViewBaseProps< Item > {\n\tview: ViewTable;\n}\n\nexport interface ViewListProps< Item > extends ViewBaseProps< Item > {\n\tview: ViewList;\n}\n\nexport interface ViewGridProps< Item > extends ViewBaseProps< Item > {\n\tview: ViewGrid;\n}\n\nexport type ViewProps< Item > =\n\t| ViewTableProps< Item >\n\t| ViewGridProps< Item >\n\t| ViewListProps< Item >;\n\nexport interface SupportedLayouts {\n\tlist?: Omit< ViewList, 'type' >;\n\tgrid?: Omit< ViewGrid, 'type' >;\n\ttable?: Omit< ViewTable, 'type' >;\n}\n\nexport type SimpleFormField = {\n\tid: string;\n\tlayout?: 'regular' | 'panel';\n\tlabelPosition?: 'side' | 'top' | 'none';\n};\n\nexport type CombinedFormField = {\n\tid: string;\n\tlabel?: string;\n\tlayout?: 'regular' | 'panel';\n\tlabelPosition?: 'side' | 'top' | 'none';\n\tchildren: Array< FormField | string >;\n};\n\nexport type FormField = SimpleFormField | CombinedFormField;\n\n/**\n * The form configuration.\n */\nexport type Form = {\n\ttype?: 'regular' | 'panel';\n\tfields?: Array< FormField | string >;\n\tlabelPosition?: 'side' | 'top' | 'none';\n};\n\nexport interface DataFormProps< Item > {\n\tdata: Item;\n\tfields: Field< Item >[];\n\tform: Form;\n\tonChange: ( value: Record< string, any > ) => void;\n}\n\nexport interface FieldLayoutProps< Item > {\n\tdata: Item;\n\tfield: FormField;\n\tonChange: ( value: any ) => void;\n\thideLabelFromVision?: boolean;\n}\n"],"mappings":"","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":[],"sources":["@wordpress/dataviews/src/types.ts"],"sourcesContent":["/**\n * External dependencies\n */\nimport type { ReactElement, ComponentType, ComponentProps } from 'react';\n\n/**\n * Internal dependencies\n */\nimport type { SetSelection } from './private-types';\n\n/**\n * WordPress dependencies\n */\nimport type { useFocusOnMount } from '@wordpress/compose';\n\nexport type SortDirection = 'asc' | 'desc';\n\n/**\n * Generic option type.\n */\nexport interface Option< Value extends any = any > {\n\tvalue: Value;\n\tlabel: string;\n\tdescription?: string;\n}\n\nexport interface FilterByConfig {\n\t/**\n\t * The list of operators supported by the field.\n\t */\n\toperators?: Operator[];\n\n\t/**\n\t * Whether it is a primary filter.\n\t *\n\t * A primary filter is always visible and is not listed in the \"Add filter\" component,\n\t * except for the list layout where it behaves like a secondary filter.\n\t */\n\tisPrimary?: boolean;\n}\n\nexport interface NormalizedFilterByConfig {\n\t/**\n\t * The list of operators supported by the field.\n\t */\n\toperators: Operator[];\n\n\t/**\n\t * Whether it is a primary filter.\n\t *\n\t * A primary filter is always visible and is not listed in the \"Add filter\" component,\n\t * except for the list layout where it behaves like a secondary filter.\n\t */\n\tisPrimary?: boolean;\n}\n\ninterface FilterConfigForType {\n\t/**\n\t * What operators are used by default.\n\t */\n\tdefaultOperators: Operator[];\n\n\t/**\n\t * What operators are supported by the field.\n\t */\n\tvalidOperators: Operator[];\n}\n\nexport type Operator =\n\t| 'is'\n\t| 'isNot'\n\t| 'isAny'\n\t| 'isNone'\n\t| 'isAll'\n\t| 'isNotAll'\n\t| 'lessThan'\n\t| 'greaterThan'\n\t| 'lessThanOrEqual'\n\t| 'greaterThanOrEqual'\n\t| 'before'\n\t| 'after'\n\t| 'beforeInc'\n\t| 'afterInc'\n\t| 'contains'\n\t| 'notContains'\n\t| 'startsWith'\n\t| 'between'\n\t| 'on'\n\t| 'notOn'\n\t| 'inThePast'\n\t| 'over';\n\nexport type FieldType =\n\t| 'text'\n\t| 'integer'\n\t| 'datetime'\n\t| 'date'\n\t| 'media'\n\t| 'boolean'\n\t| 'email'\n\t| 'array';\n\nexport type ValidationContext = {\n\telements?: Option[];\n};\n\n/**\n * An abstract interface for Field based on the field type.\n */\nexport type FieldTypeDefinition< Item > = {\n\t/**\n\t * Callback used to sort the field.\n\t */\n\tsort: ( a: Item, b: Item, direction: SortDirection ) => number;\n\n\t/**\n\t * Callback used to validate the field.\n\t */\n\tisValid: ( item: Item, context?: ValidationContext ) => boolean;\n\n\t/**\n\t * Callback used to render an edit control for the field or control name.\n\t */\n\tEdit: ComponentType< DataFormControlProps< Item > > | string | null;\n\n\t/**\n\t * Callback used to render the field.\n\t */\n\trender: ComponentType< DataViewRenderFieldProps< Item > >;\n\n\t/**\n\t * The filter config for the field.\n\t */\n\tfilterBy: FilterConfigForType | false;\n\n\t/**\n\t * Whether the field is readOnly.\n\t * If `true`, the value will be rendered using the `render` callback.\n\t */\n\treadOnly?: boolean;\n\n\t/**\n\t * Whether the field is sortable.\n\t */\n\tenableSorting: boolean;\n};\n\n/**\n * A dataview field for a specific property of a data type.\n */\nexport type Field< Item > = {\n\t/**\n\t * Type of the fields.\n\t */\n\ttype?: FieldType;\n\n\t/**\n\t * The unique identifier of the field.\n\t */\n\tid: string;\n\n\t/**\n\t * The label of the field. Defaults to the id.\n\t */\n\tlabel?: string;\n\n\t/**\n\t * The header of the field. Defaults to the label.\n\t * It allows the usage of a React Element to render the field labels.\n\t */\n\theader?: string | ReactElement;\n\n\t/**\n\t * A description of the field.\n\t */\n\tdescription?: string;\n\n\t/**\n\t * Placeholder for the field.\n\t */\n\tplaceholder?: string;\n\n\t/**\n\t * Callback used to render the field. Defaults to `field.getValue`.\n\t */\n\trender?: ComponentType< DataViewRenderFieldProps< Item > >;\n\n\t/**\n\t * Callback used to render an edit control for the field.\n\t */\n\tEdit?: ComponentType< DataFormControlProps< Item > > | string;\n\n\t/**\n\t * Callback used to sort the field.\n\t */\n\tsort?: ( a: Item, b: Item, direction: SortDirection ) => number;\n\n\t/**\n\t * Callback used to validate the field.\n\t */\n\tisValid?: ( item: Item, context?: ValidationContext ) => boolean;\n\n\t/**\n\t * Callback used to decide if a field should be displayed.\n\t */\n\tisVisible?: ( item: Item ) => boolean;\n\n\t/**\n\t * Whether the field is sortable.\n\t */\n\tenableSorting?: boolean;\n\n\t/**\n\t * Whether the field is searchable.\n\t */\n\tenableGlobalSearch?: boolean;\n\n\t/**\n\t * Whether the field is filterable.\n\t */\n\tenableHiding?: boolean;\n\n\t/**\n\t * The list of options to pick from when using the field as a filter.\n\t */\n\telements?: Option[];\n\n\t/**\n\t * Filter config for the field.\n\t */\n\tfilterBy?: FilterByConfig | false;\n\n\t/**\n\t * Whether the field is readOnly.\n\t * If `true`, the value will be rendered using the `render` callback.\n\t */\n\treadOnly?: boolean;\n\n\t/**\n\t * Callback used to retrieve the value of the field from the item.\n\t * Defaults to `item[ field.id ]`.\n\t */\n\tgetValue?: ( args: { item: Item } ) => any;\n};\n\nexport type NormalizedField< Item > = Omit< Field< Item >, 'Edit' > & {\n\tlabel: string;\n\theader: string | ReactElement;\n\tgetValue: ( args: { item: Item } ) => any;\n\trender: ComponentType< DataViewRenderFieldProps< Item > >;\n\tEdit: ComponentType< DataFormControlProps< Item > > | null;\n\tsort: ( a: Item, b: Item, direction: SortDirection ) => number;\n\tisValid: ( item: Item, context?: ValidationContext ) => boolean;\n\tenableHiding: boolean;\n\tenableSorting: boolean;\n\tfilterBy: NormalizedFilterByConfig | false;\n\treadOnly: boolean;\n};\n\n/**\n * A collection of dataview fields for a data type.\n */\nexport type Fields< Item > = Field< Item >[];\n\nexport type Data< Item > = Item[];\n\nexport type DataFormControlProps< Item > = {\n\tdata: Item;\n\tfield: NormalizedField< Item >;\n\tonChange: ( value: Record< string, any > ) => void;\n\thideLabelFromVision?: boolean;\n\t/**\n\t * The currently selected filter operator for this field.\n\t *\n\t * Used by DataViews filters to determine which control to render based on the operator type.\n\t */\n\toperator?: Operator;\n};\n\nexport type DataViewRenderFieldProps< Item > = {\n\titem: Item;\n\tfield: NormalizedField< Item >;\n};\n\n/**\n * The filters applied to the dataset.\n */\nexport interface Filter {\n\t/**\n\t * The field to filter by.\n\t */\n\tfield: string;\n\n\t/**\n\t * The operator to use.\n\t */\n\toperator: Operator;\n\n\t/**\n\t * The value to filter by.\n\t */\n\tvalue: any;\n}\n\nexport interface NormalizedFilter {\n\t/**\n\t * The field to filter by.\n\t */\n\tfield: string;\n\n\t/**\n\t * The field name.\n\t */\n\tname: string;\n\n\t/**\n\t * The list of options to pick from when using the field as a filter.\n\t */\n\telements: Option[];\n\n\t/**\n\t * Is a single selection filter.\n\t */\n\tsingleSelection: boolean;\n\n\t/**\n\t * The list of operators supported by the field.\n\t */\n\toperators: Operator[];\n\n\t/**\n\t * Whether the filter is visible.\n\t */\n\tisVisible: boolean;\n\n\t/**\n\t * Whether it is a primary filter.\n\t */\n\tisPrimary: boolean;\n}\n\ninterface ViewBase {\n\t/**\n\t * The layout of the view.\n\t */\n\ttype: string;\n\n\t/**\n\t * The global search term.\n\t */\n\tsearch?: string;\n\n\t/**\n\t * The filters to apply.\n\t */\n\tfilters?: Filter[];\n\n\t/**\n\t * The sorting configuration.\n\t */\n\tsort?: {\n\t\t/**\n\t\t * The field to sort by.\n\t\t */\n\t\tfield: string;\n\n\t\t/**\n\t\t * The direction to sort by.\n\t\t */\n\t\tdirection: SortDirection;\n\t};\n\n\t/**\n\t * The active page\n\t */\n\tpage?: number;\n\n\t/**\n\t * The number of items per page\n\t */\n\tperPage?: number;\n\n\t/**\n\t * The fields to render\n\t */\n\tfields?: string[];\n\n\t/**\n\t * Title field\n\t */\n\ttitleField?: string;\n\n\t/**\n\t * Media field\n\t */\n\tmediaField?: string;\n\n\t/**\n\t * Description field\n\t */\n\tdescriptionField?: string;\n\n\t/**\n\t * Whether to show the title\n\t */\n\tshowTitle?: boolean;\n\n\t/**\n\t * Whether to show the media\n\t */\n\tshowMedia?: boolean;\n\n\t/**\n\t * Whether to show the description\n\t */\n\tshowDescription?: boolean;\n\n\t/**\n\t * Whether to show the hierarchical levels.\n\t */\n\tshowLevels?: boolean;\n\n\t/**\n\t * The field to group by.\n\t */\n\tgroupByField?: string;\n}\n\nexport interface ColumnStyle {\n\t/**\n\t * The width of the field column.\n\t */\n\twidth?: string | number;\n\n\t/**\n\t * The minimum width of the field column.\n\t */\n\tmaxWidth?: string | number;\n\n\t/**\n\t * The maximum width of the field column.\n\t */\n\tminWidth?: string | number;\n\n\t/**\n\t * The alignment of the field column, defaults to left.\n\t */\n\talign?: 'start' | 'center' | 'end';\n}\n\nexport type Density = 'compact' | 'balanced' | 'comfortable';\n\nexport interface ViewTable extends ViewBase {\n\ttype: 'table';\n\n\tlayout?: {\n\t\t/**\n\t\t * The styles for the columns.\n\t\t */\n\t\tstyles?: Record< string, ColumnStyle >;\n\n\t\t/**\n\t\t * The density of the view.\n\t\t */\n\t\tdensity?: Density;\n\t};\n}\n\nexport interface ViewList extends ViewBase {\n\ttype: 'list';\n}\n\nexport interface ViewGrid extends ViewBase {\n\ttype: 'grid';\n\n\tlayout?: {\n\t\t/**\n\t\t * The fields to use as badge fields.\n\t\t */\n\t\tbadgeFields?: string[];\n\n\t\t/**\n\t\t * The preview size of the grid.\n\t\t */\n\t\tpreviewSize?: number;\n\t};\n}\n\nexport type View = ViewList | ViewGrid | ViewTable;\n\ninterface ActionBase< Item > {\n\t/**\n\t * The unique identifier of the action.\n\t */\n\tid: string;\n\n\t/**\n\t * The label of the action.\n\t * In case we want to adjust the label based on the selected items,\n\t * a function can be provided.\n\t */\n\tlabel: string | ( ( items: Item[] ) => string );\n\n\t/**\n\t * The icon of the action. (Either a string or an SVG element)\n\t * This should be IconType from the components package\n\t * but that import is breaking typescript build for the moment.\n\t */\n\ticon?: any;\n\n\t/**\n\t * Whether the action is disabled.\n\t */\n\tdisabled?: boolean;\n\n\t/**\n\t * Whether the action is destructive.\n\t */\n\tisDestructive?: boolean;\n\n\t/**\n\t * Whether the action is a primary action.\n\t */\n\tisPrimary?: boolean;\n\n\t/**\n\t * Whether the item passed as an argument supports the current action.\n\t */\n\tisEligible?: ( item: Item ) => boolean;\n\n\t/**\n\t * Whether the action can be used as a bulk action.\n\t */\n\tsupportsBulk?: boolean;\n\n\t/**\n\t * The context in which the action is visible.\n\t * This is only a \"meta\" information for now.\n\t */\n\tcontext?: 'list' | 'single';\n}\n\nexport interface RenderModalProps< Item > {\n\titems: Item[];\n\tcloseModal?: () => void;\n\tonActionPerformed?: ( items: Item[] ) => void;\n}\n\nexport interface ActionModal< Item > extends ActionBase< Item > {\n\t/**\n\t * Modal to render when the action is triggered.\n\t */\n\tRenderModal: ( {\n\t\titems,\n\t\tcloseModal,\n\t\tonActionPerformed,\n\t}: RenderModalProps< Item > ) => ReactElement;\n\n\t/**\n\t * Whether to hide the modal header.\n\t */\n\thideModalHeader?: boolean;\n\n\t/**\n\t * The header of the modal.\n\t */\n\tmodalHeader?: string;\n\n\t/**\n\t * The size of the modal.\n\t *\n\t * @default 'medium'\n\t */\n\tmodalSize?: 'small' | 'medium' | 'large' | 'fill';\n\n\t/**\n\t * The focus on mount property of the modal.\n\t */\n\tmodalFocusOnMount?:\n\t\t| Parameters< typeof useFocusOnMount >[ 0 ]\n\t\t| 'firstContentElement';\n}\n\nexport interface ActionButton< Item > extends ActionBase< Item > {\n\t/**\n\t * The callback to execute when the action is triggered.\n\t */\n\tcallback: (\n\t\titems: Item[],\n\t\tcontext: {\n\t\t\tregistry: any;\n\t\t\tonActionPerformed?: ( items: Item[] ) => void;\n\t\t}\n\t) => void;\n}\n\nexport type Action< Item > = ActionModal< Item > | ActionButton< Item >;\n\nexport interface ViewBaseProps< Item > {\n\tclassName?: string;\n\tactions: Action< Item >[];\n\tdata: Item[];\n\tfields: NormalizedField< Item >[];\n\tgetItemId: ( item: Item ) => string;\n\tgetItemLevel?: ( item: Item ) => number;\n\tisLoading?: boolean;\n\tonChangeView: ( view: View ) => void;\n\tonChangeSelection: SetSelection;\n\tselection: string[];\n\tsetOpenedFilter: ( fieldId: string ) => void;\n\tonClickItem?: ( item: Item ) => void;\n\trenderItemLink?: (\n\t\tprops: {\n\t\t\titem: Item;\n\t\t} & ComponentProps< 'a' >\n\t) => ReactElement;\n\tisItemClickable: ( item: Item ) => boolean;\n\tview: View;\n}\n\nexport interface ViewTableProps< Item > extends ViewBaseProps< Item > {\n\tview: ViewTable;\n}\n\nexport interface ViewListProps< Item > extends ViewBaseProps< Item > {\n\tview: ViewList;\n}\n\nexport interface ViewGridProps< Item > extends ViewBaseProps< Item > {\n\tview: ViewGrid;\n}\n\nexport type ViewProps< Item > =\n\t| ViewTableProps< Item >\n\t| ViewGridProps< Item >\n\t| ViewListProps< Item >;\n\nexport interface SupportedLayouts {\n\tlist?: Omit< ViewList, 'type' >;\n\tgrid?: Omit< ViewGrid, 'type' >;\n\ttable?: Omit< ViewTable, 'type' >;\n}\n\nexport type SimpleFormField = {\n\tid: string;\n\tlayout?: 'regular' | 'panel';\n\tlabelPosition?: 'side' | 'top' | 'none';\n};\n\nexport type CombinedFormField = {\n\tid: string;\n\tlabel?: string;\n\tlayout?: 'regular' | 'panel';\n\tlabelPosition?: 'side' | 'top' | 'none';\n\tchildren: Array< FormField | string >;\n};\n\nexport type FormField = SimpleFormField | CombinedFormField;\n\n/**\n * The form configuration.\n */\nexport type Form = {\n\ttype?: 'regular' | 'panel';\n\tfields?: Array< FormField | string >;\n\tlabelPosition?: 'side' | 'top' | 'none';\n};\n\nexport interface DataFormProps< Item > {\n\tdata: Item;\n\tfields: Field< Item >[];\n\tform: Form;\n\tonChange: ( value: Record< string, any > ) => void;\n}\n\nexport interface FieldLayoutProps< Item > {\n\tdata: Item;\n\tfield: FormField;\n\tonChange: ( value: any ) => void;\n\thideLabelFromVision?: boolean;\n}\n"],"mappings":"","ignoreList":[]}
|
package/build/utils.js
CHANGED
|
@@ -3,28 +3,20 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
7
|
-
var _constants = require("./constants");
|
|
6
|
+
exports.renderFromElements = renderFromElements;
|
|
8
7
|
/**
|
|
9
8
|
* Internal dependencies
|
|
10
9
|
*/
|
|
11
10
|
|
|
12
|
-
function
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
// Do not allow mixing single & multiselection operators.
|
|
24
|
-
// Remove multiselection operators if any of the single selection ones is present.
|
|
25
|
-
if (operators.includes(_constants.OPERATOR_IS) || operators.includes(_constants.OPERATOR_IS_NOT)) {
|
|
26
|
-
operators = operators.filter(operator => [_constants.OPERATOR_IS, _constants.OPERATOR_IS_NOT].includes(operator));
|
|
27
|
-
}
|
|
28
|
-
return operators;
|
|
11
|
+
function renderFromElements({
|
|
12
|
+
item,
|
|
13
|
+
field
|
|
14
|
+
}) {
|
|
15
|
+
const value = field.getValue({
|
|
16
|
+
item
|
|
17
|
+
});
|
|
18
|
+
return field?.elements?.find(element => element.value === value)?.label || field.getValue({
|
|
19
|
+
item
|
|
20
|
+
});
|
|
29
21
|
}
|
|
30
22
|
//# sourceMappingURL=utils.js.map
|
package/build/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["renderFromElements","item","field","value","getValue","elements","find","element","label"],"sources":["@wordpress/dataviews/src/utils.ts"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport type { DataViewRenderFieldProps } from './types';\n\nexport function renderFromElements< Item >( {\n\titem,\n\tfield,\n}: DataViewRenderFieldProps< Item > ) {\n\tconst value = field.getValue( { item } );\n\treturn (\n\t\tfield?.elements?.find( ( element ) => element.value === value )\n\t\t\t?.label || field.getValue( { item } )\n\t);\n}\n"],"mappings":";;;;;;AAAA;AACA;AACA;;AAGO,SAASA,kBAAkBA,CAAU;EAC3CC,IAAI;EACJC;AACiC,CAAC,EAAG;EACrC,MAAMC,KAAK,GAAGD,KAAK,CAACE,QAAQ,CAAE;IAAEH;EAAK,CAAE,CAAC;EACxC,OACCC,KAAK,EAAEG,QAAQ,EAAEC,IAAI,CAAIC,OAAO,IAAMA,OAAO,CAACJ,KAAK,KAAKA,KAAM,CAAC,EAC5DK,KAAK,IAAIN,KAAK,CAACE,QAAQ,CAAE;IAAEH;EAAK,CAAE,CAAC;AAExC","ignoreList":[]}
|