@linzjs/step-ag-grid 21.2.0 → 21.2.1

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": "21.2.0",
5
+ "version": "21.2.1",
6
6
  "keywords": [
7
7
  "aggrid",
8
8
  "ag-grid",
@@ -639,7 +639,24 @@ export const GridContextProvider = <TData extends GridBaseRow>(props: PropsWithC
639
639
  const onFilterChanged = useMemo(
640
640
  () =>
641
641
  debounce(() => {
642
- gridApi && gridApi.onFilterChanged();
642
+ // This is terrible, but there's no other way for me to check whether a filter has changed the grid
643
+ const getDisplayedRowsHash = () => {
644
+ const arr: any[] = [];
645
+ gridApi?.forEachNodeAfterFilter((rowNode) => {
646
+ arr.push(rowNode.id);
647
+ });
648
+ return arr.join("|");
649
+ };
650
+
651
+ if (gridApi) {
652
+ const hasFocusedCell = gridApi.getFocusedCell();
653
+ const preHash = hasFocusedCell && getDisplayedRowsHash();
654
+ gridApi.onFilterChanged();
655
+ const postHash = hasFocusedCell && getDisplayedRowsHash();
656
+ // Ag-grid has a bug where if a focused cell comes into view after a filter the filter loses focus
657
+ // So the focus is cleared to prevent this
658
+ preHash !== postHash && gridApi.clearFocusedCell();
659
+ }
643
660
  }, 200),
644
661
  [gridApi],
645
662
  );
@@ -255,7 +255,14 @@ const GridReadOnlyTemplate: StoryFn<typeof Grid> = (props: GridProps) => {
255
255
  );
256
256
  };
257
257
 
258
- const GridFilterLessThan = (props: { field: keyof ITestRow; text: string }): ReactElement => {
258
+ type KeysOfType<TObject, TValue> = {
259
+ [K in keyof TObject]: TObject[K] extends TValue ? K : never;
260
+ }[keyof TObject];
261
+
262
+ const GridFilterLessThan = (props: {
263
+ field: KeysOfType<ITestRow, number | null | undefined>;
264
+ text: string;
265
+ }): ReactElement => {
259
266
  const [value, setValue] = useState<number>();
260
267
 
261
268
  const filter = useCallback(