@linzjs/step-ag-grid 7.16.3 → 7.16.4

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 CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@linzjs/step-ag-grid",
3
3
  "repository": "github:linz/step-ag-grid.git",
4
4
  "license": "MIT",
5
- "version": "7.16.3",
5
+ "version": "7.16.4",
6
6
  "keywords": [
7
7
  "aggrid",
8
8
  "ag-grid",
@@ -171,11 +171,12 @@ export const Grid = (params: GridProps): JSX.Element => {
171
171
  const adjustColDefs = (params.columnDefs as ColDef[]).map((colDef) => {
172
172
  return {
173
173
  ...colDef,
174
- editable: params.readOnly ? false : colDef.editable,
174
+ editable: params.readOnly ? false : params.defaultColDef?.editable ?? colDef.editable,
175
175
  cellClassRules: {
176
176
  ...colDef.cellClassRules,
177
177
  "GridCell-readonly": (ccp: CellClassParams) =>
178
- params.readOnly != null && !params.readOnly && !fnOrVar(colDef.editable, ccp),
178
+ (params.readOnly != null || !params.readOnly) &&
179
+ !fnOrVar(params.defaultColDef?.editable ?? colDef.editable, ccp),
179
180
  },
180
181
  };
181
182
  });
@@ -207,7 +208,13 @@ export const Grid = (params: GridProps): JSX.Element => {
207
208
  ...adjustColDefs,
208
209
  ]
209
210
  : adjustColDefs;
210
- }, [clickSelectorCheckboxWhenContainingCellClicked, params.columnDefs, params.selectable, params.readOnly]);
211
+ }, [
212
+ clickSelectorCheckboxWhenContainingCellClicked,
213
+ params.columnDefs,
214
+ params.selectable,
215
+ params.readOnly,
216
+ params.defaultColDef,
217
+ ]);
211
218
 
