@linzjs/step-ag-grid 1.4.7 → 1.4.8
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/dist/index.js +25 -11
- package/dist/index.js.map +1 -1
- package/dist/src/components/GridCell.d.ts +1 -1
- package/dist/src/components/gridForm/GridFormPopoutMenu.d.ts +1 -0
- package/dist/src/components/gridRender/GridRenderGenericCell.d.ts +2 -2
- package/dist/step-ag-grid.esm.js +25 -11
- package/dist/step-ag-grid.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/GridCell.tsx +27 -14
- package/src/components/gridForm/GridFormPopoutMenu.tsx +11 -8
- package/src/components/gridRender/GridRenderGenericCell.tsx +6 -5
- package/src/stories/components/GridReadOnly.stories.tsx +6 -1
package/package.json
CHANGED
|
@@ -6,6 +6,8 @@ import { GenericMultiEditCellClass } from "./GenericCellClass";
|
|
|
6
6
|
import { GenericCellRendererParams, GridRendererGenericCell } from "./gridRender/GridRenderGenericCell";
|
|
7
7
|
import { ColDef, ICellEditorParams, ICellRendererParams } from "ag-grid-community";
|
|
8
8
|
import { GridLoadableCell } from "./GridLoadableCell";
|
|
9
|
+
import { GridIcon } from "@components/GridIcon";
|
|
10
|
+
import { ValueFormatterParams } from "ag-grid-community/dist/lib/entities/colDef";
|
|
9
11
|
|
|
10
12
|
export interface GridFormProps<RowType extends GridBaseRow> {
|
|
11
13
|
cellEditorParams: ICellEditorParams;
|
|
@@ -30,21 +32,26 @@ export interface GenericCellEditorColDef<
|
|
|
30
32
|
cellRendererParams?: GenericCellRendererParams<RowType>;
|
|
31
33
|
}
|
|
32
34
|
|
|
33
|
-
export const GridCellRenderer = (
|
|
35
|
+
export const GridCellRenderer = (props: ICellRendererParams) => {
|
|
34
36
|
const { checkUpdating } = useContext(UpdatingContext);
|
|
35
|
-
const colDef =
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
37
|
+
const colDef = props.colDef as ColDef;
|
|
38
|
+
|
|
39
|
+
const rendererParams = colDef.cellRendererParams as GenericCellRendererParams<any> | undefined;
|
|
40
|
+
const warningFn = rendererParams?.warning;
|
|
41
|
+
const warningText = warningFn ? warningFn(props) : undefined;
|
|
42
|
+
const infoFn = rendererParams?.info;
|
|
43
|
+
const infoText = infoFn ? infoFn(props) : undefined;
|
|
44
|
+
|
|
45
|
+
return colDef?.cellRendererParams?.originalCellRenderer ? (
|
|
46
|
+
<GridLoadableCell isLoading={checkUpdating(colDef.field ?? colDef.colId ?? "", props.data.id)}>
|
|
47
|
+
<>
|
|
48
|
+
{typeof warningText === "string" && <GridIcon icon={"ic_warning"} title={warningText} />}
|
|
49
|
+
{typeof infoText === "string" && <GridIcon icon={"ic_info"} title={infoText} />}
|
|
50
|
+
<colDef.cellRendererParams.originalCellRenderer {...props} />
|
|
51
|
+
</>
|
|
45
52
|
</GridLoadableCell>
|
|
46
53
|
) : (
|
|
47
|
-
<GridRendererGenericCell {...
|
|
54
|
+
<GridRendererGenericCell {...props} />
|
|
48
55
|
);
|
|
49
56
|
};
|
|
50
57
|
|
|
@@ -55,7 +62,6 @@ export const GridCell = <RowType extends GridBaseRow, FormProps extends GenericC
|
|
|
55
62
|
props: GenericCellEditorColDef<RowType, FormProps>,
|
|
56
63
|
): ColDef => {
|
|
57
64
|
return {
|
|
58
|
-
cellRenderer: GridCellRenderer,
|
|
59
65
|
sortable: !!(props?.field || props?.valueGetter),
|
|
60
66
|
resizable: true,
|
|
61
67
|
...(props.cellEditorParams && {
|
|
@@ -63,9 +69,16 @@ export const GridCell = <RowType extends GridBaseRow, FormProps extends GenericC
|
|
|
63
69
|
editable: true,
|
|
64
70
|
cellEditor: GenericCellEditorComponent,
|
|
65
71
|
}),
|
|
72
|
+
// Default value formatter, otherwise react freaks out on objects
|
|
73
|
+
valueFormatter: (params: ValueFormatterParams) => {
|
|
74
|
+
const types = ["number", "undefined", "boolean", "string"];
|
|
75
|
+
if (types.includes(typeof params.value)) return params.value;
|
|
76
|
+
else return JSON.stringify(params.value);
|
|
77
|
+
},
|
|
66
78
|
...props,
|
|
79
|
+
cellRenderer: GridCellRenderer,
|
|
67
80
|
cellRendererParams: {
|
|
68
|
-
|
|
81
|
+
originalCellRenderer: props.cellRenderer,
|
|
69
82
|
...props.cellRendererParams,
|
|
70
83
|
},
|
|
71
84
|
};
|
|
@@ -22,6 +22,7 @@ export interface MenuOption<RowType> {
|
|
|
22
22
|
action?: (selectedRows: RowType[]) => Promise<boolean>;
|
|
23
23
|
disabled?: string | boolean;
|
|
24
24
|
supportsMultiEdit: boolean;
|
|
25
|
+
hidden?: boolean;
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
/**
|
|
@@ -76,14 +77,16 @@ export const GridFormPopoutMenu = <RowType extends GridBaseRow>(props: GridFormP
|
|
|
76
77
|
item.label === MenuSeparator ? (
|
|
77
78
|
<MenuDivider key={`$$divider_${index}`} />
|
|
78
79
|
) : (
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
80
|
+
!item.hidden && (
|
|
81
|
+
<MenuItem
|
|
82
|
+
key={`${item.label}`}
|
|
83
|
+
onClick={() => actionClick(item)}
|
|
84
|
+
disabled={!!item.disabled || !filteredOptions?.includes(item)}
|
|
85
|
+
title={item.disabled && typeof item.disabled !== "boolean" ? item.disabled : ""}
|
|
86
|
+
>
|
|
87
|
+
{item.label as JSX.Element | string}
|
|
88
|
+
</MenuItem>
|
|
89
|
+
)
|
|
87
90
|
),
|
|
88
91
|
)}
|
|
89
92
|
</div>
|
|
@@ -20,21 +20,22 @@ export interface GenericCellColDef<RowType extends GridBaseRow, FormProps extend
|
|
|
20
20
|
|
|
21
21
|
export interface GenericCellRendererParams<RowType extends GridBaseRow> {
|
|
22
22
|
singleClickEdit?: boolean;
|
|
23
|
-
warning?: (props: RowICellRendererParams<RowType>) => string | boolean | undefined;
|
|
24
|
-
info?: (props: RowICellRendererParams<RowType>) => string | boolean | undefined;
|
|
23
|
+
warning?: (props: RowICellRendererParams<RowType>) => string | boolean | null | undefined;
|
|
24
|
+
info?: (props: RowICellRendererParams<RowType>) => string | boolean | null | undefined;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
export const GridRendererGenericCell = <RowType extends GridBaseRow>(props: ICellRendererParams): JSX.Element => {
|
|
28
28
|
const { checkUpdating } = useContext(UpdatingContext);
|
|
29
29
|
|
|
30
|
-
const
|
|
30
|
+
const colDef = props.colDef as ColDef;
|
|
31
|
+
const cellRendererParams = colDef.cellRendererParams as GenericCellRendererParams<RowType> | undefined;
|
|
31
32
|
const warningFn = cellRendererParams?.warning;
|
|
32
33
|
const warningText = warningFn ? warningFn(props) : undefined;
|
|
33
34
|
const infoFn = cellRendererParams?.info;
|
|
34
35
|
const infoText = infoFn ? infoFn(props) : undefined;
|
|
35
36
|
|
|
36
37
|
const defaultFormatter = (props: ValueFormatterParams): string => props.value;
|
|
37
|
-
const formatter =
|
|
38
|
+
const formatter = colDef.valueFormatter ?? defaultFormatter;
|
|
38
39
|
if (typeof formatter === "string") {
|
|
39
40
|
console.error("valueFormatter must be a function");
|
|
40
41
|
return <span>valueFormatter must be a function</span>;
|
|
@@ -42,7 +43,7 @@ export const GridRendererGenericCell = <RowType extends GridBaseRow>(props: ICel
|
|
|
42
43
|
const formatted = formatter(props as ValueFormatterParams);
|
|
43
44
|
|
|
44
45
|
return (
|
|
45
|
-
<GridLoadableCell isLoading={checkUpdating(
|
|
46
|
+
<GridLoadableCell isLoading={checkUpdating(colDef.field ?? colDef.colId ?? "", props.data.id)}>
|
|
46
47
|
<>
|
|
47
48
|
{typeof warningText === "string" && <GridIcon icon={"ic_warning"} title={warningText} />}
|
|
48
49
|
{typeof infoText === "string" && <GridIcon icon={"ic_info"} title={infoText} />}
|
|
@@ -86,7 +86,7 @@ const GridReadOnlyTemplate: ComponentStory<typeof Grid> = (props: GridProps) =>
|
|
|
86
86
|
GridPopoverMenu<ITestRow>({
|
|
87
87
|
headerName: "Menu",
|
|
88
88
|
cellEditorParams: {
|
|
89
|
-
options: async () => {
|
|
89
|
+
options: async (selectedItems) => {
|
|
90
90
|
// Just doing a timeout here to demonstrate deferred loading
|
|
91
91
|
await wait(500);
|
|
92
92
|
return [
|
|
@@ -113,6 +113,11 @@ const GridReadOnlyTemplate: ComponentStory<typeof Grid> = (props: GridProps) =>
|
|
|
113
113
|
disabled: "Disabled for test",
|
|
114
114
|
supportsMultiEdit: true,
|
|
115
115
|
},
|
|
116
|
+
{
|
|
117
|
+
label: "Developer Only",
|
|
118
|
+
hidden: selectedItems.some((x) => x.position != "Developer"),
|
|
119
|
+
supportsMultiEdit: true,
|
|
120
|
+
},
|
|
116
121
|
];
|
|
117
122
|
},
|
|
118
123
|
},
|