@wordpress/dataviews 0.7.0 → 0.9.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 +17 -0
- package/README.md +49 -18
- package/build/constants.js +28 -10
- package/build/constants.js.map +1 -1
- package/build/dataviews.js +3 -7
- package/build/dataviews.js.map +1 -1
- package/build/filter-and-sort-data-view.js +147 -0
- package/build/filter-and-sort-data-view.js.map +1 -0
- package/build/filter-summary.js +33 -12
- package/build/filter-summary.js.map +1 -1
- package/build/filters.js +11 -16
- package/build/filters.js.map +1 -1
- package/build/index.js +3 -9
- package/build/index.js.map +1 -1
- package/build/item-actions.js +20 -39
- package/build/item-actions.js.map +1 -1
- package/build/normalize-fields.js +25 -0
- package/build/normalize-fields.js.map +1 -0
- package/build/pagination.js +2 -2
- package/build/pagination.js.map +1 -1
- package/build/search-widget.js +34 -10
- package/build/search-widget.js.map +1 -1
- package/build/utils.js +25 -67
- package/build/utils.js.map +1 -1
- package/build/view-grid.js +25 -12
- package/build/view-grid.js.map +1 -1
- package/build/view-list.js +122 -58
- package/build/view-list.js.map +1 -1
- package/build/view-table.js +53 -8
- package/build/view-table.js.map +1 -1
- package/build-module/constants.js +27 -9
- package/build-module/constants.js.map +1 -1
- package/build-module/dataviews.js +3 -7
- package/build-module/dataviews.js.map +1 -1
- package/build-module/filter-and-sort-data-view.js +139 -0
- package/build-module/filter-and-sort-data-view.js.map +1 -0
- package/build-module/filter-summary.js +34 -13
- package/build-module/filter-summary.js.map +1 -1
- package/build-module/filters.js +12 -17
- package/build-module/filters.js.map +1 -1
- package/build-module/index.js +1 -1
- package/build-module/index.js.map +1 -1
- package/build-module/item-actions.js +20 -39
- package/build-module/item-actions.js.map +1 -1
- package/build-module/normalize-fields.js +19 -0
- package/build-module/normalize-fields.js.map +1 -0
- package/build-module/pagination.js +2 -2
- package/build-module/pagination.js.map +1 -1
- package/build-module/search-widget.js +35 -11
- package/build-module/search-widget.js.map +1 -1
- package/build-module/utils.js +25 -66
- package/build-module/utils.js.map +1 -1
- package/build-module/view-grid.js +26 -13
- package/build-module/view-grid.js.map +1 -1
- package/build-module/view-list.js +124 -60
- package/build-module/view-list.js.map +1 -1
- package/build-module/view-table.js +55 -10
- package/build-module/view-table.js.map +1 -1
- package/build-style/style-rtl.css +41 -11
- package/build-style/style.css +41 -11
- package/package.json +11 -11
- package/src/constants.js +35 -9
- package/src/dataviews.js +3 -7
- package/src/filter-and-sort-data-view.js +154 -0
- package/src/filter-summary.js +76 -23
- package/src/filters.js +20 -26
- package/src/index.js +1 -1
- package/src/item-actions.js +19 -55
- package/src/normalize-fields.js +17 -0
- package/src/pagination.js +2 -2
- package/src/search-widget.js +63 -21
- package/src/stories/fixtures.js +87 -2
- package/src/stories/index.story.js +5 -74
- package/src/style.scss +53 -14
- package/src/test/filter-and-sort-data-view.js +276 -0
- package/src/utils.js +38 -56
- package/src/view-grid.js +36 -11
- package/src/view-list.js +159 -69
- package/src/view-table.js +71 -9
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,23 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 0.9.0 (2024-04-03)
|
|
6
|
+
|
|
7
|
+
### Enhancement
|
|
8
|
+
|
|
9
|
+
- The `enumeration` type has been removed and we'll introduce new field types soon. The existing filters will still work as before given they checked for field.elements, which is still a condition filters should have.
|
|
10
|
+
|
|
11
|
+
## 0.8.0 (2024-03-21)
|
|
12
|
+
|
|
13
|
+
### Enhancement
|
|
14
|
+
|
|
15
|
+
- Two new operators have been added: `isAll` and `isNotAll`. These are meant to represent `AND` operations. For example, `Category is all: Book, Review, Science Fiction` would represent all items that have all three categories selected.
|
|
16
|
+
- DataViews now supports multi-selection. A new set of filter operators has been introduced: `is`, `isNot`, `isAny`, `isNone`. Single-selection operators are `is` and `isNot`, and multi-selection operators are `isAny` and `isNone`. If no operators are declared for a filter, it will support multi-selection. Additionally, the old filter operators `in` and `notIn` operators have been deprecated and will work as `is` and `isNot` respectively. Please, migrate to the new operators as they'll be removed soon.
|
|
17
|
+
|
|
18
|
+
### Breaking changes
|
|
19
|
+
|
|
20
|
+
- Removed the `getPaginationResults` and `sortByTextFields` utils and replaced them with a unique `filterSortAndPaginate` function.
|
|
21
|
+
|
|
5
22
|
## 0.7.0 (2024-03-06)
|
|
6
23
|
|
|
7
24
|
## 0.6.0 (2024-02-21)
|
package/README.md
CHANGED
|
@@ -59,17 +59,23 @@ The fields describe the visible items for each record in the dataset.
|
|
|
59
59
|
Example:
|
|
60
60
|
|
|
61
61
|
```js
|
|
62
|
+
const STATUSES = [
|
|
63
|
+
{ value: 'draft', label: __( 'Draft' ) },
|
|
64
|
+
{ value: 'future', label: __( 'Scheduled' ) },
|
|
65
|
+
{ value: 'pending', label: __( 'Pending Review' ) },
|
|
66
|
+
{ value: 'private', label: __( 'Private' ) },
|
|
67
|
+
{ value: 'publish', label: __( 'Published' ) },
|
|
68
|
+
{ value: 'trash', label: __( 'Trash' ) },
|
|
69
|
+
];
|
|
62
70
|
const fields = [
|
|
63
71
|
{
|
|
64
72
|
id: 'title',
|
|
65
73
|
header: 'Title',
|
|
66
|
-
getValue: ({ item }) => item.title,
|
|
67
74
|
enableHiding: false,
|
|
68
75
|
},
|
|
69
76
|
{
|
|
70
77
|
id: 'date',
|
|
71
78
|
header: 'Date',
|
|
72
|
-
getValue: ( { item } ) => item.date,
|
|
73
79
|
render: ( { item } ) => {
|
|
74
80
|
return (
|
|
75
81
|
<time>{ getFormattedDate( item.date ) }</time>
|
|
@@ -79,19 +85,32 @@ const fields = [
|
|
|
79
85
|
{
|
|
80
86
|
id: 'author',
|
|
81
87
|
header: __( 'Author' ),
|
|
82
|
-
getValue: ( { item } ) => item.author,
|
|
83
88
|
render: ( { item } ) => {
|
|
84
89
|
return (
|
|
85
90
|
<a href="...">{ item.author }</a>
|
|
86
91
|
);
|
|
87
92
|
},
|
|
88
|
-
type: 'enumeration',
|
|
89
93
|
elements: [
|
|
90
94
|
{ value: 1, label: 'Admin' }
|
|
91
95
|
{ value: 2, label: 'User' }
|
|
92
|
-
]
|
|
96
|
+
],
|
|
97
|
+
filterBy: {
|
|
98
|
+
operators: [ 'is', 'isNot' ]
|
|
99
|
+
},
|
|
93
100
|
enableSorting: false
|
|
94
|
-
}
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
header: __( 'Status' ),
|
|
104
|
+
id: 'status',
|
|
105
|
+
getValue: ( { item } ) =>
|
|
106
|
+
STATUSES.find( ( { value } ) => value === item.status )
|
|
107
|
+
?.label ?? item.status,
|
|
108
|
+
elements: STATUSES,
|
|
109
|
+
filterBy: {
|
|
110
|
+
operators: [ 'isAny' ],
|
|
111
|
+
},
|
|
112
|
+
enableSorting: false,
|
|
113
|
+
},
|
|
95
114
|
]
|
|
96
115
|
```
|
|
97
116
|
|
|
@@ -99,10 +118,10 @@ Each field is an object with the following properties:
|
|
|
99
118
|
|
|
100
119
|
- `id`: identifier for the field. Unique.
|
|
101
120
|
- `header`: the field's name to be shown in the UI.
|
|
102
|
-
- `getValue`: function that returns the value of the field
|
|
121
|
+
- `getValue`: function that returns the value of the field, defaults to `field[id]`.
|
|
103
122
|
- `render`: function that renders the field. Optional, `getValue` will be used if `render` is not defined.
|
|
104
123
|
- `elements`: the set of valid values for the field's value.
|
|
105
|
-
- `type`: the type of the field.
|
|
124
|
+
- `type`: the type of the field. See "Field types".
|
|
106
125
|
- `enableSorting`: whether the data can be sorted by the given field. True by default.
|
|
107
126
|
- `enableHiding`: whether the field can be hidden. True by default.
|
|
108
127
|
- `filterBy`: configuration for the filters.
|
|
@@ -120,8 +139,8 @@ const view = {
|
|
|
120
139
|
type: 'table',
|
|
121
140
|
search: '',
|
|
122
141
|
filters: [
|
|
123
|
-
{ field: 'author', operator: '
|
|
124
|
-
{ field: 'status', operator: '
|
|
142
|
+
{ field: 'author', operator: 'is', value: 2 },
|
|
143
|
+
{ field: 'status', operator: 'isAny', value: [ 'publish', 'draft'] }
|
|
125
144
|
],
|
|
126
145
|
page: 1,
|
|
127
146
|
perPage: 5,
|
|
@@ -140,7 +159,7 @@ Properties:
|
|
|
140
159
|
- `search`: the text search applied to the dataset.
|
|
141
160
|
- `filters`: the filters applied to the dataset. Each item describes:
|
|
142
161
|
- `field`: which field this filter is bound to.
|
|
143
|
-
- `operator`: which type of filter it is.
|
|
162
|
+
- `operator`: which type of filter it is. See "Operator types".
|
|
144
163
|
- `value`: the actual value selected by the user.
|
|
145
164
|
- `perPage`: number of records to show per page.
|
|
146
165
|
- `page`: the page that is visible.
|
|
@@ -172,8 +191,8 @@ function MyCustomPageTable() {
|
|
|
172
191
|
},
|
|
173
192
|
search: '',
|
|
174
193
|
filters: [
|
|
175
|
-
{ field: 'author', operator: '
|
|
176
|
-
{ field: 'status', operator: '
|
|
194
|
+
{ field: 'author', operator: 'is', value: 2 },
|
|
195
|
+
{ field: 'status', operator: 'isAny', value: [ 'publish', 'draft' ] }
|
|
177
196
|
],
|
|
178
197
|
hiddenFields: [ 'date', 'featured-image' ],
|
|
179
198
|
layout: {},
|
|
@@ -182,10 +201,10 @@ function MyCustomPageTable() {
|
|
|
182
201
|
const queryArgs = useMemo( () => {
|
|
183
202
|
const filters = {};
|
|
184
203
|
view.filters.forEach( ( filter ) => {
|
|
185
|
-
if ( filter.field === 'status' && filter.operator === '
|
|
204
|
+
if ( filter.field === 'status' && filter.operator === 'isAny' ) {
|
|
186
205
|
filters.status = filter.value;
|
|
187
206
|
}
|
|
188
|
-
if ( filter.field === 'author' && filter.operator === '
|
|
207
|
+
if ( filter.field === 'author' && filter.operator === 'is' ) {
|
|
189
208
|
filters.author = filter.value;
|
|
190
209
|
}
|
|
191
210
|
} );
|
|
@@ -278,12 +297,24 @@ Callback that signals the user triggered the details for one of more items, and
|
|
|
278
297
|
|
|
279
298
|
### Fields
|
|
280
299
|
|
|
281
|
-
|
|
300
|
+
> The `enumeration` type was removed as it was deemed redundant with the field.elements metadata. New types will be introduced soon.
|
|
282
301
|
|
|
283
302
|
### Operators
|
|
284
303
|
|
|
285
|
-
|
|
286
|
-
|
|
304
|
+
Allowed operators:
|
|
305
|
+
|
|
306
|
+
| Operator | Selection | Description | Example |
|
|
307
|
+
| --- | --- | --- | --- |
|
|
308
|
+
| `is` | Single item | `EQUAL TO`. The item's field is equal to a single value. | Author is Admin |
|
|
309
|
+
| `isNot` | Single item | `NOT EQUAL TO`. The item's field is not equal to a single value. | Author is not Admin |
|
|
310
|
+
| `isAny` | Multiple items | `OR`. The item's field is present in a list of values. | Author is any: Admin, Editor |
|
|
311
|
+
| `isNone` | Multiple items | `NOT OR`. The item's field is not present in a list of values. | Author is none: Admin, Editor |
|
|
312
|
+
| `isAll` | Multiple items | `AND`. The item's field has all of the values in the list. | Category is all: Book, Review, Science Fiction |
|
|
313
|
+
| `isNotAll` | Multiple items | `NOT AND`. The item's field doesn't have all of the values in the list. | Category is not all: Book, Review, Science Fiction |
|
|
314
|
+
|
|
315
|
+
`is` and `isNot` are single-selection operators, while `isAny`, `isNone`, `isAll`, and `isNotALl` are multi-selection. By default, a filter with no operators declared will support the `isAny` and `isNone` multi-selection operators. A filter cannot mix single-selection & multi-selection operators; if a single-selection operator is present in the list of valid operators, the multi-selection ones will be discarded and the filter won't allow selecting more than one item.
|
|
316
|
+
|
|
317
|
+
> The legacy operators `in` and `notIn` have been deprecated and will be removed soon. In the meantime, they work as `is` and `isNot` operators, respectively.
|
|
287
318
|
|
|
288
319
|
## Contributing to this package
|
|
289
320
|
|
package/build/constants.js
CHANGED
|
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.VIEW_LAYOUTS = exports.SORTING_DIRECTIONS = exports.
|
|
7
|
+
exports.VIEW_LAYOUTS = exports.SORTING_DIRECTIONS = exports.OPERATOR_IS_NOT_ALL = exports.OPERATOR_IS_NOT = exports.OPERATOR_IS_NONE = exports.OPERATOR_IS_ANY = exports.OPERATOR_IS_ALL = exports.OPERATOR_IS = exports.OPERATORS = exports.LAYOUT_TABLE = exports.LAYOUT_LIST = exports.LAYOUT_GRID = exports.ALL_OPERATORS = void 0;
|
|
8
8
|
var _i18n = require("@wordpress/i18n");
|
|
9
9
|
var _icons = require("@wordpress/icons");
|
|
10
10
|
var _viewTable = _interopRequireDefault(require("./view-table"));
|
|
@@ -18,20 +18,38 @@ var _viewList = _interopRequireDefault(require("./view-list"));
|
|
|
18
18
|
* Internal dependencies
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
|
-
// Field types.
|
|
22
|
-
const ENUMERATION_TYPE = exports.ENUMERATION_TYPE = 'enumeration';
|
|
23
|
-
|
|
24
21
|
// Filter operators.
|
|
25
|
-
const
|
|
26
|
-
const
|
|
22
|
+
const OPERATOR_IS = exports.OPERATOR_IS = 'is';
|
|
23
|
+
const OPERATOR_IS_NOT = exports.OPERATOR_IS_NOT = 'isNot';
|
|
24
|
+
const OPERATOR_IS_ANY = exports.OPERATOR_IS_ANY = 'isAny';
|
|
25
|
+
const OPERATOR_IS_NONE = exports.OPERATOR_IS_NONE = 'isNone';
|
|
26
|
+
const OPERATOR_IS_ALL = exports.OPERATOR_IS_ALL = 'isAll';
|
|
27
|
+
const OPERATOR_IS_NOT_ALL = exports.OPERATOR_IS_NOT_ALL = 'isNotAll';
|
|
28
|
+
const ALL_OPERATORS = exports.ALL_OPERATORS = [OPERATOR_IS, OPERATOR_IS_NOT, OPERATOR_IS_ANY, OPERATOR_IS_NONE, OPERATOR_IS_ALL, OPERATOR_IS_NOT_ALL];
|
|
27
29
|
const OPERATORS = exports.OPERATORS = {
|
|
28
|
-
[
|
|
29
|
-
key: '
|
|
30
|
+
[OPERATOR_IS]: {
|
|
31
|
+
key: 'is-filter',
|
|
30
32
|
label: (0, _i18n.__)('Is')
|
|
31
33
|
},
|
|
32
|
-
[
|
|
33
|
-
key: 'not-
|
|
34
|
+
[OPERATOR_IS_NOT]: {
|
|
35
|
+
key: 'is-not-filter',
|
|
34
36
|
label: (0, _i18n.__)('Is not')
|
|
37
|
+
},
|
|
38
|
+
[OPERATOR_IS_ANY]: {
|
|
39
|
+
key: 'is-any-filter',
|
|
40
|
+
label: (0, _i18n.__)('Is any')
|
|
41
|
+
},
|
|
42
|
+
[OPERATOR_IS_NONE]: {
|
|
43
|
+
key: 'is-none-filter',
|
|
44
|
+
label: (0, _i18n.__)('Is none')
|
|
45
|
+
},
|
|
46
|
+
[OPERATOR_IS_ALL]: {
|
|
47
|
+
key: 'is-all-filter',
|
|
48
|
+
label: (0, _i18n.__)('Is all')
|
|
49
|
+
},
|
|
50
|
+
[OPERATOR_IS_NOT_ALL]: {
|
|
51
|
+
key: 'is-not-all-filter',
|
|
52
|
+
label: (0, _i18n.__)('Is not all')
|
|
35
53
|
}
|
|
36
54
|
};
|
|
37
55
|
|
package/build/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_i18n","require","_icons","_viewTable","_interopRequireDefault","_viewGrid","_viewList","
|
|
1
|
+
{"version":3,"names":["_i18n","require","_icons","_viewTable","_interopRequireDefault","_viewGrid","_viewList","OPERATOR_IS","exports","OPERATOR_IS_NOT","OPERATOR_IS_ANY","OPERATOR_IS_NONE","OPERATOR_IS_ALL","OPERATOR_IS_NOT_ALL","ALL_OPERATORS","OPERATORS","key","label","__","SORTING_DIRECTIONS","asc","desc","LAYOUT_TABLE","LAYOUT_GRID","LAYOUT_LIST","VIEW_LAYOUTS","type","component","ViewTable","icon","blockTable","ViewGrid","category","ViewList","isRTL","formatListBulletsRTL","formatListBullets"],"sources":["@wordpress/dataviews/src/constants.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __, isRTL } from '@wordpress/i18n';\nimport {\n\tblockTable,\n\tcategory,\n\tformatListBullets,\n\tformatListBulletsRTL,\n} from '@wordpress/icons';\n\n/**\n * Internal dependencies\n */\nimport ViewTable from './view-table';\nimport ViewGrid from './view-grid';\nimport ViewList from './view-list';\n\n// Filter operators.\nexport const OPERATOR_IS = 'is';\nexport const OPERATOR_IS_NOT = 'isNot';\nexport const OPERATOR_IS_ANY = 'isAny';\nexport const OPERATOR_IS_NONE = 'isNone';\nexport const OPERATOR_IS_ALL = 'isAll';\nexport const OPERATOR_IS_NOT_ALL = 'isNotAll';\n\nexport const ALL_OPERATORS = [\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];\nexport const OPERATORS = {\n\t[ OPERATOR_IS ]: {\n\t\tkey: 'is-filter',\n\t\tlabel: __( 'Is' ),\n\t},\n\t[ OPERATOR_IS_NOT ]: {\n\t\tkey: 'is-not-filter',\n\t\tlabel: __( 'Is not' ),\n\t},\n\t[ OPERATOR_IS_ANY ]: {\n\t\tkey: 'is-any-filter',\n\t\tlabel: __( 'Is any' ),\n\t},\n\t[ OPERATOR_IS_NONE ]: {\n\t\tkey: 'is-none-filter',\n\t\tlabel: __( 'Is none' ),\n\t},\n\t[ OPERATOR_IS_ALL ]: {\n\t\tkey: 'is-all-filter',\n\t\tlabel: __( 'Is all' ),\n\t},\n\t[ OPERATOR_IS_NOT_ALL ]: {\n\t\tkey: 'is-not-all-filter',\n\t\tlabel: __( 'Is not all' ),\n\t},\n};\n\n// Sorting\nexport const SORTING_DIRECTIONS = {\n\tasc: { label: __( 'Sort ascending' ) },\n\tdesc: { label: __( 'Sort descending' ) },\n};\n\n// View layouts.\nexport const LAYOUT_TABLE = 'table';\nexport const LAYOUT_GRID = 'grid';\nexport const LAYOUT_LIST = 'list';\n\nexport const VIEW_LAYOUTS = [\n\t{\n\t\ttype: LAYOUT_TABLE,\n\t\tlabel: __( 'Table' ),\n\t\tcomponent: ViewTable,\n\t\ticon: blockTable,\n\t},\n\t{\n\t\ttype: LAYOUT_GRID,\n\t\tlabel: __( 'Grid' ),\n\t\tcomponent: ViewGrid,\n\t\ticon: category,\n\t},\n\t{\n\t\ttype: LAYOUT_LIST,\n\t\tlabel: __( 'List' ),\n\t\tcomponent: ViewList,\n\t\ticon: isRTL() ? formatListBulletsRTL : formatListBullets,\n\t},\n];\n"],"mappings":";;;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AAUA,IAAAE,UAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,IAAAI,SAAA,GAAAD,sBAAA,CAAAH,OAAA;AACA,IAAAK,SAAA,GAAAF,sBAAA,CAAAH,OAAA;AAhBA;AACA;AACA;;AASA;AACA;AACA;;AAKA;AACO,MAAMM,WAAW,GAAAC,OAAA,CAAAD,WAAA,GAAG,IAAI;AACxB,MAAME,eAAe,GAAAD,OAAA,CAAAC,eAAA,GAAG,OAAO;AAC/B,MAAMC,eAAe,GAAAF,OAAA,CAAAE,eAAA,GAAG,OAAO;AAC/B,MAAMC,gBAAgB,GAAAH,OAAA,CAAAG,gBAAA,GAAG,QAAQ;AACjC,MAAMC,eAAe,GAAAJ,OAAA,CAAAI,eAAA,GAAG,OAAO;AAC/B,MAAMC,mBAAmB,GAAAL,OAAA,CAAAK,mBAAA,GAAG,UAAU;AAEtC,MAAMC,aAAa,GAAAN,OAAA,CAAAM,aAAA,GAAG,CAC5BP,WAAW,EACXE,eAAe,EACfC,eAAe,EACfC,gBAAgB,EAChBC,eAAe,EACfC,mBAAmB,CACnB;AACM,MAAME,SAAS,GAAAP,OAAA,CAAAO,SAAA,GAAG;EACxB,CAAER,WAAW,GAAI;IAChBS,GAAG,EAAE,WAAW;IAChBC,KAAK,EAAE,IAAAC,QAAE,EAAE,IAAK;EACjB,CAAC;EACD,CAAET,eAAe,GAAI;IACpBO,GAAG,EAAE,eAAe;IACpBC,KAAK,EAAE,IAAAC,QAAE,EAAE,QAAS;EACrB,CAAC;EACD,CAAER,eAAe,GAAI;IACpB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CAAC;EACnBS,SAAS,EAAEM,iBAAQ;EACnBJ,IAAI,EAAE,IAAAK,WAAK,EAAC,CAAC,GAAGC,2BAAoB,GAAGC;AACxC,CAAC,CACD"}
|
package/build/dataviews.js
CHANGED
|
@@ -14,6 +14,7 @@ var _filters = _interopRequireDefault(require("./filters"));
|
|
|
14
14
|
var _search = _interopRequireDefault(require("./search"));
|
|
15
15
|
var _constants = require("./constants");
|
|
16
16
|
var _bulkActions = _interopRequireDefault(require("./bulk-actions"));
|
|
17
|
+
var _normalizeFields = require("./normalize-fields");
|
|
17
18
|
/**
|
|
18
19
|
* WordPress dependencies
|
|
19
20
|
*/
|
|
@@ -39,7 +40,7 @@ function DataViews({
|
|
|
39
40
|
fields,
|
|
40
41
|
search = true,
|
|
41
42
|
searchLabel = undefined,
|
|
42
|
-
actions,
|
|
43
|
+
actions = [],
|
|
43
44
|
data,
|
|
44
45
|
getItemId = defaultGetItemId,
|
|
45
46
|
isLoading = false,
|
|
@@ -63,12 +64,7 @@ function DataViews({
|
|
|
63
64
|
onSelectionChange(items);
|
|
64
65
|
}, [setSelection, getItemId, onSelectionChange]);
|
|
65
66
|
const ViewComponent = _constants.VIEW_LAYOUTS.find(v => v.type === view.type).component;
|
|
66
|
-
const _fields = (0, _element.useMemo)(() =>
|
|
67
|
-
return fields.map(field => ({
|
|
68
|
-
...field,
|
|
69
|
-
render: field.render || field.getValue
|
|
70
|
-
}));
|
|
71
|
-
}, [fields]);
|
|
67
|
+
const _fields = (0, _element.useMemo)(() => (0, _normalizeFields.normalizeFields)(fields), [fields]);
|
|
72
68
|
const hasPossibleBulkAction = useSomeItemHasAPossibleBulkAction(actions, data);
|
|
73
69
|
return (0, _react.createElement)("div", {
|
|
74
70
|
className: "dataviews-wrapper"
|
package/build/dataviews.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_components","require","_element","_pagination","_interopRequireDefault","_viewActions","_filters","_search","_constants","_bulkActions","defaultGetItemId","item","id","defaultOnSelectionChange","useSomeItemHasAPossibleBulkAction","actions","data","useMemo","some","action","supportsBulk","isEligible","DataViews","view","onChangeView","fields","search","searchLabel","undefined","getItemId","isLoading","paginationInfo","supportedLayouts","onSelectionChange","onDetailsChange","deferredRendering","selection","setSelection","useState","openedFilter","setOpenedFilter","useEffect","length","newSelection","filter","includes","onSetSelection","useCallback","items","map","ViewComponent","VIEW_LAYOUTS","find","v","type","component","_fields","
|
|
1
|
+
{"version":3,"names":["_components","require","_element","_pagination","_interopRequireDefault","_viewActions","_filters","_search","_constants","_bulkActions","_normalizeFields","defaultGetItemId","item","id","defaultOnSelectionChange","useSomeItemHasAPossibleBulkAction","actions","data","useMemo","some","action","supportsBulk","isEligible","DataViews","view","onChangeView","fields","search","searchLabel","undefined","getItemId","isLoading","paginationInfo","supportedLayouts","onSelectionChange","onDetailsChange","deferredRendering","selection","setSelection","useState","openedFilter","setOpenedFilter","useEffect","length","newSelection","filter","includes","onSetSelection","useCallback","items","map","ViewComponent","VIEW_LAYOUTS","find","v","type","component","_fields","normalizeFields","hasPossibleBulkAction","_react","createElement","className","__experimentalHStack","alignment","justify","wrap","default","label","LAYOUT_TABLE","LAYOUT_GRID"],"sources":["@wordpress/dataviews/src/dataviews.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __experimentalHStack as HStack } from '@wordpress/components';\nimport { useMemo, useState, useCallback, useEffect } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport Pagination from './pagination';\nimport ViewActions from './view-actions';\nimport Filters from './filters';\nimport Search from './search';\nimport { VIEW_LAYOUTS, LAYOUT_TABLE, LAYOUT_GRID } from './constants';\nimport BulkActions from './bulk-actions';\nimport { normalizeFields } from './normalize-fields';\n\nconst defaultGetItemId = ( item ) => item.id;\nconst defaultOnSelectionChange = () => {};\n\nfunction useSomeItemHasAPossibleBulkAction( actions, data ) {\n\treturn useMemo( () => {\n\t\treturn data.some( ( item ) => {\n\t\t\treturn actions.some( ( action ) => {\n\t\t\t\treturn action.supportsBulk && action.isEligible( item );\n\t\t\t} );\n\t\t} );\n\t}, [ actions, data ] );\n}\n\nexport default function DataViews( {\n\tview,\n\tonChangeView,\n\tfields,\n\tsearch = true,\n\tsearchLabel = undefined,\n\tactions = [],\n\tdata,\n\tgetItemId = defaultGetItemId,\n\tisLoading = false,\n\tpaginationInfo,\n\tsupportedLayouts,\n\tonSelectionChange = defaultOnSelectionChange,\n\tonDetailsChange = null,\n\tdeferredRendering = false,\n} ) {\n\tconst [ selection, setSelection ] = useState( [] );\n\tconst [ openedFilter, setOpenedFilter ] = useState( null );\n\n\tuseEffect( () => {\n\t\tif (\n\t\t\tselection.length > 0 &&\n\t\t\tselection.some(\n\t\t\t\t( id ) => ! data.some( ( item ) => getItemId( item ) === id )\n\t\t\t)\n\t\t) {\n\t\t\tconst newSelection = selection.filter( ( id ) =>\n\t\t\t\tdata.some( ( item ) => getItemId( item ) === id )\n\t\t\t);\n\t\t\tsetSelection( newSelection );\n\t\t\tonSelectionChange(\n\t\t\t\tdata.filter( ( item ) =>\n\t\t\t\t\tnewSelection.includes( getItemId( item ) )\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\t}, [ selection, data, getItemId, onSelectionChange ] );\n\n\tconst onSetSelection = useCallback(\n\t\t( items ) => {\n\t\t\tsetSelection( items.map( ( item ) => getItemId( item ) ) );\n\t\t\tonSelectionChange( items );\n\t\t},\n\t\t[ setSelection, getItemId, onSelectionChange ]\n\t);\n\n\tconst ViewComponent = VIEW_LAYOUTS.find(\n\t\t( v ) => v.type === view.type\n\t).component;\n\tconst _fields = useMemo( () => normalizeFields( fields ), [ fields ] );\n\n\tconst hasPossibleBulkAction = useSomeItemHasAPossibleBulkAction(\n\t\tactions,\n\t\tdata\n\t);\n\treturn (\n\t\t<div className=\"dataviews-wrapper\">\n\t\t\t<HStack\n\t\t\t\talignment=\"top\"\n\t\t\t\tjustify=\"start\"\n\t\t\t\tclassName=\"dataviews-filters__view-actions\"\n\t\t\t>\n\t\t\t\t<HStack\n\t\t\t\t\tjustify=\"start\"\n\t\t\t\t\tclassName=\"dataviews-filters__container\"\n\t\t\t\t\twrap\n\t\t\t\t>\n\t\t\t\t\t{ search && (\n\t\t\t\t\t\t<Search\n\t\t\t\t\t\t\tlabel={ searchLabel }\n\t\t\t\t\t\t\tview={ view }\n\t\t\t\t\t\t\tonChangeView={ onChangeView }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t\t<Filters\n\t\t\t\t\t\tfields={ _fields }\n\t\t\t\t\t\tview={ view }\n\t\t\t\t\t\tonChangeView={ onChangeView }\n\t\t\t\t\t\topenedFilter={ openedFilter }\n\t\t\t\t\t\tsetOpenedFilter={ setOpenedFilter }\n\t\t\t\t\t/>\n\t\t\t\t</HStack>\n\t\t\t\t{ [ LAYOUT_TABLE, LAYOUT_GRID ].includes( view.type ) &&\n\t\t\t\t\thasPossibleBulkAction && (\n\t\t\t\t\t\t<BulkActions\n\t\t\t\t\t\t\tactions={ actions }\n\t\t\t\t\t\t\tdata={ data }\n\t\t\t\t\t\t\tonSelectionChange={ onSetSelection }\n\t\t\t\t\t\t\tselection={ selection }\n\t\t\t\t\t\t\tgetItemId={ getItemId }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t<ViewActions\n\t\t\t\t\tfields={ _fields }\n\t\t\t\t\tview={ view }\n\t\t\t\t\tonChangeView={ onChangeView }\n\t\t\t\t\tsupportedLayouts={ supportedLayouts }\n\t\t\t\t/>\n\t\t\t</HStack>\n\t\t\t<ViewComponent\n\t\t\t\tfields={ _fields }\n\t\t\t\tview={ view }\n\t\t\t\tonChangeView={ onChangeView }\n\t\t\t\tactions={ actions }\n\t\t\t\tdata={ data }\n\t\t\t\tgetItemId={ getItemId }\n\t\t\t\tisLoading={ isLoading }\n\t\t\t\tonSelectionChange={ onSetSelection }\n\t\t\t\tonDetailsChange={ onDetailsChange }\n\t\t\t\tselection={ selection }\n\t\t\t\tdeferredRendering={ deferredRendering }\n\t\t\t\tsetOpenedFilter={ setOpenedFilter }\n\t\t\t/>\n\t\t\t<Pagination\n\t\t\t\tview={ view }\n\t\t\t\tonChangeView={ onChangeView }\n\t\t\t\tpaginationInfo={ paginationInfo }\n\t\t\t/>\n\t\t</div>\n\t);\n}\n"],"mappings":";;;;;;;;AAGA,IAAAA,WAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AAKA,IAAAE,WAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,IAAAI,YAAA,GAAAD,sBAAA,CAAAH,OAAA;AACA,IAAAK,QAAA,GAAAF,sBAAA,CAAAH,OAAA;AACA,IAAAM,OAAA,GAAAH,sBAAA,CAAAH,OAAA;AACA,IAAAO,UAAA,GAAAP,OAAA;AACA,IAAAQ,YAAA,GAAAL,sBAAA,CAAAH,OAAA;AACA,IAAAS,gBAAA,GAAAT,OAAA;AAfA;AACA;AACA;;AAIA;AACA;AACA;;AASA,MAAMU,gBAAgB,GAAKC,IAAI,IAAMA,IAAI,CAACC,EAAE;AAC5C,MAAMC,wBAAwB,GAAGA,CAAA,KAAM,CAAC,CAAC;AAEzC,SAASC,iCAAiCA,CAAEC,OAAO,EAAEC,IAAI,EAAG;EAC3D,OAAO,IAAAC,gBAAO,EAAE,MAAM;IACrB,OAAOD,IAAI,CAACE,IAAI,CAAIP,IAAI,IAAM;MAC7B,OAAOI,OAAO,CAACG,IAAI,CAAIC,MAAM,IAAM;QAClC,OAAOA,MAAM,CAACC,YAAY,IAAID,MAAM,CAACE,UAAU,CAAEV,IAAK,CAAC;MACxD,CAAE,CAAC;IACJ,CAAE,CAAC;EACJ,CAAC,EAAE,CAAEI,OAAO,EAAEC,IAAI,CAAG,CAAC;AACvB;AAEe,SAASM,SAASA,CAAE;EAClCC,IAAI;EACJC,YAAY;EACZC,MAAM;EACNC,MAAM,GAAG,IAAI;EACbC,WAAW,GAAGC,SAAS;EACvBb,OAAO,GAAG,EAAE;EACZC,IAAI;EACJa,SAAS,GAAGn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AAGA,OAAS;IACnBC,IAAI,EAAGA,IAAM;IACbiB,iBAAiB,EAAGa,cAAgB;IACpCV,SAAS,EAAGA,SAAW;IACvBP,SAAS,EAAGA;EAAW,CACvB,CACD,EACF,IAAA8B,MAAA,CAAAC,aAAA,EAACxD,YAAA,CAAA8D,OAAW;IACXzC,MAAM,EAAG+B,OAAS;IAClBjC,IAAI,EAAGA,IAAM;IACbC,YAAY,EAAGA,YAAc;IAC7BQ,gBAAgB,EAAGA;EAAkB,CACrC,CACM,CAAC,EACT,IAAA2B,MAAA,CAAAC,aAAA,EAACV,aAAa;IACbzB,MAAM,EAAG+B,OAAS;IAClBjC,IAAI,EAAGA,IAAM;IACbC,YAAY,EAAGA,YAAc;IAC7BT,OAAO,EAAGA,OAAS;IACnBC,IAAI,EAAGA,IAAM;IACba,SAAS,EAAGA,SAAW;IACvBC,SAAS,EAAGA,SAAW;IACvBG,iBAAiB,EAAGa,cAAgB;IACpCZ,eAAe,EAAGA,eAAiB;IACnCE,SAAS,EAAGA,SAAW;IACvBD,iBAAiB,EAAGA,iBAAmB;IACvCK,eAAe,EAAGA;EAAiB,CACnC,CAAC,EACF,IAAAmB,MAAA,CAAAC,aAAA,EAAC1D,WAAA,CAAAgE,OAAU;IACV3C,IAAI,EAAGA,IAAM;IACbC,YAAY,EAAGA,YAAc;IAC7BO,cAAc,EAAGA;EAAgB,CACjC,CACG,CAAC;AAER"}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.filterSortAndPaginate = filterSortAndPaginate;
|
|
8
|
+
var _removeAccents = _interopRequireDefault(require("remove-accents"));
|
|
9
|
+
var _constants = require("./constants");
|
|
10
|
+
var _normalizeFields = require("./normalize-fields");
|
|
11
|
+
/**
|
|
12
|
+
* External dependencies
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Internal dependencies
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
function normalizeSearchInput(input = '') {
|
|
20
|
+
return (0, _removeAccents.default)(input.trim().toLowerCase());
|
|
21
|
+
}
|
|
22
|
+
const EMPTY_ARRAY = [];
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Applies the filtering, sorting and pagination to the raw data based on the view configuration.
|
|
26
|
+
*
|
|
27
|
+
* @param {any[]} data Raw data.
|
|
28
|
+
* @param {Object} view View config.
|
|
29
|
+
* @param {Object[]} fields Fields config.
|
|
30
|
+
*
|
|
31
|
+
* @return {Object} { data: any[], paginationInfo: { totalItems: number, totalPages: number } }
|
|
32
|
+
*/
|
|
33
|
+
function filterSortAndPaginate(data, view, fields) {
|
|
34
|
+
if (!data) {
|
|
35
|
+
return {
|
|
36
|
+
data: EMPTY_ARRAY,
|
|
37
|
+
paginationInfo: {
|
|
38
|
+
totalItems: 0,
|
|
39
|
+
totalPages: 0
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
const _fields = (0, _normalizeFields.normalizeFields)(fields);
|
|
44
|
+
let filteredData = [...data];
|
|
45
|
+
// Handle global search.
|
|
46
|
+
if (view.search) {
|
|
47
|
+
const normalizedSearch = normalizeSearchInput(view.search);
|
|
48
|
+
filteredData = filteredData.filter(item => {
|
|
49
|
+
return _fields.filter(field => field.enableGlobalSearch).map(field => {
|
|
50
|
+
return normalizeSearchInput(field.getValue({
|
|
51
|
+
item
|
|
52
|
+
}));
|
|
53
|
+
}).some(field => field.includes(normalizedSearch));
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
if (view.filters.length > 0) {
|
|
57
|
+
view.filters.forEach(filter => {
|
|
58
|
+
const field = _fields.find(_field => _field.id === filter.field);
|
|
59
|
+
if (filter.operator === _constants.OPERATOR_IS_ANY && filter?.value?.length > 0) {
|
|
60
|
+
filteredData = filteredData.filter(item => {
|
|
61
|
+
const fieldValue = field.getValue({
|
|
62
|
+
item
|
|
63
|
+
});
|
|
64
|
+
if (Array.isArray(fieldValue)) {
|
|
65
|
+
return filter.value.some(filterValue => fieldValue.includes(filterValue));
|
|
66
|
+
} else if (typeof fieldValue === 'string') {
|
|
67
|
+
return filter.value.includes(fieldValue);
|
|
68
|
+
}
|
|
69
|
+
return false;
|
|
70
|
+
});
|
|
71
|
+
} else if (filter.operator === _constants.OPERATOR_IS_NONE && filter?.value?.length > 0) {
|
|
72
|
+
filteredData = filteredData.filter(item => {
|
|
73
|
+
const fieldValue = field.getValue({
|
|
74
|
+
item
|
|
75
|
+
});
|
|
76
|
+
if (Array.isArray(fieldValue)) {
|
|
77
|
+
return !filter.value.some(filterValue => fieldValue.includes(filterValue));
|
|
78
|
+
} else if (typeof fieldValue === 'string') {
|
|
79
|
+
return !filter.value.includes(fieldValue);
|
|
80
|
+
}
|
|
81
|
+
return false;
|
|
82
|
+
});
|
|
83
|
+
} else if (filter.operator === _constants.OPERATOR_IS_ALL && filter?.value?.length > 0) {
|
|
84
|
+
filteredData = filteredData.filter(item => {
|
|
85
|
+
return filter.value.every(value => {
|
|
86
|
+
return field.getValue({
|
|
87
|
+
item
|
|
88
|
+
}).includes(value);
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
} else if (filter.operator === _constants.OPERATOR_IS_NOT_ALL && filter?.value?.length > 0) {
|
|
92
|
+
filteredData = filteredData.filter(item => {
|
|
93
|
+
return filter.value.every(value => {
|
|
94
|
+
return !field.getValue({
|
|
95
|
+
item
|
|
96
|
+
}).includes(value);
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
} else if (filter.operator === _constants.OPERATOR_IS) {
|
|
100
|
+
filteredData = filteredData.filter(item => {
|
|
101
|
+
return filter.value === field.getValue({
|
|
102
|
+
item
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
} else if (filter.operator === _constants.OPERATOR_IS_NOT) {
|
|
106
|
+
filteredData = filteredData.filter(item => {
|
|
107
|
+
return filter.value !== field.getValue({
|
|
108
|
+
item
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Handle sorting.
|
|
116
|
+
if (view.sort) {
|
|
117
|
+
const fieldId = view.sort.field;
|
|
118
|
+
const fieldToSort = _fields.find(field => {
|
|
119
|
+
return field.id === fieldId;
|
|
120
|
+
});
|
|
121
|
+
filteredData.sort((a, b) => {
|
|
122
|
+
var _fieldToSort$getValue, _fieldToSort$getValue2;
|
|
123
|
+
const valueA = (_fieldToSort$getValue = fieldToSort.getValue({
|
|
124
|
+
item: a
|
|
125
|
+
})) !== null && _fieldToSort$getValue !== void 0 ? _fieldToSort$getValue : '';
|
|
126
|
+
const valueB = (_fieldToSort$getValue2 = fieldToSort.getValue({
|
|
127
|
+
item: b
|
|
128
|
+
})) !== null && _fieldToSort$getValue2 !== void 0 ? _fieldToSort$getValue2 : '';
|
|
129
|
+
return view.sort.direction === 'asc' ? valueA.localeCompare(valueB) : valueB.localeCompare(valueA);
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Handle pagination.
|
|
134
|
+
const hasPagination = view.page && view.perPage;
|
|
135
|
+
const start = hasPagination ? (view.page - 1) * view.perPage : 0;
|
|
136
|
+
const totalItems = filteredData?.length || 0;
|
|
137
|
+
const totalPages = hasPagination ? Math.ceil(totalItems / view.perPage) : 1;
|
|
138
|
+
filteredData = hasPagination ? filteredData?.slice(start, start + view.perPage) : filteredData;
|
|
139
|
+
return {
|
|
140
|
+
data: filteredData,
|
|
141
|
+
paginationInfo: {
|
|
142
|
+
totalItems,
|
|
143
|
+
totalPages
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
//# sourceMappingURL=filter-and-sort-data-view.js.map
|
|
@@ -0,0 +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","_fieldToSort$getValue","_fieldToSort$getValue2","valueA","valueB","direction","localeCompare","hasPagination","page","perPage","start","Math","ceil","slice"],"sources":["@wordpress/dataviews/src/filter-and-sort-data-view.js"],"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';\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 {any[]} data Raw data.\n * @param {Object} view View config.\n * @param {Object[]} fields Fields config.\n *\n * @return {Object} { data: any[], paginationInfo: { totalItems: number, totalPages: number } }\n */\nexport function filterSortAndPaginate( data, view, fields ) {\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.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 (\n\t\t\t\tfilter.operator === OPERATOR_IS_ANY &&\n\t\t\t\tfilter?.value?.length > 0\n\t\t\t) {\n\t\t\t\tfilteredData = filteredData.filter( ( item ) => {\n\t\t\t\t\tconst fieldValue = field.getValue( { item } );\n\t\t\t\t\tif ( Array.isArray( fieldValue ) ) {\n\t\t\t\t\t\treturn filter.value.some( ( filterValue ) =>\n\t\t\t\t\t\t\tfieldValue.includes( filterValue )\n\t\t\t\t\t\t);\n\t\t\t\t\t} else if ( typeof fieldValue === 'string' ) {\n\t\t\t\t\t\treturn filter.value.includes( fieldValue );\n\t\t\t\t\t}\n\t\t\t\t\treturn false;\n\t\t\t\t} );\n\t\t\t} else if (\n\t\t\t\tfilter.operator === OPERATOR_IS_NONE &&\n\t\t\t\tfilter?.value?.length > 0\n\t\t\t) {\n\t\t\t\tfilteredData = filteredData.filter( ( item ) => {\n\t\t\t\t\tconst fieldValue = field.getValue( { item } );\n\t\t\t\t\tif ( Array.isArray( fieldValue ) ) {\n\t\t\t\t\t\treturn ! filter.value.some( ( filterValue ) =>\n\t\t\t\t\t\t\tfieldValue.includes( filterValue )\n\t\t\t\t\t\t);\n\t\t\t\t\t} else if ( typeof fieldValue === 'string' ) {\n\t\t\t\t\t\treturn ! filter.value.includes( fieldValue );\n\t\t\t\t\t}\n\t\t\t\t\treturn false;\n\t\t\t\t} );\n\t\t\t} else if (\n\t\t\t\tfilter.operator === OPERATOR_IS_ALL &&\n\t\t\t\tfilter?.value?.length > 0\n\t\t\t) {\n\t\t\t\tfilteredData = filteredData.filter( ( item ) => {\n\t\t\t\t\treturn filter.value.every( ( value ) => {\n\t\t\t\t\t\treturn field.getValue( { item } ).includes( value );\n\t\t\t\t\t} );\n\t\t\t\t} );\n\t\t\t} else if (\n\t\t\t\tfilter.operator === OPERATOR_IS_NOT_ALL &&\n\t\t\t\tfilter?.value?.length > 0\n\t\t\t) {\n\t\t\t\tfilteredData = filteredData.filter( ( item ) => {\n\t\t\t\t\treturn filter.value.every( ( value ) => {\n\t\t\t\t\t\treturn ! field.getValue( { item } ).includes( value );\n\t\t\t\t\t} );\n\t\t\t\t} );\n\t\t\t} else if ( filter.operator === OPERATOR_IS ) {\n\t\t\t\tfilteredData = filteredData.filter( ( item ) => {\n\t\t\t\t\treturn filter.value === field.getValue( { item } );\n\t\t\t\t} );\n\t\t\t} else if ( filter.operator === OPERATOR_IS_NOT ) {\n\t\t\t\tfilteredData = filteredData.filter( ( item ) => {\n\t\t\t\t\treturn filter.value !== field.getValue( { item } );\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\tfilteredData.sort( ( a, b ) => {\n\t\t\tconst valueA = fieldToSort.getValue( { item: a } ) ?? '';\n\t\t\tconst valueB = fieldToSort.getValue( { item: b } ) ?? '';\n\t\t\treturn view.sort.direction === 'asc'\n\t\t\t\t? valueA.localeCompare( valueB )\n\t\t\t\t: valueB.localeCompare( valueA );\n\t\t} );\n\t}\n\n\t// Handle pagination.\n\tconst hasPagination = view.page && view.perPage;\n\tconst start = hasPagination ? ( view.page - 1 ) * view.perPage : 0;\n\tconst totalItems = filteredData?.length || 0;\n\tconst totalPages = hasPagination\n\t\t? Math.ceil( totalItems / view.perPage )\n\t\t: 1;\n\tfilteredData = hasPagination\n\t\t? filteredData?.slice( start, start + view.perPage )\n\t\t: filteredData;\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;;AAWA,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,WAAW,GAAG,EAAE;;AAEtB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,qBAAqBA,CAAEC,IAAI,EAAEC,IAAI,EAAEC,MAAM,EAAG;EAC3D,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,CAAE,GAAGR,IAAI,CAAE;EAC9B;EACA,IAAKC,IAAI,CAACQ,MAAM,EAAG;IAClB,MAAMC,gBAAgB,GAAGjB,oBAAoB,CAAEQ,IAAI,CAACQ,MAAO,CAAC;IAC5DD,YAAY,GAAGA,YAAY,CAACG,MAAM,CAAIC,IAAI,IAAM;MAC/C,OAAON,OAAO,CACZK,MAAM,CAAIE,KAAK,IAAMA,KAAK,CAACC,kBAAmB,CAAC,CAC/CC,GAAG,CAAIF,KAAK,IAAM;QAClB,OAAOpB,oBAAoB,CAAEoB,KAAK,CAACG,QAAQ,CAAE;UAAE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D,IAAI,CAACkD,OAAO;EAC/C,MAAMC,KAAK,GAAGH,aAAa,GAAG,CAAEhD,IAAI,CAACiD,IAAI,GAAG,CAAC,IAAKjD,IAAI,CAACkD,OAAO,GAAG,CAAC;EAClE,MAAM/C,UAAU,GAAGI,YAAY,EAAEY,MAAM,IAAI,CAAC;EAC5C,MAAMf,UAAU,GAAG4C,aAAa,GAC7BI,IAAI,CAACC,IAAI,CAAElD,UAAU,GAAGH,IAAI,CAACkD,OAAQ,CAAC,GACtC,CAAC;EACJ3C,YAAY,GAAGyC,aAAa,GACzBzC,YAAY,EAAE+C,KAAK,CAAEH,KAAK,EAAEA,KAAK,GAAGnD,IAAI,CAACkD,OAAQ,CAAC,GAClD3C,YAAY;EAEf,OAAO;IACNR,IAAI,EAAEQ,YAAY;IAClBL,cAAc,EAAE;MACfC,UAAU;MACVC;IACD;EACD,CAAC;AACF"}
|
package/build/filter-summary.js
CHANGED
|
@@ -27,28 +27,44 @@ var _constants = require("./constants");
|
|
|
27
27
|
*/
|
|
28
28
|
|
|
29
29
|
const FilterText = ({
|
|
30
|
-
|
|
30
|
+
activeElements,
|
|
31
31
|
filterInView,
|
|
32
32
|
filter
|
|
33
33
|
}) => {
|
|
34
|
-
if (
|
|
34
|
+
if (activeElements === undefined || activeElements.length === 0) {
|
|
35
35
|
return filter.name;
|
|
36
36
|
}
|
|
37
37
|
const filterTextWrappers = {
|
|
38
|
-
|
|
38
|
+
Name: (0, _react.createElement)("span", {
|
|
39
39
|
className: "dataviews-filter-summary__filter-text-name"
|
|
40
40
|
}),
|
|
41
|
-
|
|
41
|
+
Value: (0, _react.createElement)("span", {
|
|
42
42
|
className: "dataviews-filter-summary__filter-text-value"
|
|
43
43
|
})
|
|
44
44
|
};
|
|
45
|
-
if (
|
|
46
|
-
return (0, _element.createInterpolateElement)((0, _i18n.sprintf)( /* translators: 1: Filter name.
|
|
47
|
-
(0, _i18n.__)('<
|
|
45
|
+
if (filterInView?.operator === _constants.OPERATOR_IS_ANY) {
|
|
46
|
+
return (0, _element.createInterpolateElement)((0, _i18n.sprintf)( /* translators: 1: Filter name. 3: Filter value. e.g.: "Author is any: Admin, Editor". */
|
|
47
|
+
(0, _i18n.__)('<Name>%1$s is any: </Name><Value>%2$s</Value>'), filter.name, activeElements.map(element => element.label).join(', ')), filterTextWrappers);
|
|
48
48
|
}
|
|
49
|
-
if (
|
|
50
|
-
return (0, _element.createInterpolateElement)((0, _i18n.sprintf)( /* translators: 1: Filter name.
|
|
51
|
-
(0, _i18n.__)('<
|
|
49
|
+
if (filterInView?.operator === _constants.OPERATOR_IS_NONE) {
|
|
50
|
+
return (0, _element.createInterpolateElement)((0, _i18n.sprintf)( /* translators: 1: Filter name. 3: Filter value. e.g.: "Author is none: Admin, Editor". */
|
|
51
|
+
(0, _i18n.__)('<Name>%1$s is none: </Name><Value>%2$s</Value>'), filter.name, activeElements.map(element => element.label).join(', ')), filterTextWrappers);
|
|
52
|
+
}
|
|
53
|
+
if (filterInView?.operator === _constants.OPERATOR_IS_ALL) {
|
|
54
|
+
return (0, _element.createInterpolateElement)((0, _i18n.sprintf)( /* translators: 1: Filter name. 3: Filter value. e.g.: "Author is all: Admin, Editor". */
|
|
55
|
+
(0, _i18n.__)('<Name>%1$s is all: </Name><Value>%2$s</Value>'), filter.name, activeElements.map(element => element.label).join(', ')), filterTextWrappers);
|
|
56
|
+
}
|
|
57
|
+
if (filterInView?.operator === _constants.OPERATOR_IS_NOT_ALL) {
|
|
58
|
+
return (0, _element.createInterpolateElement)((0, _i18n.sprintf)( /* translators: 1: Filter name. 3: Filter value. e.g.: "Author is not all: Admin, Editor". */
|
|
59
|
+
(0, _i18n.__)('<Name>%1$s is not all: </Name><Value>%2$s</Value>'), filter.name, activeElements.map(element => element.label).join(', ')), filterTextWrappers);
|
|
60
|
+
}
|
|
61
|
+
if (filterInView?.operator === _constants.OPERATOR_IS) {
|
|
62
|
+
return (0, _element.createInterpolateElement)((0, _i18n.sprintf)( /* translators: 1: Filter name. 3: Filter value. e.g.: "Author is: Admin". */
|
|
63
|
+
(0, _i18n.__)('<Name>%1$s is: </Name><Value>%2$s</Value>'), filter.name, activeElements[0].label), filterTextWrappers);
|
|
64
|
+
}
|
|
65
|
+
if (filterInView?.operator === _constants.OPERATOR_IS_NOT) {
|
|
66
|
+
return (0, _element.createInterpolateElement)((0, _i18n.sprintf)( /* translators: 1: Filter name. 3: Filter value. e.g.: "Author is not: Admin". */
|
|
67
|
+
(0, _i18n.__)('<Name>%1$s is not: </Name><Value>%2$s</Value>'), filter.name, activeElements[0].label), filterTextWrappers);
|
|
52
68
|
}
|
|
53
69
|
return (0, _i18n.sprintf)( /* translators: 1: Filter name e.g.: "Unknown status for Author". */
|
|
54
70
|
(0, _i18n.__)('Unknown status for %1$s'), filter.name);
|
|
@@ -110,7 +126,12 @@ function FilterSummary({
|
|
|
110
126
|
onChangeView
|
|
111
127
|
} = commonProps;
|
|
112
128
|
const filterInView = view.filters.find(f => f.field === filter.field);
|
|
113
|
-
const
|
|
129
|
+
const activeElements = filter.elements.filter(element => {
|
|
130
|
+
if (filter.singleSelection) {
|
|
131
|
+
return element.value === filterInView?.value;
|
|
132
|
+
}
|
|
133
|
+
return filterInView?.value?.includes(element.value);
|
|
134
|
+
});
|
|
114
135
|
const isPrimary = filter.isPrimary;
|
|
115
136
|
const hasValues = filterInView?.value !== undefined;
|
|
116
137
|
const canResetOrRemove = !isPrimary || hasValues;
|
|
@@ -151,7 +172,7 @@ function FilterSummary({
|
|
|
151
172
|
"aria-expanded": isOpen,
|
|
152
173
|
ref: toggleRef
|
|
153
174
|
}, (0, _react.createElement)(FilterText, {
|
|
154
|
-
|
|
175
|
+
activeElements: activeElements,
|
|
155
176
|
filterInView: filterInView,
|
|
156
177
|
filter: filter
|
|
157
178
|
}))), canResetOrRemove && (0, _react.createElement)(_components.Tooltip, {
|