@wordpress/dataviews 11.0.0 → 11.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/README.md +140 -93
- package/build/components/dataviews-filters/filter.js +25 -267
- package/build/components/dataviews-filters/filter.js.map +2 -2
- package/build/components/dataviews-filters/input-widget.js +1 -4
- package/build/components/dataviews-filters/input-widget.js.map +2 -2
- package/build/components/dataviews-filters/use-filters.js +3 -3
- package/build/components/dataviews-filters/use-filters.js.map +2 -2
- package/build/constants.js +5 -142
- package/build/constants.js.map +2 -2
- package/build/dataform-controls/number.js +2 -1
- package/build/dataform-controls/number.js.map +2 -2
- package/build/dataform-controls/textarea.js +3 -1
- package/build/dataform-controls/textarea.js.map +2 -2
- package/build/dataform-controls/utils/get-custom-validity.js +8 -0
- package/build/dataform-controls/utils/get-custom-validity.js.map +2 -2
- package/build/dataform-controls/utils/validated-input.js +4 -2
- package/build/dataform-controls/utils/validated-input.js.map +2 -2
- package/build/dataform-controls/utils/validated-number.js +4 -2
- package/build/dataform-controls/utils/validated-number.js.map +2 -2
- package/build/dataform-layouts/panel/modal.js +14 -5
- package/build/dataform-layouts/panel/modal.js.map +2 -2
- package/build/dataviews-layouts/grid/composite-grid.js +39 -37
- package/build/dataviews-layouts/grid/composite-grid.js.map +3 -3
- package/build/dataviews-layouts/table/index.js +8 -3
- package/build/dataviews-layouts/table/index.js.map +2 -2
- package/build/field-types/array.js +27 -14
- package/build/field-types/array.js.map +3 -3
- package/build/field-types/boolean.js +13 -10
- package/build/field-types/boolean.js.map +3 -3
- package/build/field-types/color.js +14 -11
- package/build/field-types/color.js.map +3 -3
- package/build/field-types/date.js +11 -8
- package/build/field-types/date.js.map +3 -3
- package/build/field-types/datetime.js +7 -5
- package/build/field-types/datetime.js.map +3 -3
- package/build/field-types/email.js +20 -11
- package/build/field-types/email.js.map +3 -3
- package/build/field-types/index.js +12 -14
- package/build/field-types/index.js.map +3 -3
- package/build/field-types/integer.js +63 -14
- package/build/field-types/integer.js.map +3 -3
- package/build/field-types/media.js +5 -5
- package/build/field-types/media.js.map +2 -2
- package/build/field-types/no-type.js +9 -6
- package/build/field-types/no-type.js.map +3 -3
- package/build/field-types/number.js +51 -15
- package/build/field-types/number.js.map +3 -3
- package/build/field-types/password.js +13 -5
- package/build/field-types/password.js.map +3 -3
- package/build/field-types/telephone.js +13 -5
- package/build/field-types/telephone.js.map +3 -3
- package/build/field-types/text.js +13 -5
- package/build/field-types/text.js.map +3 -3
- package/build/field-types/url.js +13 -5
- package/build/field-types/url.js.map +3 -3
- package/build/field-types/utils/get-is-valid.js +89 -0
- package/build/field-types/utils/get-is-valid.js.map +7 -0
- package/build/field-types/utils/is-valid-elements.js +35 -0
- package/build/field-types/utils/is-valid-elements.js.map +7 -0
- package/build/field-types/utils/is-valid-max-length.js +36 -0
- package/build/field-types/utils/is-valid-max-length.js.map +7 -0
- package/build/field-types/utils/is-valid-max.js +36 -0
- package/build/field-types/utils/is-valid-max.js.map +7 -0
- package/build/field-types/utils/is-valid-min-length.js +36 -0
- package/build/field-types/utils/is-valid-min-length.js.map +7 -0
- package/build/field-types/utils/is-valid-min.js +36 -0
- package/build/field-types/utils/is-valid-min.js.map +7 -0
- package/build/field-types/utils/is-valid-pattern.js +41 -0
- package/build/field-types/utils/is-valid-pattern.js.map +7 -0
- package/build/field-types/utils/is-valid-required-for-array.js +32 -0
- package/build/field-types/utils/is-valid-required-for-array.js.map +7 -0
- package/build/field-types/utils/is-valid-required-for-bool.js +30 -0
- package/build/field-types/utils/is-valid-required-for-bool.js.map +7 -0
- package/build/field-types/utils/is-valid-required.js +30 -0
- package/build/field-types/utils/is-valid-required.js.map +7 -0
- package/build/hooks/use-form-validity.js +52 -102
- package/build/hooks/use-form-validity.js.map +2 -2
- package/build/types/field-api.js.map +1 -1
- package/build/types/private.js.map +1 -1
- package/build/utils/filter-sort-and-paginate.js +5 -0
- package/build/utils/filter-sort-and-paginate.js.map +3 -3
- package/build/utils/operators.js +399 -0
- package/build/utils/operators.js.map +7 -0
- package/build-module/components/dataviews-filters/filter.js +26 -292
- package/build-module/components/dataviews-filters/filter.js.map +2 -2
- package/build-module/components/dataviews-filters/input-widget.js +1 -4
- package/build-module/components/dataviews-filters/input-widget.js.map +2 -2
- package/build-module/components/dataviews-filters/use-filters.js +6 -3
- package/build-module/components/dataviews-filters/use-filters.js.map +2 -2
- package/build-module/constants.js +5 -139
- package/build-module/constants.js.map +2 -2
- package/build-module/dataform-controls/number.js +2 -1
- package/build-module/dataform-controls/number.js.map +2 -2
- package/build-module/dataform-controls/textarea.js +3 -1
- package/build-module/dataform-controls/textarea.js.map +2 -2
- package/build-module/dataform-controls/utils/get-custom-validity.js +8 -0
- package/build-module/dataform-controls/utils/get-custom-validity.js.map +2 -2
- package/build-module/dataform-controls/utils/validated-input.js +4 -2
- package/build-module/dataform-controls/utils/validated-input.js.map +2 -2
- package/build-module/dataform-controls/utils/validated-number.js +4 -2
- package/build-module/dataform-controls/utils/validated-number.js.map +2 -2
- package/build-module/dataform-layouts/panel/modal.js +14 -5
- package/build-module/dataform-layouts/panel/modal.js.map +2 -2
- package/build-module/dataviews-layouts/grid/composite-grid.js +40 -38
- package/build-module/dataviews-layouts/grid/composite-grid.js.map +3 -3
- package/build-module/dataviews-layouts/table/index.js +8 -3
- package/build-module/dataviews-layouts/table/index.js.map +2 -2
- package/build-module/field-types/array.js +17 -14
- package/build-module/field-types/array.js.map +2 -2
- package/build-module/field-types/boolean.js +13 -10
- package/build-module/field-types/boolean.js.map +2 -2
- package/build-module/field-types/color.js +14 -11
- package/build-module/field-types/color.js.map +2 -2
- package/build-module/field-types/date.js +11 -8
- package/build-module/field-types/date.js.map +2 -2
- package/build-module/field-types/datetime.js +7 -5
- package/build-module/field-types/datetime.js.map +2 -2
- package/build-module/field-types/email.js +20 -11
- package/build-module/field-types/email.js.map +2 -2
- package/build-module/field-types/index.js +12 -14
- package/build-module/field-types/index.js.map +2 -2
- package/build-module/field-types/integer.js +58 -13
- package/build-module/field-types/integer.js.map +2 -2
- package/build-module/field-types/media.js +5 -5
- package/build-module/field-types/media.js.map +2 -2
- package/build-module/field-types/no-type.js +10 -7
- package/build-module/field-types/no-type.js.map +2 -2
- package/build-module/field-types/number.js +47 -15
- package/build-module/field-types/number.js.map +2 -2
- package/build-module/field-types/password.js +13 -5
- package/build-module/field-types/password.js.map +2 -2
- package/build-module/field-types/telephone.js +13 -5
- package/build-module/field-types/telephone.js.map +2 -2
- package/build-module/field-types/text.js +13 -5
- package/build-module/field-types/text.js.map +2 -2
- package/build-module/field-types/url.js +13 -5
- package/build-module/field-types/url.js.map +2 -2
- package/build-module/field-types/utils/get-is-valid.js +68 -0
- package/build-module/field-types/utils/get-is-valid.js.map +7 -0
- package/build-module/field-types/utils/is-valid-elements.js +14 -0
- package/build-module/field-types/utils/is-valid-elements.js.map +7 -0
- package/build-module/field-types/utils/is-valid-max-length.js +15 -0
- package/build-module/field-types/utils/is-valid-max-length.js.map +7 -0
- package/build-module/field-types/utils/is-valid-max.js +15 -0
- package/build-module/field-types/utils/is-valid-max.js.map +7 -0
- package/build-module/field-types/utils/is-valid-min-length.js +15 -0
- package/build-module/field-types/utils/is-valid-min-length.js.map +7 -0
- package/build-module/field-types/utils/is-valid-min.js +15 -0
- package/build-module/field-types/utils/is-valid-min.js.map +7 -0
- package/build-module/field-types/utils/is-valid-pattern.js +20 -0
- package/build-module/field-types/utils/is-valid-pattern.js.map +7 -0
- package/build-module/field-types/utils/is-valid-required-for-array.js +11 -0
- package/build-module/field-types/utils/is-valid-required-for-array.js.map +7 -0
- package/build-module/field-types/utils/is-valid-required-for-bool.js +9 -0
- package/build-module/field-types/utils/is-valid-required-for-bool.js.map +7 -0
- package/build-module/field-types/utils/is-valid-required.js +9 -0
- package/build-module/field-types/utils/is-valid-required.js.map +7 -0
- package/build-module/hooks/use-form-validity.js +52 -102
- package/build-module/hooks/use-form-validity.js.map +2 -2
- package/build-module/utils/filter-sort-and-paginate.js +5 -0
- package/build-module/utils/filter-sort-and-paginate.js.map +2 -2
- package/build-module/utils/operators.js +394 -0
- package/build-module/utils/operators.js.map +7 -0
- package/build-style/style-rtl.css +13 -80
- package/build-style/style.css +13 -80
- package/build-types/components/dataviews-filters/filter.d.ts.map +1 -1
- package/build-types/components/dataviews-filters/input-widget.d.ts.map +1 -1
- package/build-types/components/dataviews-filters/use-filters.d.ts.map +1 -1
- package/build-types/constants.d.ts +6 -12
- package/build-types/constants.d.ts.map +1 -1
- package/build-types/dataform-controls/number.d.ts.map +1 -1
- package/build-types/dataform-controls/textarea.d.ts.map +1 -1
- package/build-types/dataform-controls/utils/get-custom-validity.d.ts +2 -2
- package/build-types/dataform-controls/utils/get-custom-validity.d.ts.map +1 -1
- package/build-types/dataform-controls/utils/validated-input.d.ts.map +1 -1
- package/build-types/dataform-controls/utils/validated-number.d.ts.map +1 -1
- package/build-types/dataform-layouts/panel/modal.d.ts.map +1 -1
- package/build-types/dataviews-layouts/grid/composite-grid.d.ts.map +1 -1
- package/build-types/dataviews-layouts/table/index.d.ts.map +1 -1
- package/build-types/field-types/array.d.ts +9 -2
- package/build-types/field-types/array.d.ts.map +1 -1
- package/build-types/field-types/boolean.d.ts +9 -2
- package/build-types/field-types/boolean.d.ts.map +1 -1
- package/build-types/field-types/color.d.ts +9 -2
- package/build-types/field-types/color.d.ts.map +1 -1
- package/build-types/field-types/date.d.ts +6 -4
- package/build-types/field-types/date.d.ts.map +1 -1
- package/build-types/field-types/datetime.d.ts +6 -4
- package/build-types/field-types/datetime.d.ts.map +1 -1
- package/build-types/field-types/email.d.ts +15 -2
- package/build-types/field-types/email.d.ts.map +1 -1
- package/build-types/field-types/index.d.ts.map +1 -1
- package/build-types/field-types/integer.d.ts +17 -4
- package/build-types/field-types/integer.d.ts.map +1 -1
- package/build-types/field-types/media.d.ts +1 -4
- package/build-types/field-types/media.d.ts.map +1 -1
- package/build-types/field-types/no-type.d.ts +6 -4
- package/build-types/field-types/no-type.d.ts.map +1 -1
- package/build-types/field-types/number.d.ts +17 -4
- package/build-types/field-types/number.d.ts.map +1 -1
- package/build-types/field-types/password.d.ts +12 -4
- package/build-types/field-types/password.d.ts.map +1 -1
- package/build-types/field-types/telephone.d.ts +12 -4
- package/build-types/field-types/telephone.d.ts.map +1 -1
- package/build-types/field-types/text.d.ts +12 -4
- package/build-types/field-types/text.d.ts.map +1 -1
- package/build-types/field-types/url.d.ts +12 -4
- package/build-types/field-types/url.d.ts.map +1 -1
- package/build-types/field-types/utils/get-is-valid.d.ts +7 -0
- package/build-types/field-types/utils/get-is-valid.d.ts.map +1 -0
- package/build-types/field-types/utils/is-valid-elements.d.ts +6 -0
- package/build-types/field-types/utils/is-valid-elements.d.ts.map +1 -0
- package/build-types/field-types/utils/is-valid-max-length.d.ts +6 -0
- package/build-types/field-types/utils/is-valid-max-length.d.ts.map +1 -0
- package/build-types/field-types/utils/is-valid-max.d.ts +6 -0
- package/build-types/field-types/utils/is-valid-max.d.ts.map +1 -0
- package/build-types/field-types/utils/is-valid-min-length.d.ts +6 -0
- package/build-types/field-types/utils/is-valid-min-length.d.ts.map +1 -0
- package/build-types/field-types/utils/is-valid-min.d.ts +6 -0
- package/build-types/field-types/utils/is-valid-min.d.ts.map +1 -0
- package/build-types/field-types/utils/is-valid-pattern.d.ts +6 -0
- package/build-types/field-types/utils/is-valid-pattern.d.ts.map +1 -0
- package/build-types/field-types/utils/is-valid-required-for-array.d.ts +6 -0
- package/build-types/field-types/utils/is-valid-required-for-array.d.ts.map +1 -0
- package/build-types/field-types/utils/is-valid-required-for-bool.d.ts +6 -0
- package/build-types/field-types/utils/is-valid-required-for-bool.d.ts.map +1 -0
- package/build-types/field-types/utils/is-valid-required.d.ts +6 -0
- package/build-types/field-types/utils/is-valid-required.d.ts.map +1 -0
- package/build-types/hooks/use-form-validity.d.ts.map +1 -1
- package/build-types/stories/dataform.story.d.ts +9 -1
- package/build-types/stories/dataform.story.d.ts.map +1 -1
- package/build-types/stories/dataviews-picker.story.d.ts.map +1 -1
- package/build-types/stories/dataviews.story.d.ts +27 -2
- package/build-types/stories/dataviews.story.d.ts.map +1 -1
- package/build-types/stories/field-types.story.d.ts +39 -2
- package/build-types/stories/field-types.story.d.ts.map +1 -1
- package/build-types/types/field-api.d.ts +72 -4
- package/build-types/types/field-api.d.ts.map +1 -1
- package/build-types/types/private.d.ts +13 -3
- package/build-types/types/private.d.ts.map +1 -1
- package/build-types/utils/filter-sort-and-paginate.d.ts.map +1 -1
- package/build-types/utils/operators.d.ts +16 -0
- package/build-types/utils/operators.d.ts.map +1 -0
- package/build-wp/index.js +1548 -1452
- package/package.json +17 -16
- package/src/components/dataviews/style.scss +3 -28
- package/src/components/dataviews-filters/filter.tsx +34 -321
- package/src/components/dataviews-filters/input-widget.tsx +7 -5
- package/src/components/dataviews-filters/use-filters.ts +6 -3
- package/src/components/dataviews-footer/style.scss +1 -7
- package/src/constants.ts +6 -140
- package/src/dataform-controls/number.tsx +3 -3
- package/src/dataform-controls/textarea.tsx +7 -1
- package/src/dataform-controls/utils/get-custom-validity.ts +10 -2
- package/src/dataform-controls/utils/validated-input.tsx +8 -2
- package/src/dataform-controls/utils/validated-number.tsx +3 -1
- package/src/dataform-layouts/panel/modal.tsx +14 -5
- package/src/dataviews-layouts/activity/style.scss +1 -1
- package/src/dataviews-layouts/grid/composite-grid.tsx +64 -57
- package/src/dataviews-layouts/grid/style.scss +3 -12
- package/src/dataviews-layouts/table/index.tsx +9 -3
- package/src/dataviews-layouts/table/style.scss +4 -15
- package/src/dataviews-layouts/utils/grid-items.scss +1 -9
- package/src/field-types/array.tsx +26 -19
- package/src/field-types/boolean.tsx +22 -15
- package/src/field-types/color.tsx +22 -15
- package/src/field-types/date.tsx +14 -11
- package/src/field-types/datetime.tsx +6 -4
- package/src/field-types/email.tsx +24 -15
- package/src/field-types/index.tsx +12 -14
- package/src/field-types/integer.tsx +83 -17
- package/src/field-types/media.tsx +4 -4
- package/src/field-types/no-type.tsx +9 -6
- package/src/field-types/number.tsx +82 -16
- package/src/field-types/password.tsx +12 -4
- package/src/field-types/telephone.tsx +12 -4
- package/src/field-types/text.tsx +12 -4
- package/src/field-types/url.tsx +12 -4
- package/src/field-types/utils/get-is-valid.ts +103 -0
- package/src/field-types/utils/is-valid-elements.ts +20 -0
- package/src/field-types/utils/is-valid-max-length.ts +23 -0
- package/src/field-types/utils/is-valid-max.ts +23 -0
- package/src/field-types/utils/is-valid-min-length.ts +23 -0
- package/src/field-types/utils/is-valid-min.ts +23 -0
- package/src/field-types/utils/is-valid-pattern.ts +29 -0
- package/src/field-types/utils/is-valid-required-for-array.ts +18 -0
- package/src/field-types/utils/is-valid-required-for-bool.ts +13 -0
- package/src/field-types/utils/is-valid-required.ts +13 -0
- package/src/hooks/use-form-validity.ts +78 -156
- package/src/stories/dataform.story.tsx +126 -30
- package/src/stories/dataviews-picker.story.tsx +27 -17
- package/src/stories/dataviews.story.tsx +79 -30
- package/src/stories/field-types.story.tsx +86 -4
- package/src/test/filter-sort-and-paginate.js +2 -1
- package/src/test/normalize-fields.ts +87 -11
- package/src/test/use-form-validity.ts +796 -31
- package/src/types/field-api.ts +90 -4
- package/src/types/private.ts +26 -8
- package/src/utils/filter-sort-and-paginate.ts +5 -0
- package/src/utils/operators.tsx +448 -0
- package/tsconfig.json +1 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -41,9 +41,11 @@ var import_icons = require("@wordpress/icons");
|
|
|
41
41
|
var import_date = require("@wordpress/date");
|
|
42
42
|
var import_search_widget = __toESM(require("./search-widget"));
|
|
43
43
|
var import_input_widget = __toESM(require("./input-widget"));
|
|
44
|
-
var
|
|
44
|
+
var import_operators = require("../../utils/operators");
|
|
45
45
|
var import_use_elements = __toESM(require("../../hooks/use-elements"));
|
|
46
46
|
var import_parse_date_time = __toESM(require("../../field-types/utils/parse-date-time"));
|
|
47
|
+
var import_number = require("../../field-types/number");
|
|
48
|
+
var import_integer = require("../../field-types/integer");
|
|
47
49
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
48
50
|
var ENTER = "Enter";
|
|
49
51
|
var SPACE = " ";
|
|
@@ -55,259 +57,9 @@ var FilterText = ({
|
|
|
55
57
|
if (activeElements === void 0 || activeElements.length === 0) {
|
|
56
58
|
return filter.name;
|
|
57
59
|
}
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
};
|
|
62
|
-
if (filterInView?.operator === import_constants.OPERATOR_IS_ANY) {
|
|
63
|
-
return (0, import_element.createInterpolateElement)(
|
|
64
|
-
(0, import_i18n.sprintf)(
|
|
65
|
-
/* translators: 1: Filter name. 2: Filter value. e.g.: "Author is any: Admin, Editor". */
|
|
66
|
-
(0, import_i18n.__)("<Name>%1$s is any: </Name><Value>%2$s</Value>"),
|
|
67
|
-
filter.name,
|
|
68
|
-
activeElements.map((element) => element.label).join(", ")
|
|
69
|
-
),
|
|
70
|
-
filterTextWrappers
|
|
71
|
-
);
|
|
72
|
-
}
|
|
73
|
-
if (filterInView?.operator === import_constants.OPERATOR_IS_NONE) {
|
|
74
|
-
return (0, import_element.createInterpolateElement)(
|
|
75
|
-
(0, import_i18n.sprintf)(
|
|
76
|
-
/* translators: 1: Filter name. 2: Filter value. e.g.: "Author is none: Admin, Editor". */
|
|
77
|
-
(0, import_i18n.__)("<Name>%1$s is none: </Name><Value>%2$s</Value>"),
|
|
78
|
-
filter.name,
|
|
79
|
-
activeElements.map((element) => element.label).join(", ")
|
|
80
|
-
),
|
|
81
|
-
filterTextWrappers
|
|
82
|
-
);
|
|
83
|
-
}
|
|
84
|
-
if (filterInView?.operator === import_constants.OPERATOR_IS_ALL) {
|
|
85
|
-
return (0, import_element.createInterpolateElement)(
|
|
86
|
-
(0, import_i18n.sprintf)(
|
|
87
|
-
/* translators: 1: Filter name. 2: Filter value. e.g.: "Author is all: Admin, Editor". */
|
|
88
|
-
(0, import_i18n.__)("<Name>%1$s is all: </Name><Value>%2$s</Value>"),
|
|
89
|
-
filter.name,
|
|
90
|
-
activeElements.map((element) => element.label).join(", ")
|
|
91
|
-
),
|
|
92
|
-
filterTextWrappers
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
if (filterInView?.operator === import_constants.OPERATOR_IS_NOT_ALL) {
|
|
96
|
-
return (0, import_element.createInterpolateElement)(
|
|
97
|
-
(0, import_i18n.sprintf)(
|
|
98
|
-
/* translators: 1: Filter name. 2: Filter value. e.g.: "Author is not all: Admin, Editor". */
|
|
99
|
-
(0, import_i18n.__)("<Name>%1$s is not all: </Name><Value>%2$s</Value>"),
|
|
100
|
-
filter.name,
|
|
101
|
-
activeElements.map((element) => element.label).join(", ")
|
|
102
|
-
),
|
|
103
|
-
filterTextWrappers
|
|
104
|
-
);
|
|
105
|
-
}
|
|
106
|
-
if (filterInView?.operator === import_constants.OPERATOR_IS) {
|
|
107
|
-
return (0, import_element.createInterpolateElement)(
|
|
108
|
-
(0, import_i18n.sprintf)(
|
|
109
|
-
/* translators: 1: Filter name. 2: Filter value. e.g.: "Author is: Admin". */
|
|
110
|
-
(0, import_i18n.__)("<Name>%1$s is: </Name><Value>%2$s</Value>"),
|
|
111
|
-
filter.name,
|
|
112
|
-
activeElements[0].label
|
|
113
|
-
),
|
|
114
|
-
filterTextWrappers
|
|
115
|
-
);
|
|
116
|
-
}
|
|
117
|
-
if (filterInView?.operator === import_constants.OPERATOR_IS_NOT) {
|
|
118
|
-
return (0, import_element.createInterpolateElement)(
|
|
119
|
-
(0, import_i18n.sprintf)(
|
|
120
|
-
/* translators: 1: Filter name. 2: Filter value. e.g.: "Author is not: Admin". */
|
|
121
|
-
(0, import_i18n.__)("<Name>%1$s is not: </Name><Value>%2$s</Value>"),
|
|
122
|
-
filter.name,
|
|
123
|
-
activeElements[0].label
|
|
124
|
-
),
|
|
125
|
-
filterTextWrappers
|
|
126
|
-
);
|
|
127
|
-
}
|
|
128
|
-
if (filterInView?.operator === import_constants.OPERATOR_LESS_THAN) {
|
|
129
|
-
return (0, import_element.createInterpolateElement)(
|
|
130
|
-
(0, import_i18n.sprintf)(
|
|
131
|
-
/* translators: 1: Filter name. 2: Filter value. e.g.: "Price is less than: 10". */
|
|
132
|
-
(0, import_i18n.__)("<Name>%1$s is less than: </Name><Value>%2$s</Value>"),
|
|
133
|
-
filter.name,
|
|
134
|
-
activeElements[0].label
|
|
135
|
-
),
|
|
136
|
-
filterTextWrappers
|
|
137
|
-
);
|
|
138
|
-
}
|
|
139
|
-
if (filterInView?.operator === import_constants.OPERATOR_GREATER_THAN) {
|
|
140
|
-
return (0, import_element.createInterpolateElement)(
|
|
141
|
-
(0, import_i18n.sprintf)(
|
|
142
|
-
/* translators: 1: Filter name. 2: Filter value. e.g.: "Price is greater than: 10". */
|
|
143
|
-
(0, import_i18n.__)("<Name>%1$s is greater than: </Name><Value>%2$s</Value>"),
|
|
144
|
-
filter.name,
|
|
145
|
-
activeElements[0].label
|
|
146
|
-
),
|
|
147
|
-
filterTextWrappers
|
|
148
|
-
);
|
|
149
|
-
}
|
|
150
|
-
if (filterInView?.operator === import_constants.OPERATOR_LESS_THAN_OR_EQUAL) {
|
|
151
|
-
return (0, import_element.createInterpolateElement)(
|
|
152
|
-
(0, import_i18n.sprintf)(
|
|
153
|
-
/* translators: 1: Filter name. 2: Filter value. e.g.: "Price is less than or equal to: 10". */
|
|
154
|
-
(0, import_i18n.__)(
|
|
155
|
-
"<Name>%1$s is less than or equal to: </Name><Value>%2$s</Value>"
|
|
156
|
-
),
|
|
157
|
-
filter.name,
|
|
158
|
-
activeElements[0].label
|
|
159
|
-
),
|
|
160
|
-
filterTextWrappers
|
|
161
|
-
);
|
|
162
|
-
}
|
|
163
|
-
if (filterInView?.operator === import_constants.OPERATOR_GREATER_THAN_OR_EQUAL) {
|
|
164
|
-
return (0, import_element.createInterpolateElement)(
|
|
165
|
-
(0, import_i18n.sprintf)(
|
|
166
|
-
/* translators: 1: Filter name. 2: Filter value. e.g.: "Price is greater than or equal to: 10". */
|
|
167
|
-
(0, import_i18n.__)(
|
|
168
|
-
"<Name>%1$s is greater than or equal to: </Name><Value>%2$s</Value>"
|
|
169
|
-
),
|
|
170
|
-
filter.name,
|
|
171
|
-
activeElements[0].label
|
|
172
|
-
),
|
|
173
|
-
filterTextWrappers
|
|
174
|
-
);
|
|
175
|
-
}
|
|
176
|
-
if (filterInView?.operator === import_constants.OPERATOR_CONTAINS) {
|
|
177
|
-
return (0, import_element.createInterpolateElement)(
|
|
178
|
-
(0, import_i18n.sprintf)(
|
|
179
|
-
/* translators: 1: Filter name. 2: Filter value. e.g.: "Title contains: Mars". */
|
|
180
|
-
(0, import_i18n.__)("<Name>%1$s contains: </Name><Value>%2$s</Value>"),
|
|
181
|
-
filter.name,
|
|
182
|
-
activeElements[0].label
|
|
183
|
-
),
|
|
184
|
-
filterTextWrappers
|
|
185
|
-
);
|
|
186
|
-
}
|
|
187
|
-
if (filterInView?.operator === import_constants.OPERATOR_NOT_CONTAINS) {
|
|
188
|
-
return (0, import_element.createInterpolateElement)(
|
|
189
|
-
(0, import_i18n.sprintf)(
|
|
190
|
-
/* translators: 1: Filter name. 2: Filter value. e.g.: "Description doesn't contain: photo". */
|
|
191
|
-
(0, import_i18n.__)("<Name>%1$s doesn't contain: </Name><Value>%2$s</Value>"),
|
|
192
|
-
filter.name,
|
|
193
|
-
activeElements[0].label
|
|
194
|
-
),
|
|
195
|
-
filterTextWrappers
|
|
196
|
-
);
|
|
197
|
-
}
|
|
198
|
-
if (filterInView?.operator === import_constants.OPERATOR_STARTS_WITH) {
|
|
199
|
-
return (0, import_element.createInterpolateElement)(
|
|
200
|
-
(0, import_i18n.sprintf)(
|
|
201
|
-
/* translators: 1: Filter name. 2: Filter value. e.g.: "Title starts with: Mar". */
|
|
202
|
-
(0, import_i18n.__)("<Name>%1$s starts with: </Name><Value>%2$s</Value>"),
|
|
203
|
-
filter.name,
|
|
204
|
-
activeElements[0].label
|
|
205
|
-
),
|
|
206
|
-
filterTextWrappers
|
|
207
|
-
);
|
|
208
|
-
}
|
|
209
|
-
if (filterInView?.operator === import_constants.OPERATOR_BEFORE) {
|
|
210
|
-
return (0, import_element.createInterpolateElement)(
|
|
211
|
-
(0, import_i18n.sprintf)(
|
|
212
|
-
/* translators: 1: Filter name. 2: Filter value. e.g.: "Date is before: 2024-01-01". */
|
|
213
|
-
(0, import_i18n.__)("<Name>%1$s is before: </Name><Value>%2$s</Value>"),
|
|
214
|
-
filter.name,
|
|
215
|
-
activeElements[0].label
|
|
216
|
-
),
|
|
217
|
-
filterTextWrappers
|
|
218
|
-
);
|
|
219
|
-
}
|
|
220
|
-
if (filterInView?.operator === import_constants.OPERATOR_AFTER) {
|
|
221
|
-
return (0, import_element.createInterpolateElement)(
|
|
222
|
-
(0, import_i18n.sprintf)(
|
|
223
|
-
/* translators: 1: Filter name. 2: Filter value. e.g.: "Date is after: 2024-01-01". */
|
|
224
|
-
(0, import_i18n.__)("<Name>%1$s is after: </Name><Value>%2$s</Value>"),
|
|
225
|
-
filter.name,
|
|
226
|
-
activeElements[0].label
|
|
227
|
-
),
|
|
228
|
-
filterTextWrappers
|
|
229
|
-
);
|
|
230
|
-
}
|
|
231
|
-
if (filterInView?.operator === import_constants.OPERATOR_BEFORE_INC) {
|
|
232
|
-
return (0, import_element.createInterpolateElement)(
|
|
233
|
-
(0, import_i18n.sprintf)(
|
|
234
|
-
/* translators: 1: Filter name. 2: Filter value. e.g.: "Date is on or before: 2024-01-01". */
|
|
235
|
-
(0, import_i18n.__)("<Name>%1$s is on or before: </Name><Value>%2$s</Value>"),
|
|
236
|
-
filter.name,
|
|
237
|
-
activeElements[0].label
|
|
238
|
-
),
|
|
239
|
-
filterTextWrappers
|
|
240
|
-
);
|
|
241
|
-
}
|
|
242
|
-
if (filterInView?.operator === import_constants.OPERATOR_AFTER_INC) {
|
|
243
|
-
return (0, import_element.createInterpolateElement)(
|
|
244
|
-
(0, import_i18n.sprintf)(
|
|
245
|
-
/* translators: 1: Filter name. 2: Filter value. e.g.: "Date is on or after: 2024-01-01". */
|
|
246
|
-
(0, import_i18n.__)("<Name>%1$s is on or after: </Name><Value>%2$s</Value>"),
|
|
247
|
-
filter.name,
|
|
248
|
-
activeElements[0].label
|
|
249
|
-
),
|
|
250
|
-
filterTextWrappers
|
|
251
|
-
);
|
|
252
|
-
}
|
|
253
|
-
if (filterInView?.operator === import_constants.OPERATOR_BETWEEN) {
|
|
254
|
-
const { label } = activeElements[0];
|
|
255
|
-
return (0, import_element.createInterpolateElement)(
|
|
256
|
-
(0, import_i18n.sprintf)(
|
|
257
|
-
/* translators: 1: Filter name. 2: Min value. 3: Max value. e.g.: "Item count between (inc): 10 and 180". */
|
|
258
|
-
(0, import_i18n.__)(
|
|
259
|
-
"<Name>%1$s between (inc): </Name><Value>%2$s and %3$s</Value>"
|
|
260
|
-
),
|
|
261
|
-
filter.name,
|
|
262
|
-
label[0],
|
|
263
|
-
label[1]
|
|
264
|
-
),
|
|
265
|
-
filterTextWrappers
|
|
266
|
-
);
|
|
267
|
-
}
|
|
268
|
-
if (filterInView?.operator === import_constants.OPERATOR_ON) {
|
|
269
|
-
return (0, import_element.createInterpolateElement)(
|
|
270
|
-
(0, import_i18n.sprintf)(
|
|
271
|
-
/* translators: 1: Filter name. 2: Filter value. e.g.: "Date is: 2024-01-01". */
|
|
272
|
-
(0, import_i18n.__)("<Name>%1$s is: </Name><Value>%2$s</Value>"),
|
|
273
|
-
filter.name,
|
|
274
|
-
activeElements[0].label
|
|
275
|
-
),
|
|
276
|
-
filterTextWrappers
|
|
277
|
-
);
|
|
278
|
-
}
|
|
279
|
-
if (filterInView?.operator === import_constants.OPERATOR_NOT_ON) {
|
|
280
|
-
return (0, import_element.createInterpolateElement)(
|
|
281
|
-
(0, import_i18n.sprintf)(
|
|
282
|
-
/* translators: 1: Filter name. 2: Filter value. e.g.: "Date is not: 2024-01-01". */
|
|
283
|
-
(0, import_i18n.__)("<Name>%1$s is not: </Name><Value>%2$s</Value>"),
|
|
284
|
-
filter.name,
|
|
285
|
-
activeElements[0].label
|
|
286
|
-
),
|
|
287
|
-
filterTextWrappers
|
|
288
|
-
);
|
|
289
|
-
}
|
|
290
|
-
if (filterInView?.operator === import_constants.OPERATOR_IN_THE_PAST) {
|
|
291
|
-
return (0, import_element.createInterpolateElement)(
|
|
292
|
-
(0, import_i18n.sprintf)(
|
|
293
|
-
/* translators: 1: Filter name. 2: Filter value. e.g.: "Date is in the past: 1 days". */
|
|
294
|
-
(0, import_i18n.__)("<Name>%1$s is in the past: </Name><Value>%2$s</Value>"),
|
|
295
|
-
filter.name,
|
|
296
|
-
`${activeElements[0].value.value} ${activeElements[0].value.unit}`
|
|
297
|
-
),
|
|
298
|
-
filterTextWrappers
|
|
299
|
-
);
|
|
300
|
-
}
|
|
301
|
-
if (filterInView?.operator === import_constants.OPERATOR_OVER) {
|
|
302
|
-
return (0, import_element.createInterpolateElement)(
|
|
303
|
-
(0, import_i18n.sprintf)(
|
|
304
|
-
/* translators: 1: Filter name. 2: Filter value. e.g.: "Date is over: 1 days ago". */
|
|
305
|
-
(0, import_i18n.__)("<Name>%1$s is over: </Name><Value>%2$s</Value> ago"),
|
|
306
|
-
filter.name,
|
|
307
|
-
`${activeElements[0].value.value} ${activeElements[0].value.unit}`
|
|
308
|
-
),
|
|
309
|
-
filterTextWrappers
|
|
310
|
-
);
|
|
60
|
+
const operator = (0, import_operators.getOperatorByName)(filterInView?.operator);
|
|
61
|
+
if (operator !== void 0) {
|
|
62
|
+
return operator.filterText(filter, activeElements);
|
|
311
63
|
}
|
|
312
64
|
return (0, import_i18n.sprintf)(
|
|
313
65
|
/* translators: 1: Filter name e.g.: "Unknown status for Author". */
|
|
@@ -322,7 +74,7 @@ function OperatorSelector({
|
|
|
322
74
|
}) {
|
|
323
75
|
const operatorOptions = filter.operators?.map((operator) => ({
|
|
324
76
|
value: operator,
|
|
325
|
-
label:
|
|
77
|
+
label: (0, import_operators.getOperatorByName)(operator)?.label || operator
|
|
326
78
|
}));
|
|
327
79
|
const currentFilter = view.filters?.find(
|
|
328
80
|
(_filter) => _filter.field === filter.field
|
|
@@ -344,26 +96,26 @@ function OperatorSelector({
|
|
|
344
96
|
value,
|
|
345
97
|
options: operatorOptions,
|
|
346
98
|
onChange: (newValue) => {
|
|
347
|
-
const
|
|
99
|
+
const newOperator = newValue;
|
|
348
100
|
const currentOperator = currentFilter?.operator;
|
|
349
101
|
const newFilters = currentFilter ? [
|
|
350
102
|
...(view.filters ?? []).map(
|
|
351
103
|
(_filter) => {
|
|
352
104
|
if (_filter.field === filter.field) {
|
|
353
|
-
const
|
|
354
|
-
import_constants.OPERATOR_BETWEEN,
|
|
355
|
-
import_constants.OPERATOR_IN_THE_PAST,
|
|
356
|
-
import_constants.OPERATOR_OVER
|
|
357
|
-
];
|
|
358
|
-
const shouldResetValue = currentOperator && (OPERATORS_SHOULD_RESET_VALUE.includes(
|
|
105
|
+
const currentOpSelectionModel = (0, import_operators.getOperatorByName)(
|
|
359
106
|
currentOperator
|
|
360
|
-
)
|
|
361
|
-
|
|
362
|
-
|
|
107
|
+
)?.selection;
|
|
108
|
+
const newOpSelectionModel = (0, import_operators.getOperatorByName)(
|
|
109
|
+
newOperator
|
|
110
|
+
)?.selection;
|
|
111
|
+
const shouldResetValue = currentOpSelectionModel !== newOpSelectionModel || [
|
|
112
|
+
currentOpSelectionModel,
|
|
113
|
+
newOpSelectionModel
|
|
114
|
+
].includes("custom");
|
|
363
115
|
return {
|
|
364
116
|
..._filter,
|
|
365
117
|
value: shouldResetValue ? void 0 : _filter.value,
|
|
366
|
-
operator
|
|
118
|
+
operator: newOperator
|
|
367
119
|
};
|
|
368
120
|
}
|
|
369
121
|
return _filter;
|
|
@@ -373,7 +125,7 @@ function OperatorSelector({
|
|
|
373
125
|
...view.filters ?? [],
|
|
374
126
|
{
|
|
375
127
|
field: filter.field,
|
|
376
|
-
operator,
|
|
128
|
+
operator: newOperator,
|
|
377
129
|
value: void 0
|
|
378
130
|
}
|
|
379
131
|
];
|
|
@@ -440,6 +192,12 @@ function Filter({
|
|
|
440
192
|
} catch (e) {
|
|
441
193
|
label = filterInView.value;
|
|
442
194
|
}
|
|
195
|
+
} else if (field?.type === "number" && typeof label === "number") {
|
|
196
|
+
const numberField = field;
|
|
197
|
+
label = (0, import_number.formatNumber)(label, numberField.format);
|
|
198
|
+
} else if (field?.type === "integer" && typeof label === "number") {
|
|
199
|
+
const integerField = field;
|
|
200
|
+
label = (0, import_integer.formatInteger)(label, integerField.format);
|
|
443
201
|
}
|
|
444
202
|
activeElements = [
|
|
445
203
|
{
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/dataviews-filters/filter.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\nimport type { RefObject } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tDropdown,\n\t__experimentalVStack as VStack,\n\t__experimentalHStack as HStack,\n\tFlexItem,\n\tSelectControl,\n\tTooltip,\n\tIcon,\n} from '@wordpress/components';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { useRef, createInterpolateElement } from '@wordpress/element';\nimport { closeSmall } from '@wordpress/icons';\nimport { dateI18n, getDate } from '@wordpress/date';\n\n/**\n * Internal dependencies\n */\nimport SearchWidget from './search-widget';\nimport InputWidget from './input-widget';\nimport {\n\tOPERATORS,\n\tOPERATOR_IS,\n\tOPERATOR_IS_NOT,\n\tOPERATOR_IS_ANY,\n\tOPERATOR_IS_NONE,\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_CONTAINS,\n\tOPERATOR_NOT_CONTAINS,\n\tOPERATOR_STARTS_WITH,\n\tOPERATOR_BEFORE,\n\tOPERATOR_AFTER,\n\tOPERATOR_BEFORE_INC,\n\tOPERATOR_AFTER_INC,\n\tOPERATOR_BETWEEN,\n\tOPERATOR_ON,\n\tOPERATOR_NOT_ON,\n\tOPERATOR_IN_THE_PAST,\n\tOPERATOR_OVER,\n} from '../../constants';\nimport type {\n\tFilter,\n\tNormalizedField,\n\tNormalizedFieldDate,\n\tNormalizedFilter,\n\tOperator,\n\tOption,\n\tView,\n} from '../../types';\nimport useElements from '../../hooks/use-elements';\nimport parseDateTime from '../../field-types/utils/parse-date-time';\n\nconst ENTER = 'Enter';\nconst SPACE = ' ';\n\ninterface FilterTextProps {\n\tactiveElements: Option[];\n\tfilterInView?: Filter;\n\tfilter: NormalizedFilter;\n}\n\ninterface OperatorSelectorProps {\n\tfilter: NormalizedFilter;\n\tview: View;\n\tonChangeView: ( view: View ) => void;\n}\n\ninterface FilterProps extends OperatorSelectorProps {\n\taddFilterRef: RefObject< HTMLButtonElement >;\n\topenedFilter: string | null;\n\tfields: NormalizedField< any >[];\n}\n\nconst FilterText = ( {\n\tactiveElements,\n\tfilterInView,\n\tfilter,\n}: FilterTextProps ) => {\n\tif ( activeElements === undefined || activeElements.length === 0 ) {\n\t\treturn filter.name;\n\t}\n\n\tconst filterTextWrappers = {\n\t\tName: <span className=\"dataviews-filters__summary-filter-text-name\" />,\n\t\tValue: (\n\t\t\t<span className=\"dataviews-filters__summary-filter-text-value\" />\n\t\t),\n\t};\n\n\tif ( filterInView?.operator === OPERATOR_IS_ANY ) {\n\t\treturn createInterpolateElement(\n\t\t\tsprintf(\n\t\t\t\t/* translators: 1: Filter name. 2: Filter value. e.g.: \"Author is any: Admin, Editor\". */\n\t\t\t\t__( '<Name>%1$s is any: </Name><Value>%2$s</Value>' ),\n\t\t\t\tfilter.name,\n\t\t\t\tactiveElements.map( ( element ) => element.label ).join( ', ' )\n\t\t\t),\n\t\t\tfilterTextWrappers\n\t\t);\n\t}\n\n\tif ( filterInView?.operator === OPERATOR_IS_NONE ) {\n\t\treturn createInterpolateElement(\n\t\t\tsprintf(\n\t\t\t\t/* translators: 1: Filter name. 2: Filter value. e.g.: \"Author is none: Admin, Editor\". */\n\t\t\t\t__( '<Name>%1$s is none: </Name><Value>%2$s</Value>' ),\n\t\t\t\tfilter.name,\n\t\t\t\tactiveElements.map( ( element ) => element.label ).join( ', ' )\n\t\t\t),\n\t\t\tfilterTextWrappers\n\t\t);\n\t}\n\n\tif ( filterInView?.operator === OPERATOR_IS_ALL ) {\n\t\treturn createInterpolateElement(\n\t\t\tsprintf(\n\t\t\t\t/* translators: 1: Filter name. 2: Filter value. e.g.: \"Author is all: Admin, Editor\". */\n\t\t\t\t__( '<Name>%1$s is all: </Name><Value>%2$s</Value>' ),\n\t\t\t\tfilter.name,\n\t\t\t\tactiveElements.map( ( element ) => element.label ).join( ', ' )\n\t\t\t),\n\t\t\tfilterTextWrappers\n\t\t);\n\t}\n\n\tif ( filterInView?.operator === OPERATOR_IS_NOT_ALL ) {\n\t\treturn createInterpolateElement(\n\t\t\tsprintf(\n\t\t\t\t/* translators: 1: Filter name. 2: Filter value. e.g.: \"Author is not all: Admin, Editor\". */\n\t\t\t\t__( '<Name>%1$s is not all: </Name><Value>%2$s</Value>' ),\n\t\t\t\tfilter.name,\n\t\t\t\tactiveElements.map( ( element ) => element.label ).join( ', ' )\n\t\t\t),\n\t\t\tfilterTextWrappers\n\t\t);\n\t}\n\n\tif ( filterInView?.operator === OPERATOR_IS ) {\n\t\treturn createInterpolateElement(\n\t\t\tsprintf(\n\t\t\t\t/* translators: 1: Filter name. 2: Filter value. e.g.: \"Author is: Admin\". */\n\t\t\t\t__( '<Name>%1$s is: </Name><Value>%2$s</Value>' ),\n\t\t\t\tfilter.name,\n\t\t\t\tactiveElements[ 0 ].label\n\t\t\t),\n\t\t\tfilterTextWrappers\n\t\t);\n\t}\n\n\tif ( filterInView?.operator === OPERATOR_IS_NOT ) {\n\t\treturn createInterpolateElement(\n\t\t\tsprintf(\n\t\t\t\t/* translators: 1: Filter name. 2: Filter value. e.g.: \"Author is not: Admin\". */\n\t\t\t\t__( '<Name>%1$s is not: </Name><Value>%2$s</Value>' ),\n\t\t\t\tfilter.name,\n\t\t\t\tactiveElements[ 0 ].label\n\t\t\t),\n\t\t\tfilterTextWrappers\n\t\t);\n\t}\n\n\tif ( filterInView?.operator === OPERATOR_LESS_THAN ) {\n\t\treturn createInterpolateElement(\n\t\t\tsprintf(\n\t\t\t\t/* translators: 1: Filter name. 2: Filter value. e.g.: \"Price is less than: 10\". */\n\t\t\t\t__( '<Name>%1$s is less than: </Name><Value>%2$s</Value>' ),\n\t\t\t\tfilter.name,\n\t\t\t\tactiveElements[ 0 ].label\n\t\t\t),\n\t\t\tfilterTextWrappers\n\t\t);\n\t}\n\n\tif ( filterInView?.operator === OPERATOR_GREATER_THAN ) {\n\t\treturn createInterpolateElement(\n\t\t\tsprintf(\n\t\t\t\t/* translators: 1: Filter name. 2: Filter value. e.g.: \"Price is greater than: 10\". */\n\t\t\t\t__( '<Name>%1$s is greater than: </Name><Value>%2$s</Value>' ),\n\t\t\t\tfilter.name,\n\t\t\t\tactiveElements[ 0 ].label\n\t\t\t),\n\t\t\tfilterTextWrappers\n\t\t);\n\t}\n\n\tif ( filterInView?.operator === OPERATOR_LESS_THAN_OR_EQUAL ) {\n\t\treturn createInterpolateElement(\n\t\t\tsprintf(\n\t\t\t\t/* translators: 1: Filter name. 2: Filter value. e.g.: \"Price is less than or equal to: 10\". */\n\t\t\t\t__(\n\t\t\t\t\t'<Name>%1$s is less than or equal to: </Name><Value>%2$s</Value>'\n\t\t\t\t),\n\t\t\t\tfilter.name,\n\t\t\t\tactiveElements[ 0 ].label\n\t\t\t),\n\t\t\tfilterTextWrappers\n\t\t);\n\t}\n\n\tif ( filterInView?.operator === OPERATOR_GREATER_THAN_OR_EQUAL ) {\n\t\treturn createInterpolateElement(\n\t\t\tsprintf(\n\t\t\t\t/* translators: 1: Filter name. 2: Filter value. e.g.: \"Price is greater than or equal to: 10\". */\n\t\t\t\t__(\n\t\t\t\t\t'<Name>%1$s is greater than or equal to: </Name><Value>%2$s</Value>'\n\t\t\t\t),\n\t\t\t\tfilter.name,\n\t\t\t\tactiveElements[ 0 ].label\n\t\t\t),\n\t\t\tfilterTextWrappers\n\t\t);\n\t}\n\n\tif ( filterInView?.operator === OPERATOR_CONTAINS ) {\n\t\treturn createInterpolateElement(\n\t\t\tsprintf(\n\t\t\t\t/* translators: 1: Filter name. 2: Filter value. e.g.: \"Title contains: Mars\". */\n\t\t\t\t__( '<Name>%1$s contains: </Name><Value>%2$s</Value>' ),\n\t\t\t\tfilter.name,\n\t\t\t\tactiveElements[ 0 ].label\n\t\t\t),\n\t\t\tfilterTextWrappers\n\t\t);\n\t}\n\n\tif ( filterInView?.operator === OPERATOR_NOT_CONTAINS ) {\n\t\treturn createInterpolateElement(\n\t\t\tsprintf(\n\t\t\t\t/* translators: 1: Filter name. 2: Filter value. e.g.: \"Description doesn't contain: photo\". */\n\t\t\t\t__( \"<Name>%1$s doesn't contain: </Name><Value>%2$s</Value>\" ),\n\t\t\t\tfilter.name,\n\t\t\t\tactiveElements[ 0 ].label\n\t\t\t),\n\t\t\tfilterTextWrappers\n\t\t);\n\t}\n\n\tif ( filterInView?.operator === OPERATOR_STARTS_WITH ) {\n\t\treturn createInterpolateElement(\n\t\t\tsprintf(\n\t\t\t\t/* translators: 1: Filter name. 2: Filter value. e.g.: \"Title starts with: Mar\". */\n\t\t\t\t__( '<Name>%1$s starts with: </Name><Value>%2$s</Value>' ),\n\t\t\t\tfilter.name,\n\t\t\t\tactiveElements[ 0 ].label\n\t\t\t),\n\t\t\tfilterTextWrappers\n\t\t);\n\t}\n\n\tif ( filterInView?.operator === OPERATOR_BEFORE ) {\n\t\treturn createInterpolateElement(\n\t\t\tsprintf(\n\t\t\t\t/* translators: 1: Filter name. 2: Filter value. e.g.: \"Date is before: 2024-01-01\". */\n\t\t\t\t__( '<Name>%1$s is before: </Name><Value>%2$s</Value>' ),\n\t\t\t\tfilter.name,\n\t\t\t\tactiveElements[ 0 ].label\n\t\t\t),\n\t\t\tfilterTextWrappers\n\t\t);\n\t}\n\n\tif ( filterInView?.operator === OPERATOR_AFTER ) {\n\t\treturn createInterpolateElement(\n\t\t\tsprintf(\n\t\t\t\t/* translators: 1: Filter name. 2: Filter value. e.g.: \"Date is after: 2024-01-01\". */\n\t\t\t\t__( '<Name>%1$s is after: </Name><Value>%2$s</Value>' ),\n\t\t\t\tfilter.name,\n\t\t\t\tactiveElements[ 0 ].label\n\t\t\t),\n\t\t\tfilterTextWrappers\n\t\t);\n\t}\n\n\tif ( filterInView?.operator === OPERATOR_BEFORE_INC ) {\n\t\treturn createInterpolateElement(\n\t\t\tsprintf(\n\t\t\t\t/* translators: 1: Filter name. 2: Filter value. e.g.: \"Date is on or before: 2024-01-01\". */\n\t\t\t\t__( '<Name>%1$s is on or before: </Name><Value>%2$s</Value>' ),\n\t\t\t\tfilter.name,\n\t\t\t\tactiveElements[ 0 ].label\n\t\t\t),\n\t\t\tfilterTextWrappers\n\t\t);\n\t}\n\n\tif ( filterInView?.operator === OPERATOR_AFTER_INC ) {\n\t\treturn createInterpolateElement(\n\t\t\tsprintf(\n\t\t\t\t/* translators: 1: Filter name. 2: Filter value. e.g.: \"Date is on or after: 2024-01-01\". */\n\t\t\t\t__( '<Name>%1$s is on or after: </Name><Value>%2$s</Value>' ),\n\t\t\t\tfilter.name,\n\t\t\t\tactiveElements[ 0 ].label\n\t\t\t),\n\t\t\tfilterTextWrappers\n\t\t);\n\t}\n\n\tif ( filterInView?.operator === OPERATOR_BETWEEN ) {\n\t\tconst { label } = activeElements[ 0 ];\n\n\t\treturn createInterpolateElement(\n\t\t\tsprintf(\n\t\t\t\t/* translators: 1: Filter name. 2: Min value. 3: Max value. e.g.: \"Item count between (inc): 10 and 180\". */\n\t\t\t\t__(\n\t\t\t\t\t'<Name>%1$s between (inc): </Name><Value>%2$s and %3$s</Value>'\n\t\t\t\t),\n\t\t\t\tfilter.name,\n\t\t\t\tlabel[ 0 ],\n\t\t\t\tlabel[ 1 ]\n\t\t\t),\n\t\t\tfilterTextWrappers\n\t\t);\n\t}\n\n\tif ( filterInView?.operator === OPERATOR_ON ) {\n\t\treturn createInterpolateElement(\n\t\t\tsprintf(\n\t\t\t\t/* translators: 1: Filter name. 2: Filter value. e.g.: \"Date is: 2024-01-01\". */\n\t\t\t\t__( '<Name>%1$s is: </Name><Value>%2$s</Value>' ),\n\t\t\t\tfilter.name,\n\t\t\t\tactiveElements[ 0 ].label\n\t\t\t),\n\t\t\tfilterTextWrappers\n\t\t);\n\t}\n\n\tif ( filterInView?.operator === OPERATOR_NOT_ON ) {\n\t\treturn createInterpolateElement(\n\t\t\tsprintf(\n\t\t\t\t/* translators: 1: Filter name. 2: Filter value. e.g.: \"Date is not: 2024-01-01\". */\n\t\t\t\t__( '<Name>%1$s is not: </Name><Value>%2$s</Value>' ),\n\t\t\t\tfilter.name,\n\t\t\t\tactiveElements[ 0 ].label\n\t\t\t),\n\t\t\tfilterTextWrappers\n\t\t);\n\t}\n\n\tif ( filterInView?.operator === OPERATOR_IN_THE_PAST ) {\n\t\treturn createInterpolateElement(\n\t\t\tsprintf(\n\t\t\t\t/* translators: 1: Filter name. 2: Filter value. e.g.: \"Date is in the past: 1 days\". */\n\t\t\t\t__( '<Name>%1$s is in the past: </Name><Value>%2$s</Value>' ),\n\t\t\t\tfilter.name,\n\t\t\t\t`${ activeElements[ 0 ].value.value } ${ activeElements[ 0 ].value.unit }`\n\t\t\t),\n\t\t\tfilterTextWrappers\n\t\t);\n\t}\n\n\tif ( filterInView?.operator === OPERATOR_OVER ) {\n\t\treturn createInterpolateElement(\n\t\t\tsprintf(\n\t\t\t\t/* translators: 1: Filter name. 2: Filter value. e.g.: \"Date is over: 1 days ago\". */\n\t\t\t\t__( '<Name>%1$s is over: </Name><Value>%2$s</Value> ago' ),\n\t\t\t\tfilter.name,\n\t\t\t\t`${ activeElements[ 0 ].value.value } ${ activeElements[ 0 ].value.unit }`\n\t\t\t),\n\t\t\tfilterTextWrappers\n\t\t);\n\t}\n\treturn sprintf(\n\t\t/* translators: 1: Filter name e.g.: \"Unknown status for Author\". */\n\t\t__( 'Unknown status for %1$s' ),\n\t\tfilter.name\n\t);\n};\n\nfunction OperatorSelector( {\n\tfilter,\n\tview,\n\tonChangeView,\n}: OperatorSelectorProps ) {\n\tconst operatorOptions = filter.operators?.map( ( operator ) => ( {\n\t\tvalue: operator,\n\t\tlabel: OPERATORS[ operator ]?.label,\n\t} ) );\n\tconst currentFilter = view.filters?.find(\n\t\t( _filter ) => _filter.field === filter.field\n\t);\n\tconst value = currentFilter?.operator || filter.operators[ 0 ];\n\treturn (\n\t\toperatorOptions.length > 1 && (\n\t\t\t<HStack\n\t\t\t\tspacing={ 2 }\n\t\t\t\tjustify=\"flex-start\"\n\t\t\t\tclassName=\"dataviews-filters__summary-operators-container\"\n\t\t\t>\n\t\t\t\t<FlexItem className=\"dataviews-filters__summary-operators-filter-name\">\n\t\t\t\t\t{ filter.name }\n\t\t\t\t</FlexItem>\n\n\t\t\t\t<SelectControl\n\t\t\t\t\tclassName=\"dataviews-filters__summary-operators-filter-select\"\n\t\t\t\t\tlabel={ __( 'Conditions' ) }\n\t\t\t\t\tvalue={ value }\n\t\t\t\t\toptions={ operatorOptions }\n\t\t\t\t\tonChange={ ( newValue ) => {\n\t\t\t\t\t\tconst operator = newValue as Operator;\n\t\t\t\t\t\tconst currentOperator = currentFilter?.operator;\n\t\t\t\t\t\tconst newFilters = currentFilter\n\t\t\t\t\t\t\t? [\n\t\t\t\t\t\t\t\t\t...( view.filters ?? [] ).map(\n\t\t\t\t\t\t\t\t\t\t( _filter ) => {\n\t\t\t\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t\t\t\t_filter.field === filter.field\n\t\t\t\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\t\t\t\t// Reset the value only when switching between operators that have different value types.\n\t\t\t\t\t\t\t\t\t\t\t\tconst OPERATORS_SHOULD_RESET_VALUE =\n\t\t\t\t\t\t\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tOPERATOR_BETWEEN,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tOPERATOR_IN_THE_PAST,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tOPERATOR_OVER,\n\t\t\t\t\t\t\t\t\t\t\t\t\t];\n\t\t\t\t\t\t\t\t\t\t\t\tconst shouldResetValue =\n\t\t\t\t\t\t\t\t\t\t\t\t\tcurrentOperator &&\n\t\t\t\t\t\t\t\t\t\t\t\t\t( OPERATORS_SHOULD_RESET_VALUE.includes(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tcurrentOperator\n\t\t\t\t\t\t\t\t\t\t\t\t\t) ||\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tOPERATORS_SHOULD_RESET_VALUE.includes(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\toperator\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t) );\n\n\t\t\t\t\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t\t\t\t\t..._filter,\n\t\t\t\t\t\t\t\t\t\t\t\t\tvalue: shouldResetValue\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t? undefined\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t: _filter.value,\n\t\t\t\t\t\t\t\t\t\t\t\t\toperator,\n\t\t\t\t\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\treturn _filter;\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t ]\n\t\t\t\t\t\t\t: [\n\t\t\t\t\t\t\t\t\t...( view.filters ?? [] ),\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tfield: filter.field,\n\t\t\t\t\t\t\t\t\t\toperator,\n\t\t\t\t\t\t\t\t\t\tvalue: undefined,\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t ];\n\t\t\t\t\t\tonChangeView( {\n\t\t\t\t\t\t\t...view,\n\t\t\t\t\t\t\tpage: 1,\n\t\t\t\t\t\t\tfilters: newFilters,\n\t\t\t\t\t\t} );\n\t\t\t\t\t} }\n\t\t\t\t\tsize=\"small\"\n\t\t\t\t\tvariant=\"minimal\"\n\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\thideLabelFromVision\n\t\t\t\t/>\n\t\t\t</HStack>\n\t\t)\n\t);\n}\n\nexport default function Filter( {\n\taddFilterRef,\n\topenedFilter,\n\tfields,\n\t...commonProps\n}: FilterProps ) {\n\tconst toggleRef = useRef< HTMLDivElement >( null );\n\tconst { filter, view, onChangeView } = commonProps;\n\tconst filterInView = view.filters?.find(\n\t\t( f ) => f.field === filter.field\n\t);\n\n\tlet activeElements: Option[] = [];\n\n\tconst { elements } = useElements( {\n\t\telements: filter.elements,\n\t\tgetElements: filter.getElements,\n\t} );\n\n\tif ( elements.length > 0 ) {\n\t\tactiveElements = elements.filter( ( element ) => {\n\t\t\tif ( filter.singleSelection ) {\n\t\t\t\treturn element.value === filterInView?.value;\n\t\t\t}\n\t\t\treturn filterInView?.value?.includes( element.value );\n\t\t} );\n\t} else if ( filterInView?.value !== undefined ) {\n\t\tconst field = fields.find( ( f ) => f.id === filter.field );\n\t\tlet label = filterInView.value;\n\n\t\tif ( field?.type === 'date' && typeof label === 'string' ) {\n\t\t\ttry {\n\t\t\t\tconst dateValue = parseDateTime( label );\n\t\t\t\tif ( dateValue !== null ) {\n\t\t\t\t\tlabel = dateI18n(\n\t\t\t\t\t\t( field as NormalizedFieldDate< any > ).format.date,\n\t\t\t\t\t\tgetDate( label )\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} catch ( e ) {\n\t\t\t\tlabel = filterInView.value;\n\t\t\t}\n\t\t} else if ( field?.type === 'datetime' && typeof label === 'string' ) {\n\t\t\ttry {\n\t\t\t\tconst dateValue = parseDateTime( label );\n\t\t\t\tif ( dateValue !== null ) {\n\t\t\t\t\tlabel = dateValue.toLocaleString();\n\t\t\t\t}\n\t\t\t} catch ( e ) {\n\t\t\t\tlabel = filterInView.value;\n\t\t\t}\n\t\t}\n\n\t\tactiveElements = [\n\t\t\t{\n\t\t\t\tvalue: filterInView.value,\n\t\t\t\tlabel,\n\t\t\t},\n\t\t];\n\t}\n\n\tconst isPrimary = filter.isPrimary;\n\tconst isLocked = filterInView?.isLocked;\n\tconst hasValues = ! isLocked && filterInView?.value !== undefined;\n\tconst canResetOrRemove = ! isLocked && ( ! isPrimary || hasValues );\n\treturn (\n\t\t<Dropdown\n\t\t\tdefaultOpen={ openedFilter === filter.field }\n\t\t\tcontentClassName=\"dataviews-filters__summary-popover\"\n\t\t\tpopoverProps={ { placement: 'bottom-start', role: 'dialog' } }\n\t\t\tonClose={ () => {\n\t\t\t\ttoggleRef.current?.focus();\n\t\t\t} }\n\t\t\trenderToggle={ ( { isOpen, onToggle } ) => (\n\t\t\t\t<div className=\"dataviews-filters__summary-chip-container\">\n\t\t\t\t\t<Tooltip\n\t\t\t\t\t\ttext={ sprintf(\n\t\t\t\t\t\t\t/* translators: 1: Filter name. */\n\t\t\t\t\t\t\t__( 'Filter by: %1$s' ),\n\t\t\t\t\t\t\tfilter.name.toLowerCase()\n\t\t\t\t\t\t) }\n\t\t\t\t\t\tplacement=\"top\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<div\n\t\t\t\t\t\t\tclassName={ clsx(\n\t\t\t\t\t\t\t\t'dataviews-filters__summary-chip',\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t'has-reset': canResetOrRemove,\n\t\t\t\t\t\t\t\t\t'has-values': hasValues,\n\t\t\t\t\t\t\t\t\t'is-not-clickable': isLocked,\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\trole=\"button\"\n\t\t\t\t\t\t\ttabIndex={ isLocked ? -1 : 0 }\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tif ( ! isLocked ) {\n\t\t\t\t\t\t\t\t\tonToggle();\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\tonKeyDown={ ( event ) => {\n\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t! isLocked &&\n\t\t\t\t\t\t\t\t\t[ ENTER, SPACE ].includes( event.key )\n\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\tonToggle();\n\t\t\t\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\taria-disabled={ isLocked }\n\t\t\t\t\t\t\taria-pressed={ isOpen }\n\t\t\t\t\t\t\taria-expanded={ isOpen }\n\t\t\t\t\t\t\tref={ toggleRef }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<FilterText\n\t\t\t\t\t\t\t\tactiveElements={ activeElements }\n\t\t\t\t\t\t\t\tfilterInView={ filterInView }\n\t\t\t\t\t\t\t\tfilter={ filter }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</Tooltip>\n\t\t\t\t\t{ canResetOrRemove && (\n\t\t\t\t\t\t<Tooltip\n\t\t\t\t\t\t\ttext={ isPrimary ? __( 'Reset' ) : __( 'Remove' ) }\n\t\t\t\t\t\t\tplacement=\"top\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\tclassName={ clsx(\n\t\t\t\t\t\t\t\t\t'dataviews-filters__summary-chip-remove',\n\t\t\t\t\t\t\t\t\t{ 'has-values': hasValues }\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\tonChangeView( {\n\t\t\t\t\t\t\t\t\t\t...view,\n\t\t\t\t\t\t\t\t\t\tpage: 1,\n\t\t\t\t\t\t\t\t\t\tfilters: view.filters?.filter(\n\t\t\t\t\t\t\t\t\t\t\t( _filter ) =>\n\t\t\t\t\t\t\t\t\t\t\t\t_filter.field !== filter.field\n\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t\t\t// If the filter is not primary and can be removed, it will be added\n\t\t\t\t\t\t\t\t\t// back to the available filters from `Add filter` component.\n\t\t\t\t\t\t\t\t\tif ( ! isPrimary ) {\n\t\t\t\t\t\t\t\t\t\taddFilterRef.current?.focus();\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\t// If is primary, focus the toggle button.\n\t\t\t\t\t\t\t\t\t\ttoggleRef.current?.focus();\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<Icon icon={ closeSmall } />\n\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t</Tooltip>\n\t\t\t\t\t) }\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\trenderContent={ () => {\n\t\t\t\treturn (\n\t\t\t\t\t<VStack spacing={ 0 } justify=\"flex-start\">\n\t\t\t\t\t\t<OperatorSelector { ...commonProps } />\n\t\t\t\t\t\t{ commonProps.filter.hasElements ? (\n\t\t\t\t\t\t\t<SearchWidget\n\t\t\t\t\t\t\t\t{ ...commonProps }\n\t\t\t\t\t\t\t\tfilter={ {\n\t\t\t\t\t\t\t\t\t...commonProps.filter,\n\t\t\t\t\t\t\t\t\telements,\n\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t) : (\n\t\t\t\t\t\t\t<InputWidget { ...commonProps } fields={ fields } />\n\t\t\t\t\t\t) }\n\t\t\t\t\t</VStack>\n\t\t\t\t);\n\t\t\t} }\n\t\t/>\n\t);\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAiB;AAMjB,wBAQO;AACP,kBAA4B;AAC5B,
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\nimport type { RefObject } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tDropdown,\n\t__experimentalVStack as VStack,\n\t__experimentalHStack as HStack,\n\tFlexItem,\n\tSelectControl,\n\tTooltip,\n\tIcon,\n} from '@wordpress/components';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { useRef } from '@wordpress/element';\nimport { closeSmall } from '@wordpress/icons';\nimport { dateI18n, getDate } from '@wordpress/date';\n\n/**\n * Internal dependencies\n */\nimport SearchWidget from './search-widget';\nimport InputWidget from './input-widget';\nimport { getOperatorByName } from '../../utils/operators';\nimport type {\n\tFilter,\n\tNormalizedField,\n\tNormalizedFieldDate,\n\tNormalizedFieldNumber,\n\tNormalizedFieldInteger,\n\tNormalizedFilter,\n\tOperator,\n\tOption,\n\tView,\n} from '../../types';\nimport useElements from '../../hooks/use-elements';\nimport parseDateTime from '../../field-types/utils/parse-date-time';\nimport { formatNumber } from '../../field-types/number';\nimport { formatInteger } from '../../field-types/integer';\n\nconst ENTER = 'Enter';\nconst SPACE = ' ';\n\ninterface FilterTextProps {\n\tactiveElements: Option[];\n\tfilterInView?: Filter;\n\tfilter: NormalizedFilter;\n}\n\ninterface OperatorSelectorProps {\n\tfilter: NormalizedFilter;\n\tview: View;\n\tonChangeView: ( view: View ) => void;\n}\n\ninterface FilterProps extends OperatorSelectorProps {\n\taddFilterRef: RefObject< HTMLButtonElement >;\n\topenedFilter: string | null;\n\tfields: NormalizedField< any >[];\n}\n\nconst FilterText = ( {\n\tactiveElements,\n\tfilterInView,\n\tfilter,\n}: FilterTextProps ) => {\n\tif ( activeElements === undefined || activeElements.length === 0 ) {\n\t\treturn filter.name;\n\t}\n\n\tconst operator = getOperatorByName( filterInView?.operator );\n\tif ( operator !== undefined ) {\n\t\treturn operator.filterText( filter, activeElements );\n\t}\n\n\treturn sprintf(\n\t\t/* translators: 1: Filter name e.g.: \"Unknown status for Author\". */\n\t\t__( 'Unknown status for %1$s' ),\n\t\tfilter.name\n\t);\n};\n\nfunction OperatorSelector( {\n\tfilter,\n\tview,\n\tonChangeView,\n}: OperatorSelectorProps ) {\n\tconst operatorOptions = filter.operators?.map( ( operator ) => ( {\n\t\tvalue: operator,\n\t\tlabel: getOperatorByName( operator )?.label || operator,\n\t} ) );\n\tconst currentFilter = view.filters?.find(\n\t\t( _filter ) => _filter.field === filter.field\n\t);\n\tconst value = currentFilter?.operator || filter.operators[ 0 ];\n\treturn (\n\t\toperatorOptions.length > 1 && (\n\t\t\t<HStack\n\t\t\t\tspacing={ 2 }\n\t\t\t\tjustify=\"flex-start\"\n\t\t\t\tclassName=\"dataviews-filters__summary-operators-container\"\n\t\t\t>\n\t\t\t\t<FlexItem className=\"dataviews-filters__summary-operators-filter-name\">\n\t\t\t\t\t{ filter.name }\n\t\t\t\t</FlexItem>\n\n\t\t\t\t<SelectControl\n\t\t\t\t\tclassName=\"dataviews-filters__summary-operators-filter-select\"\n\t\t\t\t\tlabel={ __( 'Conditions' ) }\n\t\t\t\t\tvalue={ value }\n\t\t\t\t\toptions={ operatorOptions }\n\t\t\t\t\tonChange={ ( newValue ) => {\n\t\t\t\t\t\tconst newOperator = newValue as Operator;\n\t\t\t\t\t\tconst currentOperator = currentFilter?.operator;\n\t\t\t\t\t\tconst newFilters = currentFilter\n\t\t\t\t\t\t\t? [\n\t\t\t\t\t\t\t\t\t...( view.filters ?? [] ).map(\n\t\t\t\t\t\t\t\t\t\t( _filter ) => {\n\t\t\t\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t\t\t\t_filter.field === filter.field\n\t\t\t\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\t\t\t\tconst currentOpSelectionModel =\n\t\t\t\t\t\t\t\t\t\t\t\t\tgetOperatorByName(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tcurrentOperator\n\t\t\t\t\t\t\t\t\t\t\t\t\t)?.selection;\n\t\t\t\t\t\t\t\t\t\t\t\tconst newOpSelectionModel =\n\t\t\t\t\t\t\t\t\t\t\t\t\tgetOperatorByName(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tnewOperator\n\t\t\t\t\t\t\t\t\t\t\t\t\t)?.selection;\n\n\t\t\t\t\t\t\t\t\t\t\t\tconst shouldResetValue =\n\t\t\t\t\t\t\t\t\t\t\t\t\tcurrentOpSelectionModel !==\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tnewOpSelectionModel ||\n\t\t\t\t\t\t\t\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tcurrentOpSelectionModel,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tnewOpSelectionModel,\n\t\t\t\t\t\t\t\t\t\t\t\t\t].includes( 'custom' );\n\n\t\t\t\t\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t\t\t\t\t..._filter,\n\t\t\t\t\t\t\t\t\t\t\t\t\tvalue: shouldResetValue\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t? undefined\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t: _filter.value,\n\t\t\t\t\t\t\t\t\t\t\t\t\toperator: newOperator,\n\t\t\t\t\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\treturn _filter;\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t ]\n\t\t\t\t\t\t\t: [\n\t\t\t\t\t\t\t\t\t...( view.filters ?? [] ),\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tfield: filter.field,\n\t\t\t\t\t\t\t\t\t\toperator: newOperator,\n\t\t\t\t\t\t\t\t\t\tvalue: undefined,\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t ];\n\t\t\t\t\t\tonChangeView( {\n\t\t\t\t\t\t\t...view,\n\t\t\t\t\t\t\tpage: 1,\n\t\t\t\t\t\t\tfilters: newFilters,\n\t\t\t\t\t\t} );\n\t\t\t\t\t} }\n\t\t\t\t\tsize=\"small\"\n\t\t\t\t\tvariant=\"minimal\"\n\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\thideLabelFromVision\n\t\t\t\t/>\n\t\t\t</HStack>\n\t\t)\n\t);\n}\n\nexport default function Filter( {\n\taddFilterRef,\n\topenedFilter,\n\tfields,\n\t...commonProps\n}: FilterProps ) {\n\tconst toggleRef = useRef< HTMLDivElement >( null );\n\tconst { filter, view, onChangeView } = commonProps;\n\tconst filterInView = view.filters?.find(\n\t\t( f ) => f.field === filter.field\n\t);\n\n\tlet activeElements: Option[] = [];\n\n\tconst { elements } = useElements( {\n\t\telements: filter.elements,\n\t\tgetElements: filter.getElements,\n\t} );\n\n\tif ( elements.length > 0 ) {\n\t\tactiveElements = elements.filter( ( element ) => {\n\t\t\tif ( filter.singleSelection ) {\n\t\t\t\treturn element.value === filterInView?.value;\n\t\t\t}\n\t\t\treturn filterInView?.value?.includes( element.value );\n\t\t} );\n\t} else if ( filterInView?.value !== undefined ) {\n\t\tconst field = fields.find( ( f ) => f.id === filter.field );\n\t\tlet label = filterInView.value;\n\n\t\tif ( field?.type === 'date' && typeof label === 'string' ) {\n\t\t\ttry {\n\t\t\t\tconst dateValue = parseDateTime( label );\n\t\t\t\tif ( dateValue !== null ) {\n\t\t\t\t\tlabel = dateI18n(\n\t\t\t\t\t\t( field as NormalizedFieldDate< any > ).format.date,\n\t\t\t\t\t\tgetDate( label )\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} catch ( e ) {\n\t\t\t\tlabel = filterInView.value;\n\t\t\t}\n\t\t} else if ( field?.type === 'datetime' && typeof label === 'string' ) {\n\t\t\ttry {\n\t\t\t\tconst dateValue = parseDateTime( label );\n\t\t\t\tif ( dateValue !== null ) {\n\t\t\t\t\tlabel = dateValue.toLocaleString();\n\t\t\t\t}\n\t\t\t} catch ( e ) {\n\t\t\t\tlabel = filterInView.value;\n\t\t\t}\n\t\t} else if ( field?.type === 'number' && typeof label === 'number' ) {\n\t\t\tconst numberField = field as NormalizedFieldNumber< any >;\n\t\t\tlabel = formatNumber( label, numberField.format );\n\t\t} else if ( field?.type === 'integer' && typeof label === 'number' ) {\n\t\t\tconst integerField = field as NormalizedFieldInteger< any >;\n\t\t\tlabel = formatInteger( label, integerField.format );\n\t\t}\n\n\t\tactiveElements = [\n\t\t\t{\n\t\t\t\tvalue: filterInView.value,\n\t\t\t\tlabel,\n\t\t\t},\n\t\t];\n\t}\n\n\tconst isPrimary = filter.isPrimary;\n\tconst isLocked = filterInView?.isLocked;\n\tconst hasValues = ! isLocked && filterInView?.value !== undefined;\n\tconst canResetOrRemove = ! isLocked && ( ! isPrimary || hasValues );\n\treturn (\n\t\t<Dropdown\n\t\t\tdefaultOpen={ openedFilter === filter.field }\n\t\t\tcontentClassName=\"dataviews-filters__summary-popover\"\n\t\t\tpopoverProps={ { placement: 'bottom-start', role: 'dialog' } }\n\t\t\tonClose={ () => {\n\t\t\t\ttoggleRef.current?.focus();\n\t\t\t} }\n\t\t\trenderToggle={ ( { isOpen, onToggle } ) => (\n\t\t\t\t<div className=\"dataviews-filters__summary-chip-container\">\n\t\t\t\t\t<Tooltip\n\t\t\t\t\t\ttext={ sprintf(\n\t\t\t\t\t\t\t/* translators: 1: Filter name. */\n\t\t\t\t\t\t\t__( 'Filter by: %1$s' ),\n\t\t\t\t\t\t\tfilter.name.toLowerCase()\n\t\t\t\t\t\t) }\n\t\t\t\t\t\tplacement=\"top\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<div\n\t\t\t\t\t\t\tclassName={ clsx(\n\t\t\t\t\t\t\t\t'dataviews-filters__summary-chip',\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t'has-reset': canResetOrRemove,\n\t\t\t\t\t\t\t\t\t'has-values': hasValues,\n\t\t\t\t\t\t\t\t\t'is-not-clickable': isLocked,\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\trole=\"button\"\n\t\t\t\t\t\t\ttabIndex={ isLocked ? -1 : 0 }\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tif ( ! isLocked ) {\n\t\t\t\t\t\t\t\t\tonToggle();\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\tonKeyDown={ ( event ) => {\n\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t! isLocked &&\n\t\t\t\t\t\t\t\t\t[ ENTER, SPACE ].includes( event.key )\n\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\tonToggle();\n\t\t\t\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\taria-disabled={ isLocked }\n\t\t\t\t\t\t\taria-pressed={ isOpen }\n\t\t\t\t\t\t\taria-expanded={ isOpen }\n\t\t\t\t\t\t\tref={ toggleRef }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<FilterText\n\t\t\t\t\t\t\t\tactiveElements={ activeElements }\n\t\t\t\t\t\t\t\tfilterInView={ filterInView }\n\t\t\t\t\t\t\t\tfilter={ filter }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</Tooltip>\n\t\t\t\t\t{ canResetOrRemove && (\n\t\t\t\t\t\t<Tooltip\n\t\t\t\t\t\t\ttext={ isPrimary ? __( 'Reset' ) : __( 'Remove' ) }\n\t\t\t\t\t\t\tplacement=\"top\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\tclassName={ clsx(\n\t\t\t\t\t\t\t\t\t'dataviews-filters__summary-chip-remove',\n\t\t\t\t\t\t\t\t\t{ 'has-values': hasValues }\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t\tonChangeView( {\n\t\t\t\t\t\t\t\t\t\t...view,\n\t\t\t\t\t\t\t\t\t\tpage: 1,\n\t\t\t\t\t\t\t\t\t\tfilters: view.filters?.filter(\n\t\t\t\t\t\t\t\t\t\t\t( _filter ) =>\n\t\t\t\t\t\t\t\t\t\t\t\t_filter.field !== filter.field\n\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t\t\t// If the filter is not primary and can be removed, it will be added\n\t\t\t\t\t\t\t\t\t// back to the available filters from `Add filter` component.\n\t\t\t\t\t\t\t\t\tif ( ! isPrimary ) {\n\t\t\t\t\t\t\t\t\t\taddFilterRef.current?.focus();\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\t// If is primary, focus the toggle button.\n\t\t\t\t\t\t\t\t\t\ttoggleRef.current?.focus();\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<Icon icon={ closeSmall } />\n\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t</Tooltip>\n\t\t\t\t\t) }\n\t\t\t\t</div>\n\t\t\t) }\n\t\t\trenderContent={ () => {\n\t\t\t\treturn (\n\t\t\t\t\t<VStack spacing={ 0 } justify=\"flex-start\">\n\t\t\t\t\t\t<OperatorSelector { ...commonProps } />\n\t\t\t\t\t\t{ commonProps.filter.hasElements ? (\n\t\t\t\t\t\t\t<SearchWidget\n\t\t\t\t\t\t\t\t{ ...commonProps }\n\t\t\t\t\t\t\t\tfilter={ {\n\t\t\t\t\t\t\t\t\t...commonProps.filter,\n\t\t\t\t\t\t\t\t\telements,\n\t\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t) : (\n\t\t\t\t\t\t\t<InputWidget { ...commonProps } fields={ fields } />\n\t\t\t\t\t\t) }\n\t\t\t\t\t</VStack>\n\t\t\t\t);\n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;AAAA;AAAA,QACD;AAAA,QACE,oBACD;AAAA,UAAC;AAAA;AAAA,YACA,MAAO,gBAAY,gBAAI,OAAQ,QAAI,gBAAI,QAAS;AAAA,YAChD,WAAU;AAAA,YAEV;AAAA,cAAC;AAAA;AAAA,gBACA,eAAY,YAAAA;AAAA,kBACX;AAAA,kBACA,EAAE,cAAc,UAAU;AAAA,gBAC3B;AAAA,gBACA,SAAU,MAAM;AACf,+BAAc;AAAA,oBACb,GAAG;AAAA,oBACH,MAAM;AAAA,oBACN,SAAS,KAAK,SAAS;AAAA,sBACtB,CAAE,YACD,QAAQ,UAAU,OAAO;AAAA,oBAC3B;AAAA,kBACD,CAAE;AAGF,sBAAK,CAAE,WAAY;AAClB,iCAAa,SAAS,MAAM;AAAA,kBAC7B,OAAO;AAEN,8BAAU,SAAS,MAAM;AAAA,kBAC1B;AAAA,gBACD;AAAA,gBAEA,sDAAC,0BAAK,MAAO,yBAAa;AAAA;AAAA,YAC3B;AAAA;AAAA,QACD;AAAA,SAEF;AAAA,MAED,eAAgB,MAAM;AACrB,eACC,6CAAC,kBAAAC,sBAAA,EAAO,SAAU,GAAI,SAAQ,cAC7B;AAAA,sDAAC,oBAAmB,GAAG,aAAc;AAAA,UACnC,YAAY,OAAO,cACpB;AAAA,YAAC,qBAAAC;AAAA,YAAA;AAAA,cACE,GAAG;AAAA,cACL,QAAS;AAAA,gBACR,GAAG,YAAY;AAAA,gBACf;AAAA,cACD;AAAA;AAAA,UACD,IAEA,4CAAC,oBAAAC,SAAA,EAAc,GAAG,aAAc,QAAkB;AAAA,WAEpD;AAAA,MAEF;AAAA;AAAA,EACD;AAEF;",
|
|
6
6
|
"names": ["HStack", "useElements", "parseDateTime", "clsx", "VStack", "SearchWidget", "InputWidget"]
|
|
7
7
|
}
|
|
@@ -55,10 +55,7 @@ function InputWidget({
|
|
|
55
55
|
return {
|
|
56
56
|
...currentField,
|
|
57
57
|
// Deactivate validation for filters.
|
|
58
|
-
isValid: {
|
|
59
|
-
required: false,
|
|
60
|
-
custom: () => null
|
|
61
|
-
},
|
|
58
|
+
isValid: {},
|
|
62
59
|
// Configure getValue/setValue as if Item was a plain object.
|
|
63
60
|
getValue: ({ item }) => item[currentField.id],
|
|
64
61
|
setValue: ({ value }) => ({
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/dataviews-filters/input-widget.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport fastDeepEqual from 'fast-deep-equal/es6';\n\n/**\n * WordPress dependencies\n */\nimport { useEvent } from '@wordpress/compose';\nimport { useMemo } from '@wordpress/element';\nimport { Flex } from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport type {
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAA0B;AAK1B,qBAAyB;AACzB,qBAAwB;AACxB,wBAAqB;
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport fastDeepEqual from 'fast-deep-equal/es6';\n\n/**\n * WordPress dependencies\n */\nimport { useEvent } from '@wordpress/compose';\nimport { useMemo } from '@wordpress/element';\nimport { Flex } from '@wordpress/components';\n\n/**\n * Internal dependencies\n */\nimport type {\n\tView,\n\tNormalizedFilter,\n\tNormalizedField,\n\tNormalizedRules,\n} from '../../types';\nimport { getCurrentValue } from './utils';\n\ninterface UserInputWidgetProps {\n\tview: View;\n\tfilter: NormalizedFilter;\n\tonChangeView: ( view: View ) => void;\n\tfields: NormalizedField< any >[];\n}\n\nexport default function InputWidget( {\n\tfilter,\n\tview,\n\tonChangeView,\n\tfields,\n}: UserInputWidgetProps ) {\n\tconst currentFilter = view.filters?.find(\n\t\t( f ) => f.field === filter.field\n\t);\n\tconst currentValue = getCurrentValue( filter, currentFilter );\n\n\t/*\n\t * We are reusing the field.Edit component for filters. By doing so,\n\t * we get for free a filter control specific to the field type\n\t * and other aspects of the field API (Edit control configuration, etc.).\n\t *\n\t * This approach comes with an issue: the field.Edit controls work with getValue\n\t * and setValue methods, which take an item (Item) as parameter. But, at this point,\n\t * we don't have an item and we don't know how to create one, either.\n\t *\n\t * So, what we do is to prepare the data and the relevant field configuration\n\t * as if Item was a plain object whose keys are the field ids:\n\t *\n\t * {\n\t * [ fieldOne.id ]: value,\n\t * [ fieldTwo.id ]: value,\n\t * }\n\t *\n\t */\n\tconst field = useMemo( () => {\n\t\tconst currentField = fields.find( ( f ) => f.id === filter.field );\n\t\tif ( currentField ) {\n\t\t\treturn {\n\t\t\t\t...currentField,\n\t\t\t\t// Deactivate validation for filters.\n\t\t\t\tisValid: {} satisfies NormalizedRules< any >,\n\t\t\t\t// Configure getValue/setValue as if Item was a plain object.\n\t\t\t\tgetValue: ( { item }: { item: any } ) =>\n\t\t\t\t\titem[ currentField.id ],\n\t\t\t\tsetValue: ( { value }: { value: any } ) => ( {\n\t\t\t\t\t[ currentField.id ]: value,\n\t\t\t\t} ),\n\t\t\t};\n\t\t}\n\t\treturn currentField;\n\t}, [ fields, filter.field ] );\n\n\tconst data = useMemo( () => {\n\t\treturn ( view.filters ?? [] ).reduce(\n\t\t\t( acc, activeFilter ) => {\n\t\t\t\t// We can now assume the field is stored as a Item prop.\n\t\t\t\tacc[ activeFilter.field ] = activeFilter.value;\n\t\t\t\treturn acc;\n\t\t\t},\n\t\t\t{} as Record< string, any >\n\t\t);\n\t}, [ view.filters ] );\n\n\tconst handleChange = useEvent( ( updatedData: Record< string, any > ) => {\n\t\tif ( ! field || ! currentFilter ) {\n\t\t\treturn;\n\t\t}\n\t\tconst nextValue = field.getValue( { item: updatedData } );\n\t\tif ( fastDeepEqual( nextValue, currentValue ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\tonChangeView( {\n\t\t\t...view,\n\t\t\tfilters: ( view.filters ?? [] ).map( ( _filter ) =>\n\t\t\t\t_filter.field === filter.field\n\t\t\t\t\t? {\n\t\t\t\t\t\t\t..._filter,\n\t\t\t\t\t\t\toperator:\n\t\t\t\t\t\t\t\tcurrentFilter.operator || filter.operators[ 0 ],\n\t\t\t\t\t\t\t// Consider empty strings as undefined:\n\t\t\t\t\t\t\t//\n\t\t\t\t\t\t\t// - undefined as value means the filter is unset: the filter widget displays no value and the search returns all records\n\t\t\t\t\t\t\t// - empty string as value means \"search empty string\": returns only the records that have an empty string as value\n\t\t\t\t\t\t\t//\n\t\t\t\t\t\t\t// In practice, this means the filter will not be able to find an empty string as the value.\n\t\t\t\t\t\t\tvalue: nextValue === '' ? undefined : nextValue,\n\t\t\t\t\t }\n\t\t\t\t\t: _filter\n\t\t\t),\n\t\t} );\n\t} );\n\n\tif ( ! field || ! field.Edit || ! currentFilter ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<Flex\n\t\t\tclassName=\"dataviews-filters__user-input-widget\"\n\t\t\tgap={ 2.5 }\n\t\t\tdirection=\"column\"\n\t\t>\n\t\t\t<field.Edit\n\t\t\t\thideLabelFromVision\n\t\t\t\tdata={ data }\n\t\t\t\tfield={ field }\n\t\t\t\toperator={ currentFilter.operator }\n\t\t\t\tonChange={ handleChange }\n\t\t\t/>\n\t\t</Flex>\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAA0B;AAK1B,qBAAyB;AACzB,qBAAwB;AACxB,wBAAqB;AAWrB,mBAAgC;AA2G7B;AAlGY,SAAR,YAA8B;AAAA,EACpC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAA0B;AACzB,QAAM,gBAAgB,KAAK,SAAS;AAAA,IACnC,CAAE,MAAO,EAAE,UAAU,OAAO;AAAA,EAC7B;AACA,QAAM,mBAAe,8BAAiB,QAAQ,aAAc;AAoB5D,QAAM,YAAQ,wBAAS,MAAM;AAC5B,UAAM,eAAe,OAAO,KAAM,CAAE,MAAO,EAAE,OAAO,OAAO,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MACN,WAAU;AAAA,MAEV;AAAA,QAAC,MAAM;AAAA,QAAN;AAAA,UACA,qBAAmB;AAAA,UACnB;AAAA,UACA;AAAA,UACA,UAAW,cAAc;AAAA,UACzB,UAAW;AAAA;AAAA,MACZ;AAAA;AAAA,EACD;AAEF;",
|
|
6
6
|
"names": ["fastDeepEqual"]
|
|
7
7
|
}
|
|
@@ -24,7 +24,7 @@ __export(use_filters_exports, {
|
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(use_filters_exports);
|
|
26
26
|
var import_element = require("@wordpress/element");
|
|
27
|
-
var
|
|
27
|
+
var import_operators = require("../../utils/operators");
|
|
28
28
|
function useFilters(fields, view) {
|
|
29
29
|
return (0, import_element.useMemo)(() => {
|
|
30
30
|
const filters = [];
|
|
@@ -44,11 +44,11 @@ function useFilters(fields, view) {
|
|
|
44
44
|
getElements: field.getElements,
|
|
45
45
|
hasElements: field.hasElements,
|
|
46
46
|
singleSelection: operators.some(
|
|
47
|
-
(op) =>
|
|
47
|
+
(op) => (0, import_operators.isSingleSelectionOperator)(op)
|
|
48
48
|
),
|
|
49
49
|
operators,
|
|
50
50
|
isVisible: isLocked || isPrimary || !!view.filters?.some(
|
|
51
|
-
(f) => f.field === field.id &&
|
|
51
|
+
(f) => f.field === field.id && (0, import_operators.isRegisteredOperator)(f.operator)
|
|
52
52
|
),
|
|
53
53
|
isPrimary,
|
|
54
54
|
isLocked
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/dataviews-filters/use-filters.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useMemo } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport {
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAAwB;AAKxB,
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useMemo } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport {\n\tisRegisteredOperator,\n\tisSingleSelectionOperator,\n} from '../../utils/operators';\nimport type { NormalizedFilter, NormalizedField, View } from '../../types';\n\nfunction useFilters( fields: NormalizedField< any >[], view: View ) {\n\treturn useMemo( () => {\n\t\tconst filters: NormalizedFilter[] = [];\n\t\tfields.forEach( ( field ) => {\n\t\t\tif (\n\t\t\t\tfield.filterBy === false ||\n\t\t\t\t( ! field.hasElements && ! field.Edit )\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst operators = field.filterBy.operators;\n\t\t\tconst isPrimary = !! field.filterBy?.isPrimary;\n\t\t\tconst isLocked =\n\t\t\t\tview.filters?.some(\n\t\t\t\t\t( f ) => f.field === field.id && !! f.isLocked\n\t\t\t\t) ?? false;\n\t\t\tfilters.push( {\n\t\t\t\tfield: field.id,\n\t\t\t\tname: field.label,\n\t\t\t\telements: field.elements,\n\t\t\t\tgetElements: field.getElements,\n\t\t\t\thasElements: field.hasElements,\n\t\t\t\tsingleSelection: operators.some( ( op ) =>\n\t\t\t\t\tisSingleSelectionOperator( op )\n\t\t\t\t),\n\t\t\t\toperators,\n\t\t\t\tisVisible:\n\t\t\t\t\tisLocked ||\n\t\t\t\t\tisPrimary ||\n\t\t\t\t\t!! view.filters?.some(\n\t\t\t\t\t\t( f ) =>\n\t\t\t\t\t\t\tf.field === field.id &&\n\t\t\t\t\t\t\tisRegisteredOperator( f.operator )\n\t\t\t\t\t),\n\t\t\t\tisPrimary,\n\t\t\t\tisLocked,\n\t\t\t} );\n\t\t} );\n\n\t\t// Sort filters by:\n\t\t// - locked filters go first\n\t\t// - primary filters go next\n\t\t// - then, sort by name\n\t\tfilters.sort( ( a, b ) => {\n\t\t\tif ( a.isLocked && ! b.isLocked ) {\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\tif ( ! a.isLocked && b.isLocked ) {\n\t\t\t\treturn 1;\n\t\t\t}\n\t\t\tif ( a.isPrimary && ! b.isPrimary ) {\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t\tif ( ! a.isPrimary && b.isPrimary ) {\n\t\t\t\treturn 1;\n\t\t\t}\n\t\t\treturn a.name.localeCompare( b.name );\n\t\t} );\n\t\treturn filters;\n\t}, [ fields, view ] );\n}\n\nexport default useFilters;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAAwB;AAKxB,uBAGO;AAGP,SAAS,WAAY,QAAkC,MAAa;AACnE,aAAO,wBAAS,MAAM;AACrB,UAAM,UAA8B,CAAC;AACrC,WAAO,QAAS,CAAE,UAAW;AAC5B,UACC,MAAM,aAAa,SACjB,CAAE,MAAM,eAAe,CAAE,MAAM,MAChC;AACD;AAAA,MACD;AAEA,YAAM,YAAY,MAAM,SAAS;AACjC,YAAM,YAAY,CAAC,CAAE,MAAM,UAAU;AACrC,YAAM,WACL,KAAK,SAAS;AAAA,QACb,CAAE,MAAO,EAAE,UAAU,MAAM,MAAM,CAAC,CAAE,EAAE;AAAA,MACvC,KAAK;AACN,cAAQ,KAAM;AAAA,QACb,OAAO,MAAM;AAAA,QACb,MAAM,MAAM;AAAA,QACZ,UAAU,MAAM;AAAA,QAChB,aAAa,MAAM;AAAA,QACnB,aAAa,MAAM;AAAA,QACnB,iBAAiB,UAAU;AAAA,UAAM,CAAE,WAClC,4CAA2B,EAAG;AAAA,QAC/B;AAAA,QACA;AAAA,QACA,WACC,YACA,aACA,CAAC,CAAE,KAAK,SAAS;AAAA,UAChB,CAAE,MACD,EAAE,UAAU,MAAM,UAClB,uCAAsB,EAAE,QAAS;AAAA,QACnC;AAAA,QACD;AAAA,QACA;AAAA,MACD,CAAE;AAAA,IACH,CAAE;AAMF,YAAQ,KAAM,CAAE,GAAG,MAAO;AACzB,UAAK,EAAE,YAAY,CAAE,EAAE,UAAW;AACjC,eAAO;AAAA,MACR;AACA,UAAK,CAAE,EAAE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