@trackunit/react-table 0.0.5 → 0.0.6
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/index.cjs.js +42 -25
- package/index.esm.js +43 -26
- package/package.json +5 -5
- package/src/menus/ColumnFilter.d.ts +3 -1
- package/src/types.d.ts +1 -0
package/index.cjs.js
CHANGED
|
@@ -8950,37 +8950,41 @@ const cvaColumnFilterGrabbable = cssClassVarianceUtilities.cvaMerge(["flex", "it
|
|
|
8950
8950
|
* @param {IColumnFilterProps<T, V>} props - The props object containing necessary properties.
|
|
8951
8951
|
* @returns {JSX.Element | null} A React JSX element representing the ColumnFilter component or null if columns are not provided.
|
|
8952
8952
|
*/
|
|
8953
|
-
const ColumnFilter = ({ columns, setColumnOrder, onUserEvent, }) => {
|
|
8953
|
+
const ColumnFilter = ({ columns, setColumnOrder, defaultColumnOrder, columnOrder, onUserEvent, }) => {
|
|
8954
8954
|
var _a;
|
|
8955
8955
|
const [t] = useTranslation();
|
|
8956
8956
|
const numberOfHiddenColumns = (_a = columns === null || columns === void 0 ? void 0 : columns.filter(column => !column.getIsVisible())) === null || _a === void 0 ? void 0 : _a.length;
|
|
8957
|
-
const resetHiddenColumns = React__namespace.useCallback((
|
|
8958
|
-
columns === null || columns === void 0 ? void 0 : columns.forEach(column => column.toggleVisibility(true));
|
|
8959
|
-
setColumnOrder([]);
|
|
8960
|
-
|
|
8961
|
-
|
|
8957
|
+
const resetHiddenColumns = React__namespace.useCallback(() => {
|
|
8958
|
+
columns === null || columns === void 0 ? void 0 : columns.forEach(column => { var _a, _b; return column.toggleVisibility((_b = !((_a = column.columnDef.meta) === null || _a === void 0 ? void 0 : _a.hiddenByDefault)) !== null && _b !== void 0 ? _b : true); });
|
|
8959
|
+
setColumnOrder(defaultColumnOrder || []);
|
|
8960
|
+
}, [columns, defaultColumnOrder, setColumnOrder]);
|
|
8961
|
+
const sortedColumns = React.useMemo(() => {
|
|
8962
|
+
const result = columnOrder && ((columnOrder === null || columnOrder === void 0 ? void 0 : columnOrder.length) || 0) > 0
|
|
8963
|
+
? columns === null || columns === void 0 ? void 0 : columns.sort((a, b) => columnOrder.indexOf(a.id) - columnOrder.indexOf(b.id))
|
|
8964
|
+
: columns;
|
|
8965
|
+
return result;
|
|
8966
|
+
}, [columnOrder, columns]);
|
|
8962
8967
|
if (!columns) {
|
|
8963
8968
|
return null;
|
|
8964
8969
|
}
|
|
8965
8970
|
return (jsxRuntime.jsx(DndProvider, { backend: HTML5Backend, children: jsxRuntime.jsx(reactComponents.Tooltip, { label: t("table.columnFilters.tooltip"), placement: "bottom-start", children: jsxRuntime.jsxs(reactComponents.Popover, { placement: "bottom-start", children: [jsxRuntime.jsx(reactComponents.PopoverTrigger, { children: jsxRuntime.jsx(reactComponents.Button, { prefix: jsxRuntime.jsx(reactComponents.Icon, { name: "ViewColumnsIcon", size: "small" }), color: "secondary", variant: "transparent", size: "small", children: jsxRuntime.jsx("span", { className: "hidden sm:block", children: numberOfHiddenColumns > 0
|
|
8966
8971
|
? t("table.columnFilters.hiddenColumnCount", { count: numberOfHiddenColumns })
|
|
8967
|
-
: t("table.columnFilters.columns") }) }) }), jsxRuntime.jsx(reactComponents.PopoverContent, { children:
|
|
8972
|
+
: t("table.columnFilters.columns") }) }) }), jsxRuntime.jsx(reactComponents.PopoverContent, { children: () => (jsxRuntime.jsxs(reactComponents.MenuList, { className: "max-h-[55vh] w-72 overflow-y-auto relative pr-4", children: [jsxRuntime.jsxs("div", { className: "flex items-center justify-between mb-2", children: [jsxRuntime.jsx(reactComponents.Text, { subtle: true, size: "small", children: t("table.columnFilters.title") }), jsxRuntime.jsx(reactComponents.Button, { className: "p-0", color: "secondary", variant: "transparent", size: "small", onClick: () => resetHiddenColumns(), children: t("layout.actions.reset") })] }), jsxRuntime.jsx(ColumnFiltersDragAndDrop, { columns: sortedColumns, setColumnOrder: setColumnOrder, onUserEvent: onUserEvent })] })) })] }) }) }));
|
|
8968
8973
|
};
|
|
8969
8974
|
const ColumnFiltersDragAndDrop = ({ columns, setColumnOrder, onUserEvent, }) => {
|
|
8970
8975
|
const [localColumns, setLocalColumns] = React__namespace.useState(columns);
|
|
8971
|
-
const debouncedColumns = reactComponents.useDebounce(localColumns, 300);
|
|
8972
8976
|
React__namespace.useEffect(() => {
|
|
8973
|
-
|
|
8974
|
-
|
|
8975
|
-
|
|
8976
|
-
|
|
8977
|
+
setLocalColumns(columns);
|
|
8978
|
+
}, [columns]);
|
|
8979
|
+
const onColumDrop = React__namespace.useCallback(() => {
|
|
8980
|
+
setColumnOrder(localColumns.map(column => column.id));
|
|
8981
|
+
}, [localColumns, setColumnOrder]);
|
|
8982
|
+
const onCancelColumDrop = React__namespace.useCallback(() => {
|
|
8983
|
+
setLocalColumns(columns);
|
|
8984
|
+
}, [columns]);
|
|
8977
8985
|
const moveColumn = React__namespace.useCallback((dragIndex, hoverIndex) => {
|
|
8978
|
-
var _a
|
|
8986
|
+
var _a;
|
|
8979
8987
|
const dragColumn = localColumns[dragIndex];
|
|
8980
|
-
const hoveredColumn = localColumns[hoverIndex];
|
|
8981
|
-
if ((_b = (_a = hoveredColumn.columnDef) === null || _a === void 0 ? void 0 : _a.meta) === null || _b === void 0 ? void 0 : _b.required) {
|
|
8982
|
-
return;
|
|
8983
|
-
}
|
|
8984
8988
|
setLocalColumns(update(localColumns, {
|
|
8985
8989
|
$splice: [
|
|
8986
8990
|
[dragIndex, 1],
|
|
@@ -8988,7 +8992,7 @@ const ColumnFiltersDragAndDrop = ({ columns, setColumnOrder, onUserEvent, }) =>
|
|
|
8988
8992
|
],
|
|
8989
8993
|
}));
|
|
8990
8994
|
onUserEvent === null || onUserEvent === void 0 ? void 0 : onUserEvent("Column Reordering", {
|
|
8991
|
-
columnReordered: (
|
|
8995
|
+
columnReordered: (_a = dragColumn === null || dragColumn === void 0 ? void 0 : dragColumn.columnDef.header) !== null && _a !== void 0 ? _a : "",
|
|
8992
8996
|
});
|
|
8993
8997
|
}, [localColumns, onUserEvent]);
|
|
8994
8998
|
return (jsxRuntime.jsx("div", { className: "flex flex-col gap-2 max-h-full max-w-[400px] overflow-y-auto overflow-x-hidden whitespace-nowrap", children: localColumns === null || localColumns === void 0 ? void 0 : localColumns.map((column, index) => {
|
|
@@ -8997,7 +9001,7 @@ const ColumnFiltersDragAndDrop = ({ columns, setColumnOrder, onUserEvent, }) =>
|
|
|
8997
9001
|
if (!columnDef.header || ((_a = columnDef.header) === null || _a === void 0 ? void 0 : _a.length) === 0) {
|
|
8998
9002
|
return null;
|
|
8999
9003
|
}
|
|
9000
|
-
return (jsxRuntime.jsx(ColumnFilterItem, { id: column.id, index: index, moveColumn: moveColumn, name: columnDef.header.toString(), toggled: column.getIsVisible(), disabled: !!((_b = column.columnDef.meta) === null || _b === void 0 ? void 0 : _b.required), onToggle: (toggled, event) => {
|
|
9004
|
+
return (jsxRuntime.jsx(ColumnFilterItem, { id: column.id, index: index, moveColumn: moveColumn, onDrop: onColumDrop, onCancelDrop: onCancelColumDrop, name: columnDef.header.toString(), toggled: column.getIsVisible(), disabled: !!((_b = column.columnDef.meta) === null || _b === void 0 ? void 0 : _b.required), onToggle: (toggled, event) => {
|
|
9001
9005
|
column.getToggleVisibilityHandler()(event);
|
|
9002
9006
|
onUserEvent === null || onUserEvent === void 0 ? void 0 : onUserEvent("Column Filter", {
|
|
9003
9007
|
columnName: column.id,
|
|
@@ -9009,7 +9013,7 @@ const ColumnFiltersDragAndDrop = ({ columns, setColumnOrder, onUserEvent, }) =>
|
|
|
9009
9013
|
const ItemTypes = {
|
|
9010
9014
|
COLUMN: "column",
|
|
9011
9015
|
};
|
|
9012
|
-
const ColumnFilterItem = ({ name, onToggle, toggled, disabled, index, moveColumn, id }) => {
|
|
9016
|
+
const ColumnFilterItem = ({ name, onToggle, toggled, disabled, index, moveColumn, onDrop, onCancelDrop, id, }) => {
|
|
9013
9017
|
const ref = React__namespace.useRef(null);
|
|
9014
9018
|
const [, drop] = useDrop({
|
|
9015
9019
|
accept: ItemTypes.COLUMN,
|
|
@@ -9036,18 +9040,26 @@ const ColumnFilterItem = ({ name, onToggle, toggled, disabled, index, moveColumn
|
|
|
9036
9040
|
moveColumn(dragIndex, hoverIndex);
|
|
9037
9041
|
item.index = hoverIndex;
|
|
9038
9042
|
},
|
|
9043
|
+
drop(item, monitor) {
|
|
9044
|
+
onDrop();
|
|
9045
|
+
},
|
|
9039
9046
|
});
|
|
9040
9047
|
const [{ isDragging }, drag] = useDrag({
|
|
9041
9048
|
type: ItemTypes.COLUMN,
|
|
9042
9049
|
item: { type: ItemTypes.COLUMN, id, index },
|
|
9043
|
-
canDrag:
|
|
9050
|
+
canDrag: true,
|
|
9044
9051
|
collect: (monitor) => ({
|
|
9045
9052
|
isDragging: monitor.isDragging(),
|
|
9046
9053
|
}),
|
|
9054
|
+
end(draggedItem, monitor) {
|
|
9055
|
+
if (!monitor.didDrop()) {
|
|
9056
|
+
onCancelDrop();
|
|
9057
|
+
}
|
|
9058
|
+
},
|
|
9047
9059
|
});
|
|
9048
9060
|
const opacity = isDragging ? 0 : 1;
|
|
9049
9061
|
drag(drop(ref));
|
|
9050
|
-
return (jsxRuntime.jsxs("div", { className: "items-center w-full grid grid-cols-[min-content,1fr,min-content] gap-2", ref: ref, style: { opacity: opacity }, children: [jsxRuntime.jsx("div", { className: cvaColumnFilterGrabbable({ disabled }), children:
|
|
9062
|
+
return (jsxRuntime.jsxs("div", { className: "items-center w-full grid grid-cols-[min-content,1fr,min-content] gap-2", ref: ref, style: { opacity: opacity }, children: [jsxRuntime.jsx("div", { className: cvaColumnFilterGrabbable({ disabled: false }), children: jsxRuntime.jsx(reactComponents.Icon, { name: "Bars3Icon", size: "small" }) }), jsxRuntime.jsxs("div", { className: "grid w-full grid-cols-[1fr,min-content]", children: [jsxRuntime.jsx(reactComponents.Text, { className: "overflow-hidden whitespace-nowrap text-ellipsis", children: name }), disabled ? jsxRuntime.jsx(reactComponents.Icon, { name: "LockClosedIcon", size: "small" }) : null] }), jsxRuntime.jsx(reactFormComponents.Toggle, { id: id, toggled: toggled, onChange: (isToggled, event) => event && onToggle(isToggled, event), size: "small", disabled: disabled })] }));
|
|
9051
9063
|
};
|
|
9052
9064
|
|
|
9053
9065
|
/**
|
|
@@ -9103,7 +9115,7 @@ const Sorting = ({ columns }) => {
|
|
|
9103
9115
|
const chosenColumn = sortableColumns.find(column => column.id === currentSortValue);
|
|
9104
9116
|
chosenColumn === null || chosenColumn === void 0 ? void 0 : chosenColumn.toggleSorting(selectedValue === "desc");
|
|
9105
9117
|
};
|
|
9106
|
-
return (jsxRuntime.jsx(reactComponents.Tooltip, { label: t("table.sorting.toolip"), placement: "bottom-start", children: jsxRuntime.jsxs(reactComponents.Popover, { placement: "bottom-start", children: [jsxRuntime.jsx(reactComponents.PopoverTrigger, { children: jsxRuntime.jsx(reactComponents.Button, { prefix: currentSortDirection === "asc" ? (jsxRuntime.jsx(reactComponents.Icon, { name: "BarsArrowUpIcon", size: "small" })) : (jsxRuntime.jsx(reactComponents.Icon, { name: "BarsArrowDownIcon", size: "small" })), color: "secondary", variant: "transparent", size: "small", children: jsxRuntime.jsx("span", { className: "hidden sm:block", children: t("table.sorting.label") }) }) }), jsxRuntime.jsx(reactComponents.PopoverContent, { children: jsxRuntime.jsxs(reactComponents.MenuList, { showDivider: true, children: [jsxRuntime.jsx(reactFormComponents.RadioGroup, { id: "sortProperty", onChange: handleSelectionChange, value: currentSortValue !== null && currentSortValue !== void 0 ? currentSortValue : "", children: sortableColumns.map(column => {
|
|
9118
|
+
return (jsxRuntime.jsx(reactComponents.Tooltip, { label: t("table.sorting.toolip"), placement: "bottom-start", children: jsxRuntime.jsxs(reactComponents.Popover, { placement: "bottom-start", children: [jsxRuntime.jsx(reactComponents.PopoverTrigger, { children: jsxRuntime.jsx(reactComponents.Button, { prefix: currentSortDirection === "asc" ? (jsxRuntime.jsx(reactComponents.Icon, { name: "BarsArrowUpIcon", size: "small" })) : (jsxRuntime.jsx(reactComponents.Icon, { name: "BarsArrowDownIcon", size: "small" })), color: "secondary", variant: "transparent", size: "small", children: jsxRuntime.jsx("span", { className: "hidden sm:block", children: t("table.sorting.label") }) }) }), jsxRuntime.jsx(reactComponents.PopoverContent, { children: jsxRuntime.jsxs(reactComponents.MenuList, { showDivider: true, className: "max-h-full h-96 overflow-y-auto", children: [jsxRuntime.jsx(reactFormComponents.RadioGroup, { id: "sortProperty", onChange: handleSelectionChange, value: currentSortValue !== null && currentSortValue !== void 0 ? currentSortValue : "", children: sortableColumns.map(column => {
|
|
9107
9119
|
var _a, _b, _c;
|
|
9108
9120
|
return (jsxRuntime.jsx(reactFormComponents.RadioItem, { className: "w-full", label: (_c = (_b = (_a = column === null || column === void 0 ? void 0 : column.columnDef) === null || _a === void 0 ? void 0 : _a.header) === null || _b === void 0 ? void 0 : _b.toString()) !== null && _c !== void 0 ? _c : "", value: column.id }, column.id));
|
|
9109
9121
|
}) }), jsxRuntime.jsxs(reactFormComponents.RadioGroup, { id: "sortOrder", onChange: onSelectOrder, value: currentSortDirection, children: [jsxRuntime.jsx(reactFormComponents.RadioItem, { className: "w-full", label: t("table.sorting.ascending"), value: "asc" }), jsxRuntime.jsx(reactFormComponents.RadioItem, { className: "w-full", label: t("table.sorting.descending"), value: "desc" })] })] }) })] }) }));
|
|
@@ -9173,14 +9185,19 @@ const useTable = (_a) => {
|
|
|
9173
9185
|
const [columnOrder, setColumnOrder] = React.useState(((_c = reactTableProps.state) === null || _c === void 0 ? void 0 : _c.columnOrder) || (initialState === null || initialState === void 0 ? void 0 : initialState.columnOrder) || []);
|
|
9174
9186
|
const [sorting, setSorting] = React.useState(((_d = reactTableProps.state) === null || _d === void 0 ? void 0 : _d.sorting) || (initialState === null || initialState === void 0 ? void 0 : initialState.sorting) || []);
|
|
9175
9187
|
const [columnSizing, setColumnSizing] = React.useState(((_e = reactTableProps.state) === null || _e === void 0 ? void 0 : _e.columnSizing) || (initialState === null || initialState === void 0 ? void 0 : initialState.columnSizing) || {});
|
|
9188
|
+
const hiddenByDefaultState = React.useMemo(() => {
|
|
9189
|
+
return Object.fromEntries(reactTableProps.columns.map(column => { var _a, _b; return [column.id, (_b = (_a = column.meta) === null || _a === void 0 ? void 0 : _a.hiddenByDefault) !== null && _b !== void 0 ? _b : true]; }));
|
|
9190
|
+
}, [reactTableProps.columns]);
|
|
9176
9191
|
React.useEffect(() => {
|
|
9177
9192
|
if (initialState) {
|
|
9178
|
-
setColumnVisibility(initialState.columnVisibility || {})
|
|
9193
|
+
setColumnVisibility(Object.keys(initialState.columnVisibility || {}).length > 0
|
|
9194
|
+
? initialState.columnVisibility
|
|
9195
|
+
: hiddenByDefaultState || {});
|
|
9179
9196
|
setColumnOrder(initialState.columnOrder || []);
|
|
9180
9197
|
setSorting(initialState.sorting || []);
|
|
9181
9198
|
setColumnSizing(initialState.columnSizing || {});
|
|
9182
9199
|
}
|
|
9183
|
-
}, [initialState]);
|
|
9200
|
+
}, [hiddenByDefaultState, initialState]);
|
|
9184
9201
|
const state = React.useMemo(() => {
|
|
9185
9202
|
return Object.assign({ sorting,
|
|
9186
9203
|
columnVisibility,
|
package/index.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
2
|
import { registerTranslations, useNamespaceTranslation } from '@trackunit/i18n-library-translation';
|
|
3
|
-
import { useContainerProps, IconButton, Icon, Text, MoreMenu, MenuList, Button, Card, EmptyState, Tooltip, Popover, PopoverTrigger, PopoverContent
|
|
3
|
+
import { useContainerProps, IconButton, Icon, Text, MoreMenu, MenuList, Button, Card, EmptyState, Tooltip, Popover, PopoverTrigger, PopoverContent } from '@trackunit/react-components';
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import React__default, { useState, useEffect, useCallback, useRef, createContext, memo as memo$1, isValidElement, cloneElement, useLayoutEffect, useMemo, useContext } from 'react';
|
|
6
6
|
import { Link } from 'react-router-dom';
|
|
@@ -8924,37 +8924,41 @@ const cvaColumnFilterGrabbable = cvaMerge(["flex", "items-center", "justify-cent
|
|
|
8924
8924
|
* @param {IColumnFilterProps<T, V>} props - The props object containing necessary properties.
|
|
8925
8925
|
* @returns {JSX.Element | null} A React JSX element representing the ColumnFilter component or null if columns are not provided.
|
|
8926
8926
|
*/
|
|
8927
|
-
const ColumnFilter = ({ columns, setColumnOrder, onUserEvent, }) => {
|
|
8927
|
+
const ColumnFilter = ({ columns, setColumnOrder, defaultColumnOrder, columnOrder, onUserEvent, }) => {
|
|
8928
8928
|
var _a;
|
|
8929
8929
|
const [t] = useTranslation();
|
|
8930
8930
|
const numberOfHiddenColumns = (_a = columns === null || columns === void 0 ? void 0 : columns.filter(column => !column.getIsVisible())) === null || _a === void 0 ? void 0 : _a.length;
|
|
8931
|
-
const resetHiddenColumns = React.useCallback((
|
|
8932
|
-
columns === null || columns === void 0 ? void 0 : columns.forEach(column => column.toggleVisibility(true));
|
|
8933
|
-
setColumnOrder([]);
|
|
8934
|
-
|
|
8935
|
-
|
|
8931
|
+
const resetHiddenColumns = React.useCallback(() => {
|
|
8932
|
+
columns === null || columns === void 0 ? void 0 : columns.forEach(column => { var _a, _b; return column.toggleVisibility((_b = !((_a = column.columnDef.meta) === null || _a === void 0 ? void 0 : _a.hiddenByDefault)) !== null && _b !== void 0 ? _b : true); });
|
|
8933
|
+
setColumnOrder(defaultColumnOrder || []);
|
|
8934
|
+
}, [columns, defaultColumnOrder, setColumnOrder]);
|
|
8935
|
+
const sortedColumns = useMemo(() => {
|
|
8936
|
+
const result = columnOrder && ((columnOrder === null || columnOrder === void 0 ? void 0 : columnOrder.length) || 0) > 0
|
|
8937
|
+
? columns === null || columns === void 0 ? void 0 : columns.sort((a, b) => columnOrder.indexOf(a.id) - columnOrder.indexOf(b.id))
|
|
8938
|
+
: columns;
|
|
8939
|
+
return result;
|
|
8940
|
+
}, [columnOrder, columns]);
|
|
8936
8941
|
if (!columns) {
|
|
8937
8942
|
return null;
|
|
8938
8943
|
}
|
|
8939
8944
|
return (jsx(DndProvider, { backend: HTML5Backend, children: jsx(Tooltip, { label: t("table.columnFilters.tooltip"), placement: "bottom-start", children: jsxs(Popover, { placement: "bottom-start", children: [jsx(PopoverTrigger, { children: jsx(Button, { prefix: jsx(Icon, { name: "ViewColumnsIcon", size: "small" }), color: "secondary", variant: "transparent", size: "small", children: jsx("span", { className: "hidden sm:block", children: numberOfHiddenColumns > 0
|
|
8940
8945
|
? t("table.columnFilters.hiddenColumnCount", { count: numberOfHiddenColumns })
|
|
8941
|
-
: t("table.columnFilters.columns") }) }) }), jsx(PopoverContent, { children:
|
|
8946
|
+
: t("table.columnFilters.columns") }) }) }), jsx(PopoverContent, { children: () => (jsxs(MenuList, { className: "max-h-[55vh] w-72 overflow-y-auto relative pr-4", children: [jsxs("div", { className: "flex items-center justify-between mb-2", children: [jsx(Text, { subtle: true, size: "small", children: t("table.columnFilters.title") }), jsx(Button, { className: "p-0", color: "secondary", variant: "transparent", size: "small", onClick: () => resetHiddenColumns(), children: t("layout.actions.reset") })] }), jsx(ColumnFiltersDragAndDrop, { columns: sortedColumns, setColumnOrder: setColumnOrder, onUserEvent: onUserEvent })] })) })] }) }) }));
|
|
8942
8947
|
};
|
|
8943
8948
|
const ColumnFiltersDragAndDrop = ({ columns, setColumnOrder, onUserEvent, }) => {
|
|
8944
8949
|
const [localColumns, setLocalColumns] = React.useState(columns);
|
|
8945
|
-
const debouncedColumns = useDebounce(localColumns, 300);
|
|
8946
8950
|
React.useEffect(() => {
|
|
8947
|
-
|
|
8948
|
-
|
|
8949
|
-
|
|
8950
|
-
|
|
8951
|
+
setLocalColumns(columns);
|
|
8952
|
+
}, [columns]);
|
|
8953
|
+
const onColumDrop = React.useCallback(() => {
|
|
8954
|
+
setColumnOrder(localColumns.map(column => column.id));
|
|
8955
|
+
}, [localColumns, setColumnOrder]);
|
|
8956
|
+
const onCancelColumDrop = React.useCallback(() => {
|
|
8957
|
+
setLocalColumns(columns);
|
|
8958
|
+
}, [columns]);
|
|
8951
8959
|
const moveColumn = React.useCallback((dragIndex, hoverIndex) => {
|
|
8952
|
-
var _a
|
|
8960
|
+
var _a;
|
|
8953
8961
|
const dragColumn = localColumns[dragIndex];
|
|
8954
|
-
const hoveredColumn = localColumns[hoverIndex];
|
|
8955
|
-
if ((_b = (_a = hoveredColumn.columnDef) === null || _a === void 0 ? void 0 : _a.meta) === null || _b === void 0 ? void 0 : _b.required) {
|
|
8956
|
-
return;
|
|
8957
|
-
}
|
|
8958
8962
|
setLocalColumns(update(localColumns, {
|
|
8959
8963
|
$splice: [
|
|
8960
8964
|
[dragIndex, 1],
|
|
@@ -8962,7 +8966,7 @@ const ColumnFiltersDragAndDrop = ({ columns, setColumnOrder, onUserEvent, }) =>
|
|
|
8962
8966
|
],
|
|
8963
8967
|
}));
|
|
8964
8968
|
onUserEvent === null || onUserEvent === void 0 ? void 0 : onUserEvent("Column Reordering", {
|
|
8965
|
-
columnReordered: (
|
|
8969
|
+
columnReordered: (_a = dragColumn === null || dragColumn === void 0 ? void 0 : dragColumn.columnDef.header) !== null && _a !== void 0 ? _a : "",
|
|
8966
8970
|
});
|
|
8967
8971
|
}, [localColumns, onUserEvent]);
|
|
8968
8972
|
return (jsx("div", { className: "flex flex-col gap-2 max-h-full max-w-[400px] overflow-y-auto overflow-x-hidden whitespace-nowrap", children: localColumns === null || localColumns === void 0 ? void 0 : localColumns.map((column, index) => {
|
|
@@ -8971,7 +8975,7 @@ const ColumnFiltersDragAndDrop = ({ columns, setColumnOrder, onUserEvent, }) =>
|
|
|
8971
8975
|
if (!columnDef.header || ((_a = columnDef.header) === null || _a === void 0 ? void 0 : _a.length) === 0) {
|
|
8972
8976
|
return null;
|
|
8973
8977
|
}
|
|
8974
|
-
return (jsx(ColumnFilterItem, { id: column.id, index: index, moveColumn: moveColumn, name: columnDef.header.toString(), toggled: column.getIsVisible(), disabled: !!((_b = column.columnDef.meta) === null || _b === void 0 ? void 0 : _b.required), onToggle: (toggled, event) => {
|
|
8978
|
+
return (jsx(ColumnFilterItem, { id: column.id, index: index, moveColumn: moveColumn, onDrop: onColumDrop, onCancelDrop: onCancelColumDrop, name: columnDef.header.toString(), toggled: column.getIsVisible(), disabled: !!((_b = column.columnDef.meta) === null || _b === void 0 ? void 0 : _b.required), onToggle: (toggled, event) => {
|
|
8975
8979
|
column.getToggleVisibilityHandler()(event);
|
|
8976
8980
|
onUserEvent === null || onUserEvent === void 0 ? void 0 : onUserEvent("Column Filter", {
|
|
8977
8981
|
columnName: column.id,
|
|
@@ -8983,7 +8987,7 @@ const ColumnFiltersDragAndDrop = ({ columns, setColumnOrder, onUserEvent, }) =>
|
|
|
8983
8987
|
const ItemTypes = {
|
|
8984
8988
|
COLUMN: "column",
|
|
8985
8989
|
};
|
|
8986
|
-
const ColumnFilterItem = ({ name, onToggle, toggled, disabled, index, moveColumn, id }) => {
|
|
8990
|
+
const ColumnFilterItem = ({ name, onToggle, toggled, disabled, index, moveColumn, onDrop, onCancelDrop, id, }) => {
|
|
8987
8991
|
const ref = React.useRef(null);
|
|
8988
8992
|
const [, drop] = useDrop({
|
|
8989
8993
|
accept: ItemTypes.COLUMN,
|
|
@@ -9010,18 +9014,26 @@ const ColumnFilterItem = ({ name, onToggle, toggled, disabled, index, moveColumn
|
|
|
9010
9014
|
moveColumn(dragIndex, hoverIndex);
|
|
9011
9015
|
item.index = hoverIndex;
|
|
9012
9016
|
},
|
|
9017
|
+
drop(item, monitor) {
|
|
9018
|
+
onDrop();
|
|
9019
|
+
},
|
|
9013
9020
|
});
|
|
9014
9021
|
const [{ isDragging }, drag] = useDrag({
|
|
9015
9022
|
type: ItemTypes.COLUMN,
|
|
9016
9023
|
item: { type: ItemTypes.COLUMN, id, index },
|
|
9017
|
-
canDrag:
|
|
9024
|
+
canDrag: true,
|
|
9018
9025
|
collect: (monitor) => ({
|
|
9019
9026
|
isDragging: monitor.isDragging(),
|
|
9020
9027
|
}),
|
|
9028
|
+
end(draggedItem, monitor) {
|
|
9029
|
+
if (!monitor.didDrop()) {
|
|
9030
|
+
onCancelDrop();
|
|
9031
|
+
}
|
|
9032
|
+
},
|
|
9021
9033
|
});
|
|
9022
9034
|
const opacity = isDragging ? 0 : 1;
|
|
9023
9035
|
drag(drop(ref));
|
|
9024
|
-
return (jsxs("div", { className: "items-center w-full grid grid-cols-[min-content,1fr,min-content] gap-2", ref: ref, style: { opacity: opacity }, children: [jsx("div", { className: cvaColumnFilterGrabbable({ disabled }), children:
|
|
9036
|
+
return (jsxs("div", { className: "items-center w-full grid grid-cols-[min-content,1fr,min-content] gap-2", ref: ref, style: { opacity: opacity }, children: [jsx("div", { className: cvaColumnFilterGrabbable({ disabled: false }), children: jsx(Icon, { name: "Bars3Icon", size: "small" }) }), jsxs("div", { className: "grid w-full grid-cols-[1fr,min-content]", children: [jsx(Text, { className: "overflow-hidden whitespace-nowrap text-ellipsis", children: name }), disabled ? jsx(Icon, { name: "LockClosedIcon", size: "small" }) : null] }), jsx(Toggle, { id: id, toggled: toggled, onChange: (isToggled, event) => event && onToggle(isToggled, event), size: "small", disabled: disabled })] }));
|
|
9025
9037
|
};
|
|
9026
9038
|
|
|
9027
9039
|
/**
|
|
@@ -9077,7 +9089,7 @@ const Sorting = ({ columns }) => {
|
|
|
9077
9089
|
const chosenColumn = sortableColumns.find(column => column.id === currentSortValue);
|
|
9078
9090
|
chosenColumn === null || chosenColumn === void 0 ? void 0 : chosenColumn.toggleSorting(selectedValue === "desc");
|
|
9079
9091
|
};
|
|
9080
|
-
return (jsx(Tooltip, { label: t("table.sorting.toolip"), placement: "bottom-start", children: jsxs(Popover, { placement: "bottom-start", children: [jsx(PopoverTrigger, { children: jsx(Button, { prefix: currentSortDirection === "asc" ? (jsx(Icon, { name: "BarsArrowUpIcon", size: "small" })) : (jsx(Icon, { name: "BarsArrowDownIcon", size: "small" })), color: "secondary", variant: "transparent", size: "small", children: jsx("span", { className: "hidden sm:block", children: t("table.sorting.label") }) }) }), jsx(PopoverContent, { children: jsxs(MenuList, { showDivider: true, children: [jsx(RadioGroup, { id: "sortProperty", onChange: handleSelectionChange, value: currentSortValue !== null && currentSortValue !== void 0 ? currentSortValue : "", children: sortableColumns.map(column => {
|
|
9092
|
+
return (jsx(Tooltip, { label: t("table.sorting.toolip"), placement: "bottom-start", children: jsxs(Popover, { placement: "bottom-start", children: [jsx(PopoverTrigger, { children: jsx(Button, { prefix: currentSortDirection === "asc" ? (jsx(Icon, { name: "BarsArrowUpIcon", size: "small" })) : (jsx(Icon, { name: "BarsArrowDownIcon", size: "small" })), color: "secondary", variant: "transparent", size: "small", children: jsx("span", { className: "hidden sm:block", children: t("table.sorting.label") }) }) }), jsx(PopoverContent, { children: jsxs(MenuList, { showDivider: true, className: "max-h-full h-96 overflow-y-auto", children: [jsx(RadioGroup, { id: "sortProperty", onChange: handleSelectionChange, value: currentSortValue !== null && currentSortValue !== void 0 ? currentSortValue : "", children: sortableColumns.map(column => {
|
|
9081
9093
|
var _a, _b, _c;
|
|
9082
9094
|
return (jsx(RadioItem, { className: "w-full", label: (_c = (_b = (_a = column === null || column === void 0 ? void 0 : column.columnDef) === null || _a === void 0 ? void 0 : _a.header) === null || _b === void 0 ? void 0 : _b.toString()) !== null && _c !== void 0 ? _c : "", value: column.id }, column.id));
|
|
9083
9095
|
}) }), jsxs(RadioGroup, { id: "sortOrder", onChange: onSelectOrder, value: currentSortDirection, children: [jsx(RadioItem, { className: "w-full", label: t("table.sorting.ascending"), value: "asc" }), jsx(RadioItem, { className: "w-full", label: t("table.sorting.descending"), value: "desc" })] })] }) })] }) }));
|
|
@@ -9147,14 +9159,19 @@ const useTable = (_a) => {
|
|
|
9147
9159
|
const [columnOrder, setColumnOrder] = useState(((_c = reactTableProps.state) === null || _c === void 0 ? void 0 : _c.columnOrder) || (initialState === null || initialState === void 0 ? void 0 : initialState.columnOrder) || []);
|
|
9148
9160
|
const [sorting, setSorting] = useState(((_d = reactTableProps.state) === null || _d === void 0 ? void 0 : _d.sorting) || (initialState === null || initialState === void 0 ? void 0 : initialState.sorting) || []);
|
|
9149
9161
|
const [columnSizing, setColumnSizing] = useState(((_e = reactTableProps.state) === null || _e === void 0 ? void 0 : _e.columnSizing) || (initialState === null || initialState === void 0 ? void 0 : initialState.columnSizing) || {});
|
|
9162
|
+
const hiddenByDefaultState = useMemo(() => {
|
|
9163
|
+
return Object.fromEntries(reactTableProps.columns.map(column => { var _a, _b; return [column.id, (_b = (_a = column.meta) === null || _a === void 0 ? void 0 : _a.hiddenByDefault) !== null && _b !== void 0 ? _b : true]; }));
|
|
9164
|
+
}, [reactTableProps.columns]);
|
|
9150
9165
|
useEffect(() => {
|
|
9151
9166
|
if (initialState) {
|
|
9152
|
-
setColumnVisibility(initialState.columnVisibility || {})
|
|
9167
|
+
setColumnVisibility(Object.keys(initialState.columnVisibility || {}).length > 0
|
|
9168
|
+
? initialState.columnVisibility
|
|
9169
|
+
: hiddenByDefaultState || {});
|
|
9153
9170
|
setColumnOrder(initialState.columnOrder || []);
|
|
9154
9171
|
setSorting(initialState.sorting || []);
|
|
9155
9172
|
setColumnSizing(initialState.columnSizing || {});
|
|
9156
9173
|
}
|
|
9157
|
-
}, [initialState]);
|
|
9174
|
+
}, [hiddenByDefaultState, initialState]);
|
|
9158
9175
|
const state = useMemo(() => {
|
|
9159
9176
|
return Object.assign({ sorting,
|
|
9160
9177
|
columnVisibility,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/react-table",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"engines": {
|
|
@@ -12,12 +12,12 @@
|
|
|
12
12
|
"@trackunit/css-class-variance-utilities": "0.0.12",
|
|
13
13
|
"@trackunit/css-core": "0.0.93",
|
|
14
14
|
"@trackunit/i18n-library-translation": "0.0.72",
|
|
15
|
-
"@trackunit/react-components": "0.1.
|
|
15
|
+
"@trackunit/react-components": "0.1.151",
|
|
16
16
|
"@trackunit/react-core-contexts-api": "0.2.53",
|
|
17
|
-
"@trackunit/react-core-contexts-test": "0.1.
|
|
18
|
-
"@trackunit/react-form-components": "0.0.
|
|
17
|
+
"@trackunit/react-core-contexts-test": "0.1.100",
|
|
18
|
+
"@trackunit/react-form-components": "0.0.129",
|
|
19
19
|
"@trackunit/react-table-base-components": "0.0.1",
|
|
20
|
-
"@trackunit/shared-utils": "0.0.
|
|
20
|
+
"@trackunit/shared-utils": "0.0.4",
|
|
21
21
|
"@trackunit/ui-icons": "0.0.73",
|
|
22
22
|
"immutability-helper": "3.1.1",
|
|
23
23
|
"react": "18.2.0",
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
import { Column, ColumnOrderState, Updater } from "@tanstack/react-table";
|
|
3
3
|
export interface IColumnFilterProps<T extends object, V> {
|
|
4
4
|
columns: Column<T, V>[];
|
|
5
|
+
defaultColumnOrder: ColumnOrderState;
|
|
6
|
+
columnOrder?: ColumnOrderState;
|
|
5
7
|
className?: string;
|
|
6
8
|
setColumnOrder: (updater: Updater<ColumnOrderState>) => void;
|
|
7
9
|
onUserEvent?: (event: "Column Reordering" | "Column Filter", payload: Record<string, unknown>) => void;
|
|
@@ -14,7 +16,7 @@ export interface IColumnFilterProps<T extends object, V> {
|
|
|
14
16
|
* @param {IColumnFilterProps<T, V>} props - The props object containing necessary properties.
|
|
15
17
|
* @returns {JSX.Element | null} A React JSX element representing the ColumnFilter component or null if columns are not provided.
|
|
16
18
|
*/
|
|
17
|
-
export declare const ColumnFilter: <T extends Object, V>({ columns, setColumnOrder, onUserEvent, }: IColumnFilterProps<T, V>) => JSX.Element | null;
|
|
19
|
+
export declare const ColumnFilter: <T extends Object, V>({ columns, setColumnOrder, defaultColumnOrder, columnOrder, onUserEvent, }: IColumnFilterProps<T, V>) => JSX.Element | null;
|
|
18
20
|
export interface ColumnFiltersDragAndDropProps<T extends object, V> {
|
|
19
21
|
columns: Column<T, V>[];
|
|
20
22
|
setColumnOrder: (updater: Updater<ColumnOrderState>) => void;
|