@linzjs/step-ag-grid 13.1.2 → 13.2.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": "13.1.2",
5
+ "version": "13.2.0",
6
6
  "keywords": [
7
7
  "aggrid",
8
8
  "ag-grid",
@@ -1,7 +1,7 @@
1
1
  import { CellClickedEvent, ColDef, ModelUpdatedEvent } from "ag-grid-community";
2
2
  import { CellClassParams, EditableCallback, EditableCallbackParams } from "ag-grid-community/dist/lib/entities/colDef";
3
3
  import { GridOptions } from "ag-grid-community/dist/lib/entities/gridOptions";
4
- import { AgGridEvent, CellEvent, GridReadyEvent, SelectionChangedEvent } from "ag-grid-community/dist/lib/events";
4
+ import { CellEvent, GridReadyEvent, SelectionChangedEvent } from "ag-grid-community/dist/lib/events";
5
5
  import { AgGridReact } from "ag-grid-react";
6
6
  import clsx from "clsx";
7
7
  import { difference, isEmpty, last, xorBy } from "lodash-es";
@@ -10,6 +10,7 @@ import { useCallback, useContext, useEffect, useMemo, useRef, useState } from "r
10
10
  import { GridContext } from "../contexts/GridContext";
11
11
  import { GridUpdatingContext } from "../contexts/GridUpdatingContext";
12
12
  import { fnOrVar, isNotEmpty } from "../utils/util";
13
+ import { GridNoRowsOverlay } from "./GridNoRowsOverlay";
13
14
  import { usePostSortRowsHook } from "./PostSortRowsHook";
14
15
  import { GridHeaderSelect } from "./gridHeader";
15
16
 
@@ -35,12 +36,20 @@ export interface GridProps {
35
36
  autoSelectFirstRow?: boolean;
36
37
  onColumnMoved?: GridOptions["onColumnMoved"];
37
38
  alwaysShowVerticalScroll?: boolean;
39
+ onGridSizeChanged: GridOptions["onGridSizeChanged"];
40
+ onFirstDataRendered: GridOptions["onFirstDataRendered"];
41
+ suppressColumnVirtualization: GridOptions["suppressColumnVirtualisation"];
38
42
  }
39
43
 
40
44
  /**
41
45
  * Wrapper for AgGrid to add commonly used functionality.
42
46
  */
43
- export const Grid = ({ rowSelection = "multiple", "data-testid": dataTestId, ...params }: GridProps): JSX.Element => {
47
+ export const Grid = ({
48
+ "data-testid": dataTestId,
49
+ rowSelection = "multiple",
50
+ suppressColumnVirtualization = true,
51
+ ...params
52
+ }: GridProps): JSX.Element => {
44
53
  const {
45
54
  gridReady,
46
55
  setApis,
@@ -213,23 +222,6 @@ export const Grid = ({ rowSelection = "multiple", "data-testid": dataTestId, ...
213
222
  [dataTestId, setApis, synchroniseExternallySelectedItemsToGrid],
214
223
  );
215
224
 
216
- const noRowsOverlayComponent = useCallback(
217
- (event: AgGridEvent) => {
218
- const hasData = (params.rowData?.length ?? 0) > 0;
219
- const hasFilteredData = event.api.getDisplayedRowCount() > 0;
220
- return (
221
- <span>
222
- {!hasData
223
- ? params.noRowsOverlayText ?? "There are currently no rows"
224
- : !hasFilteredData
225
- ? "All rows have been filtered"
226
- : ""}
227
- </span>
228
- );
229
- },
230
- [params.noRowsOverlayText, params.rowData?.length],
231
- );
232
-
233
225
  const onModelUpdated = useCallback((event: ModelUpdatedEvent) => {
234
226
  event.api.getDisplayedRowCount() === 0 ? event.api.showNoRowsOverlay() : event.api.hideOverlay();
235
227
  }, []);
@@ -328,8 +320,9 @@ export const Grid = ({ rowSelection = "multiple", "data-testid": dataTestId, ...
328
320
  rowSelection={rowSelection}
329
321
  suppressBrowserResizeObserver={true}
330
322
  colResizeDefault={"shift"}
331
- onFirstDataRendered={sizeColumnsToFit}
332
- onGridSizeChanged={sizeColumnsToFit}
323
+ onFirstDataRendered={params.onFirstDataRendered ?? sizeColumnsToFit}
324
+ onGridSizeChanged={params.onGridSizeChanged ?? sizeColumnsToFit}
325
+ suppressColumnVirtualisation={suppressColumnVirtualization}
333
326
  suppressClickEdit={true}
334
327
  onCellKeyPress={onCellKeyPress}
335
328
  onCellClicked={onCellClicked}
@@ -338,7 +331,8 @@ export const Grid = ({ rowSelection = "multiple", "data-testid": dataTestId, ...
338
331
  domLayout={params.domLayout}
339
332
  columnDefs={columnDefs}
340
333
  rowData={params.rowData}
341
- noRowsOverlayComponent={noRowsOverlayComponent}
334
+ noRowsOverlayComponent={GridNoRowsOverlay}
335
+ noRowsOverlayComponentParams={{ rowData: params.rowData, noRowsOverlayText: params.noRowsOverlayText }}
342
336
  onModelUpdated={onModelUpdated}
343
337
  onGridReady={onGridReady}
344
338
  onSortChanged={ensureSelectedRowIsVisible}
@@ -0,0 +1,12 @@
1
+ import { isEmpty } from "lodash-es";
2
+
3
+ export const GridNoRowsOverlay = (params: {
4
+ rowData: any[] | null | undefined;
5
+ noRowsOverlayText: string | undefined;
6
+ }) => (
7
+ <span>
8
+ {isEmpty(params.rowData)
9
+ ? params.noRowsOverlayText ?? "There are currently no rows"
10
+ : "All rows have been filtered"}
11
+ </span>
12
+ );
@@ -8,6 +8,7 @@ export * from "./gridForm";
8
8
  export * from "./gridHeader";
9
9
  export * from "./GridIcon";
10
10
  export * from "./GridLoadableCell";
11
+ export * from "./GridNoRowsOverlay";
11
12
  export * from "./gridPopoverEdit";
12
13
  export * from "./GridPopoverHook";
13
14
  export * from "./gridRender";
@@ -0,0 +1,36 @@
1
+ import { expect } from "@storybook/jest";
2
+ import { ComponentMeta, ComponentStory } from "@storybook/react/dist/ts3.9/client/preview/types-6-3";
3
+ import { within } from "@storybook/testing-library";
4
+
5
+ import "@linzjs/lui/dist/fonts";
6
+ import "@linzjs/lui/dist/scss/base.scss";
7
+
8
+ import { GridNoRowsOverlay } from "../../components";
9
+
10
+ export default {
11
+ title: "Components / Grids / GridNoRowsOverlay",
12
+ component: GridNoRowsOverlay,
13
+ args: {},
14
+ } as ComponentMeta<typeof GridNoRowsOverlay>;
15
+
16
+ const GridNoRowsOverlayTemplate: ComponentStory<typeof GridNoRowsOverlay> = (params) => {
17
+ return <GridNoRowsOverlay {...params} />;
18
+ };
19
+
20
+ export const GridNoRowsEmpty = GridNoRowsOverlayTemplate.bind({});
21
+ GridNoRowsEmpty.args = {
22
+ rowData: [],
23
+ };
24
+ GridNoRowsEmpty.play = async ({ canvasElement }) => {
25
+ const canvas = within(canvasElement);
26
+ expect(await canvas.findByText("There are currently no rows")).toBeInTheDocument();
27
+ };
28
+
29
+ export const GridNoRowsFiltered = GridNoRowsOverlayTemplate.bind({});
30
+ GridNoRowsFiltered.args = {
31
+ rowData: [{}],
32
+ };
33
+ GridNoRowsFiltered.play = async ({ canvasElement }) => {
34
+ const canvas = within(canvasElement);
35
+ expect(await canvas.findByText("All rows have been filtered")).toBeInTheDocument();
36
+ };
@@ -20,9 +20,9 @@ import {
20
20
  GridUpdatingContextProvider,
21
21
  MenuOption,
22
22
  wait,
23
- } from "../..";
24
- import "../../styles/GridTheme.scss";
25
- import "../../styles/index.scss";
23
+ } from "../../../";
24
+ import "../../../styles/GridTheme.scss";
25
+ import "../../../styles/index.scss";
26
26
 
27
27
  export default {
28
28
  title: "Components / Grids",