@linzjs/step-ag-grid 29.16.0 → 29.19.0
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/README.md +1 -1
- package/dist/index.css +27 -0
- package/dist/src/components/Grid.d.ts +3 -2
- package/dist/src/components/gridForm/GridFormInlineTextInput.d.ts +15 -0
- package/dist/src/components/gridForm/index.d.ts +1 -0
- package/dist/src/components/gridHook/useGridRangeSelection.d.ts +1 -1
- package/dist/src/components/gridPopoverEdit/GridInlineTextInput.d.ts +5 -0
- package/dist/src/components/gridPopoverEdit/index.d.ts +1 -0
- package/dist/src/contexts/GridContext.d.ts +1 -1
- package/dist/src/utils/__tests__/storybookTestUtil.ts +5 -1
- package/dist/step-ag-grid.cjs +212 -84
- package/dist/step-ag-grid.cjs.map +1 -1
- package/dist/step-ag-grid.esm.js +211 -85
- package/dist/step-ag-grid.esm.js.map +1 -1
- package/package.json +14 -12
- package/src/components/Grid.tsx +33 -10
- package/src/components/GridPopoverHook.tsx +5 -2
- package/src/components/gridForm/GridFormInlineTextInput.tsx +119 -0
- package/src/components/gridForm/index.ts +1 -0
- package/src/components/gridHook/useGridContextMenu.tsx +3 -1
- package/src/components/gridHook/useGridCopy.ts +5 -2
- package/src/components/gridHook/useGridRangeSelection.ts +25 -4
- package/src/components/gridPopoverEdit/GridInlineTextInput.ts +13 -0
- package/src/components/gridPopoverEdit/index.ts +1 -0
- package/src/contexts/GridContext.tsx +6 -1
- package/src/contexts/GridContextProvider.tsx +30 -13
- package/src/stories/grid/GridFilterColumnsMultiSelect.stories.tsx +43 -2
- package/src/stories/grid/GridInlineText.stories.tsx +185 -0
- package/src/stories/grid/interactions/GridKeyboardInteractions.stories.tsx +3 -3
- package/src/styles/Grid.scss +5 -0
- package/src/styles/GridFormInlineTextInput.scss +23 -0
- package/src/styles/index.scss +1 -1
- package/src/utils/__tests__/storybookTestUtil.ts +5 -1
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import '../../styles/GridTheme.scss';
|
|
2
|
+
import '../../styles/index.scss';
|
|
3
|
+
import '@linzjs/lui/dist/scss/base.scss';
|
|
4
|
+
import '@linzjs/lui/dist/fonts';
|
|
5
|
+
|
|
6
|
+
import { Meta, StoryFn } from '@storybook/react-vite';
|
|
7
|
+
import { useCallback, useContext, useMemo, useState } from 'react';
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
ActionButton,
|
|
11
|
+
ColDefT,
|
|
12
|
+
Grid,
|
|
13
|
+
GridCell,
|
|
14
|
+
GridContext,
|
|
15
|
+
GridContextProvider,
|
|
16
|
+
GridInlineTextInput,
|
|
17
|
+
GridPopoverMenu,
|
|
18
|
+
GridProps,
|
|
19
|
+
GridUpdatingContextProvider,
|
|
20
|
+
wait,
|
|
21
|
+
} from '../..';
|
|
22
|
+
import { waitForGridReady } from '../../utils/__tests__/storybookTestUtil';
|
|
23
|
+
|
|
24
|
+
interface IFormTestRow {
|
|
25
|
+
id: number;
|
|
26
|
+
text1: string | null;
|
|
27
|
+
text2: string | null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export default {
|
|
31
|
+
title: 'Components / Grids',
|
|
32
|
+
component: Grid,
|
|
33
|
+
args: {
|
|
34
|
+
quickFilterValue: '',
|
|
35
|
+
selectable: true,
|
|
36
|
+
},
|
|
37
|
+
decorators: [
|
|
38
|
+
(Story) => (
|
|
39
|
+
<div style={{ width: 1024, height: 400 }}>
|
|
40
|
+
<GridUpdatingContextProvider>
|
|
41
|
+
<GridContextProvider>
|
|
42
|
+
<Story />
|
|
43
|
+
</GridContextProvider>
|
|
44
|
+
</GridUpdatingContextProvider>
|
|
45
|
+
<GridUpdatingContextProvider>
|
|
46
|
+
<GridContextProvider>
|
|
47
|
+
<Story />
|
|
48
|
+
</GridContextProvider>
|
|
49
|
+
</GridUpdatingContextProvider>
|
|
50
|
+
</div>
|
|
51
|
+
),
|
|
52
|
+
],
|
|
53
|
+
} as Meta<typeof Grid>;
|
|
54
|
+
|
|
55
|
+
const GridInlineTextTemplate: StoryFn<typeof Grid<IFormTestRow>> = (props: GridProps<IFormTestRow>) => {
|
|
56
|
+
const { selectRowsWithFlashDiff } = useContext(GridContext);
|
|
57
|
+
const [externalSelectedItems, setExternalSelectedItems] = useState<any[]>([]);
|
|
58
|
+
const [rowData, setRowData] = useState([
|
|
59
|
+
{
|
|
60
|
+
id: 1000,
|
|
61
|
+
text1: 'a text1',
|
|
62
|
+
text2: 'a text2',
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
id: 1001,
|
|
66
|
+
text1: 'b text1',
|
|
67
|
+
text2: 'b text2',
|
|
68
|
+
},
|
|
69
|
+
] as IFormTestRow[]);
|
|
70
|
+
|
|
71
|
+
const columnDefs: ColDefT<IFormTestRow>[] = useMemo(
|
|
72
|
+
() => [
|
|
73
|
+
GridCell({
|
|
74
|
+
field: 'id',
|
|
75
|
+
headerName: 'Id',
|
|
76
|
+
}),
|
|
77
|
+
GridInlineTextInput(
|
|
78
|
+
{
|
|
79
|
+
field: 'text1',
|
|
80
|
+
headerName: 'Text input 1',
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
editorParams: {
|
|
84
|
+
placeholder: 'Enter some text...',
|
|
85
|
+
onSave: ({ selectedRowIds, value }) => {
|
|
86
|
+
setRowData(rowData.map((data) => (selectedRowIds.includes(data.id) ? { ...data, text1: value } : data)));
|
|
87
|
+
return true;
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
),
|
|
92
|
+
GridInlineTextInput(
|
|
93
|
+
{
|
|
94
|
+
field: 'text2',
|
|
95
|
+
headerName: 'Text input 2',
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
editorParams: {
|
|
99
|
+
required: true,
|
|
100
|
+
maxLength: 12,
|
|
101
|
+
placeholder: 'Enter some text...',
|
|
102
|
+
invalid: (value: string) => {
|
|
103
|
+
if (value === 'never') return "The value 'never' is not allowed";
|
|
104
|
+
return null;
|
|
105
|
+
},
|
|
106
|
+
onSave: ({ selectedRowIds, value }) => {
|
|
107
|
+
setRowData(rowData.map((data) => (selectedRowIds.includes(data.id) ? { ...data, text2: value } : data)));
|
|
108
|
+
return true;
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
),
|
|
113
|
+
GridPopoverMenu(
|
|
114
|
+
{},
|
|
115
|
+
{
|
|
116
|
+
multiEdit: true,
|
|
117
|
+
editorParams: {
|
|
118
|
+
defaultAction: ({ menuOption }) => {
|
|
119
|
+
// eslint-disable-next-line no-console
|
|
120
|
+
console.log('clicked', { menuOption });
|
|
121
|
+
},
|
|
122
|
+
options: async (selectedItems) => {
|
|
123
|
+
// Just doing a timeout here to demonstrate deferred loading
|
|
124
|
+
await wait(500);
|
|
125
|
+
return [
|
|
126
|
+
{
|
|
127
|
+
label: 'Test',
|
|
128
|
+
action: () => {
|
|
129
|
+
// empty
|
|
130
|
+
},
|
|
131
|
+
disabled: selectedItems.length > 1,
|
|
132
|
+
},
|
|
133
|
+
];
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
),
|
|
138
|
+
],
|
|
139
|
+
[rowData],
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
const addRowAction = useCallback(async () => {
|
|
143
|
+
await wait(1000);
|
|
144
|
+
|
|
145
|
+
const lastRow = rowData[rowData.length - 1];
|
|
146
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
|
147
|
+
await selectRowsWithFlashDiff(async () => {
|
|
148
|
+
setRowData([
|
|
149
|
+
...rowData,
|
|
150
|
+
{
|
|
151
|
+
id: (lastRow?.id ?? 0) + 1,
|
|
152
|
+
text1: '?',
|
|
153
|
+
text2: '?',
|
|
154
|
+
},
|
|
155
|
+
]);
|
|
156
|
+
});
|
|
157
|
+
}, [rowData, selectRowsWithFlashDiff]);
|
|
158
|
+
|
|
159
|
+
return (
|
|
160
|
+
<>
|
|
161
|
+
<Grid
|
|
162
|
+
{...props}
|
|
163
|
+
enableRangeSelection={true}
|
|
164
|
+
enableMultilineBulkEdit={true}
|
|
165
|
+
hideSelectedRow={true}
|
|
166
|
+
externalSelectedItems={externalSelectedItems}
|
|
167
|
+
setExternalSelectedItems={setExternalSelectedItems}
|
|
168
|
+
columnDefs={columnDefs}
|
|
169
|
+
rowData={rowData}
|
|
170
|
+
domLayout={'autoHeight'}
|
|
171
|
+
defaultColDef={{ minWidth: 70 }}
|
|
172
|
+
sizeColumns={'auto'}
|
|
173
|
+
singleClickEdit={true}
|
|
174
|
+
onBulkEditingComplete={() => {
|
|
175
|
+
/* eslint-disable-next-line no-console */
|
|
176
|
+
console.log('onBulkEditingComplete()');
|
|
177
|
+
}}
|
|
178
|
+
/>
|
|
179
|
+
<ActionButton icon={'ic_add'} name={'Add new row'} inProgressName={'Adding...'} onClick={addRowAction} />
|
|
180
|
+
</>
|
|
181
|
+
);
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
export const _EditInlineText = GridInlineTextTemplate.bind({});
|
|
185
|
+
_EditInlineText.play = waitForGridReady;
|
|
@@ -256,7 +256,7 @@ KeyboardInteractions.play = async ({ canvasElement }) => {
|
|
|
256
256
|
await userEvent.keyboard('{arrowright}{arrowright}{arrowright}{arrowright}{arrowright}{arrowright}{arrowright}');
|
|
257
257
|
|
|
258
258
|
// Test enter post focus
|
|
259
|
-
const test = async (fn: () => any,
|
|
259
|
+
const test = async (fn: () => any, coldIndex: string, rowIndex: string) => {
|
|
260
260
|
await userEvent.keyboard('{Enter}');
|
|
261
261
|
await wait(1000);
|
|
262
262
|
await userEvent.keyboard('{arrowdown}{arrowdown}');
|
|
@@ -265,8 +265,8 @@ KeyboardInteractions.play = async ({ canvasElement }) => {
|
|
|
265
265
|
await waitFor(() => {
|
|
266
266
|
const activeCell = canvasElement.ownerDocument.activeElement;
|
|
267
267
|
expect(activeCell).toHaveClass('ag-cell-focus');
|
|
268
|
-
expect(activeCell).toHaveAttribute('aria-colindex',
|
|
269
|
-
expect(activeCell?.parentElement).toHaveAttribute('row-index',
|
|
268
|
+
expect(activeCell).toHaveAttribute('aria-colindex', coldIndex);
|
|
269
|
+
expect(activeCell?.parentElement).toHaveAttribute('row-index', rowIndex);
|
|
270
270
|
});
|
|
271
271
|
await wait(200);
|
|
272
272
|
};
|
package/src/styles/Grid.scss
CHANGED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
@use "../../node_modules/@linzjs/lui/dist/scss/Core" as lui;
|
|
2
|
+
|
|
3
|
+
.GridFormInlineTextInput {
|
|
4
|
+
height: 100%;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.GridFormInlineTextInput-error > input {
|
|
8
|
+
border: 2px solid red !important;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.GridFormInlineTextInput > input {
|
|
12
|
+
display: block;
|
|
13
|
+
left:0;
|
|
14
|
+
top:0;
|
|
15
|
+
right:0;
|
|
16
|
+
bottom:0;
|
|
17
|
+
position: absolute;
|
|
18
|
+
padding-left: 9px;
|
|
19
|
+
padding-right: 9px;
|
|
20
|
+
outline: 0;
|
|
21
|
+
border: 0;
|
|
22
|
+
font-family: "Open Sans", system-ui, sans-serif;
|
|
23
|
+
}
|
package/src/styles/index.scss
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { sortBy } from 'lodash-es';
|
|
2
2
|
import { expect, userEvent, waitFor } from 'storybook/test';
|
|
3
3
|
|
|
4
|
-
import { findQuick, getAllQuick } from './testQuick';
|
|
4
|
+
import { findQuick, getAllQuick, queryAllQuick } from './testQuick';
|
|
5
5
|
|
|
6
6
|
export const waitForGridReady = ({ canvasElement }: { canvasElement: HTMLElement }) =>
|
|
7
7
|
waitFor(() => expect(canvasElement.querySelector('.Grid-ready')).toBeInTheDocument(), { timeout: 5000 });
|
|
@@ -22,6 +22,10 @@ export const clickColumnHeaderToSort = async (colId: string, within: HTMLElement
|
|
|
22
22
|
await user.keyboard('{Enter}');
|
|
23
23
|
};
|
|
24
24
|
|
|
25
|
+
export const getNumberOfGridRows = (props?: { grid?: HTMLElement }): number => {
|
|
26
|
+
return queryAllQuick({ classes: '.ag-row' }, props?.grid).length;
|
|
27
|
+
};
|
|
28
|
+
|
|
25
29
|
export const gridColumnValues = (colId: string, within: HTMLElement): string[] => {
|
|
26
30
|
return sortBy(
|
|
27
31
|
getAllQuick({ tagName: `[col-id="${colId}"]`, classes: `.ag-cell` }, within),
|