@linzjs/step-ag-grid 32.7.1 → 34.0.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/dist/src/components/PostSortRowsHook.test.d.ts +1 -0
- package/dist/src/components/gridFilter/GridFilterColumnsMultiSelect.d.ts +6 -25
- package/dist/src/components/gridForm/GridFormTextInput.d.ts +2 -1
- package/dist/src/utils/__tests__/storybookTestUtil.ts +1 -1
- package/dist/step-ag-grid.cjs +190 -206
- package/dist/step-ag-grid.cjs.map +1 -1
- package/dist/step-ag-grid.esm.js +190 -206
- package/dist/step-ag-grid.esm.js.map +1 -1
- package/package.json +17 -17
- package/src/components/Grid.tsx +8 -10
- package/src/components/PostSortRowsHook.test.ts +300 -0
- package/src/components/PostSortRowsHook.ts +127 -24
- package/src/components/gridFilter/GridFilterColumnsMultiSelect.tsx +110 -199
- package/src/components/gridForm/GridFormTextInput.tsx +2 -1
- package/src/components/gridHook/useGridRangeSelection.ts +8 -6
- package/src/contexts/GridContextProvider.tsx +5 -9
- package/src/react-menu3/components/ControlledMenu.tsx +5 -3
- package/src/react-menu3/components/MenuList.tsx +7 -3
- package/src/react-menu3/hooks/useItems.ts +1 -1
- package/src/stories/components/ActionButton.stories.tsx +12 -11
- package/src/stories/decorators/withOpenInPanelDecorator.tsx +35 -0
- package/src/stories/grid/GridCopy.stories.tsx +38 -35
- package/src/stories/grid/GridDragRow.stories.tsx +41 -36
- package/src/stories/grid/GridFilterButtons.stories.tsx +25 -19
- package/src/stories/grid/GridFilterColumnsMultiSelect.stories.tsx +42 -37
- package/src/stories/grid/GridInlineText.stories.tsx +62 -49
- package/src/stories/grid/GridNoRowsOverlay.stories.tsx +28 -23
- package/src/stories/grid/GridNonEditableRow.stories.tsx +30 -24
- package/src/stories/grid/GridPinnedRow.stories.tsx +37 -31
- package/src/stories/grid/GridPopoutContextMenu.stories.tsx +29 -24
- package/src/stories/grid/GridPopoutEditBoolean.stories.tsx +89 -82
- package/src/stories/grid/GridPopoutEditGeneric.stories.tsx +27 -22
- package/src/stories/grid/GridPopoutEditGenericTextArea.stories.tsx +29 -24
- package/src/stories/grid/GridPopoverEditBearing.stories.tsx +30 -25
- package/src/stories/grid/GridPopoverEditDropDown.stories.tsx +29 -24
- package/src/stories/grid/GridPopoverEditMultiSelect.stories.tsx +29 -24
- package/src/stories/grid/GridPopoverEditMultiSelectGrid.stories.tsx +28 -24
- package/src/stories/grid/GridReadOnly.stories.tsx +56 -52
- package/src/stories/grid/GridSorting.stories.tsx +498 -86
- package/src/stories/grid/GridViewList.stories.tsx +31 -26
- package/src/stories/grid/GridViewSelectableList.stories.tsx +31 -26
- package/src/stories/grid/gridAutosize/GridAutoSize.stories.tsx +41 -37
- package/src/stories/grid/gridAutosize/GridFitSize.stories.tsx +40 -36
- package/src/stories/grid/gridAutosize/GridFitSizeFlex.stories.tsx +40 -36
- package/src/stories/grid/gridAutosize/ShowPanelResizingAgGrid/ShowPanelResizingStepAgGrid.tsx +14 -6
- package/src/stories/grid/gridFormInteraction/GridFormDropDownInteraction.stories.tsx +74 -74
- package/src/stories/grid/gridFormInteraction/GridFormEditBearingCorrectionInteraction.stories.tsx +59 -59
- package/src/stories/grid/gridFormInteraction/GridFormEditBearingInteraction.stories.tsx +58 -58
- package/src/stories/grid/gridFormInteraction/GridFormMultiSelectGridInteraction.stories.tsx +62 -62
- package/src/stories/grid/gridFormInteraction/GridFormMultiSelectInteraction.stories.tsx +118 -118
- package/src/stories/grid/gridFormInteraction/GridFormPopoverMenuInteraction.stories.tsx +107 -105
- package/src/stories/grid/gridFormInteraction/GridFormTextAreaInteraction.stories.tsx +72 -64
- package/src/stories/grid/gridFormInteraction/GridFormTextInputInteraction.stories.tsx +82 -73
- package/src/stories/grid/gridFormStatic/GridFormDropDown.stories.tsx +12 -13
- package/src/stories/grid/gridFormStatic/GridFormEditBearing.stories.tsx +12 -13
- package/src/stories/grid/gridFormStatic/GridFormEditBearingCorrection.stories.tsx +11 -13
- package/src/stories/grid/gridFormStatic/GridFormMessage.stories.tsx +11 -13
- package/src/stories/grid/gridFormStatic/GridFormMultiSelect.stories.tsx +11 -13
- package/src/stories/grid/gridFormStatic/GridFormPopoverMenu.stories.tsx +11 -13
- package/src/stories/grid/gridFormStatic/GridFormTextArea.stories.tsx +11 -13
- package/src/stories/grid/gridFormStatic/GridFormTextInput.stories.tsx +11 -13
- package/src/stories/grid/interactions/GridKeyboardInteractions.stories.tsx +110 -107
- package/src/stories/react-menu/ReactMenu.stories.tsx +70 -73
- package/src/styles/GridLoadableCell.scss +1 -1
- package/src/utils/__tests__/storybookTestUtil.ts +1 -1
- package/src/utils/useSharedInterval.ts +3 -3
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import './GridFilterColumnsMultiSelect.scss';
|
|
2
2
|
|
|
3
3
|
import { LuiCheckboxInput } from '@linzjs/lui';
|
|
4
|
-
import type { IDoesFilterPassParams,
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
4
|
+
import type { IDoesFilterPassParams, IFilterParams } from 'ag-grid-community';
|
|
5
|
+
import { CustomFilterProps, useGridFilter } from 'ag-grid-react';
|
|
6
|
+
import React, { useEffect, useMemo, useRef } from 'react';
|
|
7
7
|
|
|
8
8
|
export interface CheckboxMultiFilterParams extends IFilterParams {
|
|
9
9
|
labels?: Record<string, string>;
|
|
@@ -15,28 +15,106 @@ export interface CheckboxMultiFilterModel {
|
|
|
15
15
|
values: string[];
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
interface FilterUIProps {
|
|
19
|
-
allValues: string[];
|
|
20
|
-
selected: Set<string>;
|
|
21
|
-
labels: Record<string, string>;
|
|
22
|
-
labelFormatter?: (value: string) => string;
|
|
23
|
-
onToggleAll: (checked: boolean) => void;
|
|
24
|
-
onToggleOne: (value: string, checked: boolean) => void;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
18
|
const EMPTY_KEY = '__EMPTY__';
|
|
28
19
|
const DEFAULT_EMPTY_LABEL = '-';
|
|
29
20
|
const filterStateMap = new Map<string, boolean>();
|
|
30
21
|
const filterClickCountMap = new Map<string, number>();
|
|
31
22
|
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
23
|
+
const normalizeCellValue = (value: unknown): string => {
|
|
24
|
+
if (typeof value === 'string') return value.trim() === '' ? EMPTY_KEY : value;
|
|
25
|
+
return EMPTY_KEY;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const loadFieldValues = (params: CheckboxMultiFilterParams): string[] => {
|
|
29
|
+
const field = params.colDef.field as string;
|
|
30
|
+
const values = new Set<string>();
|
|
31
|
+
|
|
32
|
+
params.api.forEachNode((node) => {
|
|
33
|
+
const data = node.data ?? {};
|
|
34
|
+
values.add(normalizeCellValue((data as Record<string, unknown>)[field]));
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const { customOrder } = params;
|
|
38
|
+
const orderMap = customOrder?.length ? new Map(customOrder.map((val, idx) => [val, idx])) : null;
|
|
39
|
+
|
|
40
|
+
return Array.from(values).sort((a, b) => {
|
|
41
|
+
if (orderMap) {
|
|
42
|
+
const aIdx = orderMap.get(a) ?? Infinity;
|
|
43
|
+
const bIdx = orderMap.get(b) ?? Infinity;
|
|
44
|
+
if (aIdx !== bIdx) return aIdx - bIdx;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (a === EMPTY_KEY) return b === EMPTY_KEY ? 0 : -1;
|
|
48
|
+
if (b === EMPTY_KEY) return 1;
|
|
49
|
+
return a.localeCompare(b);
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
type GridFilterColumnsMultiSelectProps = CustomFilterProps<any, any, CheckboxMultiFilterModel> &
|
|
54
|
+
CheckboxMultiFilterParams;
|
|
55
|
+
|
|
56
|
+
export const GridFilterColumnsMultiSelect = (props: GridFilterColumnsMultiSelectProps) => {
|
|
57
|
+
const { model, onModelChange, colDef, column, labels: labelsParam, labelFormatter } = props;
|
|
58
|
+
const containerRef = useRef<HTMLDivElement>(null);
|
|
59
|
+
|
|
60
|
+
// Loaded once when the filter is first opened, matching the previous IFilterComp's init() behaviour.
|
|
61
|
+
const allValues = useMemo(() => loadFieldValues(props), []); // eslint-disable-line react-hooks/exhaustive-deps
|
|
62
|
+
const labels = useMemo<Record<string, string>>(
|
|
63
|
+
() => ({ [EMPTY_KEY]: DEFAULT_EMPTY_LABEL, ...labelsParam }),
|
|
64
|
+
[labelsParam],
|
|
65
|
+
);
|
|
66
|
+
const selected = useMemo(() => new Set(model?.values ?? allValues), [model, allValues]);
|
|
67
|
+
|
|
68
|
+
useGridFilter({
|
|
69
|
+
doesFilterPass: (p: IDoesFilterPassParams): boolean => {
|
|
70
|
+
if (selected.size === 0) return false;
|
|
71
|
+
|
|
72
|
+
const field = colDef.field as string;
|
|
73
|
+
if (!p.data || typeof p.data !== 'object') return selected.has(EMPTY_KEY);
|
|
74
|
+
|
|
75
|
+
const raw = (p.data as Record<string, unknown>)[field];
|
|
76
|
+
return selected.has(normalizeCellValue(raw));
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
// AG Grid's header filter button re-opens the popup on every click; intercept it so a second
|
|
81
|
+
// click, while the popup is already open, closes it instead. Scoped via containerRef's
|
|
82
|
+
// ownerDocument rather than the global `document` so it keeps working when the grid is popped out.
|
|
83
|
+
useEffect(() => {
|
|
84
|
+
const ownerDocument = containerRef.current?.ownerDocument;
|
|
85
|
+
const columnId = column.getColId();
|
|
86
|
+
const filterButton = ownerDocument?.querySelector(`[col-id="${columnId}"] .ag-header-cell-filter-button`);
|
|
87
|
+
if (!filterButton) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const listener = (e: Event) => {
|
|
92
|
+
const clickCount = filterClickCountMap.get(columnId) || 0;
|
|
93
|
+
filterClickCountMap.set(columnId, clickCount + 1);
|
|
94
|
+
|
|
95
|
+
if (clickCount === 0) {
|
|
96
|
+
e.stopImmediatePropagation();
|
|
97
|
+
e.preventDefault();
|
|
98
|
+
props.api.hidePopupMenu();
|
|
99
|
+
filterStateMap.set(columnId, false);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const isOpen = filterStateMap.get(columnId) || false;
|
|
104
|
+
if (isOpen) {
|
|
105
|
+
e.stopImmediatePropagation();
|
|
106
|
+
e.preventDefault();
|
|
107
|
+
props.api.hidePopupMenu();
|
|
108
|
+
filterStateMap.set(columnId, false);
|
|
109
|
+
} else {
|
|
110
|
+
filterStateMap.set(columnId, true);
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
filterButton.addEventListener('click', listener, true);
|
|
115
|
+
return () => filterButton.removeEventListener('click', listener, true);
|
|
116
|
+
}, [column, props.api]);
|
|
117
|
+
|
|
40
118
|
const allChecked = allValues.length > 0 && selected.size === allValues.length;
|
|
41
119
|
|
|
42
120
|
const getDisplayLabel = (raw: string): string => {
|
|
@@ -44,15 +122,19 @@ const FilterUI: React.FC<FilterUIProps> = ({
|
|
|
44
122
|
return labelFormatter ? labelFormatter(base) : base;
|
|
45
123
|
};
|
|
46
124
|
|
|
125
|
+
const applySelection = (next: Set<string>): void => {
|
|
126
|
+
onModelChange(next.size === allValues.length ? null : { values: Array.from(next) });
|
|
127
|
+
};
|
|
128
|
+
|
|
47
129
|
return (
|
|
48
|
-
<div className="GridFilterColsMultiSelect">
|
|
130
|
+
<div className="GridFilterColsMultiSelect" ref={containerRef}>
|
|
49
131
|
<span className="LuiSelect-label-text">Filter column</span>
|
|
50
132
|
<LuiCheckboxInput
|
|
51
133
|
className="LuiCheckboxInput-selectAll"
|
|
52
134
|
label={'Select All'}
|
|
53
135
|
value="true"
|
|
54
136
|
isChecked={allChecked}
|
|
55
|
-
onChange={(e) =>
|
|
137
|
+
onChange={(e) => applySelection(e.target.checked ? new Set(allValues) : new Set())}
|
|
56
138
|
/>
|
|
57
139
|
{allValues.map((val) => (
|
|
58
140
|
<LuiCheckboxInput
|
|
@@ -61,189 +143,18 @@ const FilterUI: React.FC<FilterUIProps> = ({
|
|
|
61
143
|
label={getDisplayLabel(val)}
|
|
62
144
|
value={val}
|
|
63
145
|
isChecked={selected.has(val)}
|
|
64
|
-
onChange={(e) =>
|
|
146
|
+
onChange={(e) => {
|
|
147
|
+
const next = new Set(selected);
|
|
148
|
+
if (e.target.checked) next.add(val);
|
|
149
|
+
else next.delete(val);
|
|
150
|
+
applySelection(next);
|
|
151
|
+
}}
|
|
65
152
|
/>
|
|
66
153
|
))}
|
|
67
154
|
</div>
|
|
68
155
|
);
|
|
69
156
|
};
|
|
70
157
|
|
|
71
|
-
export class GridFilterColumnsMultiSelect implements IFilterComp {
|
|
72
|
-
private params!: CheckboxMultiFilterParams;
|
|
73
|
-
private selectedValues = new Set<string>();
|
|
74
|
-
private labels: Record<string, string> = {};
|
|
75
|
-
private allValues: string[] = [];
|
|
76
|
-
private gui!: HTMLElement;
|
|
77
|
-
private labelFormatter?: (value: string) => string;
|
|
78
|
-
private reactRoot: Root | null = null;
|
|
79
|
-
private filterButtonClickListener: ((e: Event) => void) | null = null;
|
|
80
|
-
private filterButton: Element | null = null;
|
|
81
|
-
|
|
82
|
-
private normalizeCellValue(value: unknown): string {
|
|
83
|
-
if (typeof value === 'string') return value.trim() === '' ? EMPTY_KEY : value;
|
|
84
|
-
return EMPTY_KEY;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
private loadFieldValues(): string[] {
|
|
88
|
-
const field = this.params.colDef.field as string;
|
|
89
|
-
const values = new Set<string>();
|
|
90
|
-
|
|
91
|
-
this.params.api.forEachNode((node) => {
|
|
92
|
-
const data = node.data ?? {};
|
|
93
|
-
const raw = (data as Record<string, unknown>)[field];
|
|
94
|
-
const norm = this.normalizeCellValue(raw);
|
|
95
|
-
values.add(norm);
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
const { customOrder } = this.params;
|
|
99
|
-
const orderMap = customOrder?.length ? new Map(customOrder.map((val, idx) => [val, idx])) : null;
|
|
100
|
-
|
|
101
|
-
return Array.from(values).sort((a, b) => {
|
|
102
|
-
if (orderMap) {
|
|
103
|
-
const aIdx = orderMap.get(a) ?? Infinity;
|
|
104
|
-
const bIdx = orderMap.get(b) ?? Infinity;
|
|
105
|
-
if (aIdx !== bIdx) return aIdx - bIdx;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
if (a === EMPTY_KEY) return b === EMPTY_KEY ? 0 : -1;
|
|
109
|
-
if (b === EMPTY_KEY) return 1;
|
|
110
|
-
return a.localeCompare(b);
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
init(params: CheckboxMultiFilterParams): void {
|
|
115
|
-
this.params = params;
|
|
116
|
-
this.labels = { ...params.labels };
|
|
117
|
-
this.labelFormatter = params.labelFormatter;
|
|
118
|
-
|
|
119
|
-
if (!(EMPTY_KEY in this.labels)) {
|
|
120
|
-
this.labels[EMPTY_KEY] = DEFAULT_EMPTY_LABEL;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
this.allValues = this.loadFieldValues();
|
|
124
|
-
this.selectedValues = new Set(this.allValues);
|
|
125
|
-
|
|
126
|
-
this.gui = document.createElement('div');
|
|
127
|
-
this.reactRoot = createRoot(this.gui);
|
|
128
|
-
this.render();
|
|
129
|
-
this.setupFilterButtonListener();
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
private setupFilterButtonListener(): void {
|
|
133
|
-
const columnId = this.params.column.getColId();
|
|
134
|
-
this.filterButton = document.querySelector(`[col-id="${columnId}"] .ag-header-cell-filter-button`);
|
|
135
|
-
|
|
136
|
-
if (this.filterButton) {
|
|
137
|
-
this.filterButtonClickListener = (e: Event) => {
|
|
138
|
-
const clickCount = filterClickCountMap.get(columnId) || 0;
|
|
139
|
-
filterClickCountMap.set(columnId, clickCount + 1);
|
|
140
|
-
|
|
141
|
-
if (clickCount === 0) {
|
|
142
|
-
e.stopImmediatePropagation();
|
|
143
|
-
e.preventDefault();
|
|
144
|
-
this.params.api.hidePopupMenu();
|
|
145
|
-
filterStateMap.set(columnId, false);
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
const isOpen = filterStateMap.get(columnId) || false;
|
|
150
|
-
if (isOpen) {
|
|
151
|
-
e.stopImmediatePropagation();
|
|
152
|
-
e.preventDefault();
|
|
153
|
-
this.params.api.hidePopupMenu();
|
|
154
|
-
filterStateMap.set(columnId, false);
|
|
155
|
-
} else {
|
|
156
|
-
filterStateMap.set(columnId, true);
|
|
157
|
-
}
|
|
158
|
-
};
|
|
159
|
-
|
|
160
|
-
this.filterButton.addEventListener('click', this.filterButtonClickListener, true);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
private render(): void {
|
|
165
|
-
if (!this.reactRoot) return;
|
|
166
|
-
this.reactRoot.render(
|
|
167
|
-
<FilterUI
|
|
168
|
-
allValues={this.allValues}
|
|
169
|
-
selected={this.selectedValues}
|
|
170
|
-
labels={this.labels}
|
|
171
|
-
labelFormatter={this.labelFormatter}
|
|
172
|
-
onToggleAll={this.handleToggleAll.bind(this)}
|
|
173
|
-
onToggleOne={this.handleToggleOne.bind(this)}
|
|
174
|
-
/>,
|
|
175
|
-
);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
private handleToggleAll(checked: boolean): void {
|
|
179
|
-
if (checked) {
|
|
180
|
-
this.allValues.forEach((val) => this.selectedValues.add(val));
|
|
181
|
-
} else {
|
|
182
|
-
this.selectedValues.clear();
|
|
183
|
-
}
|
|
184
|
-
this.render();
|
|
185
|
-
this.params.filterChangedCallback();
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
private handleToggleOne(value: string, checked: boolean): void {
|
|
189
|
-
if (checked) {
|
|
190
|
-
this.selectedValues.add(value);
|
|
191
|
-
} else {
|
|
192
|
-
this.selectedValues.delete(value);
|
|
193
|
-
}
|
|
194
|
-
this.render();
|
|
195
|
-
this.params.filterChangedCallback();
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
getGui(): HTMLElement {
|
|
199
|
-
return this.gui;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
isFilterActive(): boolean {
|
|
203
|
-
return this.selectedValues.size !== this.allValues.length;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
doesFilterPass(p: IDoesFilterPassParams): boolean {
|
|
207
|
-
if (this.selectedValues.size === 0) {
|
|
208
|
-
return false;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
const field = this.params.colDef.field as string;
|
|
212
|
-
if (!p.data || typeof p.data !== 'object') {
|
|
213
|
-
return this.selectedValues.has(EMPTY_KEY);
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
const raw = (p.data as Record<string, unknown>)[field];
|
|
217
|
-
const norm = this.normalizeCellValue(raw);
|
|
218
|
-
return this.selectedValues.has(norm);
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
getModel(): CheckboxMultiFilterModel | null {
|
|
222
|
-
if (this.selectedValues.size !== this.allValues.length) {
|
|
223
|
-
return { values: Array.from(this.selectedValues) };
|
|
224
|
-
}
|
|
225
|
-
return null;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
setModel(model: CheckboxMultiFilterModel | null): void {
|
|
229
|
-
this.selectedValues = new Set(model?.values || []);
|
|
230
|
-
this.render();
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
destroy(): void {
|
|
234
|
-
if (this.filterButtonClickListener && this.filterButton) {
|
|
235
|
-
this.filterButton.removeEventListener('click', this.filterButtonClickListener, true);
|
|
236
|
-
this.filterButtonClickListener = null;
|
|
237
|
-
this.filterButton = null;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
if (this.reactRoot) {
|
|
241
|
-
this.reactRoot.unmount();
|
|
242
|
-
this.reactRoot = null;
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
|
|
247
158
|
export const createCheckboxMultiFilterParams = (
|
|
248
159
|
labels: Record<string, string> = {},
|
|
249
160
|
labelFormatter?: (value: string) => string,
|
|
@@ -11,13 +11,14 @@ import {
|
|
|
11
11
|
import { CellEditorCommon } from '../GridCell';
|
|
12
12
|
import { useGridPopoverHook } from '../GridPopoverHook';
|
|
13
13
|
import { GridBaseRow } from '../types';
|
|
14
|
+
import { MaybePromise } from '../../utils/util';
|
|
14
15
|
|
|
15
16
|
export interface GridFormTextInputProps<TData extends GridBaseRow>
|
|
16
17
|
extends TextInputValidatorProps<TData>, CellEditorCommon {
|
|
17
18
|
placeholder?: string;
|
|
18
19
|
units?: string;
|
|
19
20
|
width?: string | number;
|
|
20
|
-
onSave?: (props: { selectedRows: TData[]; value: string }) =>
|
|
21
|
+
onSave?: (props: { selectedRows: TData[]; value: string }) => MaybePromise<boolean>;
|
|
21
22
|
helpText?: string;
|
|
22
23
|
disableUnicodeCharacterFilter?: boolean;
|
|
23
24
|
}
|
|
@@ -198,13 +198,14 @@ export const useGridRangeSelection = <TData extends GridBaseRow>({
|
|
|
198
198
|
);
|
|
199
199
|
|
|
200
200
|
useEffect(() => {
|
|
201
|
-
|
|
202
|
-
|
|
201
|
+
const doc = gridDivRef.current?.ownerDocument;
|
|
202
|
+
doc?.addEventListener('mousedown', trackMouseDown, { capture: true });
|
|
203
|
+
doc?.addEventListener('mouseup', trackMouseUp, { capture: true });
|
|
203
204
|
return () => {
|
|
204
|
-
|
|
205
|
-
|
|
205
|
+
doc?.removeEventListener('mousemove', trackMouseDown, { capture: true });
|
|
206
|
+
doc?.removeEventListener('mouseup', trackMouseUp, { capture: true });
|
|
206
207
|
};
|
|
207
|
-
}, [trackMouseDown, trackMouseUp]);
|
|
208
|
+
}, [trackMouseDown, trackMouseUp, gridDivRef]);
|
|
208
209
|
|
|
209
210
|
const onCellMouseOver = useCallback(
|
|
210
211
|
(e: CellMouseOverEvent, mouseDown?: boolean) => {
|
|
@@ -239,7 +240,7 @@ export const useGridRangeSelection = <TData extends GridBaseRow>({
|
|
|
239
240
|
) {
|
|
240
241
|
e.api.stopEditing();
|
|
241
242
|
hasSelectedMoreThanOneCellRef.current = true;
|
|
242
|
-
|
|
243
|
+
gridDivRef.current?.ownerDocument.defaultView?.getSelection()?.removeAllRanges();
|
|
243
244
|
}
|
|
244
245
|
|
|
245
246
|
updateRangeSelectionCellClasses();
|
|
@@ -251,6 +252,7 @@ export const useGridRangeSelection = <TData extends GridBaseRow>({
|
|
|
251
252
|
rangeEndRef,
|
|
252
253
|
rangeSortedNodesRef,
|
|
253
254
|
rangeStartRef,
|
|
255
|
+
gridDivRef,
|
|
254
256
|
],
|
|
255
257
|
);
|
|
256
258
|
|
|
@@ -767,15 +767,11 @@ export const GridContextProvider = <TData extends GridBaseRow>(props: PropsWithC
|
|
|
767
767
|
}
|
|
768
768
|
|
|
769
769
|
if (ok) {
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
// This is needed to trigger postSortRowsHook
|
|
776
|
-
if (!gridApi.isDestroyed) {
|
|
777
|
-
gridApi.refreshClientSideRowModel();
|
|
778
|
-
}
|
|
770
|
+
defer(() => {
|
|
771
|
+
if (!gridApi.isDestroyed()) {
|
|
772
|
+
gridApi.refreshClientSideRowModel();
|
|
773
|
+
}
|
|
774
|
+
});
|
|
779
775
|
}
|
|
780
776
|
|
|
781
777
|
void (async () => {
|
|
@@ -288,7 +288,7 @@ export const ControlledMenuFr = (
|
|
|
288
288
|
const onBlur = (e: FocusEvent) => {
|
|
289
289
|
if (
|
|
290
290
|
isMenuOpen(state) &&
|
|
291
|
-
!e.currentTarget.contains(e.relatedTarget ||
|
|
291
|
+
!e.currentTarget.contains(e.relatedTarget || e.currentTarget.ownerDocument.activeElement) &&
|
|
292
292
|
!isWithinMenu(e.relatedTarget)
|
|
293
293
|
) {
|
|
294
294
|
safeCall(onClose, { reason: CloseReason.BLUR });
|
|
@@ -348,8 +348,10 @@ export const ControlledMenuFr = (
|
|
|
348
348
|
|
|
349
349
|
if (portal) {
|
|
350
350
|
if (typeof portal === 'boolean') {
|
|
351
|
-
|
|
352
|
-
|
|
351
|
+
const thisDocument =
|
|
352
|
+
containerRef.current?.ownerDocument ?? (typeof document !== 'undefined' ? document : undefined);
|
|
353
|
+
if (portal && thisDocument) {
|
|
354
|
+
return createPortal(menuList, thisDocument.body);
|
|
353
355
|
}
|
|
354
356
|
} else {
|
|
355
357
|
return portal.target ? createPortal(menuList, portal.target) : portal.stablePosition ? null : menuList;
|
|
@@ -192,10 +192,11 @@ export const MenuList = ({
|
|
|
192
192
|
}
|
|
193
193
|
|
|
194
194
|
if (!scrollNodes.menu) {
|
|
195
|
+
const thisWindow = containerRef.current.ownerDocument.defaultView ?? window;
|
|
195
196
|
scrollNodes.menu =
|
|
196
197
|
(boundingBoxRef
|
|
197
198
|
? boundingBoxRef.current // user explicitly sets boundingBoxRef
|
|
198
|
-
: getScrollAncestor(rootMenuRef?.current)) ||
|
|
199
|
+
: getScrollAncestor(rootMenuRef?.current)) || thisWindow; // try to discover bounding box automatically
|
|
199
200
|
}
|
|
200
201
|
|
|
201
202
|
const positionHelpers = getPositionHelpers(containerRef, menuRef, scrollNodes.menu, boundingBoxPadding);
|
|
@@ -298,7 +299,8 @@ export const MenuList = ({
|
|
|
298
299
|
let { menu: menuScroll } = scrollNodes;
|
|
299
300
|
if (!isOpen || !menuScroll) return;
|
|
300
301
|
|
|
301
|
-
|
|
302
|
+
const thisWindow = containerRef?.current?.ownerDocument.defaultView ?? window;
|
|
303
|
+
menuScroll = menuScroll.addEventListener ? menuScroll : thisWindow;
|
|
302
304
|
if (!scrollNodes.anchors) {
|
|
303
305
|
scrollNodes.anchors = [];
|
|
304
306
|
let anchorScroll = getScrollAncestor(rootAnchorRef && rootAnchorRef.current);
|
|
@@ -323,6 +325,7 @@ export const MenuList = ({
|
|
|
323
325
|
const scrollObservers = scrollNodes.anchors.concat(viewScroll !== 'initial' ? menuScroll : []);
|
|
324
326
|
scrollObservers.forEach((o: any) => o.addEventListener('scroll', handleScroll));
|
|
325
327
|
return () => scrollObservers.forEach((o) => o.removeEventListener('scroll', handleScroll));
|
|
328
|
+
// oxlint-disable-next-line react/refs react-hooks/exhaustive-deps
|
|
326
329
|
}, [rootAnchorRef, scrollNodes, isOpen, onClose, viewScroll, handlePosition]);
|
|
327
330
|
|
|
328
331
|
const hasOverflow = !!overflowData && overflowData.overflowAmt != null && overflowData.overflowAmt > 0;
|
|
@@ -403,6 +406,7 @@ export const MenuList = ({
|
|
|
403
406
|
useEffect(() => {
|
|
404
407
|
if (!isOpen) {
|
|
405
408
|
dispatch(HoverActionTypes.RESET, undefined, 0);
|
|
409
|
+
// oxlint-disable-next-line react/set-state-in-effect
|
|
406
410
|
if (!closeTransition) setOverflowData(undefined);
|
|
407
411
|
return () => {};
|
|
408
412
|
}
|
|
@@ -425,7 +429,7 @@ export const MenuList = ({
|
|
|
425
429
|
const id = setTimeout(
|
|
426
430
|
() => {
|
|
427
431
|
// If focus has already been set to a children element, don't set focus on menu or item
|
|
428
|
-
if (menuRef.current && !menuRef.current.contains(
|
|
432
|
+
if (menuRef.current && !menuRef.current.contains(menuRef.current.ownerDocument.activeElement)) {
|
|
429
433
|
// Handle popover portal focus
|
|
430
434
|
const popupElement = focusRef.current?.nextSibling;
|
|
431
435
|
if (!focusFirstInput(popupElement)) {
|
|
@@ -29,7 +29,7 @@ export const useItems = (menuRef: MutableRefObject<any>, focusRef: MutableRefObj
|
|
|
29
29
|
const index = items.indexOf(item);
|
|
30
30
|
if (index > -1) {
|
|
31
31
|
items.splice(index, 1);
|
|
32
|
-
if (item.contains(
|
|
32
|
+
if (item.contains(item.ownerDocument.activeElement)) {
|
|
33
33
|
focusRef?.current?.focus();
|
|
34
34
|
setHoverItem(undefined);
|
|
35
35
|
}
|
|
@@ -1,18 +1,10 @@
|
|
|
1
|
-
import '@
|
|
2
|
-
|
|
3
|
-
import { Meta, StoryFn } from '@storybook/react-vite';
|
|
1
|
+
import { Meta, StoryObj } from '@storybook/react-vite';
|
|
4
2
|
import { useCallback } from 'react';
|
|
5
3
|
|
|
6
4
|
import { ActionButton } from '../../lui/ActionButton';
|
|
7
5
|
import { wait } from '../../utils/util';
|
|
8
6
|
|
|
9
|
-
|
|
10
|
-
title: 'Components / ActionButton',
|
|
11
|
-
component: ActionButton,
|
|
12
|
-
args: {},
|
|
13
|
-
} as Meta<typeof ActionButton>;
|
|
14
|
-
|
|
15
|
-
const ActionButtonTemplate: StoryFn<typeof ActionButton> = () => {
|
|
7
|
+
const ActionButtonTemplate = () => {
|
|
16
8
|
const performAction = useCallback(async () => {
|
|
17
9
|
await wait(1000);
|
|
18
10
|
}, []);
|
|
@@ -54,4 +46,13 @@ const ActionButtonTemplate: StoryFn<typeof ActionButton> = () => {
|
|
|
54
46
|
);
|
|
55
47
|
};
|
|
56
48
|
|
|
57
|
-
|
|
49
|
+
const meta: Meta<typeof ActionButtonTemplate> = {
|
|
50
|
+
title: 'Components / ActionButton',
|
|
51
|
+
component: ActionButtonTemplate,
|
|
52
|
+
args: {},
|
|
53
|
+
};
|
|
54
|
+
export default meta;
|
|
55
|
+
|
|
56
|
+
type Story = StoryObj<typeof meta>;
|
|
57
|
+
|
|
58
|
+
export const ActionButtonSimple: Story = {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Panel,
|
|
3
|
+
PanelContent,
|
|
4
|
+
PanelHeader,
|
|
5
|
+
PanelsContextProvider,
|
|
6
|
+
RibbonButtonOpenPanel,
|
|
7
|
+
RibbonContainer,
|
|
8
|
+
} from '@linzjs/windows';
|
|
9
|
+
import type { Decorator } from '@storybook/react-vite';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Adds an "Open in panel" button above the story. The panel it opens has a built-in
|
|
13
|
+
* Pop-out/Pop-in toggle (via @linzjs/windows) that moves its content into a real,
|
|
14
|
+
* separate browser window - useful for manually testing grid behaviour when popped out.
|
|
15
|
+
*/
|
|
16
|
+
export const withOpenInPanelDecorator: Decorator = (Story) => (
|
|
17
|
+
<PanelsContextProvider baseZIndex={500} panelStateOptions={null}>
|
|
18
|
+
<RibbonContainer>
|
|
19
|
+
<RibbonButtonOpenPanel
|
|
20
|
+
title="Open in panel"
|
|
21
|
+
uniqueId={'openInPanel'}
|
|
22
|
+
icon={'ic_launch_modal'}
|
|
23
|
+
componentFn={() => (
|
|
24
|
+
<Panel title={'Open in panel'} size={{ width: 1100, height: 600 }}>
|
|
25
|
+
<PanelHeader />
|
|
26
|
+
<PanelContent>
|
|
27
|
+
<Story />
|
|
28
|
+
</PanelContent>
|
|
29
|
+
</Panel>
|
|
30
|
+
)}
|
|
31
|
+
/>
|
|
32
|
+
</RibbonContainer>
|
|
33
|
+
<Story />
|
|
34
|
+
</PanelsContextProvider>
|
|
35
|
+
);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LuiMessagingContextProvider } from '@linzjs/lui';
|
|
2
|
-
import { Meta, StoryFn } from '@storybook/react-vite';
|
|
2
|
+
import { Meta, StoryFn, StoryObj } from '@storybook/react-vite';
|
|
3
3
|
import { useMemo, useState } from 'react';
|
|
4
4
|
|
|
5
5
|
import {
|
|
@@ -19,38 +19,7 @@ import { GridFilterColumnsToggle, GridFilterDownloadCsvButton } from '../../comp
|
|
|
19
19
|
import { GridCellFiller } from '../../components/GridCellFiller';
|
|
20
20
|
import { SeededRandomForTests } from '../../utils/__tests__/random';
|
|
21
21
|
import { waitForGridReady } from '../../utils/__tests__/storybookTestUtil';
|
|
22
|
-
|
|
23
|
-
export default {
|
|
24
|
-
title: 'Components / Grids',
|
|
25
|
-
component: Grid,
|
|
26
|
-
args: {
|
|
27
|
-
quickFilter: true,
|
|
28
|
-
quickFilterValue: '',
|
|
29
|
-
quickFilterPlaceholder: 'Quick filter...',
|
|
30
|
-
selectable: false,
|
|
31
|
-
rowSelection: 'multiple',
|
|
32
|
-
}, // Storybook hangs otherwise
|
|
33
|
-
parameters: {
|
|
34
|
-
docs: {
|
|
35
|
-
source: {
|
|
36
|
-
type: 'code',
|
|
37
|
-
},
|
|
38
|
-
},
|
|
39
|
-
},
|
|
40
|
-
decorators: [
|
|
41
|
-
(Story) => (
|
|
42
|
-
<LuiMessagingContextProvider version="v2">
|
|
43
|
-
<div style={{ width: 1024, height: '80vh', display: 'flex', flexDirection: 'column' }}>
|
|
44
|
-
<GridUpdatingContextProvider>
|
|
45
|
-
<GridContextProvider>
|
|
46
|
-
<Story />
|
|
47
|
-
</GridContextProvider>
|
|
48
|
-
</GridUpdatingContextProvider>
|
|
49
|
-
</div>
|
|
50
|
-
</LuiMessagingContextProvider>
|
|
51
|
-
),
|
|
52
|
-
],
|
|
53
|
-
} as Meta<typeof Grid>;
|
|
22
|
+
import { withOpenInPanelDecorator } from '../decorators/withOpenInPanelDecorator';
|
|
54
23
|
|
|
55
24
|
interface ITestRow {
|
|
56
25
|
id: number;
|
|
@@ -155,5 +124,39 @@ const GridCopyTemplate: StoryFn<typeof Grid<ITestRow>> = (props: GridProps<ITest
|
|
|
155
124
|
);
|
|
156
125
|
};
|
|
157
126
|
|
|
158
|
-
|
|
159
|
-
|
|
127
|
+
const meta: Meta<typeof GridCopyTemplate> = {
|
|
128
|
+
title: 'Components / Grids',
|
|
129
|
+
component: GridCopyTemplate,
|
|
130
|
+
args: {
|
|
131
|
+
selectable: false,
|
|
132
|
+
rowSelection: 'multiple',
|
|
133
|
+
}, // Storybook hangs otherwise
|
|
134
|
+
parameters: {
|
|
135
|
+
docs: {
|
|
136
|
+
source: {
|
|
137
|
+
type: 'code',
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
decorators: [
|
|
142
|
+
(Story) => (
|
|
143
|
+
<LuiMessagingContextProvider version="v2">
|
|
144
|
+
<div style={{ width: 1024, height: '80vh', display: 'flex', flexDirection: 'column' }}>
|
|
145
|
+
<GridUpdatingContextProvider>
|
|
146
|
+
<GridContextProvider>
|
|
147
|
+
<Story />
|
|
148
|
+
</GridContextProvider>
|
|
149
|
+
</GridUpdatingContextProvider>
|
|
150
|
+
</div>
|
|
151
|
+
</LuiMessagingContextProvider>
|
|
152
|
+
),
|
|
153
|
+
withOpenInPanelDecorator,
|
|
154
|
+
],
|
|
155
|
+
};
|
|
156
|
+
export default meta;
|
|
157
|
+
|
|
158
|
+
type Story = StoryObj<typeof meta>;
|
|
159
|
+
|
|
160
|
+
export const GridCopy: Story = {
|
|
161
|
+
play: waitForGridReady,
|
|
162
|
+
};
|