@linzjs/step-ag-grid 29.15.0 → 29.16.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/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": "29.15.0",
5
+ "version": "29.16.0",
6
6
  "keywords": [
7
7
  "aggrid",
8
8
  "ag-grid",
@@ -8,6 +8,7 @@ import { createRoot, Root } from 'react-dom/client';
8
8
  export interface CheckboxMultiFilterParams extends IFilterParams {
9
9
  labels?: Record<string, string>;
10
10
  labelFormatter?: (value: string) => string;
11
+ customOrder?: string[];
11
12
  }
12
13
 
13
14
  export interface CheckboxMultiFilterModel {
@@ -91,9 +92,18 @@ export class GridFilterColumnsMultiSelect implements IFilterComp {
91
92
  values.add(norm);
92
93
  });
93
94
 
95
+ const { customOrder } = this.params;
96
+ const orderMap = customOrder?.length ? new Map(customOrder.map((val, idx) => [val, idx])) : null;
97
+
94
98
  return Array.from(values).sort((a, b) => {
95
- if (a === EMPTY_KEY && b !== EMPTY_KEY) return -1;
96
- if (b === EMPTY_KEY && a !== EMPTY_KEY) return 1;
99
+ if (orderMap) {
100
+ const aIdx = orderMap.get(a) ?? Infinity;
101
+ const bIdx = orderMap.get(b) ?? Infinity;
102
+ if (aIdx !== bIdx) return aIdx - bIdx;
103
+ }
104
+
105
+ if (a === EMPTY_KEY) return b === EMPTY_KEY ? 0 : -1;
106
+ if (b === EMPTY_KEY) return 1;
97
107
  return a.localeCompare(b);
98
108
  });
99
109
  }
@@ -155,10 +165,14 @@ export class GridFilterColumnsMultiSelect implements IFilterComp {
155
165
  }
156
166
 
157
167
  isFilterActive(): boolean {
158
- return this.selectedValues.size > 0;
168
+ return this.selectedValues.size !== this.allValues.length;
159
169
  }
160
170
 
161
171
  doesFilterPass(p: IDoesFilterPassParams): boolean {
172
+ if (this.selectedValues.size === 0) {
173
+ return false;
174
+ }
175
+
162
176
  const field = this.params.colDef.field as string;
163
177
  if (!p.data || typeof p.data !== 'object') {
164
178
  return this.selectedValues.has(EMPTY_KEY);
@@ -170,7 +184,10 @@ export class GridFilterColumnsMultiSelect implements IFilterComp {
170
184
  }
171
185
 
172
186
  getModel(): CheckboxMultiFilterModel | null {
173
- return this.selectedValues.size > 0 ? { values: Array.from(this.selectedValues) } : null;
187
+ if (this.selectedValues.size !== this.allValues.length) {
188
+ return { values: Array.from(this.selectedValues) };
189
+ }
190
+ return null;
174
191
  }
175
192
 
176
193
  setModel(model: CheckboxMultiFilterModel | null): void {
@@ -189,7 +206,9 @@ export class GridFilterColumnsMultiSelect implements IFilterComp {
189
206
  export const createCheckboxMultiFilterParams = (
190
207
  labels: Record<string, string> = {},
191
208
  labelFormatter?: (value: string) => string,
209
+ customOrder?: string[],
192
210
  ): Partial<CheckboxMultiFilterParams> => ({
193
211
  labels: { [EMPTY_KEY]: DEFAULT_EMPTY_LABEL, ...labels },
194
212
  labelFormatter,
213
+ customOrder,
195
214
  });
@@ -57,11 +57,15 @@ const GridFilterColumnsMultiSelectTemplate: StoryFn<typeof Grid<ITestRow>> = (pr
57
57
  field: 'position',
58
58
  headerName: 'Position',
59
59
  filter: GridFilterColumnsMultiSelect,
60
- filterParams: createCheckboxMultiFilterParams({
61
- Developer: 'FE Dev',
62
- Manager: 'Tech Manager',
63
- __EMPTY__: 'None',
64
- }),
60
+ filterParams: createCheckboxMultiFilterParams(
61
+ {
62
+ Developer: 'FE Dev',
63
+ Manager: 'Tech Manager',
64
+ __EMPTY__: 'None',
65
+ },
66
+ undefined,
67
+ ['Manager', 'Developer', '__EMPTY__', 'Tester'],
68
+ ),
65
69
  }),
66
70
  GridCell({
67
71
  field: 'desc',