@mailstep/design-system 0.11.1 → 0.12.0-beta.1
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/package.json +1 -1
- package/ui/Blocks/CommonGrid/components/Filters/ActionsFilter/ActionsFilter.js +2 -3
- package/ui/Blocks/CommonGrid/components/gridCells/IconButtonInCell.js +0 -1
- package/ui/Blocks/CommonGrid/components/gridCells/RowActionsCell.d.ts +1 -0
- package/ui/Blocks/CommonGrid/components/gridCells/RowActionsCell.js +10 -10
- package/ui/Blocks/CommonGrid/hooks/useEditReadAsColumn.js +18 -5
- package/ui/Blocks/CommonGrid/types.d.ts +4 -5
- package/ui/Blocks/CommonGrid/utils/index.d.ts +10 -1
- package/ui/Blocks/CommonGrid/utils/index.js +21 -1
package/package.json
CHANGED
|
@@ -5,8 +5,7 @@ import { jsx, jsxs } from "react/jsx-runtime";
|
|
|
5
5
|
//#region packages/ui/Blocks/CommonGrid/components/Filters/ActionsFilter/ActionsFilter.tsx
|
|
6
6
|
const ActionsFilter = ({ actionColumn, rowsData, uxState, handleUxChange }) => {
|
|
7
7
|
const [allChecked, toggleCheckbox] = useToggleAllCheckbox(rowsData, uxState, handleUxChange);
|
|
8
|
-
const
|
|
9
|
-
const rowsNumberLabel = actionColumn?.addRowNumbersLabel ?? "#";
|
|
8
|
+
const rowsNumberLabel = actionColumn?.addRowNumbersLabel;
|
|
10
9
|
const displayCheckbox = actionColumn?.actionOptions?.length || actionColumn?.forceCheckboxes;
|
|
11
10
|
return /* @__PURE__ */ jsxs(x.div, {
|
|
12
11
|
display: "flex",
|
|
@@ -21,7 +20,7 @@ const ActionsFilter = ({ actionColumn, rowsData, uxState, handleUxChange }) => {
|
|
|
21
20
|
onChange: toggleCheckbox,
|
|
22
21
|
label: ""
|
|
23
22
|
}, "check-all")
|
|
24
|
-
}),
|
|
23
|
+
}), actionColumn?.addRowNumbersLabel && /* @__PURE__ */ jsx(x.div, {
|
|
25
24
|
w: "100%",
|
|
26
25
|
pr: "12px",
|
|
27
26
|
display: "flex",
|
|
@@ -3,9 +3,9 @@ import { IconButtonInCell } from "./IconButtonInCell.js";
|
|
|
3
3
|
import { useCallback, useMemo } from "react";
|
|
4
4
|
import { x } from "@xstyled/styled-components";
|
|
5
5
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
-
import { isFunction } from "lodash/fp";
|
|
6
|
+
import { isFunction, omit } from "lodash/fp";
|
|
7
7
|
//#region packages/ui/Blocks/CommonGrid/components/gridCells/RowActionsCell.tsx
|
|
8
|
-
const RowActionsCell = ({ actionColumnDefinition, rowData, addRowNumbers, rowIndex, checkedRows, withCheckboxes, onUxChange, onRowAction }) => {
|
|
8
|
+
const RowActionsCell = ({ actionColumnDefinition, rowData, addRowNumbers, rowIndex, rowNumberWidth = 0, checkedRows, withCheckboxes, onUxChange, onRowAction }) => {
|
|
9
9
|
const rowDataId = rowData?.id;
|
|
10
10
|
const canEdit = isFunction(actionColumnDefinition?.canRowEdit) ? actionColumnDefinition?.canRowEdit(rowData) : actionColumnDefinition?.canRowEdit;
|
|
11
11
|
const canRead = isFunction(actionColumnDefinition?.canRowRead) ? actionColumnDefinition?.canRowRead(rowData) : actionColumnDefinition?.canRowRead;
|
|
@@ -26,9 +26,10 @@ const RowActionsCell = ({ actionColumnDefinition, rowData, addRowNumbers, rowInd
|
|
|
26
26
|
}, [canEdit, rowData?.id]);
|
|
27
27
|
const isChecked = !!checkedRows?.[rowDataId];
|
|
28
28
|
const onCheckboxChange = useCallback(() => {
|
|
29
|
-
const newCheckedRows =
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
const newCheckedRows = isChecked ? omit(rowDataId, checkedRows || {}) : {
|
|
30
|
+
...checkedRows || {},
|
|
31
|
+
[rowDataId]: true
|
|
32
|
+
};
|
|
32
33
|
onUxChange?.("checkedRows", newCheckedRows);
|
|
33
34
|
}, [
|
|
34
35
|
onUxChange,
|
|
@@ -40,14 +41,13 @@ const RowActionsCell = ({ actionColumnDefinition, rowData, addRowNumbers, rowInd
|
|
|
40
41
|
if (isFunction(onClick)) onClick();
|
|
41
42
|
}, [onClick]);
|
|
42
43
|
return /* @__PURE__ */ jsxs(x.div, {
|
|
43
|
-
w: "100%",
|
|
44
44
|
display: "flex",
|
|
45
|
-
gap: "
|
|
45
|
+
gap: "12px",
|
|
46
46
|
pl: "4px",
|
|
47
47
|
pr: "4px",
|
|
48
48
|
children: [
|
|
49
49
|
withCheckboxes && /* @__PURE__ */ jsx(x.div, {
|
|
50
|
-
w: "
|
|
50
|
+
w: "18px",
|
|
51
51
|
children: /* @__PURE__ */ jsx(Checkbox_default, {
|
|
52
52
|
checked: isChecked,
|
|
53
53
|
onChange: onCheckboxChange,
|
|
@@ -58,8 +58,8 @@ const RowActionsCell = ({ actionColumnDefinition, rowData, addRowNumbers, rowInd
|
|
|
58
58
|
display: "flex",
|
|
59
59
|
alignItems: "center",
|
|
60
60
|
justifyContent: "center",
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
w: `${rowNumberWidth}px`,
|
|
62
|
+
flexShrink: 0,
|
|
63
63
|
children: rowIndex
|
|
64
64
|
}),
|
|
65
65
|
canEdit && /* @__PURE__ */ jsx(IconButtonInCell, {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getActionsColumnExtraWidth, getRowNumbersExtraWidth } from "../utils/index.js";
|
|
1
2
|
import "../types.js";
|
|
2
3
|
import withProps from "../HoC/withProps.js";
|
|
3
4
|
import { RowActionsCell } from "../components/gridCells/RowActionsCell.js";
|
|
@@ -5,25 +6,35 @@ import "../components/gridCells/index.js";
|
|
|
5
6
|
import { useCallback, useMemo } from "react";
|
|
6
7
|
//#region packages/ui/Blocks/CommonGrid/hooks/useEditReadAsColumn.tsx
|
|
7
8
|
const useEditReadAsColumn = (props) => {
|
|
8
|
-
const { onRowAction, actionColumnDefinition, columnsDefinitions, gridSelectors, gridActions, onRowEditClick, onRowReadClick } = props;
|
|
9
|
+
const { onRowAction, actionColumnDefinition, columnsDefinitions, gridSelectors, gridActions, onRowEditClick, onRowReadClick, rowsData } = props;
|
|
9
10
|
const modifiedOnRowAction = useCallback((id, field, value, rowData) => {
|
|
10
11
|
if (field === "row_edit" || field === "row_read") {
|
|
11
12
|
if (field === "row_edit" && onRowEditClick) onRowEditClick(id, value);
|
|
12
13
|
if (field === "row_read" && onRowReadClick) onRowReadClick(id, value);
|
|
13
|
-
} else if (onRowAction)
|
|
14
|
+
} else if (onRowAction) onRowAction(id, field, value, rowData);
|
|
14
15
|
}, [
|
|
15
16
|
onRowAction,
|
|
16
17
|
onRowEditClick,
|
|
17
18
|
onRowReadClick
|
|
18
19
|
]);
|
|
19
|
-
const { canRowEdit, canRowRead, addRowNumbers, stickTo = "left", flexBasis =
|
|
20
|
+
const { canRowEdit, canRowRead, addRowNumbers, stickTo = "left", flexBasis = 0 } = actionColumnDefinition || {};
|
|
20
21
|
const withCheckboxes = !!actionColumnDefinition?.actionOptions?.length || actionColumnDefinition?.forceCheckboxes;
|
|
21
22
|
const hasActions = canRowEdit || canRowRead || withCheckboxes || addRowNumbers;
|
|
23
|
+
const page = gridSelectors?.page || 1;
|
|
24
|
+
const maxRowNumber = (gridSelectors?.rowsPerPage || 10) * (page - 1) + (rowsData?.length || 0);
|
|
25
|
+
const actionColumnFlexBasis = flexBasis + getActionsColumnExtraWidth({
|
|
26
|
+
addRowNumbers,
|
|
27
|
+
withCheckboxes,
|
|
28
|
+
canRowEdit,
|
|
29
|
+
canRowRead,
|
|
30
|
+
maxRowNumber
|
|
31
|
+
});
|
|
32
|
+
const rowNumberWidth = getRowNumbersExtraWidth(maxRowNumber);
|
|
22
33
|
return {
|
|
23
34
|
columnsDefinitions: useMemo(() => {
|
|
24
35
|
const editReadColumnDefinition = {
|
|
25
36
|
name: "actions-cell-cg",
|
|
26
|
-
flexBasis,
|
|
37
|
+
flexBasis: actionColumnFlexBasis,
|
|
27
38
|
filtering: withCheckboxes || addRowNumbers,
|
|
28
39
|
filteringType: "actions",
|
|
29
40
|
sorting: false,
|
|
@@ -34,6 +45,7 @@ const useEditReadAsColumn = (props) => {
|
|
|
34
45
|
actionColumnDefinition,
|
|
35
46
|
withCheckboxes,
|
|
36
47
|
addRowNumbers: actionColumnDefinition?.addRowNumbers,
|
|
48
|
+
rowNumberWidth,
|
|
37
49
|
checkedRows: gridSelectors?.uxState?.checkedRows,
|
|
38
50
|
onUxChange: gridActions?.handleUxChange
|
|
39
51
|
})(RowActionsCell)
|
|
@@ -42,7 +54,8 @@ const useEditReadAsColumn = (props) => {
|
|
|
42
54
|
else return [...columnsDefinitions, editReadColumnDefinition];
|
|
43
55
|
}, [
|
|
44
56
|
addRowNumbers,
|
|
45
|
-
|
|
57
|
+
actionColumnFlexBasis,
|
|
58
|
+
rowNumberWidth,
|
|
46
59
|
stickTo,
|
|
47
60
|
hasActions,
|
|
48
61
|
columnsDefinitions,
|
|
@@ -86,11 +86,9 @@ export type RowProps = {
|
|
|
86
86
|
id: string;
|
|
87
87
|
[rowClassSymbol]?: string;
|
|
88
88
|
};
|
|
89
|
-
type ColumnBaseProps = {
|
|
90
|
-
flexBasis: number;
|
|
91
|
-
};
|
|
92
89
|
export type RowValueType = string | React.ReactNode | number | void;
|
|
93
|
-
export type ColumnDefinition<ColumnName extends string = string> =
|
|
90
|
+
export type ColumnDefinition<ColumnName extends string = string> = {
|
|
91
|
+
flexBasis: number;
|
|
94
92
|
asyncLoadKey?: string;
|
|
95
93
|
name: ColumnName;
|
|
96
94
|
group?: Group['name'];
|
|
@@ -140,7 +138,8 @@ type batchAction = {
|
|
|
140
138
|
isEnabled?: (checkedRows: any[]) => boolean;
|
|
141
139
|
};
|
|
142
140
|
export type OnBatchActionFn<T = RowProps> = (action: batchAction, affectedRows: T[]) => void;
|
|
143
|
-
export type ActionColumn =
|
|
141
|
+
export type ActionColumn = {
|
|
142
|
+
flexBasis?: number;
|
|
144
143
|
actionOptions?: batchAction[];
|
|
145
144
|
canRowEdit?: boolean | ((row: any) => boolean);
|
|
146
145
|
canRowRead?: boolean | ((row: any) => boolean);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ColumnDefinition, ColumnConfig, FilterProps, Group, StickTo, FiltersConfig } from '../types';
|
|
1
|
+
import type { ColumnDefinition, ColumnConfig, FilterProps, Group, StickTo, FiltersConfig, ActionColumn } from '../types';
|
|
2
2
|
type CellSizePropsResult = {
|
|
3
3
|
flexBasis?: number;
|
|
4
4
|
flexGrow?: number;
|
|
@@ -13,6 +13,15 @@ export declare const calculatePaginator: (page: number, rowsPerPage: number) =>
|
|
|
13
13
|
offset: number;
|
|
14
14
|
limit: number;
|
|
15
15
|
};
|
|
16
|
+
export declare const getRowNumbersExtraWidth: (maxRowNumber?: number) => number;
|
|
17
|
+
type ActionsColumnExtraWidthParams = {
|
|
18
|
+
addRowNumbers?: boolean;
|
|
19
|
+
withCheckboxes?: boolean;
|
|
20
|
+
canRowEdit?: ActionColumn['canRowEdit'];
|
|
21
|
+
canRowRead?: ActionColumn['canRowRead'];
|
|
22
|
+
maxRowNumber?: number;
|
|
23
|
+
};
|
|
24
|
+
export declare const getActionsColumnExtraWidth: ({ addRowNumbers, withCheckboxes, canRowEdit, canRowRead, maxRowNumber }: ActionsColumnExtraWidthParams) => number;
|
|
16
25
|
export declare const createFilterType: (columnDefinition: ColumnDefinition) => FilterProps["type"];
|
|
17
26
|
export declare const getGroups: (columns: ColumnDefinition[]) => Group[];
|
|
18
27
|
export declare const getGroupClassNames: (group?: Group) => string;
|
|
@@ -4,6 +4,7 @@ import BooleanSelect_default from "../components/Filters/BooleanSelect/index.js"
|
|
|
4
4
|
import DatePickerRange_default from "../components/Filters/DatePickerRange/index.js";
|
|
5
5
|
import NumberRange_default from "../components/Filters/NumberRange/index.js";
|
|
6
6
|
import TextRange_default from "../components/Filters/TextRange/index.js";
|
|
7
|
+
import sum from "lodash/sum";
|
|
7
8
|
//#region packages/ui/Blocks/CommonGrid/utils/index.ts
|
|
8
9
|
const isDefined = (val) => typeof val !== "undefined";
|
|
9
10
|
const getCellSizeProps = (column, columnWidth) => {
|
|
@@ -34,6 +35,25 @@ const calculatePaginator = (page, rowsPerPage) => ({
|
|
|
34
35
|
offset: rowsPerPage ? rowsPerPage * (page - 1) : rowsPerPage,
|
|
35
36
|
limit: rowsPerPage
|
|
36
37
|
});
|
|
38
|
+
const ROW_NUMBER_DIGIT_WIDTH = 8;
|
|
39
|
+
const CHECKBOX_WIDTH = 18;
|
|
40
|
+
const ICON_BUTTON_WIDTH = 20;
|
|
41
|
+
const ACTIONS_CELL_GAP = 12;
|
|
42
|
+
const ACTIONS_CELL_PADDING = 16;
|
|
43
|
+
const getRowNumbersExtraWidth = (maxRowNumber = 0) => {
|
|
44
|
+
return String(maxRowNumber).length * ROW_NUMBER_DIGIT_WIDTH;
|
|
45
|
+
};
|
|
46
|
+
const getActionsColumnExtraWidth = ({ addRowNumbers, withCheckboxes, canRowEdit, canRowRead, maxRowNumber = 0 }) => {
|
|
47
|
+
const hasActionIcon = !!canRowEdit || !!canRowRead;
|
|
48
|
+
const parts = [];
|
|
49
|
+
if (withCheckboxes) parts.push(CHECKBOX_WIDTH);
|
|
50
|
+
if (addRowNumbers) parts.push(getRowNumbersExtraWidth(maxRowNumber));
|
|
51
|
+
if (hasActionIcon) parts.push(ICON_BUTTON_WIDTH);
|
|
52
|
+
if (!parts.length) return 0;
|
|
53
|
+
const gaps = (parts.length - 1) * ACTIONS_CELL_GAP;
|
|
54
|
+
parts.push(ACTIONS_CELL_PADDING);
|
|
55
|
+
return sum(parts) + gaps;
|
|
56
|
+
};
|
|
37
57
|
const createFilterType = (columnDefinition) => {
|
|
38
58
|
if (columnDefinition.filterOptions || columnDefinition.asyncLoadKey) return "options";
|
|
39
59
|
else return columnDefinition.filteringType || "text";
|
|
@@ -75,4 +95,4 @@ const checksColumnsOrder = (colsOrder, columnsDefinitions) => {
|
|
|
75
95
|
if (stickyRightColls.length && colsOrder.indexOf(stickyRightColls[0].name) !== colsOrder.length - 1 && stickyRightColls[0].name !== "actions-cell-cg") console.error("The Right sticky column should be the last one in a row");
|
|
76
96
|
};
|
|
77
97
|
//#endregion
|
|
78
|
-
export { calculatePaginator, checksColumnsOrder, createFilterType, getCellSizeProps, getFilterName, getFilters, getGroupClassNames, getGroups, getSortName, getStickyCollClassNames, isColumnOn, isFilterActive };
|
|
98
|
+
export { calculatePaginator, checksColumnsOrder, createFilterType, getActionsColumnExtraWidth, getCellSizeProps, getFilterName, getFilters, getGroupClassNames, getGroups, getRowNumbersExtraWidth, getSortName, getStickyCollClassNames, isColumnOn, isFilterActive };
|