@wordpress/dataviews 1.1.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +27 -5
- package/README.md +33 -30
- package/build/add-filter.js +30 -22
- package/build/add-filter.js.map +1 -1
- package/build/bulk-actions-toolbar.js +187 -0
- package/build/bulk-actions-toolbar.js.map +1 -0
- package/build/bulk-actions.js +75 -62
- package/build/bulk-actions.js.map +1 -1
- package/build/constants.js +17 -10
- package/build/constants.js.map +1 -1
- package/build/dataviews.js +64 -50
- package/build/dataviews.js.map +1 -1
- package/build/filter-and-sort-data-view.js +2 -2
- package/build/filter-and-sort-data-view.js.map +1 -1
- package/build/filter-summary.js +106 -96
- package/build/filter-summary.js.map +1 -1
- package/build/filters.js +18 -17
- package/build/filters.js.map +1 -1
- package/build/index.js.map +1 -1
- package/build/item-actions.js +101 -69
- package/build/item-actions.js.map +1 -1
- package/build/layouts.js.map +1 -1
- package/build/lock-unlock.js.map +1 -1
- package/build/normalize-fields.js.map +1 -1
- package/build/pagination.js +66 -57
- package/build/pagination.js.map +1 -1
- package/build/reset-filters.js +9 -4
- package/build/reset-filters.js.map +1 -1
- package/build/search-widget.js +108 -89
- package/build/search-widget.js.map +1 -1
- package/build/search.js +13 -6
- package/build/search.js.map +1 -1
- package/build/single-selection-checkbox.js +6 -2
- package/build/single-selection-checkbox.js.map +1 -1
- package/build/types.js.map +1 -1
- package/build/utils.js +3 -15
- package/build/utils.js.map +1 -1
- package/build/view-actions.js +168 -120
- package/build/view-actions.js.map +1 -1
- package/build/view-grid.js +119 -106
- package/build/view-grid.js.map +1 -1
- package/build/view-list.js +217 -83
- package/build/view-list.js.map +1 -1
- package/build/view-table.js +227 -199
- package/build/view-table.js.map +1 -1
- package/build-module/add-filter.js +30 -22
- package/build-module/add-filter.js.map +1 -1
- package/build-module/bulk-actions-toolbar.js +182 -0
- package/build-module/bulk-actions-toolbar.js.map +1 -0
- package/build-module/bulk-actions.js +77 -62
- package/build-module/bulk-actions.js.map +1 -1
- package/build-module/constants.js +16 -9
- package/build-module/constants.js.map +1 -1
- package/build-module/dataviews.js +65 -50
- package/build-module/dataviews.js.map +1 -1
- package/build-module/filter-and-sort-data-view.js +2 -2
- package/build-module/filter-and-sort-data-view.js.map +1 -1
- package/build-module/filter-summary.js +107 -97
- package/build-module/filter-summary.js.map +1 -1
- package/build-module/filters.js +18 -17
- package/build-module/filters.js.map +1 -1
- package/build-module/index.js.map +1 -1
- package/build-module/item-actions.js +102 -71
- package/build-module/item-actions.js.map +1 -1
- package/build-module/layouts.js.map +1 -1
- package/build-module/lock-unlock.js.map +1 -1
- package/build-module/normalize-fields.js.map +1 -1
- package/build-module/pagination.js +67 -57
- package/build-module/pagination.js.map +1 -1
- package/build-module/reset-filters.js +9 -4
- package/build-module/reset-filters.js.map +1 -1
- package/build-module/search-widget.js +109 -89
- package/build-module/search-widget.js.map +1 -1
- package/build-module/search.js +13 -6
- package/build-module/search.js.map +1 -1
- package/build-module/single-selection-checkbox.js +6 -2
- package/build-module/single-selection-checkbox.js.map +1 -1
- package/build-module/types.js.map +1 -1
- package/build-module/utils.js +2 -13
- package/build-module/utils.js.map +1 -1
- package/build-module/view-actions.js +170 -121
- package/build-module/view-actions.js.map +1 -1
- package/build-module/view-grid.js +121 -106
- package/build-module/view-grid.js.map +1 -1
- package/build-module/view-list.js +219 -85
- package/build-module/view-list.js.map +1 -1
- package/build-module/view-table.js +230 -201
- package/build-module/view-table.js.map +1 -1
- package/build-style/style-rtl.css +168 -44
- package/build-style/style.css +168 -44
- package/build-types/add-filter.d.ts +11 -0
- package/build-types/add-filter.d.ts.map +1 -0
- package/build-types/bulk-actions-toolbar.d.ts +12 -0
- package/build-types/bulk-actions-toolbar.d.ts.map +1 -0
- package/build-types/bulk-actions.d.ts +14 -0
- package/build-types/bulk-actions.d.ts.map +1 -0
- package/build-types/constants.d.ts +19 -32
- package/build-types/constants.d.ts.map +1 -1
- package/build-types/dataviews.d.ts +22 -0
- package/build-types/dataviews.d.ts.map +1 -0
- package/build-types/filter-and-sort-data-view.d.ts +3 -3
- package/build-types/filter-and-sort-data-view.d.ts.map +1 -1
- package/build-types/filter-summary.d.ts +14 -0
- package/build-types/filter-summary.d.ts.map +1 -0
- package/build-types/filters.d.ts +13 -0
- package/build-types/filters.d.ts.map +1 -0
- package/build-types/index.d.ts +4 -0
- package/build-types/index.d.ts.map +1 -0
- package/build-types/item-actions.d.ts +35 -0
- package/build-types/item-actions.d.ts.map +1 -0
- package/build-types/layouts.d.ts +24 -0
- package/build-types/layouts.d.ts.map +1 -0
- package/build-types/lock-unlock.d.ts +2 -0
- package/build-types/lock-unlock.d.ts.map +1 -0
- package/build-types/normalize-fields.d.ts +2 -2
- package/build-types/normalize-fields.d.ts.map +1 -1
- package/build-types/pagination.d.ts +16 -0
- package/build-types/pagination.d.ts.map +1 -0
- package/build-types/reset-filters.d.ts +13 -0
- package/build-types/reset-filters.d.ts.map +1 -0
- package/build-types/search-widget.d.ts +10 -0
- package/build-types/search-widget.d.ts.map +1 -0
- package/build-types/search.d.ts +13 -0
- package/build-types/search.d.ts.map +1 -0
- package/build-types/single-selection-checkbox.d.ts +17 -0
- package/build-types/single-selection-checkbox.d.ts.map +1 -0
- package/build-types/stories/fixtures.d.ts +114 -0
- package/build-types/stories/fixtures.d.ts.map +1 -0
- package/build-types/stories/index.story.d.ts +15 -0
- package/build-types/stories/index.story.d.ts.map +1 -0
- package/build-types/types.d.ts +221 -21
- package/build-types/types.d.ts.map +1 -1
- package/build-types/utils.d.ts +3 -0
- package/build-types/utils.d.ts.map +1 -0
- package/build-types/view-actions.d.ts +12 -0
- package/build-types/view-actions.d.ts.map +1 -0
- package/build-types/view-grid.d.ts +4 -0
- package/build-types/view-grid.d.ts.map +1 -0
- package/build-types/view-list.d.ts +4 -0
- package/build-types/view-list.d.ts.map +1 -0
- package/build-types/view-table.d.ts +5 -0
- package/build-types/view-table.d.ts.map +1 -0
- package/package.json +12 -13
- package/src/{add-filter.js → add-filter.tsx} +17 -1
- package/src/bulk-actions-toolbar.tsx +272 -0
- package/src/{bulk-actions.js → bulk-actions.tsx} +77 -17
- package/src/constants.ts +12 -5
- package/src/{dataviews.js → dataviews.tsx} +54 -14
- package/src/filter-and-sort-data-view.ts +13 -8
- package/src/{filter-summary.js → filter-summary.tsx} +38 -9
- package/src/{filters.js → filters.tsx} +18 -6
- package/src/{item-actions.js → item-actions.tsx} +119 -30
- package/src/normalize-fields.ts +4 -2
- package/src/{pagination.js → pagination.tsx} +29 -8
- package/src/{reset-filters.js → reset-filters.tsx} +17 -2
- package/src/{search-widget.js → search-widget.tsx} +27 -7
- package/src/{search.js → search.tsx} +22 -5
- package/src/{single-selection-checkbox.js → single-selection-checkbox.tsx} +17 -2
- package/src/style.scss +166 -43
- package/src/types.ts +286 -21
- package/src/{utils.js → utils.ts} +5 -13
- package/src/{view-actions.js → view-actions.tsx} +105 -49
- package/src/{view-grid.js → view-grid.tsx} +31 -18
- package/src/view-list.tsx +410 -0
- package/src/{view-table.js → view-table.tsx} +99 -40
- package/tsconfig.json +3 -4
- package/tsconfig.tsbuildinfo +1 -1
- package/build/dropdown-menu-helper.js +0 -71
- package/build/dropdown-menu-helper.js.map +0 -1
- package/build-module/dropdown-menu-helper.js +0 -64
- package/build-module/dropdown-menu-helper.js.map +0 -1
- package/src/dropdown-menu-helper.js +0 -61
- package/src/view-list.js +0 -207
- /package/src/{index.js → index.ts} +0 -0
- /package/src/{layouts.js → layouts.ts} +0 -0
- /package/src/{lock-unlock.js → lock-unlock.ts} +0 -0
package/build/view-table.js
CHANGED
|
@@ -5,8 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.default = void 0;
|
|
8
|
-
var
|
|
9
|
-
var _classnames = _interopRequireDefault(require("classnames"));
|
|
8
|
+
var _clsx = _interopRequireDefault(require("clsx"));
|
|
10
9
|
var _i18n = require("@wordpress/i18n");
|
|
11
10
|
var _icons = require("@wordpress/icons");
|
|
12
11
|
var _components = require("@wordpress/components");
|
|
@@ -17,6 +16,7 @@ var _itemActions = _interopRequireDefault(require("./item-actions"));
|
|
|
17
16
|
var _utils = require("./utils");
|
|
18
17
|
var _constants = require("./constants");
|
|
19
18
|
var _bulkActions = require("./bulk-actions");
|
|
19
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
20
20
|
/**
|
|
21
21
|
* External dependencies
|
|
22
22
|
*/
|
|
@@ -40,15 +40,11 @@ const {
|
|
|
40
40
|
function WithDropDownMenuSeparators({
|
|
41
41
|
children
|
|
42
42
|
}) {
|
|
43
|
-
return _element.Children.toArray(children).filter(Boolean).map((child, i) => (0,
|
|
44
|
-
|
|
45
|
-
}, i
|
|
43
|
+
return _element.Children.toArray(children).filter(Boolean).map((child, i) => /*#__PURE__*/(0, _jsxRuntime.jsxs)(_element.Fragment, {
|
|
44
|
+
children: [i > 0 && /*#__PURE__*/(0, _jsxRuntime.jsx)(DropdownMenuSeparator, {}), child]
|
|
45
|
+
}, i));
|
|
46
46
|
}
|
|
47
|
-
const
|
|
48
|
-
asc: '↑',
|
|
49
|
-
desc: '↓'
|
|
50
|
-
};
|
|
51
|
-
const HeaderMenu = (0, _element.forwardRef)(function HeaderMenu({
|
|
47
|
+
const _HeaderMenu = (0, _element.forwardRef)(function HeaderMenu({
|
|
52
48
|
field,
|
|
53
49
|
view,
|
|
54
50
|
onChangeView,
|
|
@@ -67,72 +63,91 @@ const HeaderMenu = (0, _element.forwardRef)(function HeaderMenu({
|
|
|
67
63
|
if (!isSortable && !isHidable && !canAddFilter) {
|
|
68
64
|
return field.header;
|
|
69
65
|
}
|
|
70
|
-
return (0,
|
|
66
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(DropdownMenu, {
|
|
71
67
|
align: "start",
|
|
72
|
-
trigger: (0,
|
|
68
|
+
trigger: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.Button, {
|
|
73
69
|
size: "compact",
|
|
74
70
|
className: "dataviews-view-table-header-button",
|
|
75
71
|
ref: ref,
|
|
76
|
-
variant: "tertiary"
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
72
|
+
variant: "tertiary",
|
|
73
|
+
children: [field.header, view.sort && isSorted && /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
|
74
|
+
"aria-hidden": "true",
|
|
75
|
+
children: _constants.sortArrows[view.sort.direction]
|
|
76
|
+
})]
|
|
77
|
+
}),
|
|
80
78
|
style: {
|
|
81
79
|
minWidth: '240px'
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
})
|
|
133
|
-
|
|
134
|
-
|
|
80
|
+
},
|
|
81
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(WithDropDownMenuSeparators, {
|
|
82
|
+
children: [isSortable && /*#__PURE__*/(0, _jsxRuntime.jsx)(DropdownMenuGroup, {
|
|
83
|
+
children: _constants.SORTING_DIRECTIONS.map(direction => {
|
|
84
|
+
const isChecked = view.sort && isSorted && view.sort.direction === direction;
|
|
85
|
+
const value = `${field.id}-${direction}`;
|
|
86
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(DropdownMenuRadioItem, {
|
|
87
|
+
// All sorting radio items share the same name, so that
|
|
88
|
+
// selecting a sorting option automatically deselects the
|
|
89
|
+
// previously selected one, even if it is displayed in
|
|
90
|
+
// another submenu. The field and direction are passed via
|
|
91
|
+
// the `value` prop.
|
|
92
|
+
name: "view-table-sorting",
|
|
93
|
+
value: value,
|
|
94
|
+
checked: isChecked,
|
|
95
|
+
onChange: () => {
|
|
96
|
+
onChangeView({
|
|
97
|
+
...view,
|
|
98
|
+
sort: {
|
|
99
|
+
field: field.id,
|
|
100
|
+
direction
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
},
|
|
104
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(DropdownMenuItemLabel, {
|
|
105
|
+
children: _constants.sortLabels[direction]
|
|
106
|
+
})
|
|
107
|
+
}, value);
|
|
108
|
+
})
|
|
109
|
+
}), canAddFilter && /*#__PURE__*/(0, _jsxRuntime.jsx)(DropdownMenuGroup, {
|
|
110
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(DropdownMenuItem, {
|
|
111
|
+
prefix: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Icon, {
|
|
112
|
+
icon: _icons.funnel
|
|
113
|
+
}),
|
|
114
|
+
onClick: () => {
|
|
115
|
+
setOpenedFilter(field.id);
|
|
116
|
+
onChangeView({
|
|
117
|
+
...view,
|
|
118
|
+
page: 1,
|
|
119
|
+
filters: [...(view.filters || []), {
|
|
120
|
+
field: field.id,
|
|
121
|
+
value: undefined,
|
|
122
|
+
operator: operators[0]
|
|
123
|
+
}]
|
|
124
|
+
});
|
|
125
|
+
},
|
|
126
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(DropdownMenuItemLabel, {
|
|
127
|
+
children: (0, _i18n.__)('Add filter')
|
|
128
|
+
})
|
|
129
|
+
})
|
|
130
|
+
}), isHidable && /*#__PURE__*/(0, _jsxRuntime.jsx)(DropdownMenuItem, {
|
|
131
|
+
prefix: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Icon, {
|
|
132
|
+
icon: _icons.unseen
|
|
133
|
+
}),
|
|
134
|
+
onClick: () => {
|
|
135
|
+
onHide(field);
|
|
136
|
+
onChangeView({
|
|
137
|
+
...view,
|
|
138
|
+
hiddenFields: view.hiddenFields.concat(field.id)
|
|
139
|
+
});
|
|
140
|
+
},
|
|
141
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(DropdownMenuItemLabel, {
|
|
142
|
+
children: (0, _i18n.__)('Hide')
|
|
143
|
+
})
|
|
144
|
+
})]
|
|
145
|
+
})
|
|
146
|
+
});
|
|
135
147
|
});
|
|
148
|
+
|
|
149
|
+
// @ts-expect-error Lift the `Item` type argument through the forwardRef.
|
|
150
|
+
const HeaderMenu = _HeaderMenu;
|
|
136
151
|
function BulkSelectionCheckbox({
|
|
137
152
|
selection,
|
|
138
153
|
onSelectionChange,
|
|
@@ -141,15 +156,15 @@ function BulkSelectionCheckbox({
|
|
|
141
156
|
}) {
|
|
142
157
|
const selectableItems = (0, _element.useMemo)(() => {
|
|
143
158
|
return data.filter(item => {
|
|
144
|
-
return actions.some(action => action.supportsBulk && action.isEligible(item));
|
|
159
|
+
return actions.some(action => action.supportsBulk && (!action.isEligible || action.isEligible(item)));
|
|
145
160
|
});
|
|
146
161
|
}, [data, actions]);
|
|
147
162
|
const areAllSelected = selection.length === selectableItems.length;
|
|
148
|
-
return (0,
|
|
163
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.CheckboxControl, {
|
|
149
164
|
className: "dataviews-view-table-selection-checkbox",
|
|
150
165
|
__nextHasNoMarginBottom: true,
|
|
151
166
|
checked: areAllSelected,
|
|
152
|
-
indeterminate: !areAllSelected && selection.length,
|
|
167
|
+
indeterminate: !areAllSelected && !!selection.length,
|
|
153
168
|
onChange: () => {
|
|
154
169
|
if (areAllSelected) {
|
|
155
170
|
onSelectionChange([]);
|
|
@@ -186,8 +201,8 @@ function TableRow({
|
|
|
186
201
|
// `onClick` and can be used to exclude touchscreen devices from certain
|
|
187
202
|
// behaviours.
|
|
188
203
|
const isTouchDevice = (0, _element.useRef)(false);
|
|
189
|
-
return (0,
|
|
190
|
-
className: (0,
|
|
204
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)("tr", {
|
|
205
|
+
className: (0, _clsx.default)('dataviews-view-table__row', {
|
|
191
206
|
'is-selected': hasPossibleBulkAction && isSelected,
|
|
192
207
|
'is-hovered': isHovered,
|
|
193
208
|
'has-bulk-actions': hasPossibleBulkAction
|
|
@@ -198,7 +213,7 @@ function TableRow({
|
|
|
198
213
|
isTouchDevice.current = true;
|
|
199
214
|
},
|
|
200
215
|
onClick: () => {
|
|
201
|
-
if (!isTouchDevice.current && document.getSelection()
|
|
216
|
+
if (!isTouchDevice.current && document.getSelection()?.type !== 'Range') {
|
|
202
217
|
if (!isSelected) {
|
|
203
218
|
onSelectionChange(data.filter(_item => {
|
|
204
219
|
const itemId = getItemId?.(_item);
|
|
@@ -211,64 +226,68 @@ function TableRow({
|
|
|
211
226
|
}));
|
|
212
227
|
}
|
|
213
228
|
}
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
229
|
+
},
|
|
230
|
+
children: [hasBulkActions && /*#__PURE__*/(0, _jsxRuntime.jsx)("td", {
|
|
231
|
+
className: "dataviews-view-table__checkbox-column",
|
|
232
|
+
style: {
|
|
233
|
+
width: '1%'
|
|
234
|
+
},
|
|
235
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
236
|
+
className: "dataviews-view-table__cell-content-wrapper",
|
|
237
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_singleSelectionCheckbox.default, {
|
|
238
|
+
item: item,
|
|
239
|
+
selection: selection,
|
|
240
|
+
onSelectionChange: onSelectionChange,
|
|
241
|
+
getItemId: getItemId,
|
|
242
|
+
data: data,
|
|
243
|
+
primaryField: primaryField,
|
|
244
|
+
disabled: !hasPossibleBulkAction
|
|
245
|
+
})
|
|
246
|
+
})
|
|
247
|
+
}), visibleFields.map(field => /*#__PURE__*/(0, _jsxRuntime.jsx)("td", {
|
|
248
|
+
style: {
|
|
249
|
+
width: field.width || undefined,
|
|
250
|
+
minWidth: field.minWidth || undefined,
|
|
251
|
+
maxWidth: field.maxWidth || undefined
|
|
252
|
+
},
|
|
253
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
254
|
+
className: (0, _clsx.default)('dataviews-view-table__cell-content-wrapper', {
|
|
255
|
+
'dataviews-view-table__primary-field': primaryField?.id === field.id
|
|
256
|
+
}),
|
|
257
|
+
children: field.render({
|
|
258
|
+
item
|
|
259
|
+
})
|
|
260
|
+
})
|
|
261
|
+
}, field.id)), !!actions?.length &&
|
|
262
|
+
/*#__PURE__*/
|
|
263
|
+
// Disable reason: we are not making the element interactive,
|
|
264
|
+
// but preventing any click events from bubbling up to the
|
|
265
|
+
// table row. This allows us to add a click handler to the row
|
|
266
|
+
// itself (to toggle row selection) without erroneously
|
|
267
|
+
// intercepting click events from ItemActions.
|
|
268
|
+
/* eslint-disable jsx-a11y/no-noninteractive-element-interactions, jsx-a11y/click-events-have-key-events */
|
|
269
|
+
(0, _jsxRuntime.jsx)("td", {
|
|
270
|
+
className: "dataviews-view-table__actions-column",
|
|
271
|
+
onClick: e => e.stopPropagation(),
|
|
272
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_itemActions.default, {
|
|
273
|
+
item: item,
|
|
274
|
+
actions: actions
|
|
275
|
+
})
|
|
241
276
|
})
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
})))), !!actions?.length &&
|
|
245
|
-
// Disable reason: we are not making the element interactive,
|
|
246
|
-
// but preventing any click events from bubbling up to the
|
|
247
|
-
// table row. This allows us to add a click handler to the row
|
|
248
|
-
// itself (to toggle row selection) without erroneously
|
|
249
|
-
// intercepting click events from ItemActions.
|
|
250
|
-
|
|
251
|
-
/* eslint-disable jsx-a11y/no-noninteractive-element-interactions, jsx-a11y/click-events-have-key-events */
|
|
252
|
-
(0, _react.createElement)("td", {
|
|
253
|
-
className: "dataviews-view-table__actions-column",
|
|
254
|
-
onClick: e => e.stopPropagation()
|
|
255
|
-
}, (0, _react.createElement)(_itemActions.default, {
|
|
256
|
-
item: item,
|
|
257
|
-
actions: actions
|
|
258
|
-
}))
|
|
259
|
-
/* eslint-enable jsx-a11y/no-noninteractive-element-interactions, jsx-a11y/click-events-have-key-events */);
|
|
277
|
+
/* eslint-enable jsx-a11y/no-noninteractive-element-interactions, jsx-a11y/click-events-have-key-events */]
|
|
278
|
+
});
|
|
260
279
|
}
|
|
261
280
|
function ViewTable({
|
|
262
|
-
view,
|
|
263
|
-
onChangeView,
|
|
264
|
-
fields,
|
|
265
281
|
actions,
|
|
266
282
|
data,
|
|
283
|
+
fields,
|
|
267
284
|
getItemId,
|
|
268
285
|
isLoading = false,
|
|
269
|
-
|
|
286
|
+
onChangeView,
|
|
270
287
|
onSelectionChange,
|
|
271
|
-
|
|
288
|
+
selection,
|
|
289
|
+
setOpenedFilter,
|
|
290
|
+
view
|
|
272
291
|
}) {
|
|
273
292
|
const headerMenuRefs = (0, _element.useRef)(new Map());
|
|
274
293
|
const headerMenuToFocusRef = (0, _element.useRef)();
|
|
@@ -287,89 +306,98 @@ function ViewTable({
|
|
|
287
306
|
// Clearing out the focus directive is necessary to make sure
|
|
288
307
|
// future renders don't cause unexpected focus jumps.
|
|
289
308
|
headerMenuToFocusRef.current = nextHeaderMenuToFocus;
|
|
290
|
-
setNextHeaderMenuToFocus();
|
|
309
|
+
setNextHeaderMenuToFocus(undefined);
|
|
291
310
|
return;
|
|
292
311
|
}
|
|
293
312
|
const onHide = field => {
|
|
294
313
|
const hidden = headerMenuRefs.current.get(field.id);
|
|
295
|
-
const fallback = headerMenuRefs.current.get(hidden.fallback);
|
|
314
|
+
const fallback = hidden ? headerMenuRefs.current.get(hidden.fallback) : undefined;
|
|
296
315
|
setNextHeaderMenuToFocus(fallback?.node);
|
|
297
316
|
};
|
|
298
317
|
const visibleFields = fields.filter(field => !view.hiddenFields.includes(field.id) && ![view.layout.mediaField].includes(field.id));
|
|
299
318
|
const hasData = !!data?.length;
|
|
300
|
-
const sortValues = {
|
|
301
|
-
asc: 'ascending',
|
|
302
|
-
desc: 'descending'
|
|
303
|
-
};
|
|
304
319
|
const primaryField = fields.find(field => field.id === view.layout.primaryField);
|
|
305
|
-
return (0,
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
320
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
321
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("table", {
|
|
322
|
+
className: "dataviews-view-table",
|
|
323
|
+
"aria-busy": isLoading,
|
|
324
|
+
"aria-describedby": tableNoticeId,
|
|
325
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("thead", {
|
|
326
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("tr", {
|
|
327
|
+
className: "dataviews-view-table__row",
|
|
328
|
+
children: [hasBulkActions && /*#__PURE__*/(0, _jsxRuntime.jsx)("th", {
|
|
329
|
+
className: "dataviews-view-table__checkbox-column",
|
|
330
|
+
style: {
|
|
331
|
+
width: '1%'
|
|
332
|
+
},
|
|
333
|
+
"data-field-id": "selection",
|
|
334
|
+
scope: "col",
|
|
335
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(BulkSelectionCheckbox, {
|
|
336
|
+
selection: selection,
|
|
337
|
+
onSelectionChange: onSelectionChange,
|
|
338
|
+
data: data,
|
|
339
|
+
actions: actions
|
|
340
|
+
})
|
|
341
|
+
}), visibleFields.map((field, index) => /*#__PURE__*/(0, _jsxRuntime.jsx)("th", {
|
|
342
|
+
style: {
|
|
343
|
+
width: field.width || undefined,
|
|
344
|
+
minWidth: field.minWidth || undefined,
|
|
345
|
+
maxWidth: field.maxWidth || undefined
|
|
346
|
+
},
|
|
347
|
+
"data-field-id": field.id,
|
|
348
|
+
"aria-sort": view.sort?.field === field.id ? _constants.sortValues[view.sort.direction] : undefined,
|
|
349
|
+
scope: "col",
|
|
350
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(HeaderMenu, {
|
|
351
|
+
ref: node => {
|
|
352
|
+
if (node) {
|
|
353
|
+
headerMenuRefs.current.set(field.id, {
|
|
354
|
+
node,
|
|
355
|
+
fallback: visibleFields[index > 0 ? index - 1 : 1]?.id
|
|
356
|
+
});
|
|
357
|
+
} else {
|
|
358
|
+
headerMenuRefs.current.delete(field.id);
|
|
359
|
+
}
|
|
360
|
+
},
|
|
361
|
+
field: field,
|
|
362
|
+
view: view,
|
|
363
|
+
onChangeView: onChangeView,
|
|
364
|
+
onHide: onHide,
|
|
365
|
+
setOpenedFilter: setOpenedFilter
|
|
366
|
+
})
|
|
367
|
+
}, field.id)), !!actions?.length && /*#__PURE__*/(0, _jsxRuntime.jsx)("th", {
|
|
368
|
+
"data-field-id": "actions",
|
|
369
|
+
className: "dataviews-view-table__actions-column",
|
|
370
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
|
|
371
|
+
className: "dataviews-view-table-header",
|
|
372
|
+
children: (0, _i18n.__)('Actions')
|
|
373
|
+
})
|
|
374
|
+
})]
|
|
375
|
+
})
|
|
376
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("tbody", {
|
|
377
|
+
children: hasData && data.map((item, index) => /*#__PURE__*/(0, _jsxRuntime.jsx)(TableRow, {
|
|
378
|
+
item: item,
|
|
379
|
+
hasBulkActions: hasBulkActions,
|
|
380
|
+
actions: actions,
|
|
381
|
+
id: getItemId(item) || index.toString(),
|
|
382
|
+
visibleFields: visibleFields,
|
|
383
|
+
primaryField: primaryField,
|
|
384
|
+
selection: selection,
|
|
385
|
+
getItemId: getItemId,
|
|
386
|
+
onSelectionChange: onSelectionChange,
|
|
387
|
+
data: data
|
|
388
|
+
}, getItemId(item)))
|
|
389
|
+
})]
|
|
390
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
|
|
391
|
+
className: (0, _clsx.default)({
|
|
392
|
+
'dataviews-loading': isLoading,
|
|
393
|
+
'dataviews-no-results': !hasData && !isLoading
|
|
394
|
+
}),
|
|
395
|
+
id: tableNoticeId,
|
|
396
|
+
children: !hasData && /*#__PURE__*/(0, _jsxRuntime.jsx)("p", {
|
|
397
|
+
children: isLoading ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Spinner, {}) : (0, _i18n.__)('No results')
|
|
398
|
+
})
|
|
399
|
+
})]
|
|
400
|
+
});
|
|
373
401
|
}
|
|
374
402
|
var _default = exports.default = ViewTable;
|
|
375
403
|
//# sourceMappingURL=view-table.js.map
|