@economic/taco 2.23.0 → 2.24.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/components/Card/Card.d.ts +1 -0
- package/dist/components/Checkbox/Checkbox.d.ts +2 -0
- package/dist/components/Provider/Localization.d.ts +4 -0
- package/dist/components/Report/components/Body/Body.d.ts +0 -1
- package/dist/components/Report/components/Footer/Summary.d.ts +0 -1
- package/dist/components/Report/components/Toolbar/components/Filters/components/Filter.d.ts +2 -2
- package/dist/components/Report/components/Toolbar/components/Filters/components/FilterColumn.d.ts +5 -2
- package/dist/components/Report/useReport.d.ts +0 -1
- package/dist/components/Select2/Select2.d.ts +4 -0
- package/dist/components/Select2/hooks/useChildren.d.ts +1 -0
- package/dist/components/Table3/components/toolbar/Filter/filters/components/Filter.d.ts +2 -2
- package/dist/components/Table3/components/toolbar/Filter/filters/components/FilterColumn.d.ts +5 -2
- package/dist/esm/index.css +55 -46
- package/dist/esm/packages/taco/src/components/Button/util.js +8 -8
- package/dist/esm/packages/taco/src/components/Button/util.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Card/Card.js +2 -1
- package/dist/esm/packages/taco/src/components/Card/Card.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Checkbox/Checkbox.js +11 -2
- package/dist/esm/packages/taco/src/components/Checkbox/Checkbox.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Listbox/ScrollableList.js +1 -1
- package/dist/esm/packages/taco/src/components/Provider/Localization.js +5 -1
- package/dist/esm/packages/taco/src/components/Provider/Localization.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Report/Report.js +3 -8
- package/dist/esm/packages/taco/src/components/Report/Report.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Report/components/Body/Body.js +1 -2
- package/dist/esm/packages/taco/src/components/Report/components/Body/Body.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Report/components/Footer/Footer.js +14 -2
- package/dist/esm/packages/taco/src/components/Report/components/Footer/Footer.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Report/components/Footer/Summary.js +2 -2
- package/dist/esm/packages/taco/src/components/Report/components/Footer/Summary.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Report/components/Internal/Selection.js +47 -11
- package/dist/esm/packages/taco/src/components/Report/components/Internal/Selection.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Report/components/Toolbar/components/Filters/ManageFiltersPopover.js +28 -43
- package/dist/esm/packages/taco/src/components/Report/components/Toolbar/components/Filters/ManageFiltersPopover.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Report/components/Toolbar/components/Filters/components/Filter.js +14 -7
- package/dist/esm/packages/taco/src/components/Report/components/Toolbar/components/Filters/components/Filter.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Report/components/Toolbar/components/Filters/components/FilterColumn.js +4 -3
- package/dist/esm/packages/taco/src/components/Report/components/Toolbar/components/Filters/components/FilterColumn.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Report/components/Toolbar/components/Print/Print.js +10 -8
- package/dist/esm/packages/taco/src/components/Report/components/Toolbar/components/Print/Print.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Report/listeners/useTableRowActiveListener.js +2 -2
- package/dist/esm/packages/taco/src/components/Report/listeners/useTableRowActiveListener.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Report/styles/useCssGridStylesheet.js +7 -4
- package/dist/esm/packages/taco/src/components/Report/styles/useCssGridStylesheet.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Report/util/useTableGlobalShortcuts.js +3 -10
- package/dist/esm/packages/taco/src/components/Report/util/useTableGlobalShortcuts.js.map +1 -1
- package/dist/esm/packages/taco/src/components/SearchInput2/SearchInput2.js +2 -1
- package/dist/esm/packages/taco/src/components/SearchInput2/SearchInput2.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Select2/Select2.js +43 -4
- package/dist/esm/packages/taco/src/components/Select2/Select2.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Select2/hooks/useChildren.js +1 -1
- package/dist/esm/packages/taco/src/components/Select2/hooks/useChildren.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/Table3.js +4 -6
- package/dist/esm/packages/taco/src/components/Table3/Table3.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/columns/internal/Selection.js +66 -14
- package/dist/esm/packages/taco/src/components/Table3/components/columns/internal/Selection.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/toolbar/Filter/filters/Filters.js +27 -44
- package/dist/esm/packages/taco/src/components/Table3/components/toolbar/Filter/filters/Filters.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/toolbar/Filter/filters/components/Filter.js +14 -7
- package/dist/esm/packages/taco/src/components/Table3/components/toolbar/Filter/filters/components/Filter.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/toolbar/Filter/filters/components/FilterColumn.js +4 -3
- package/dist/esm/packages/taco/src/components/Table3/components/toolbar/Filter/filters/components/FilterColumn.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/toolbar/Filter/filters/components/FilterComparator.js +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/toolbar/Filter/filters/components/FilterComparator.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/toolbar/PrintButton/PrintButton.js +2 -0
- package/dist/esm/packages/taco/src/components/Table3/components/toolbar/PrintButton/PrintButton.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/components/toolbar/PrintButton/PrintIFrame.js +1 -1
- package/dist/esm/packages/taco/src/components/Table3/hooks/features/useSettings.js +1 -1
- package/dist/esm/packages/taco/src/components/Table3/hooks/listeners/useSettingsStateListener.js +3 -1
- package/dist/esm/packages/taco/src/components/Table3/hooks/listeners/useSettingsStateListener.js.map +1 -1
- package/dist/esm/packages/taco/src/components/Table3/hooks/useTable.js +10 -3
- package/dist/esm/packages/taco/src/components/Table3/hooks/useTable.js.map +1 -1
- package/dist/esm/packages/taco/src/hooks/useLocalStorage.js.map +1 -1
- package/dist/esm/packages/taco/src/index.js +1 -1
- package/dist/esm/packages/taco/src/primitives/Button.js +1 -0
- package/dist/esm/packages/taco/src/primitives/Button.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/types.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTable/features/useTablePrinting.js +24 -4
- package/dist/esm/packages/taco/src/primitives/Table/useTable/features/useTablePrinting.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTable/features/useTableSettings.js +1 -2
- package/dist/esm/packages/taco/src/primitives/Table/useTable/features/useTableSettings.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTable/listeners/useTableSettingsListener.js +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTable/listeners/useTableSettingsListener.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTable/useTable.js +7 -5
- package/dist/esm/packages/taco/src/primitives/Table/useTable/useTable.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTable/util/columns.js +33 -7
- package/dist/esm/packages/taco/src/primitives/Table/useTable/util/columns.js.map +1 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTable/util/settings.js +0 -1
- package/dist/esm/packages/taco/src/primitives/Table/useTable/util/settings.js.map +1 -1
- package/dist/esm/packages/taco/src/utils/dom.js +12 -3
- package/dist/esm/packages/taco/src/utils/dom.js.map +1 -1
- package/dist/esm/packages/taco/src/utils/keyboard.js +2 -2
- package/dist/esm/packages/taco/src/utils/keyboard.js.map +1 -1
- package/dist/hooks/useLocalStorage.d.ts +2 -1
- package/dist/index.css +55 -46
- package/dist/primitives/Table/types.d.ts +0 -2
- package/dist/primitives/Table/useTable/features/useTablePrinting.d.ts +10 -3
- package/dist/primitives/Table/useTable/useTable.d.ts +1 -1
- package/dist/primitives/Table/useTable/util/settings.d.ts +0 -1
- package/dist/taco.cjs.development.js +511 -387
- package/dist/taco.cjs.development.js.map +1 -1
- package/dist/taco.cjs.production.min.js +1 -1
- package/dist/taco.cjs.production.min.js.map +1 -1
- package/dist/utils/dom.d.ts +3 -1
- package/package.json +2 -2
- package/types.json +6781 -6993
- package/dist/components/Report/components/Toolbar/components/Filters/components/Placeholder.d.ts +0 -12
- package/dist/components/Table3/components/toolbar/Filter/filters/components/Placeholder.d.ts +0 -12
- package/dist/esm/packages/taco/src/components/Report/components/Toolbar/components/Filters/components/Placeholder.js +0 -41
- package/dist/esm/packages/taco/src/components/Report/components/Toolbar/components/Filters/components/Placeholder.js.map +0 -1
- package/dist/esm/packages/taco/src/components/Table3/components/toolbar/Filter/filters/components/Placeholder.js +0 -41
- package/dist/esm/packages/taco/src/components/Table3/components/toolbar/Filter/filters/components/Placeholder.js.map +0 -1
package/dist/esm/packages/taco/src/components/Table3/components/columns/internal/Selection.js
CHANGED
@@ -5,6 +5,7 @@ import { useLocalization } from '../../../../Provider/Localization.js';
|
|
5
5
|
import { Checkbox } from '../../../../Checkbox/Checkbox.js';
|
6
6
|
import { Shortcut } from '../../../../Shortcut/Shortcut.js';
|
7
7
|
import { getRadioClassnames } from '../../../../RadioGroup/util.js';
|
8
|
+
import { TableServerLoadAllState } from '../../../../../primitives/Table/types.js';
|
8
9
|
import { Header as Header$1 } from '../header/Header.js';
|
9
10
|
import { RowContext } from '../../rows/RowContext.js';
|
10
11
|
import { DisplayCell } from '../cell/DisplayCell.js';
|
@@ -19,6 +20,25 @@ function Header(context) {
|
|
19
20
|
const isAllRowsSelected = context.table.getIsAllRowsSelected();
|
20
21
|
const isSomeRowsSelected = context.table.getIsSomeRowsSelected();
|
21
22
|
const title = isAllRowsSelected ? texts.table3.columns.select.deselectAll : texts.table3.columns.select.selectAll;
|
23
|
+
const tableMeta = context.table.options.meta;
|
24
|
+
const isServerloading = tableMeta.server.loadAllStatus === TableServerLoadAllState.Loading;
|
25
|
+
const isLoadingAll = isAllRowsSelected && isServerloading;
|
26
|
+
const isLoadingPreviousRows = tableMeta.rowSelection.lastSelectedRowIndex !== undefined && isServerloading;
|
27
|
+
const toggleSelectAll = function () {
|
28
|
+
try {
|
29
|
+
const _temp = function () {
|
30
|
+
if (!isServerloading) {
|
31
|
+
var _tableMeta$server, _tableMeta$server$loa;
|
32
|
+
return Promise.resolve((_tableMeta$server = tableMeta.server) === null || _tableMeta$server === void 0 ? void 0 : (_tableMeta$server$loa = _tableMeta$server.loadAllIfNeeded) === null || _tableMeta$server$loa === void 0 ? void 0 : _tableMeta$server$loa.call(_tableMeta$server, context.table.getState().sorting, context.table.getState().columnFilters, undefined)).then(function () {
|
33
|
+
context.table.toggleAllRowsSelected(!isAllRowsSelected);
|
34
|
+
});
|
35
|
+
}
|
36
|
+
}();
|
37
|
+
return Promise.resolve(_temp && _temp.then ? _temp.then(function () {}) : void 0);
|
38
|
+
} catch (e) {
|
39
|
+
return Promise.reject(e);
|
40
|
+
}
|
41
|
+
};
|
22
42
|
return /*#__PURE__*/React__default.createElement(Header$1, Object.assign({}, context), /*#__PURE__*/React__default.createElement(Tooltip, {
|
23
43
|
title: title
|
24
44
|
}, /*#__PURE__*/React__default.createElement(Checkbox, {
|
@@ -27,8 +47,9 @@ function Header(context) {
|
|
27
47
|
key: String(`${isAllRowsSelected}_${isSomeRowsSelected}`),
|
28
48
|
checked: isAllRowsSelected,
|
29
49
|
indeterminate: isSomeRowsSelected,
|
30
|
-
onChange:
|
31
|
-
tabIndex: -1
|
50
|
+
onChange: toggleSelectAll,
|
51
|
+
tabIndex: -1,
|
52
|
+
loading: isLoadingAll || isLoadingPreviousRows
|
32
53
|
})));
|
33
54
|
} else {
|
34
55
|
return /*#__PURE__*/React__default.createElement(Header$1, Object.assign({}, context));
|
@@ -50,18 +71,49 @@ const Cell = /*#__PURE__*/React__default.memo(function MemoedCell(context) {
|
|
50
71
|
const isActiveRow = tableMeta.rowActive.rowActiveIndex === rowIndex;
|
51
72
|
const isSelected = context.row.getIsSelected();
|
52
73
|
const title = isSelected ? texts.table3.columns.select.deselect : texts.table3.columns.select.select;
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
var _tableMeta$rowSelecti;
|
58
|
-
const [fromIndex, toIndex] = toggleBetween((_tableMeta$rowSelecti = tableMeta.rowSelection.lastSelectedRowIndex.current) !== null && _tableMeta$rowSelecti !== void 0 ? _tableMeta$rowSelecti : 0, rowIndex);
|
59
|
-
context.table.getRowModel().rows.slice(fromIndex, toIndex + 1).forEach(row => row.toggleSelected(true));
|
60
|
-
} else {
|
61
|
-
context.row.toggleSelected();
|
74
|
+
const handleCheckboxClick = function (event) {
|
75
|
+
try {
|
76
|
+
function _temp5() {
|
77
|
+
tableMeta.rowSelection.lastSelectedRowIndex.current = rowIndex;
|
62
78
|
}
|
63
|
-
|
64
|
-
|
79
|
+
event.stopPropagation();
|
80
|
+
const _temp4 = function () {
|
81
|
+
if (event.shiftKey) {
|
82
|
+
var _tableMeta$rowSelecti;
|
83
|
+
function _temp3() {
|
84
|
+
const currentlySelected = context.table.getSelectedRowModel().rows;
|
85
|
+
// concat currently selected with selection range and get rid of duplicates using "Set".
|
86
|
+
// converting allSelected array into updater object: {[row.id]: true}
|
87
|
+
const allSelected = [...new Set(currentlySelected.concat(selectionRangeRows))];
|
88
|
+
const updater = allSelected.reduce((obj, row) => Object.assign(obj, {
|
89
|
+
[row.id]: true
|
90
|
+
}), {});
|
91
|
+
context.table.setRowSelection(updater);
|
92
|
+
}
|
93
|
+
const [fromIndex, toIndex] = toggleBetween((_tableMeta$rowSelecti = tableMeta.rowSelection.lastSelectedRowIndex.current) !== null && _tableMeta$rowSelecti !== void 0 ? _tableMeta$rowSelecti : 0, rowIndex);
|
94
|
+
const selectionRangeRows = context.table.getRowModel().rows.slice(fromIndex, toIndex + 1);
|
95
|
+
// Table data loader filling-in all the rest of unloaded items with the undefined values,
|
96
|
+
// so we can easily check if at least one of the rows in the selection range is undefined,
|
97
|
+
// then it means that we need to call load all.
|
98
|
+
const hasUndefinedRows = selectionRangeRows.some(row => row.original === undefined);
|
99
|
+
const _temp2 = function () {
|
100
|
+
if (hasUndefinedRows) {
|
101
|
+
var _tableMeta$server2, _tableMeta$server2$lo;
|
102
|
+
// We don't need to await and freeze UI
|
103
|
+
return Promise.resolve((_tableMeta$server2 = tableMeta.server) === null || _tableMeta$server2 === void 0 ? void 0 : (_tableMeta$server2$lo = _tableMeta$server2.loadAllIfNeeded) === null || _tableMeta$server2$lo === void 0 ? void 0 : _tableMeta$server2$lo.call(_tableMeta$server2, context.table.getState().sorting, context.table.getState().columnFilters, undefined)).then(function () {});
|
104
|
+
}
|
105
|
+
}();
|
106
|
+
return _temp2 && _temp2.then ? _temp2.then(_temp3) : _temp3(_temp2);
|
107
|
+
} else {
|
108
|
+
context.row.toggleSelected();
|
109
|
+
}
|
110
|
+
}();
|
111
|
+
return Promise.resolve(_temp4 && _temp4.then ? _temp4.then(_temp5) : _temp5(_temp4));
|
112
|
+
} catch (e) {
|
113
|
+
return Promise.reject(e);
|
114
|
+
}
|
115
|
+
};
|
116
|
+
if (context.table.options.enableMultiRowSelection) {
|
65
117
|
return /*#__PURE__*/React__default.createElement(DisplayCell, Object.assign({}, context), /*#__PURE__*/React__default.createElement(Tooltip, {
|
66
118
|
title: /*#__PURE__*/React__default.createElement(React__default.Fragment, null, title, /*#__PURE__*/React__default.createElement(Shortcut, {
|
67
119
|
className: "ml-2",
|
@@ -71,7 +123,7 @@ const Cell = /*#__PURE__*/React__default.memo(function MemoedCell(context) {
|
|
71
123
|
"aria-label": title,
|
72
124
|
className: "!mt-0",
|
73
125
|
checked: isSelected,
|
74
|
-
onClick:
|
126
|
+
onClick: handleCheckboxClick,
|
75
127
|
// this is necessary to remove console spam from eslint
|
76
128
|
onChange: () => false,
|
77
129
|
tabIndex: isActiveRow ? 0 : -1
|
package/dist/esm/packages/taco/src/components/Table3/components/columns/internal/Selection.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Selection.js","sources":["../../../../../../../../../../src/components/Table3/components/columns/internal/Selection.tsx"],"sourcesContent":["import React from 'react';\nimport { HeaderContext, CellContext, DisplayColumnDef, TableMeta } from '@tanstack/react-table';\nimport cn from 'clsx';\nimport { Checkbox } from '../../../../Checkbox/Checkbox';\nimport { Header as ColumnHeader } from '../header/Header';\nimport { DisplayCell } from '../cell/DisplayCell';\nimport { Tooltip } from '../../../../Tooltip/Tooltip';\nimport { useLocalization } from '../../../../Provider/Localization';\nimport { RowContext } from '../../rows/RowContext';\nimport { Footer } from '../footer/Footer';\nimport { getRadioClassnames } from '../../../../RadioGroup/util';\nimport { Shortcut } from '../../../../Shortcut/Shortcut';\n\nexport const COLUMN_ID = '__select';\n\nfunction Header<TType = unknown>(context: HeaderContext<TType, unknown>) {\n const { texts } = useLocalization();\n\n if (context.table.options.enableMultiRowSelection) {\n const isAllRowsSelected = context.table.getIsAllRowsSelected();\n const isSomeRowsSelected = context.table.getIsSomeRowsSelected();\n const title = isAllRowsSelected ? texts.table3.columns.select.deselectAll : texts.table3.columns.select.selectAll;\n\n return (\n <ColumnHeader {...context}>\n <Tooltip title={title}>\n <Checkbox\n aria-label={title}\n className=\"hover:border-blue !mt-0\"\n key={String(`${isAllRowsSelected}_${isSomeRowsSelected}`)}\n checked={isAllRowsSelected}\n indeterminate={isSomeRowsSelected}\n onChange={context.table.toggleAllRowsSelected}\n tabIndex={-1}\n />\n </Tooltip>\n </ColumnHeader>\n );\n } else {\n return <ColumnHeader {...context}></ColumnHeader>;\n }\n}\n\nconst toggleBetween = (fromRowIndex: number, toRowIndex: number): [number, number] => {\n const fromIndex = toRowIndex < fromRowIndex ? toRowIndex : fromRowIndex;\n const toIndex = toRowIndex > fromRowIndex ? toRowIndex : fromRowIndex;\n\n return [fromIndex, toIndex];\n};\n\nconst Cell = React.memo(\n function MemoedCell<TType = unknown>(context: CellContext<TType, unknown>) {\n const { texts } = useLocalization();\n const { rowIndex } = React.useContext(RowContext);\n const tableMeta = context.table.options.meta as TableMeta<TType>;\n\n const isActiveRow = tableMeta.rowActive.rowActiveIndex === rowIndex;\n const isSelected = context.row.getIsSelected();\n const title = isSelected ? texts.table3.columns.select.deselect : texts.table3.columns.select.select;\n\n if (context.table.options.enableMultiRowSelection) {\n const handleClick = (event: React.MouseEvent): void => {\n event.stopPropagation();\n\n if (event.shiftKey) {\n const [fromIndex, toIndex] = toggleBetween(\n tableMeta.rowSelection.lastSelectedRowIndex.current ?? 0,\n rowIndex\n );\n\n context.table\n .getRowModel()\n .rows.slice(fromIndex, toIndex + 1)\n .forEach(row => row.toggleSelected(true));\n } else {\n context.row.toggleSelected();\n }\n\n tableMeta.rowSelection.lastSelectedRowIndex.current = rowIndex;\n };\n\n return (\n <DisplayCell {...context}>\n <Tooltip\n title={\n <>\n {title}\n <Shortcut className=\"ml-2\" keys=\"Space\" />\n </>\n }>\n <Checkbox\n aria-label={title}\n className=\"!mt-0\"\n checked={isSelected}\n onClick={handleClick}\n // this is necessary to remove console spam from eslint\n onChange={() => false}\n tabIndex={isActiveRow ? 0 : -1}\n />\n </Tooltip>\n </DisplayCell>\n );\n } else {\n const className = cn('!mt-0', getRadioClassnames());\n\n const handleClick = (event: React.MouseEvent): void => {\n event.stopPropagation();\n context.row.toggleSelected();\n tableMeta.rowSelection.lastSelectedRowIndex.current = rowIndex;\n };\n\n return (\n <DisplayCell {...context}>\n <button\n className={className}\n aria-checked={isSelected}\n onClick={handleClick}\n role=\"radio\"\n tabIndex={-1}\n type=\"button\">\n {isSelected ? <span className=\"h-2 w-2 rounded-full bg-white\" /> : null}\n </button>\n </DisplayCell>\n );\n }\n },\n function arePropsEqual(oldProps: CellContext<unknown, unknown>, newProps: CellContext<unknown, unknown>) {\n const oldTableMeta = oldProps.table.options.meta as TableMeta<unknown>;\n const newTableMeta = newProps.table.options.meta as TableMeta<unknown>;\n\n // we memo because we don't want the row re-rendering and removing focus from the checkbox\n // we can't default to the standard comparison because we need currentRow off the table meta\n // and we don't really care about re-rendering in any other scenario\n return (\n newTableMeta.rowActive.rowActiveIndex === oldTableMeta.rowActive.rowActiveIndex &&\n newProps.row.getIsSelected() !== oldProps.row.getIsSelected()\n );\n }\n) as <TType = unknown>(context: CellContext<TType, unknown>) => JSX.Element;\n\nexport function createRowSelectionColumn<TType = unknown>(\n hasDrag: boolean,\n hasExpansion: boolean\n): DisplayColumnDef<TType, unknown> {\n const size = hasDrag && hasExpansion ? 22 : 40;\n\n return {\n id: COLUMN_ID,\n header: Header,\n cell: Cell,\n footer: Footer,\n meta: {\n align: 'center',\n className: cn('!pt-[var(--table3-cell-padding-y)] !justify-end !p-0', {\n '!pr-0.5': hasExpansion,\n '!pr-3': !hasExpansion,\n }),\n enableOrdering: false,\n enableSearch: false,\n enableTruncate: false,\n header: '',\n headerClassName: cn('items-center !justify-end !p-0', { '!pr-0.5': hasExpansion, '!pr-3': !hasExpansion }),\n },\n // options\n enableResizing: false,\n size,\n minSize: size,\n };\n}\n"],"names":["COLUMN_ID","Header","context","texts","useLocalization","table","options","enableMultiRowSelection","isAllRowsSelected","getIsAllRowsSelected","isSomeRowsSelected","getIsSomeRowsSelected","title","table3","columns","select","deselectAll","selectAll","React","ColumnHeader","Tooltip","Checkbox","className","key","String","checked","indeterminate","onChange","toggleAllRowsSelected","tabIndex","toggleBetween","fromRowIndex","toRowIndex","fromIndex","toIndex","Cell","memo","MemoedCell","rowIndex","useContext","RowContext","tableMeta","meta","isActiveRow","rowActive","rowActiveIndex","isSelected","row","getIsSelected","deselect","handleClick","event","stopPropagation","shiftKey","_tableMeta$rowSelecti","rowSelection","lastSelectedRowIndex","current","getRowModel","rows","slice","forEach","toggleSelected","DisplayCell","Shortcut","keys","onClick","cn","getRadioClassnames","role","type","arePropsEqual","oldProps","newProps","oldTableMeta","newTableMeta","createRowSelectionColumn","hasDrag","hasExpansion","size","id","header","cell","footer","Footer","align","enableOrdering","enableSearch","enableTruncate","headerClassName","enableResizing","minSize"],"mappings":";;;;;;;;;;;;MAaaA,SAAS,GAAG;AAEzB,SAASC,MAAMA,CAAkBC,OAAsC;EACnE,MAAM;IAAEC;GAAO,GAAGC,eAAe,EAAE;EAEnC,IAAIF,OAAO,CAACG,KAAK,CAACC,O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EAChBC,YAAqB;EAErB,MAAMC,IAAI,GAAGF,OAAO,IAAIC,YAAY,GAAG,EAAE,GAAG,EAAE;EAE9C,OAAO;IACHE,EAAE,EAAEhF,SAAS;IACbiF,MAAM,EAAEhF,MAAM;IACdiF,IAAI,EAAE/C,IAAI;IACVgD,MAAM,EAAEC,MAAM;IACd1C,IAAI,EAAE;MACF2C,KAAK,EAAE,QAAQ;MACf/D,SAAS,EAAE6C,EAAE,CAAC,sDAAsD,EAAE;QAClE,SAAS,EAAEW,YAAY;QACvB,OAAO,EAAE,CAACA;OACb,CAAC;MACFQ,cAAc,EAAE,KAAK;MACrBC,YAAY,EAAE,KAAK;MACnBC,cAAc,EAAE,KAAK;MACrBP,MAAM,EAAE,EAAE;MACVQ,eAAe,EAAEtB,EAAE,CAAC,gCAAgC,EAAE;QAAE,SAAS,EAAEW,YAAY;QAAE,OAAO,EAAE,CAACA;OAAc;KAC5G;;IAEDY,cAAc,EAAE,KAAK;IACrBX,IAAI;IACJY,OAAO,EAAEZ;GACZ;AACL;;;;"}
|
1
|
+
{"version":3,"file":"Selection.js","sources":["../../../../../../../../../../src/components/Table3/components/columns/internal/Selection.tsx"],"sourcesContent":["import React from 'react';\nimport { HeaderContext, CellContext, DisplayColumnDef, TableMeta, RowSelectionState } from '@tanstack/react-table';\nimport cn from 'clsx';\nimport { Checkbox } from '../../../../Checkbox/Checkbox';\nimport { Header as ColumnHeader } from '../header/Header';\nimport { DisplayCell } from '../cell/DisplayCell';\nimport { Tooltip } from '../../../../Tooltip/Tooltip';\nimport { useLocalization } from '../../../../Provider/Localization';\nimport { RowContext } from '../../rows/RowContext';\nimport { Footer } from '../footer/Footer';\nimport { getRadioClassnames } from '../../../../RadioGroup/util';\nimport { Shortcut } from '../../../../Shortcut/Shortcut';\nimport { TableServerLoadAllState } from '../../../../../primitives/Table/types';\n\nexport const COLUMN_ID = '__select';\n\nfunction Header<TType = unknown>(context: HeaderContext<TType, unknown>) {\n const { texts } = useLocalization();\n\n if (context.table.options.enableMultiRowSelection) {\n const isAllRowsSelected = context.table.getIsAllRowsSelected();\n const isSomeRowsSelected = context.table.getIsSomeRowsSelected();\n const title = isAllRowsSelected ? texts.table3.columns.select.deselectAll : texts.table3.columns.select.selectAll;\n const tableMeta = context.table.options.meta as TableMeta<TType>;\n const isServerloading = tableMeta.server.loadAllStatus === TableServerLoadAllState.Loading;\n const isLoadingAll = isAllRowsSelected && isServerloading;\n const isLoadingPreviousRows = tableMeta.rowSelection.lastSelectedRowIndex !== undefined && isServerloading;\n\n const toggleSelectAll = async () => {\n if (!isServerloading) {\n await tableMeta.server?.loadAllIfNeeded?.(\n context.table.getState().sorting,\n context.table.getState().columnFilters,\n undefined\n );\n context.table.toggleAllRowsSelected(!isAllRowsSelected);\n }\n };\n\n return (\n <ColumnHeader {...context}>\n <Tooltip title={title}>\n <Checkbox\n aria-label={title}\n className=\"hover:border-blue !mt-0\"\n key={String(`${isAllRowsSelected}_${isSomeRowsSelected}`)}\n checked={isAllRowsSelected}\n indeterminate={isSomeRowsSelected}\n onChange={toggleSelectAll}\n tabIndex={-1}\n loading={isLoadingAll || isLoadingPreviousRows}\n />\n </Tooltip>\n </ColumnHeader>\n );\n } else {\n return <ColumnHeader {...context}></ColumnHeader>;\n }\n}\n\nconst toggleBetween = (fromRowIndex: number, toRowIndex: number): [number, number] => {\n const fromIndex = toRowIndex < fromRowIndex ? toRowIndex : fromRowIndex;\n const toIndex = toRowIndex > fromRowIndex ? toRowIndex : fromRowIndex;\n\n return [fromIndex, toIndex];\n};\n\nconst Cell = React.memo(\n function MemoedCell<TType = unknown>(context: CellContext<TType, unknown>) {\n const { texts } = useLocalization();\n const { rowIndex } = React.useContext(RowContext);\n const tableMeta = context.table.options.meta as TableMeta<TType>;\n\n const isActiveRow = tableMeta.rowActive.rowActiveIndex === rowIndex;\n const isSelected = context.row.getIsSelected();\n const title = isSelected ? texts.table3.columns.select.deselect : texts.table3.columns.select.select;\n\n const handleCheckboxClick = async (event: React.MouseEvent) => {\n event.stopPropagation();\n\n if (event.shiftKey) {\n const [fromIndex, toIndex] = toggleBetween(tableMeta.rowSelection.lastSelectedRowIndex.current ?? 0, rowIndex);\n\n const selectionRangeRows = context.table.getRowModel().rows.slice(fromIndex, toIndex + 1);\n\n // Table data loader filling-in all the rest of unloaded items with the undefined values,\n // so we can easily check if at least one of the rows in the selection range is undefined,\n // then it means that we need to call load all.\n const hasUndefinedRows = selectionRangeRows.some(row => row.original === undefined);\n\n if (hasUndefinedRows) {\n // We don't need to await and freeze UI\n await tableMeta.server?.loadAllIfNeeded?.(\n context.table.getState().sorting,\n context.table.getState().columnFilters,\n undefined\n );\n }\n\n const currentlySelected = context.table.getSelectedRowModel().rows;\n // concat currently selected with selection range and get rid of duplicates using \"Set\".\n const allSelected = [...new Set(currentlySelected.concat(selectionRangeRows))];\n // converting allSelected array into updater object: {[row.id]: true}\n const updater: RowSelectionState = allSelected.reduce((obj, row) => Object.assign(obj, { [row.id]: true }), {});\n\n context.table.setRowSelection(updater);\n } else {\n context.row.toggleSelected();\n }\n\n tableMeta.rowSelection.lastSelectedRowIndex.current = rowIndex;\n };\n\n if (context.table.options.enableMultiRowSelection) {\n return (\n <DisplayCell {...context}>\n <Tooltip\n title={\n <>\n {title}\n <Shortcut className=\"ml-2\" keys=\"Space\" />\n </>\n }>\n <Checkbox\n aria-label={title}\n className=\"!mt-0\"\n checked={isSelected}\n onClick={handleCheckboxClick}\n // this is necessary to remove console spam from eslint\n onChange={() => false}\n tabIndex={isActiveRow ? 0 : -1}\n />\n </Tooltip>\n </DisplayCell>\n );\n } else {\n const className = cn('!mt-0', getRadioClassnames());\n\n const handleClick = (event: React.MouseEvent): void => {\n event.stopPropagation();\n context.row.toggleSelected();\n tableMeta.rowSelection.lastSelectedRowIndex.current = rowIndex;\n };\n\n return (\n <DisplayCell {...context}>\n <button\n className={className}\n aria-checked={isSelected}\n onClick={handleClick}\n role=\"radio\"\n tabIndex={-1}\n type=\"button\">\n {isSelected ? <span className=\"h-2 w-2 rounded-full bg-white\" /> : null}\n </button>\n </DisplayCell>\n );\n }\n },\n function arePropsEqual(oldProps: CellContext<unknown, unknown>, newProps: CellContext<unknown, unknown>) {\n const oldTableMeta = oldProps.table.options.meta as TableMeta<unknown>;\n const newTableMeta = newProps.table.options.meta as TableMeta<unknown>;\n\n // we memo because we don't want the row re-rendering and removing focus from the checkbox\n // we can't default to the standard comparison because we need currentRow off the table meta\n // and we don't really care about re-rendering in any other scenario\n return (\n newTableMeta.rowActive.rowActiveIndex === oldTableMeta.rowActive.rowActiveIndex &&\n newProps.row.getIsSelected() !== oldProps.row.getIsSelected()\n );\n }\n) as <TType = unknown>(context: CellContext<TType, unknown>) => JSX.Element;\n\nexport function createRowSelectionColumn<TType = unknown>(\n hasDrag: boolean,\n hasExpansion: boolean\n): DisplayColumnDef<TType, unknown> {\n const size = hasDrag && hasExpansion ? 22 : 40;\n\n return {\n id: COLUMN_ID,\n header: Header,\n cell: Cell,\n footer: Footer,\n meta: {\n align: 'center',\n className: cn('!pt-[var(--table3-cell-padding-y)] !justify-end !p-0', {\n '!pr-0.5': hasExpansion,\n '!pr-3': !hasExpansion,\n }),\n enableOrdering: false,\n enableSearch: false,\n enableTruncate: false,\n header: '',\n headerClassName: cn('items-center !justify-end !p-0', { '!pr-0.5': hasExpansion, '!pr-3': !hasExpansion }),\n },\n // options\n enableResizing: false,\n size,\n minSize: size,\n };\n}\n"],"names":["COLUMN_ID","Header","context","texts","useLocalization","table","options","enableMultiRowSelection","isAllRowsSelected","getIsAllRowsSelected","isSomeRowsSelected","getIsSomeRowsSelected","title","table3","columns","select","deselectAll","selectAll","tableMeta","meta","isServerloading","server","loadAllStatus","TableServerLoadAllState","Loading","isLoadingAll","isLoadingPreviousRows","rowSelection","lastSelectedRowIndex","undefined","toggleSelectAll","_tableMeta$server","_tableMeta$server$loa","Promise","resolve","loadAllIfNeeded","call","getState","sorting","columnFilters","then","toggleAllRowsSelected","_temp","e","reject","React","ColumnHeader","Tooltip","Checkbox","className","key","String","checked","indeterminate","onChange","tabIndex","loading","toggleBetween","fromRowIndex","toRowIndex","fromIndex","toIndex","Cell","memo","MemoedCell","rowIndex","useContext","RowContext","isActiveRow","rowActive","rowActiveIndex","isSelected","row","getIsSelected","deselect","handleCheckboxClick","event","current","stopPropagation","_temp4","shiftKey","_tableMeta$rowSelecti","_temp3","currentlySelected","getSelectedRowModel","rows","allSelected","Set","concat","selectionRangeRows","updater","reduce","obj","Object","assign","id","setRowSelection","getRowModel","slice","hasUndefinedRows","some","original","_temp2","_tableMeta$server2","_tableMeta$server2$lo","toggleSelected","_temp5","DisplayCell","Shortcut","keys","onClick","cn","getRadioClassnames","handleClick","role","type","arePropsEqual","oldProps","newProps","oldTableMeta","newTableMeta","createRowSelectionColumn","hasDrag","hasExpansion","size","header","cell","footer","Footer","align","enableOrdering","enableSearch","enableTruncate","headerClassName","enableResizing","minSize"],"mappings":";;;;;;;;;;;;;MAcaA,SAAS,GAAG;AAEzB,SAASC,MAAMA,CAAkBC,OAAsC;EACnE,MAAM;IAAEC;GAAO,GAAGC,eAAe,EAAE;EAEnC,IAAIF,OAAO,CAACG,KAAK,CAACC,OAAO,CAACC,uBAAuB,EAAE;IAC/C,MAAMC,iBAAiB,GAAGN,OAAO,CAACG,KAAK,CAACI,oBAAoB,EAAE;IAC9D,MAAMC,kBAAkB,GAAGR,OAAO,CAACG,KAAK,CAACM,qBAAqB,EAAE;IAChE,MAAMC,KAAK,GAAGJ,iBAAiB,GAAGL,KAAK,CAACU,MAAM,CAACC,OAAO,CAACC,MAAM,CAACC,WAAW,GAAGb,KAAK,CAACU,MAAM,CAACC,OAAO,CAACC,MAAM,CAACE,SAAS;IACjH,MAAMC,SAAS,GAAGhB,OAAO,CAACG,KAAK,CAACC,OAAO,CAACa,IAAwB;IAChE,MAAMC,eAAe,GAAGF,SAAS,CAACG,MAAM,CAACC,aAAa,KAAKC,uBAAuB,CAACC,OAAO;IAC1F,MAAMC,YAAY,GAAGjB,iBAAiB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table3/components/toolbar/Filter/filters/Filters.js
CHANGED
@@ -10,13 +10,19 @@ import { Shortcut } from '../../../../../Shortcut/Shortcut.js';
|
|
10
10
|
import { useIsLargeScreen } from '../../../../../../hooks/useIsLargeScreen.js';
|
11
11
|
import { isInternalColumn } from '../../../../util/columns.js';
|
12
12
|
import { Table3FilterComparator } from '../../../../types.js';
|
13
|
-
import { Placeholder } from './components/Placeholder.js';
|
14
13
|
import { Filter } from './components/Filter.js';
|
15
14
|
|
16
15
|
function sortByHeader(a, b) {
|
17
16
|
var _a$columnDef$meta, _a$columnDef$meta$hea, _a$columnDef$meta$hea2, _b$columnDef$meta;
|
18
17
|
return (_a$columnDef$meta = a.columnDef.meta) === null || _a$columnDef$meta === void 0 ? void 0 : (_a$columnDef$meta$hea = _a$columnDef$meta.header) === null || _a$columnDef$meta$hea === void 0 ? void 0 : (_a$columnDef$meta$hea2 = _a$columnDef$meta$hea.localeCompare) === null || _a$columnDef$meta$hea2 === void 0 ? void 0 : _a$columnDef$meta$hea2.call(_a$columnDef$meta$hea, (_b$columnDef$meta = b.columnDef.meta) === null || _b$columnDef$meta === void 0 ? void 0 : _b$columnDef$meta.header);
|
19
18
|
}
|
19
|
+
const placeholderFilter = {
|
20
|
+
id: null,
|
21
|
+
value: {
|
22
|
+
comparator: Table3FilterComparator.Contains,
|
23
|
+
value: undefined
|
24
|
+
}
|
25
|
+
};
|
20
26
|
function FiltersButton(props) {
|
21
27
|
const {
|
22
28
|
total,
|
@@ -36,41 +42,28 @@ function FiltersButton(props) {
|
|
36
42
|
shift: true
|
37
43
|
};
|
38
44
|
// state, since we "apply" filters
|
39
|
-
const [filters, setFilters] = React__default.useState(appliedFilters);
|
40
|
-
const [placeholderCount, setPlaceholderCount] = React__default.useState(1);
|
45
|
+
const [filters, setFilters] = React__default.useState(appliedFilters.length ? appliedFilters : [placeholderFilter]);
|
41
46
|
// filters
|
42
|
-
const handleChangeFilter = (
|
47
|
+
const handleChangeFilter = (position, filter) => {
|
43
48
|
setFilters(currentFilters => {
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
49
|
+
return currentFilters.map((current, index) => {
|
50
|
+
if (index === position) {
|
51
|
+
return filter;
|
52
|
+
}
|
53
|
+
return current;
|
54
|
+
});
|
48
55
|
});
|
49
56
|
};
|
50
|
-
const handleRemoveFilter =
|
51
|
-
if (filters.length === 1
|
52
|
-
|
57
|
+
const handleRemoveFilter = position => {
|
58
|
+
if (filters.length === 1) {
|
59
|
+
setFilters([placeholderFilter]);
|
60
|
+
return;
|
53
61
|
}
|
54
|
-
setFilters(currentFilters => currentFilters.filter(
|
55
|
-
};
|
56
|
-
// placeholders
|
57
|
-
const handleCreateFilterFromPlaceholder = columnId => {
|
58
|
-
setFilters(currentFilters => [...currentFilters, {
|
59
|
-
id: columnId,
|
60
|
-
value: {
|
61
|
-
comparator: Table3FilterComparator.Contains,
|
62
|
-
value: undefined
|
63
|
-
}
|
64
|
-
}]);
|
65
|
-
handleRemovePlaceholder();
|
66
|
-
};
|
67
|
-
const handleCreatePlaceholder = () => {
|
68
|
-
setPlaceholderCount(count => count + 1);
|
62
|
+
setFilters(currentFilters => currentFilters.filter((_, index) => index !== position));
|
69
63
|
};
|
70
|
-
const
|
71
|
-
|
64
|
+
const handleCreateNew = () => {
|
65
|
+
setFilters(filters.concat(placeholderFilter));
|
72
66
|
};
|
73
|
-
//
|
74
67
|
const handleApply = () => {
|
75
68
|
table.setColumnFilters(() => {
|
76
69
|
const newFilters = filters.filter(f => {
|
@@ -90,20 +83,17 @@ function FiltersButton(props) {
|
|
90
83
|
};
|
91
84
|
const handleClear = () => {
|
92
85
|
table.resetColumnFilters();
|
93
|
-
setFilters([]);
|
94
|
-
setPlaceholderCount(1);
|
86
|
+
setFilters([placeholderFilter]);
|
95
87
|
};
|
96
88
|
const handleClose = React__default.useCallback(open => {
|
97
89
|
if (!open) {
|
98
|
-
setFilters(appliedFilters);
|
99
|
-
setPlaceholderCount(appliedFilters.length === 0 ? 1 : 0);
|
90
|
+
setFilters(appliedFilters.length === 0 ? [placeholderFilter] : appliedFilters);
|
100
91
|
}
|
101
92
|
}, [appliedFilters]);
|
102
93
|
// Because filters can be reset from outside
|
103
94
|
React__default.useEffect(() => {
|
104
95
|
if (appliedFilters.length === 0) {
|
105
|
-
setFilters([]);
|
106
|
-
setPlaceholderCount(1);
|
96
|
+
setFilters([placeholderFilter]);
|
107
97
|
}
|
108
98
|
}, [appliedFilters]);
|
109
99
|
const buttonProps = {
|
@@ -133,19 +123,12 @@ function FiltersButton(props) {
|
|
133
123
|
filters: filters,
|
134
124
|
position: index,
|
135
125
|
onChange: handleChangeFilter,
|
136
|
-
onRemove: handleRemoveFilter
|
137
|
-
}))), [...Array(placeholderCount)].map((_, index) => ( /*#__PURE__*/React__default.createElement(Placeholder, {
|
138
|
-
key: `placeholder_${index}`,
|
139
|
-
allColumns: allColumns,
|
140
|
-
filters: filters,
|
141
|
-
position: filters.length + index,
|
142
|
-
onCreate: handleCreateFilterFromPlaceholder,
|
143
|
-
onRemove: placeholderCount > 1 || filters.length > 0 ? handleRemovePlaceholder : undefined
|
126
|
+
onRemove: filters.length > 0 && filters.some(f => f.id) || filters.length > 1 ? handleRemoveFilter : undefined
|
144
127
|
}))), /*#__PURE__*/React__default.createElement("div", {
|
145
128
|
className: "justify-start"
|
146
129
|
}, /*#__PURE__*/React__default.createElement(Button, {
|
147
130
|
appearance: "discrete",
|
148
|
-
onClick:
|
131
|
+
onClick: handleCreateNew
|
149
132
|
}, "+ ", texts.table3.filters.buttons.addFilter))), /*#__PURE__*/React__default.createElement(Group, {
|
150
133
|
className: "ml-auto"
|
151
134
|
}, /*#__PURE__*/React__default.createElement(Popover.Close, null, /*#__PURE__*/React__default.createElement(Button, null, "Cancel")), /*#__PURE__*/React__default.createElement(Button, {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Filters.js","sources":["../../../../../../../../../../../src/components/Table3/components/toolbar/Filter/filters/Filters.tsx"],"sourcesContent":["import React from 'react';\nimport cn from 'clsx';\nimport { Table as RTable, Column as RTColumn } from '@tanstack/react-table';\nimport { Button } from '../../../../../Button/Button';\nimport { Icon } from '../../../../../Icon/Icon';\nimport { Popover } from '../../../../../Popover/Popover';\nimport { Table3FilterValue, Table3FilterComparator, Table3Filter, ColumnFilter } from '../../../../types';\nimport { Shortcut } from '../../../../../Shortcut/Shortcut';\nimport { useLocalization } from '../../../../../Provider/Localization';\nimport { isInternalColumn } from '../../../../util/columns';\nimport { Placeholder } from './components/Placeholder';\nimport { Filter } from './components/Filter';\nimport { Group } from '../../../../../Group/Group';\nimport { useIsLargeScreen } from '../../../../../../hooks/useIsLargeScreen';\nimport { IconButton } from '../../../../../IconButton/IconButton';\n\nfunction sortByHeader<TType = unknown>(a: RTColumn<TType>, b: RTColumn<TType>) {\n return (a.columnDef.meta?.header as string)?.localeCompare?.(b.columnDef.meta?.header as string);\n}\n\nexport type FiltersProps<TType = unknown> = {\n total: number;\n table: RTable<TType>;\n};\n\nexport function FiltersButton<TType = unknown>(props: FiltersProps<TType>) {\n const { total, table } = props;\n const { locale, texts } = useLocalization();\n const ref = React.useRef<HTMLButtonElement>(null);\n const isLargeScreen = useIsLargeScreen();\n const allColumns = table\n .getAllLeafColumns()\n .filter(column => !isInternalColumn(column.id))\n .sort(sortByHeader);\n const appliedFilters = table.getState().columnFilters as Table3Filter[];\n\n const shortcut = { key: 'f', meta: true, shift: true };\n\n // state, since we \"apply\" filters\n const [filters, setFilters] = React.useState<Table3Filter[]>(appliedFilters);\n const [placeholderCount, setPlaceholderCount] = React.useState(1);\n\n // filters\n const handleChangeFilter = (currentId: string | null, filter: { id: string | null; value: Table3FilterValue }) => {\n setFilters(currentFilters => {\n const nextFilters = [...currentFilters];\n const index = nextFilters.findIndex(f => f.id === currentId);\n nextFilters[index] = filter;\n return nextFilters;\n });\n };\n\n const handleRemoveFilter = (columnId: string | null) => {\n if (filters.length === 1 && placeholderCount === 0) {\n setPlaceholderCount(count => count + 1);\n }\n\n setFilters(currentFilters => currentFilters.filter(f => f.id !== columnId));\n };\n\n // placeholders\n const handleCreateFilterFromPlaceholder = (columnId: string) => {\n setFilters(currentFilters => [\n ...currentFilters,\n {\n id: columnId,\n value: {\n comparator: Table3FilterComparator.Contains,\n value: undefined,\n },\n },\n ]);\n handleRemovePlaceholder();\n };\n\n const handleCreatePlaceholder = () => {\n setPlaceholderCount(count => count + 1);\n };\n\n const handleRemovePlaceholder = () => {\n setPlaceholderCount(count => count - 1);\n };\n\n //\n const handleApply = () => {\n table.setColumnFilters(() => {\n const newFilters = filters.filter(f => {\n if (f.id === null) {\n return false;\n }\n\n const controlRenderer = (allColumns.find(c => c.id === f.id) as RTColumn<TType, unknown>)?.columnDef.meta\n ?.control;\n if (\n f.value.comparator === Table3FilterComparator.IsEmpty ||\n f.value.comparator === Table3FilterComparator.IsNotEmpty ||\n controlRenderer === 'switch'\n ) {\n return true;\n }\n return !!f.value.value;\n });\n // Compiler didn't get that we stripped out filters with null ids, so we still need to cast a ColumnFilter type here\n return newFilters as ColumnFilter[];\n });\n };\n\n const handleClear = () => {\n table.resetColumnFilters();\n setFilters([]);\n setPlaceholderCount(1);\n };\n\n const handleClose = React.useCallback(\n (open: boolean) => {\n if (!open) {\n setFilters(appliedFilters);\n setPlaceholderCount(appliedFilters.length === 0 ? 1 : 0);\n }\n },\n [appliedFilters]\n );\n\n // Because filters can be reset from outside\n React.useEffect(() => {\n if (appliedFilters.length === 0) {\n setFilters([]);\n setPlaceholderCount(1);\n }\n }, [appliedFilters]);\n\n const buttonProps = {\n 'aria-label': texts.table3.filters.tooltip,\n className: cn({ '!wcag-blue-100': appliedFilters.length }),\n shortcut,\n popover: popoverProps => (\n <Popover {...popoverProps} onChange={handleClose}>\n <Popover.Content>\n <div className=\"flex w-[40rem] flex-col gap-4\">\n <div className=\"flex h-8\">\n <div className=\"flex w-full items-center gap-2\">\n <h4 className=\"mb-0 inline-flex\">{texts.table3.filters.button}</h4>\n <p className=\"text-grey-700 mb-0 mr-auto mt-px inline-flex\">\n {texts.table3.filters.total\n .replace(\n '[CURRENT]',\n new Intl.NumberFormat(locale).format(table.getFilteredRowModel().rows.length)\n )\n .replace('[TOTAL]', new Intl.NumberFormat(locale).format(total))}\n </p>\n </div>\n </div>\n <div className=\"flex flex-col gap-2\">\n {filters.map((filter, index) => (\n <Filter\n key={`filter_${index}`}\n allColumns={allColumns as RTColumn<unknown, unknown>[]}\n filter={filter}\n filters={filters}\n position={index}\n onChange={handleChangeFilter}\n onRemove={handleRemoveFilter}\n />\n ))}\n {[...Array(placeholderCount)].map((_, index) => (\n <Placeholder\n key={`placeholder_${index}`}\n allColumns={allColumns as RTColumn<unknown, unknown>[]}\n filters={filters}\n position={filters.length + index}\n onCreate={handleCreateFilterFromPlaceholder as any}\n onRemove={placeholderCount > 1 || filters.length > 0 ? handleRemovePlaceholder : undefined}\n />\n ))}\n <div className=\"justify-start\">\n <Button appearance=\"discrete\" onClick={handleCreatePlaceholder}>\n + {texts.table3.filters.buttons.addFilter}\n </Button>\n </div>\n </div>\n <Group className=\"ml-auto\">\n <Popover.Close>\n <Button>Cancel</Button>\n </Popover.Close>\n <Button onClick={handleClear}>Clear</Button>\n <Button appearance=\"primary\" onClick={handleApply}>\n Apply\n </Button>\n </Group>\n </div>\n </Popover.Content>\n </Popover>\n ),\n ref,\n tooltip: (\n <>\n {texts.table3.filters.tooltip}\n <Shortcut className=\"ml-2\" keys={{ key: 'f', meta: true, shift: true }} />\n </>\n ),\n };\n\n if (!isLargeScreen && !appliedFilters.length) {\n return <IconButton {...buttonProps} icon=\"filter\" />;\n }\n return (\n <Button {...buttonProps}>\n <Icon className={cn({ '-mr-1.5': !isLargeScreen })} name={appliedFilters.length ? 'filter-solid' : 'filter'} />\n {isLargeScreen ? texts.table3.filters.button : ''}\n {appliedFilters.length ? `(${appliedFilters.length})` : ''}\n </Button>\n );\n}\n"],"names":["sortByHeader","a","b","_a$columnDef$meta","columnDef","meta","_a$columnDef$meta$hea","header","_a$columnDef$meta$hea2","localeCompare","call","_b$columnDef$meta","FiltersButton","props","total","table","locale","texts","useLocalization","ref","React","useRef","isLargeScreen","useIsLargeScreen","allColumns","getAllLeafColumns","filter","column","isInternalColumn","id","sort","appliedFilters","getState","columnFilters","shortcut","key","shift","filters","setFilters","useState","placeholderCount","setPlaceholderCount","handleChangeFilter","currentId","currentFilters","nextFilters","index","findIndex","f","handleRemoveFilter","columnId","length","count","handleCreateFilterFromPlaceholder","value","comparator","Table3FilterComparator","Contains","undefined","handleRemovePlaceholder","handleCreatePlaceholder","handleApply","setColumnFilters","newFilters","controlRenderer","_allColumns$find","find","c","_allColumns$find$colu","control","IsEmpty","IsNotEmpty","handleClear","resetColumnFilters","handleClose","useCallback","open","useEffect","buttonProps","table3","tooltip","className","cn","popover","popoverProps","Popover","onChange","Content","button","replace","Intl","NumberFormat","format","getFilteredRowModel","rows","map","Filter","position","onRemove","Array","_","Placeholder","onCreate","Button","appearance","onClick","buttons","addFilter","Group","Close","Shortcut","keys","IconButton","icon","Icon","name"],"mappings":";;;;;;;;;;;;;;;AAgBA,SAASA,YAAYA,CAAkBC,CAAkB,EAAEC,CAAkB;;EACzE,QAAAC,iBAAA,GAAQF,CAAC,CAACG,SAAS,CAACC,IAAI,cAAAF,iBAAA,wBAAAG,qBAAA,GAAhBH,iBAAA,CAAkBI,MAAiB,cAAAD,qBAAA,wBAAAE,sBAAA,GAAnCF,qBAAA,CAAqCG,aAAa,cAAAD,sBAAA,uBAAlDA,sBAAA,CAAAE,IAAA,CAAAJ,qBAAA,GAAAK,iBAAA,GAAqDT,CAAC,CAACE,SAAS,CAACC,IAAI,cAAAM,iBAAA,uBAAhBA,iBAAA,CAAkBJ,MAAgB,CAAC;AACpG;SAOgBK,aAAaA,CAAkBC,KAA0B;EACrE,MAAM;IAAEC,KAAK;IAAEC;GAAO,GAAGF,KAAK;EAC9B,MAAM;IAAEG,MAAM;IAAEC;GAAO,GAAGC,eAAe,EAAE;EAC3C,MAAMC,GAAG,GAAGC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nF,6BAACmF,MAAM;MAACE,OAAO,EAAEjC;eAA2B,eAC5CpD,6BAACmF,MAAM;MAACC,UAAU,EAAC,SAAS;MAACC,OAAO,EAAE5C;eAE7B,CACL,CACN,CACQ,CACZ,CACb;IACD1C,GAAG;IACH6D,OAAO,iBACH5D,4DACKH,KAAK,CAAC8D,MAAM,CAAC1C,OAAO,CAAC2C,OAAO,eAC7B5D,6BAAC0F,QAAQ;MAAC7B,SAAS,EAAC,MAAM;MAAC8B,IAAI,EAAE;QAAE5E,GAAG,EAAE,GAAG;QAAE9B,IAAI,EAAE,IAAI;QAAE+B,KAAK,EAAE;;MAAU,CAC3E;GAEV;EAED,IAAI,CAACd,aAAa,IAAI,CAACS,cAAc,CAACoB,MAAM,EAAE;IAC1C,oBAAO/B,6BAAC4F,UAAU,oBAAKlC,WAAW;MAAEmC,IAAI,EAAC;OAAW;;EAExD,oBACI7F,6BAACmF,MAAM,oBAAKzB,WAAW,gBACnB1D,6BAAC8F,IAAI;IAACjC,SAAS,EAAEC,EAAE,CAAC;MAAE,SAAS,EAAE,CAAC5D;KAAe,CAAC;IAAE6F,IAAI,EAAEpF,cAAc,CAACoB,MAAM,GAAG,cAAc,GAAG;IAAY,EAC9G7B,aAAa,GAAGL,KAAK,CAAC8D,MAAM,CAAC1C,OAAO,CAACmD,MAAM,GAAG,EAAE,EAChDzD,cAAc,CAACoB,MAAM,OAAOpB,cAAc,CAACoB,SAAS,GAAG,EAAE,CACrD;AAEjB;;;;"}
|
1
|
+
{"version":3,"file":"Filters.js","sources":["../../../../../../../../../../../src/components/Table3/components/toolbar/Filter/filters/Filters.tsx"],"sourcesContent":["import React from 'react';\nimport cn from 'clsx';\nimport { Table as RTable, Column as RTColumn } from '@tanstack/react-table';\nimport { Button } from '../../../../../Button/Button';\nimport { Icon } from '../../../../../Icon/Icon';\nimport { Popover } from '../../../../../Popover/Popover';\nimport { Table3FilterValue, Table3FilterComparator, Table3Filter, ColumnFilter } from '../../../../types';\nimport { Shortcut } from '../../../../../Shortcut/Shortcut';\nimport { useLocalization } from '../../../../../Provider/Localization';\nimport { isInternalColumn } from '../../../../util/columns';\nimport { Filter } from './components/Filter';\nimport { Group } from '../../../../../Group/Group';\nimport { useIsLargeScreen } from '../../../../../../hooks/useIsLargeScreen';\nimport { IconButton } from '../../../../../IconButton/IconButton';\n\nfunction sortByHeader<TType = unknown>(a: RTColumn<TType>, b: RTColumn<TType>) {\n return (a.columnDef.meta?.header as string)?.localeCompare?.(b.columnDef.meta?.header as string);\n}\n\nexport type FiltersProps<TType = unknown> = {\n total: number;\n table: RTable<TType>;\n};\n\nconst placeholderFilter: Table3Filter = { id: null, value: { comparator: Table3FilterComparator.Contains, value: undefined } };\n\nexport function FiltersButton<TType = unknown>(props: FiltersProps<TType>) {\n const { total, table } = props;\n const { locale, texts } = useLocalization();\n const ref = React.useRef<HTMLButtonElement>(null);\n const isLargeScreen = useIsLargeScreen();\n const allColumns = table\n .getAllLeafColumns()\n .filter(column => !isInternalColumn(column.id))\n .sort(sortByHeader);\n\n const appliedFilters = table.getState().columnFilters as Table3Filter[];\n const shortcut = { key: 'f', meta: true, shift: true };\n\n // state, since we \"apply\" filters\n const [filters, setFilters] = React.useState<Table3Filter[]>(appliedFilters.length ? appliedFilters : [placeholderFilter]);\n\n // filters\n const handleChangeFilter = (position: number, filter: { id: string | null; value: Table3FilterValue }) => {\n setFilters(currentFilters => {\n return currentFilters.map((current, index) => {\n if (index === position) {\n return filter;\n }\n return current;\n });\n });\n };\n\n const handleRemoveFilter = position => {\n if (filters.length === 1) {\n setFilters([placeholderFilter]);\n return;\n }\n\n setFilters(currentFilters => currentFilters.filter((_, index) => index !== position));\n };\n\n const handleCreateNew = () => {\n setFilters(filters.concat(placeholderFilter));\n };\n\n const handleApply = () => {\n table.setColumnFilters(() => {\n const newFilters = filters.filter(f => {\n if (f.id === null) {\n return false;\n }\n\n const controlRenderer = (allColumns.find(c => c.id === f.id) as RTColumn<TType, unknown>)?.columnDef.meta\n ?.control;\n if (\n f.value.comparator === Table3FilterComparator.IsEmpty ||\n f.value.comparator === Table3FilterComparator.IsNotEmpty ||\n controlRenderer === 'switch'\n ) {\n return true;\n }\n return !!f.value.value;\n });\n // Compiler didn't get that we stripped out filters with null ids, so we still need to cast a ColumnFilter type here\n return newFilters as ColumnFilter[];\n });\n };\n\n const handleClear = () => {\n table.resetColumnFilters();\n setFilters([placeholderFilter]);\n };\n\n const handleClose = React.useCallback(\n (open: boolean) => {\n if (!open) {\n setFilters(appliedFilters.length === 0 ? [placeholderFilter] : appliedFilters);\n }\n },\n [appliedFilters]\n );\n\n // Because filters can be reset from outside\n React.useEffect(() => {\n if (appliedFilters.length === 0) {\n setFilters([placeholderFilter]);\n }\n }, [appliedFilters]);\n\n const buttonProps = {\n 'aria-label': texts.table3.filters.tooltip,\n className: cn({ '!wcag-blue-100': appliedFilters.length }),\n shortcut,\n popover: popoverProps => (\n <Popover {...popoverProps} onChange={handleClose}>\n <Popover.Content>\n <div className=\"flex w-[40rem] flex-col gap-4\">\n <div className=\"flex h-8\">\n <div className=\"flex w-full items-center gap-2\">\n <h4 className=\"mb-0 inline-flex\">{texts.table3.filters.button}</h4>\n <p className=\"text-grey-700 mb-0 mr-auto mt-px inline-flex\">\n {texts.table3.filters.total\n .replace(\n '[CURRENT]',\n new Intl.NumberFormat(locale).format(table.getFilteredRowModel().rows.length)\n )\n .replace('[TOTAL]', new Intl.NumberFormat(locale).format(total))}\n </p>\n </div>\n </div>\n <div className=\"flex flex-col gap-2\">\n {filters.map((filter, index) => (\n <Filter\n key={`filter_${index}`}\n allColumns={allColumns}\n filter={filter}\n filters={filters}\n position={index}\n onChange={handleChangeFilter}\n onRemove={\n (filters.length > 0 && filters.some(f => f.id)) || filters.length > 1\n ? handleRemoveFilter\n : undefined\n }\n />\n ))}\n <div className=\"justify-start\">\n <Button appearance=\"discrete\" onClick={handleCreateNew}>\n + {texts.table3.filters.buttons.addFilter}\n </Button>\n </div>\n </div>\n <Group className=\"ml-auto\">\n <Popover.Close>\n <Button>Cancel</Button>\n </Popover.Close>\n <Button onClick={handleClear}>Clear</Button>\n <Button appearance=\"primary\" onClick={handleApply}>\n Apply\n </Button>\n </Group>\n </div>\n </Popover.Content>\n </Popover>\n ),\n ref,\n tooltip: (\n <>\n {texts.table3.filters.tooltip}\n <Shortcut className=\"ml-2\" keys={{ key: 'f', meta: true, shift: true }} />\n </>\n ),\n };\n\n if (!isLargeScreen && !appliedFilters.length) {\n return <IconButton {...buttonProps} icon=\"filter\" />;\n }\n return (\n <Button {...buttonProps}>\n <Icon className={cn({ '-mr-1.5': !isLargeScreen })} name={appliedFilters.length ? 'filter-solid' : 'filter'} />\n {isLargeScreen ? texts.table3.filters.button : ''}\n {appliedFilters.length ? `(${appliedFilters.length})` : ''}\n </Button>\n );\n}\n"],"names":["sortByHeader","a","b","_a$columnDef$meta","columnDef","meta","_a$columnDef$meta$hea","header","_a$columnDef$meta$hea2","localeCompare","call","_b$columnDef$meta","placeholderFilter","id","value","comparator","Table3FilterComparator","Contains","undefined","FiltersButton","props","total","table","locale","texts","useLocalization","ref","React","useRef","isLargeScreen","useIsLargeScreen","allColumns","getAllLeafColumns","filter","column","isInternalColumn","sort","appliedFilters","getState","columnFilters","shortcut","key","shift","filters","setFilters","useState","length","handleChangeFilter","position","currentFilters","map","current","index","handleRemoveFilter","_","handleCreateNew","concat","handleApply","setColumnFilters","newFilters","f","controlRenderer","_allColumns$find","find","c","_allColumns$find$colu","control","IsEmpty","IsNotEmpty","handleClear","resetColumnFilters","handleClose","useCallback","open","useEffect","buttonProps","table3","tooltip","className","cn","popover","popoverProps","Popover","onChange","Content","button","replace","Intl","NumberFormat","format","getFilteredRowModel","rows","Filter","onRemove","some","Button","appearance","onClick","buttons","addFilter","Group","Close","Shortcut","keys","IconButton","icon","Icon","name"],"mappings":";;;;;;;;;;;;;;AAeA,SAASA,YAAYA,CAAkBC,CAAkB,EAAEC,CAAkB;;EACzE,QAAAC,iBAAA,GAAQF,CAAC,CAACG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,KAAK,CAACoD,MAAM,CAACjC,OAAO,CAACkC,OAAO,eAC7BlD,6BAAC2E,QAAQ;MAACxB,SAAS,EAAC,MAAM;MAACyB,IAAI,EAAE;QAAE9D,GAAG,EAAE,GAAG;QAAEpC,IAAI,EAAE,IAAI;QAAEqC,KAAK,EAAE;;MAAU,CAC3E;GAEV;EAED,IAAI,CAACb,aAAa,IAAI,CAACQ,cAAc,CAACS,MAAM,EAAE;IAC1C,oBAAOnB,6BAAC6E,UAAU,oBAAK7B,WAAW;MAAE8B,IAAI,EAAC;OAAW;;EAExD,oBACI9E,6BAACoE,MAAM,oBAAKpB,WAAW,gBACnBhD,6BAAC+E,IAAI;IAAC5B,SAAS,EAAEC,EAAE,CAAC;MAAE,SAAS,EAAE,CAAClD;KAAe,CAAC;IAAE8E,IAAI,EAAEtE,cAAc,CAACS,MAAM,GAAG,cAAc,GAAG;IAAY,EAC9GjB,aAAa,GAAGL,KAAK,CAACoD,MAAM,CAACjC,OAAO,CAAC0C,MAAM,GAAG,EAAE,EAChDhD,cAAc,CAACS,MAAM,OAAOT,cAAc,CAACS,SAAS,GAAG,EAAE,CACrD;AAEjB;;;;"}
|
@@ -19,6 +19,7 @@ function Filter(props) {
|
|
19
19
|
texts
|
20
20
|
} = useLocalization();
|
21
21
|
const column = allColumns.find(c => c.id === filter.id);
|
22
|
+
const ref = React__default.useRef(null);
|
22
23
|
const {
|
23
24
|
id,
|
24
25
|
value: {
|
@@ -37,7 +38,7 @@ function Filter(props) {
|
|
37
38
|
comparator: null,
|
38
39
|
value: null
|
39
40
|
};
|
40
|
-
handleChange(
|
41
|
+
handleChange(position, {
|
41
42
|
id: columnId,
|
42
43
|
value
|
43
44
|
});
|
@@ -47,7 +48,7 @@ function Filter(props) {
|
|
47
48
|
if (comparator === Table3FilterComparator.IsEmpty || comparator === Table3FilterComparator.IsNotEmpty) {
|
48
49
|
nextValue = undefined;
|
49
50
|
}
|
50
|
-
handleChange(
|
51
|
+
handleChange(position, {
|
51
52
|
id,
|
52
53
|
value: {
|
53
54
|
comparator,
|
@@ -56,7 +57,7 @@ function Filter(props) {
|
|
56
57
|
});
|
57
58
|
};
|
58
59
|
const handleChangeValue = value => {
|
59
|
-
handleChange(
|
60
|
+
handleChange(position, {
|
60
61
|
id,
|
61
62
|
value: {
|
62
63
|
...filter.value,
|
@@ -64,7 +65,12 @@ function Filter(props) {
|
|
64
65
|
}
|
65
66
|
});
|
66
67
|
};
|
67
|
-
const handleRemove = () => onRemove(
|
68
|
+
const handleRemove = () => onRemove === null || onRemove === void 0 ? void 0 : onRemove(position);
|
69
|
+
React__default.useEffect(() => {
|
70
|
+
if (ref.current && !id) {
|
71
|
+
ref.current.focus(); // after adding a new filter placeholder, we want to focus it right way.
|
72
|
+
}
|
73
|
+
}, [id]);
|
68
74
|
return /*#__PURE__*/React__default.createElement("div", {
|
69
75
|
className: "flex items-start gap-2"
|
70
76
|
}, /*#__PURE__*/React__default.createElement("div", {
|
@@ -73,7 +79,8 @@ function Filter(props) {
|
|
73
79
|
allColumns: allColumns,
|
74
80
|
filters: filters,
|
75
81
|
onChange: handleChangeColumn,
|
76
|
-
value: id
|
82
|
+
value: id,
|
83
|
+
ref: ref
|
77
84
|
}), /*#__PURE__*/React__default.createElement(FilterComparator, {
|
78
85
|
column: column,
|
79
86
|
onChange: handleChangeComparator,
|
@@ -83,12 +90,12 @@ function Filter(props) {
|
|
83
90
|
comparator: comparator,
|
84
91
|
onChange: handleChangeValue,
|
85
92
|
value: value
|
86
|
-
}), /*#__PURE__*/React__default.createElement(IconButton, {
|
93
|
+
}), onRemove ? /*#__PURE__*/React__default.createElement(IconButton, {
|
87
94
|
appearance: "discrete",
|
88
95
|
className: "ml-auto",
|
89
96
|
icon: "close",
|
90
97
|
onClick: handleRemove
|
91
|
-
}));
|
98
|
+
}) : null);
|
92
99
|
}
|
93
100
|
|
94
101
|
export { Filter };
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Filter.js","sources":["../../../../../../../../../../../../src/components/Table3/components/toolbar/Filter/filters/components/Filter.tsx"],"sourcesContent":["import React from 'react';\nimport { Column as RTColumn } from '@tanstack/react-table';\nimport { IconButton } from '../../../../../../IconButton/IconButton';\nimport { Table3Filter, Table3FilterComparator } from '../../../../../types';\nimport { useLocalization } from '../../../../../../Provider/Localization';\nimport { FilterColumn } from './FilterColumn';\nimport { FilterComparator } from './FilterComparator';\nimport { FilterValue } from './FilterValue';\n\nexport type FilterProps<TType = unknown> = {\n allColumns: RTColumn<TType, unknown>[];\n filter: Table3Filter;\n filters: Table3Filter[];\n position: number;\n onChange: (
|
1
|
+
{"version":3,"file":"Filter.js","sources":["../../../../../../../../../../../../src/components/Table3/components/toolbar/Filter/filters/components/Filter.tsx"],"sourcesContent":["import React from 'react';\nimport { Column as RTColumn } from '@tanstack/react-table';\nimport { IconButton } from '../../../../../../IconButton/IconButton';\nimport { Table3Filter, Table3FilterComparator } from '../../../../../types';\nimport { useLocalization } from '../../../../../../Provider/Localization';\nimport { FilterColumn } from './FilterColumn';\nimport { FilterComparator } from './FilterComparator';\nimport { FilterValue } from './FilterValue';\n\nexport type FilterProps<TType = unknown> = {\n allColumns: RTColumn<TType, unknown>[];\n filter: Table3Filter;\n filters: Table3Filter[];\n position: number;\n onChange: (position: number, value: Table3Filter) => void;\n onRemove?: (position: number) => void;\n};\n\nexport function Filter<TType = unknown>(props: FilterProps<TType>) {\n const { allColumns, filter, filters, onChange: handleChange, onRemove, position } = props;\n const { texts } = useLocalization();\n const column = allColumns.find(c => c.id === filter.id) as RTColumn<TType, unknown>;\n const ref = React.useRef<HTMLButtonElement>(null);\n\n const {\n id,\n value: { comparator, value },\n } = filter;\n\n const handleChangeColumn = (columnId: string | null) => {\n const columnPrev = allColumns.find(column => column.id === id);\n const columnNext = allColumns.find(column => column.id === columnId);\n // UX requirement: if old column data type is the same as next column data type,\n // then we applying the same filter value for the next column,\n // but when data types are different, we're reseting comparator ans value for the next column\n const value =\n columnPrev?.columnDef.meta?.dataType === columnNext?.columnDef.meta?.dataType\n ? filter.value\n : { comparator: null, value: null };\n\n handleChange(position, { id: columnId, value });\n };\n\n const handleChangeComparator = (comparator: Table3FilterComparator) => {\n let nextValue = filter.value.value;\n\n if (comparator === Table3FilterComparator.IsEmpty || comparator === Table3FilterComparator.IsNotEmpty) {\n nextValue = undefined;\n }\n handleChange(position, { id, value: { comparator, value: nextValue } });\n };\n\n const handleChangeValue = (value: any) => {\n handleChange(position, { id, value: { ...filter.value, value } });\n };\n\n const handleRemove = () => onRemove?.(position);\n\n React.useEffect(() => {\n if (ref.current && !id) {\n ref.current.focus(); // after adding a new filter placeholder, we want to focus it right way.\n }\n }, [id]);\n\n return (\n <div className=\"flex items-start gap-2\">\n <div className=\"flex min-h-[theme(spacing.8)] w-14 flex-shrink-0 items-center justify-end pr-2 text-right\">\n {position > 0 ? texts.table3.filters.conditions.and : texts.table3.filters.conditions.where}\n </div>\n <FilterColumn\n allColumns={allColumns as any}\n filters={filters}\n onChange={handleChangeColumn as any}\n value={id}\n ref={ref}\n />\n <FilterComparator column={column} onChange={handleChangeComparator as any} value={comparator} />\n <FilterValue column={column} comparator={comparator} onChange={handleChangeValue} value={value} />\n {onRemove ? <IconButton appearance=\"discrete\" className=\"ml-auto\" icon=\"close\" onClick={handleRemove} /> : null}\n </div>\n );\n}\n"],"names":["Filter","props","allColumns","filter","filters","onChange","handleChange","onRemove","position","texts","useLocalization","column","find","c","id","ref","React","useRef","value","comparator","handleChangeColumn","columnId","columnPrev","columnNext","_columnPrev$columnDef","columnDef","meta","dataType","_columnNext$columnDef","handleChangeComparator","nextValue","Table3FilterComparator","IsEmpty","IsNotEmpty","undefined","handleChangeValue","handleRemove","useEffect","current","focus","className","table3","conditions","and","where","FilterColumn","FilterComparator","FilterValue","IconButton","appearance","icon","onClick"],"mappings":";;;;;;;;SAkBgBA,MAAMA,CAAkBC,KAAyB;EAC7D,MAAM;IAAEC,UAAU;IAAEC,MAAM;IAAEC,OAAO;IAAEC,QAAQ,EAAE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Q,gBAAGS,6BAACgC,UAAU;IAACC,UAAU,EAAC,UAAU;IAACT,SAAS,EAAC,SAAS;IAACU,IAAI,EAAC,OAAO;IAACC,OAAO,EAAEf;IAAgB,GAAG,IAAI,CAC7G;AAEd;;;;"}
|
@@ -5,7 +5,7 @@ import { useLocalization } from '../../../../../../Provider/Localization.js';
|
|
5
5
|
import { Field } from '../../../../../../Field/Field.js';
|
6
6
|
import { Select2 } from '../../../../../../Select2/Select2.js';
|
7
7
|
|
8
|
-
|
8
|
+
const FilterColumn = /*#__PURE__*/React__default.forwardRef((props, ref) => {
|
9
9
|
const {
|
10
10
|
allColumns,
|
11
11
|
filters,
|
@@ -25,7 +25,8 @@ function FilterColumn(props) {
|
|
25
25
|
warning: warning,
|
26
26
|
className: "min-h-[theme(spacing.8)]"
|
27
27
|
}, /*#__PURE__*/React__default.createElement(Select2, Object.assign({}, attributes, {
|
28
|
-
|
28
|
+
ref: ref,
|
29
|
+
className: "focus:yt-focus !w-32 flex-shrink-0",
|
29
30
|
emptyValue: null,
|
30
31
|
onChange: handleChange,
|
31
32
|
value: value
|
@@ -43,7 +44,7 @@ function FilterColumn(props) {
|
|
43
44
|
disabled: column.id !== value && (!column.getCanFilter() || !!filters.find(f => f.id === column.id))
|
44
45
|
}, ((_column$columnDef$met = column.columnDef.meta) === null || _column$columnDef$met === void 0 ? void 0 : _column$columnDef$met.header) + (column.parent ? ` (${(_column$parent = column.parent) === null || _column$parent === void 0 ? void 0 : (_column$parent$column = _column$parent.columnDef.meta) === null || _column$parent$column === void 0 ? void 0 : _column$parent$column.header})` : ''));
|
45
46
|
}))));
|
46
|
-
}
|
47
|
+
});
|
47
48
|
|
48
49
|
export { FilterColumn };
|
49
50
|
//# sourceMappingURL=FilterColumn.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"FilterColumn.js","sources":["../../../../../../../../../../../../src/components/Table3/components/toolbar/Filter/filters/components/FilterColumn.tsx"],"sourcesContent":["import React from 'react';\nimport { Column as RTColumn } from '@tanstack/react-table';\nimport { Select2, Select2Props } from '../../../../../../Select2/Select2';\nimport { Icon } from '../../../../../../Icon/Icon';\nimport { Tooltip } from '../../../../../../Tooltip/Tooltip';\nimport { useLocalization } from '../../../../../../Provider/Localization';\nimport { Field } from '../../../../../../Field/Field';\nimport { Table3Filter } from '../../../../../types';\n\nexport type FilterColumnProps<TType = unknown> = Omit<Select2Props, 'children'> & {\n allColumns: RTColumn<TType, unknown>[];\n filters: Table3Filter[];\n};\n\nexport
|
1
|
+
{"version":3,"file":"FilterColumn.js","sources":["../../../../../../../../../../../../src/components/Table3/components/toolbar/Filter/filters/components/FilterColumn.tsx"],"sourcesContent":["import React from 'react';\nimport { Column as RTColumn } from '@tanstack/react-table';\nimport { Select2, Select2Props } from '../../../../../../Select2/Select2';\nimport { Icon } from '../../../../../../Icon/Icon';\nimport { Tooltip } from '../../../../../../Tooltip/Tooltip';\nimport { useLocalization } from '../../../../../../Provider/Localization';\nimport { Field } from '../../../../../../Field/Field';\nimport { Table3Filter } from '../../../../../types';\n\nexport type FilterColumnProps<TType = unknown> = Omit<Select2Props, 'children'> & {\n allColumns: RTColumn<TType, unknown>[];\n filters: Table3Filter[];\n};\n\nexport const FilterColumn = React.forwardRef<HTMLButtonElement, FilterColumnProps>((props, ref) => {\n const { allColumns, filters, onChange: handleChange, value = null, ...attributes } = props;\n const { texts } = useLocalization();\n const selectedColumn = allColumns.find(column => column.id === value);\n const warning = selectedColumn && !selectedColumn.getIsVisible();\n\n return (\n <div className=\"flex flex-col\">\n <Field\n message={warning ? texts.table3.filters.hiddenColumn : undefined}\n warning={warning}\n className=\"min-h-[theme(spacing.8)]\">\n <Select2\n {...attributes}\n ref={ref}\n className=\"focus:yt-focus !w-32 flex-shrink-0\"\n emptyValue={null}\n onChange={handleChange}\n value={value}>\n {allColumns.map(column => (\n <Select2.Option\n key={column.id}\n value={column.id}\n postfix={\n !column.getIsVisible() ? (\n <Tooltip title={texts.table3.filters.hiddenColumn}>\n <Icon name=\"eye-off\" className=\"text-grey-500 !h-5 !w-5\" />\n </Tooltip>\n ) : undefined\n }\n disabled={column.id !== value && (!column.getCanFilter() || !!filters.find(f => f.id === column.id))}>\n {(column.columnDef.meta?.header as string) +\n (column.parent ? ` (${column.parent?.columnDef.meta?.header})` : '')}\n </Select2.Option>\n ))}\n </Select2>\n </Field>\n </div>\n );\n});\n"],"names":["FilterColumn","React","forwardRef","props","ref","allColumns","filters","onChange","handleChange","value","attributes","texts","useLocalization","selectedColumn","find","column","id","warning","getIsVisible","className","Field","message","table3","hiddenColumn","undefined","Select2","emptyValue","map","_column$columnDef$met","_column$parent","_column$parent$column","Option","key","postfix","Tooltip","title","Icon","name","disabled","getCanFilter","f","columnDef","meta","header","parent"],"mappings":";;;;;;;MAcaA,YAAY,gBAAGC,cAAK,CAACC,UAAU,CAAuC,CAACC,KAAK,EAAEC,GAAG;EAC1F,MAAM;IAAEC,UAAU;IAAEC,OAAO;IAAEC,QAAQ,EAAEC,YAAY;IAAEC,KAAK,GAAG,IAAI;IAAE,GAAGC;GAAY,GAAGP,KAAK;EAC1F,MAAM;IAAEQ;GAAO,GAAGC,eAAe,EAAE;EACnC,MAAMC,cAAc,GAAGR,UAAU,CAACS,IAAI,CAACC,MAAM,IAAIA,MAAM,CAACC,EAAE,KAAKP,KAAK,CAAC;EACrE,MAAMQ,OAAO,GAAGJ,cAAc,IAAI,CAACA,cAAc,CAACK,YAAY,EAAE;EAEhE,oBACIjB;IAAKkB,SAAS,EAAC;kBACXlB,6BAACmB,KAAK;IACFC,OAAO,EAAEJ,OAAO,GAAGN,KAAK,CAACW,MAAM,CAAChB,OAAO,CAACiB,YAAY,GAAGC,SAAS;IAChEP,OAAO,EAAEA,OAAO;IAChBE,SAAS,EAAC;kBACVlB,6BAACwB,OAAO,oBACAf,UAAU;IACdN,GAAG,EAAEA,GAAG;IACRe,SAAS,EAAC,oCAAoC;IAC9CO,UAAU,EAAE,IAAI;IAChBnB,QAAQ,EAAEC,YAAY;IACtBC,KAAK,EAAEA;MACNJ,UAAU,CAACsB,GAAG,CAACZ,MAAM;IAAA,IAAAa,qBAAA,EAAAC,cAAA,EAAAC,qBAAA;IAAA,oBAClB7B,6BAACwB,OAAO,CAACM,MAAM;MACXC,GAAG,EAAEjB,MAAM,CAACC,EAAE;MACdP,KAAK,EAAEM,MAAM,CAACC,EAAE;MAChBiB,OAAO,EACH,CAAClB,MAAM,CAACG,YAAY,EAAE,kBAClBjB,6BAACiC,OAAO;QAACC,KAAK,EAAExB,KAAK,CAACW,MAAM,CAAChB,OAAO,CAACiB;sBACjCtB,6BAACmC,IAAI;QAACC,IAAI,EAAC,SAAS;QAAClB,SAAS,EAAC;QAA4B,CACrD,IACVK,SAAS;MAEjBc,QAAQ,EAAEvB,MAAM,CAACC,EAAE,KAAKP,KAAK,KAAK,CAACM,MAAM,CAACwB,YAAY,EAAE,IAAI,CAAC,CAACjC,OAAO,CAACQ,IAAI,CAAC0B,CAAC,IAAIA,CAAC,CAACxB,EAAE,KAAKD,MAAM,CAACC,EAAE,CAAC;OACjG,EAAAY,qBAAA,GAAAb,MAAM,CAAC0B,SAAS,CAACC,IAAI,cAAAd,qBAAA,uBAArBA,qBAAA,CAAuBe,MAAiB,KACrC5B,MAAM,CAAC6B,MAAM,0BAAQ7B,MAAM,CAAC6B,MAAM,cAAAf,cAAA,wBAAAC,qBAAA,GAAbD,cAAA,CAAeY,SAAS,CAACC,IAAI,cAAAZ,qBAAA,uBAA7BA,qBAAA,CAA+Ba,SAAS,GAAG,EAAE,CAAC,CAC3D;GACpB,CAAC,CACI,CACN,CACN;AAEd,CAAC;;;;"}
|
@@ -20,7 +20,7 @@ function FilterComparator(props) {
|
|
20
20
|
}
|
21
21
|
}, [validComparators]);
|
22
22
|
return /*#__PURE__*/React__default.createElement(Select2, Object.assign({}, attributes, {
|
23
|
-
className: "!w-32 flex-shrink-0",
|
23
|
+
className: "focus:yt-focus !w-32 flex-shrink-0",
|
24
24
|
disabled: !column,
|
25
25
|
onChange: handleChange,
|
26
26
|
value: value
|