@linzjs/step-ag-grid 7.11.6 → 7.11.7

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.11.6",
5
+ "version": "7.11.7",
6
6
  "keywords": [
7
7
  "aggrid",
8
8
  "ag-grid",
@@ -178,6 +178,18 @@ export const Grid = (params: GridProps): JSX.Element => {
178
178
  suppressSizeToFit: true,
179
179
  checkboxSelection: true,
180
180
  headerComponent: GridHeaderSelect,
181
+ suppressHeaderKeyboardEvent: (e) => {
182
+ if (e.event.key === "Enter" && !e.event.repeat) {
183
+ const selectedNodeCount = e.api.getSelectedRows().length;
184
+ if (selectedNodeCount == 0) {
185
+ e.api.selectAllFiltered();
186
+ } else {
187
+ e.api.deselectAll();
188
+ }
189
+ return false;
190
+ }
191
+ return true;
192
+ },
181
193
  onCellClicked: clickSelectorCheckboxWhenContainingCellClicked,
182
194
  },
183
195
  ...adjustColDefs,
@@ -1,6 +1,6 @@
1
1
  import clsx from "clsx";
2
2
  import { IHeaderParams } from "ag-grid-community";
3
- import { useCallback, useEffect, useState } from "react";
3
+ import { useEffect, useState } from "react";
4
4
 
5
5
  /**
6
6
  * AgGrid's existing select header doesn't work the way we want.
@@ -12,9 +12,9 @@ export const GridHeaderSelect = ({ api }: IHeaderParams) => {
12
12
  const [updateCounter, setUpdateCounter] = useState(0);
13
13
  const selectedNodeCount = api.getSelectedRows().length;
14
14
 
15
- const clickHandler = useCallback(() => {
15
+ const clickHandler = () => {
16
16
  setUpdateCounter(updateCounter + 1);
17
- }, [updateCounter]);
17
+ };
18
18
 
19
19
  useEffect(() => {
20
20
  api.addEventListener("selectionChanged", clickHandler);
@@ -1,5 +1,5 @@
1
1
  import { ReactElement, ReactNode, useContext, useRef, useState } from "react";
2
- import { GridApi, RowNode } from "ag-grid-community";
2
+ import { ColDef, GridApi, RowNode } from "ag-grid-community";
3
3
  import { GridContext } from "./GridContext";
4
4
  import { delay, difference, isEmpty, last, sortBy } from "lodash-es";
5
5
  import { isNotEmpty, wait } from "../utils/util";
@@ -131,7 +131,18 @@ export const GridContextProvider = (props: GridContextProps): ReactElement => {
131
131
  (node) => node.data.id,
132
132
  );
133
133
  const firstNode = rowsThatNeedSelecting[0];
134
- firstNode && gridApi.ensureNodeVisible(firstNode);
134
+ if (firstNode) {
135
+ gridApi.ensureNodeVisible(firstNode);
136
+ const colDefs = gridApi.getColumnDefs();
137
+ if (colDefs && colDefs.length) {
138
+ const col = colDefs[0] as ColDef; // We don't support ColGroupDef
139
+ const rowIndex = firstNode.rowIndex;
140
+ if (rowIndex != null && col != null) {
141
+ const colId = col.colId;
142
+ colId != null && setTimeout(() => gridApi.setFocusedCell(rowIndex, colId), 100);
143
+ }
144
+ }
145
+ }
135
146
  if (select) {
136
147
  // Select rows that shouldn't be selected
137
148
  rowsThatNeedSelecting.forEach((node) => node.setSelected(true));
@@ -7,7 +7,7 @@ import { ComponentMeta, ComponentStory } from "@storybook/react/dist/ts3.9/clien
7
7
  import { GridUpdatingContextProvider } from "../../contexts/GridUpdatingContextProvider";
8
8
  import { GridContextProvider } from "../../contexts/GridContextProvider";
9
9
  import { Grid, GridProps } from "../../components/Grid";
10
- import { useCallback, useMemo, useState } from "react";
10
+ import { useCallback, useContext, useMemo, useState } from "react";
11
11
  import { ColDefT, GridCell } from "../../components/GridCell";
12
12
  import { IFormTestRow } from "./FormTest";
13
13
  import { isFloat, wait } from "../../utils/util";
@@ -15,6 +15,7 @@ import { GridPopoverTextArea } from "../../components/gridPopoverEdit/GridPopove
15
15
  import { GridPopoverTextInput } from "../../components/gridPopoverEdit/GridPopoverTextInput";
16
16
  import { ActionButton } from "../../lui/ActionButton";
17
17
  import { GridPopoverMenu } from "../../components/gridPopoverEdit/GridPopoverMenu";
18
+ import { GridContext } from "../../contexts/GridContext";
18
19
 
19
20
  export default {
20
21
  title: "Components / Grids",
@@ -37,6 +38,7 @@ export default {
37
38
  } as ComponentMeta<typeof Grid>;
38
39
 
39
40
  const GridPopoutEditGenericTemplate: ComponentStory<typeof Grid> = (props: GridProps) => {
41
+ const { selectRowsWithFlashDiff } = useContext(GridContext);
40
42
  const [externalSelectedItems, setExternalSelectedItems] = useState<any[]>([]);
41
43
  const [rowData, setRowData] = useState([
42
44
  { id: 1000, name: "IS IS DP12345", nameType: "IS", numba: "IX", plan: "DP 12345", distance: 10 },
@@ -155,9 +157,12 @@ const GridPopoutEditGenericTemplate: ComponentStory<typeof Grid> = (props: GridP
155
157
 
156
158
  const addRowAction = useCallback(async () => {
157
159
  await wait(1000);
160
+
158
161
  const lastRow = rowData[rowData.length - 1];
159
- setRowData([...rowData, { id: lastRow.id + 1, name: "?", nameType: "?", numba: "?", plan: "", distance: null }]);
160
- }, [rowData]);
162
+ await selectRowsWithFlashDiff(async () => {
163
+ setRowData([...rowData, { id: lastRow.id + 1, name: "?", nameType: "?", numba: "?", plan: "", distance: null }]);
164
+ });
165
+ }, [rowData, selectRowsWithFlashDiff]);
161
166
 
162
167
  return (
163
168
  <>