212
219
  const onGridReady = useCallback(
213
220
  (event: GridReadyEvent) => {
@@ -0,0 +1,184 @@
1
+ import "@linzjs/lui/dist/scss/base.scss";
2
+ import "@linzjs/lui/dist/fonts";
3
+ import "../../styles/index.scss";
4
+ import "../../styles/GridTheme.scss";
5
+
6
+ import { ComponentMeta, ComponentStory } from "@storybook/react/dist/ts3.9/client/preview/types-6-3";
7
+ import { GridUpdatingContextProvider } from "../../contexts/GridUpdatingContextProvider";
8
+ import { GridContextProvider } from "../../contexts/GridContextProvider";
9
+ import { Grid, GridProps } from "../../components/Grid";
10
+ import { useMemo, useState } from "react";
11
+ import { wait } from "../../utils/util";
12
+ import { GridPopoverMenu } from "../../components/gridPopoverEdit/GridPopoverMenu";
13
+ import { ColDefT, GridCell } from "../../components/GridCell";
14
+ import { MenuOption } from "../../components/gridForm/GridFormPopoverMenu";
15
+ import { GridFormSubComponentTextInput } from "../../components/gridForm/GridFormSubComponentTextInput";
16
+ import { GridFormSubComponentTextArea } from "../../components/gridForm/GridFormSubComponentTextArea";
17
+ import { GridPopoverTextArea } from "components/gridPopoverEdit/GridPopoverTextArea";
18
+ import { GridPopoverEditDropDown } from "components/gridPopoverEdit/GridPopoverEditDropDown";
19
+ import { ColDef } from "ag-grid-community";
20
+
21
+ export default {
22
+ title: "Components / Grids",
23
+ component: Grid,
24
+ args: {
25
+ quickFilter: true,
26
+ quickFilterValue: "",
27
+ quickFilterPlaceholder: "Quick filter...",
28
+ selectable: false,
29
+ rowSelection: "single",
30
+ },
31
+ decorators: [
32
+ (Story) => (
33
+ <div style={{ width: 1024, height: 400 }}>
34
+ <GridUpdatingContextProvider>
35
+ <GridContextProvider>
36
+ <Story />
37
+ </GridContextProvider>
38
+ </GridUpdatingContextProvider>
39
+ </div>
40
+ ),
41
+ ],
42
+ } as ComponentMeta<typeof Grid>;
43
+
44
+ interface ITestRow {
45
+ id: number;
46
+ position: string;
47
+ age: number;
48
+ desc: string;
49
+ }
50
+
51
+ const GridNonEditableRowTemplate: ComponentStory<typeof Grid> = (props: GridProps) => {
52
+ const [externalSelectedItems, setExternalSelectedItems] = useState<any[]>([]);
53
+ const columnDefs: ColDefT<ITestRow>[] = useMemo(
54
+ () => [
55
+ GridCell({
56
+ field: "id",
57
+ headerName: "Id",
58
+ initialWidth: 65,
59
+ maxWidth: 85,
60
+ }),
61
+ GridPopoverEditDropDown(
62
+ {
63
+ field: "position",
64
+ initialWidth: 65,
65
+ maxWidth: 150,
66
+ headerName: "Position",
67
+ },
68
+ {
69
+ multiEdit: true,
70
+ editorParams: {
71
+ filtered: "local",
72
+ filterPlaceholder: "Filter",
73
+ options: ["Architect", "Developer", "Product Owner", "Scrum Master", "Tester"],
74
+ },
75
+ },
76
+ ),
77
+ GridCell({
78
+ field: "age",
79
+ headerName: "Age",
80
+ initialWidth: 65,
81
+ maxWidth: 85,
82
+ }),
83
+ GridPopoverTextArea(
84
+ {
85
+ field: "desc",
86
+ headerName: "Description",
87
+ initialWidth: 150,
88
+ maxWidth: 200,
89
+ },
90
+ {},
91
+ ),
92
+ GridPopoverMenu(
93
+ {},
94
+ {
95
+ multiEdit: true,
96
+ editorParams: {
97
+ options: async (selectedItems) => {
98
+ // Just doing a timeout here to demonstrate deferred loading
99
+ await wait(500);
100
+ return [
101
+ {
102
+ label: "Single edit only",
103
+ action: async (selectedRows) => {
104
+ alert(`Single-edit: ${selectedRows.map((r) => r.id)} rowId(s) selected`);
105
+ await wait(1500);
106
+ },
107
+ disabled: selectedItems.length > 1,
108
+ },
109
+ {
110
+ label: "Multi-edit",
111
+ action: async (selectedRows) => {
112
+ alert(`Multi-edit: ${selectedRows.map((r) => r.id)} rowId(s) selected`);
113
+ await wait(1500);
114
+ },
115
+ },
116
+ {
117
+ label: "Disabled item",
118
+ disabled: "Disabled for test",
119
+ },
120
+ {
121
+ label: "Developer Only",
122
+ hidden: selectedItems.some((x) => x.position != "Developer"),
123
+ },
124
+ {
125
+ label: "Other (TextInput)",
126
+ action: async (_, menuOptionResult) => {
127
+ // eslint-disable-next-line no-console
128
+ console.log(`Sub selected value was ${JSON.stringify(menuOptionResult.subValue)}`);
129
+ await wait(500);
130
+ },
131
+ subComponent: () => (
132
+ <GridFormSubComponentTextInput placeholder={"Other"} maxLength={5} required defaultValue={""} />
133
+ ),
134
+ },
135
+ {
136
+ label: "Other (TextArea)",
137
+ action: async (_, menuOptionResult) => {
138
+ // eslint-disable-next-line no-console
139
+ console.log(`Sub selected value was ${JSON.stringify(menuOptionResult.subValue)}`);
140
+ await wait(500);
141
+ },
142
+ subComponent: () => (
143
+ <GridFormSubComponentTextArea placeholder={"Other"} maxLength={5} required defaultValue={""} />
144
+ ),
145
+ },
146
+ ] as MenuOption<ITestRow>[];
147
+ },
148
+ },
149
+ },
150
+ ),
151
+ ],
152
+ [],
153
+ );
154
+
155
+ const [rowData] = useState([
156
+ { id: 1000, position: "Tester", age: 30, desc: "Tests application", dd: "1" },
157
+ { id: 1001, position: "Developer", age: 12, desc: "Develops application", dd: "2" },
158
+ { id: 1002, position: "Manager", age: 65, desc: "Manages", dd: "3" },
159
+ ]);
160
+
161
+ const defaultColDef: ColDef = useMemo(
162
+ () => ({
163
+ editable: (params) => (params.data as ITestRow).position !== "Manager",
164
+ }),
165
+ [],
166
+ );
167
+
168
+ return (
169
+ <Grid
170
+ {...props}
171
+ selectable={true}
172
+ externalSelectedItems={externalSelectedItems}
173
+ setExternalSelectedItems={setExternalSelectedItems}
174
+ defaultColDef={defaultColDef}
175
+ columnDefs={columnDefs}
176
+ rowData={rowData}
177
+ domLayout={"autoHeight"}
178
+ autoSelectFirstRow={true}
179
+ readOnly={false}
180
+ />
181
+ );
182
+ };
183
+
184
+ export const NonEditableRow = GridNonEditableRowTemplate.bind({});