@linzjs/step-ag-grid 2.4.1 → 2.4.2

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": "2.4.1",
5
+ "version": "2.4.2",
6
6
  "keywords": [
7
7
  "aggrid",
8
8
  "ag-grid",
@@ -12,14 +12,14 @@ import { GenericCellColDef } from "../gridRender/GridRenderGenericCell";
12
12
  */
13
13
  export const GridPopoverMenu = <RowType extends GridBaseRow>(
14
14
  colDef: GenericCellColDef<RowType>,
15
- props: GenericCellEditorProps<GridFormPopoutMenuProps<RowType>>,
15
+ custom: GenericCellEditorProps<GridFormPopoutMenuProps<RowType>>,
16
16
  ): ColDefT<RowType> =>
17
17
  GridCell<RowType, GridFormPopoutMenuProps<RowType>>(
18
18
  {
19
19
  maxWidth: 64,
20
20
  editable: colDef.editable != null ? colDef.editable : true,
21
21
  cellRenderer: GridRenderPopoutMenuCell,
22
- cellClass: colDef?.cellEditorParams?.multiEdit !== false ? GenericMultiEditCellClass : undefined,
22
+ cellClass: custom?.multiEdit ? GenericMultiEditCellClass : undefined,
23
23
  ...colDef,
24
24
  cellRendererParams: {
25
25
  // Menus open on single click, this parameter is picked up in Grid.tsx
@@ -28,6 +28,6 @@ export const GridPopoverMenu = <RowType extends GridBaseRow>(
28
28
  },
29
29
  {
30
30
  editor: GridFormPopoutMenu,
31
- ...props,
31
+ ...custom,
32
32
  },
33
33
  );
@@ -1,7 +1,7 @@
1
1
  import "./ActionButton.scss";
2
2
 
3
3
  import clsx from "clsx";
4
- import { useEffect } from "react";
4
+ import { useEffect, useState } from "react";
5
5
  import { LuiButton, LuiIcon, LuiMiniSpinner } from "@linzjs/lui";
6
6
  import { IconName } from "@linzjs/lui/dist/components/LuiIcon/LuiIcon";
7
7
  import { usePrevious } from "./reactUtils";
@@ -15,8 +15,9 @@ export interface ActionButtonProps {
15
15
  dataTestId?: string;
16
16
  size?: "xs" | "sm" | "md" | "lg" | "xl" | "ns";
17
17
  className?: string;
18
- onClick?: () => void;
19
- inProgress?: boolean;
18
+ onAction: () => Promise<void>;
19
+ // Used for external code to get access to whether action is in progress
20
+ externalSetInProgress?: () => void;
20
21
  }
21
22
 
22
23
  // Kept this less than one second, so I don't have issues with waitFor as it defaults to 1s
@@ -27,14 +28,15 @@ export const ActionButton = ({
27
28
  name,
28
29
  inProgressName,
29
30
  dataTestId,
30
- inProgress,
31
31
  className,
32
32
  title,
33
- onClick,
33
+ onAction,
34
+ externalSetInProgress,
34
35
  size = "sm",
35
36
  }: ActionButtonProps): JSX.Element => {
37
+ const [inProgress, setInProgress] = useState(false);
36
38
  const lastInProgress = usePrevious(inProgress ?? false);
37
- const [localInProgress, setLocalInProgress, setLocalInProgressDeferred] = useStateDeferred<boolean>(!!inProgress);
39
+ const [localInProgress, setLocalInProgress, setLocalInProgressDeferred] = useStateDeferred<boolean>(inProgress);
38
40
 
39
41
  useEffect(() => {
40
42
  if (inProgress == lastInProgress) return;
@@ -50,7 +52,13 @@ export const ActionButton = ({
50
52
  aria-label={name}
51
53
  className={clsx("lui-button-icon", "ActionButton", className, localInProgress && "ActionButton-inProgress")}
52
54
  size={"lg"}
53
- onClick={onClick}
55
+ onClick={async () => {
56
+ setInProgress(true);
57
+ externalSetInProgress && setInProgress(true);
58
+ await onAction();
59
+ externalSetInProgress && setInProgress(false);
60
+ setInProgress(false);
61
+ }}
54
62
  disabled={localInProgress}
55
63
  >
56
64
  {localInProgress ? (
@@ -3,7 +3,7 @@ import "@linzjs/lui/dist/fonts";
3
3
 
4
4
  import { ComponentMeta, ComponentStory } from "@storybook/react/dist/ts3.9/client/preview/types-6-3";
5
5
  import { ActionButton } from "../../lui/ActionButton";
6
- import { useCallback, useState } from "react";
6
+ import { useCallback } from "react";
7
7
  import { wait } from "../../utils/util";
8
8
 
9
9
  export default {
@@ -13,21 +13,10 @@ export default {
13
13
  } as ComponentMeta<typeof ActionButton>;
14
14
 
15
15
  const ActionButtonTemplate: ComponentStory<typeof ActionButton> = () => {
16
- const [inProgress, setInProgress] = useState(false);
17
16
  const performAction = useCallback(async () => {
18
- setInProgress(true);
19
17
  await wait(1000);
20
- setInProgress(false);
21
18
  }, []);
22
- return (
23
- <ActionButton
24
- icon={"ic_add"}
25
- name={"Add new row"}
26
- inProgressName={"Adding..."}
27
- inProgress={inProgress}
28
- onClick={performAction}
29
- />
30
- );
19
+ return <ActionButton icon={"ic_add"} name={"Add new row"} inProgressName={"Adding..."} onAction={performAction} />;
31
20
  };
32
21
 
33
22
  export const ActionButtonSimple = ActionButtonTemplate.bind({});
@@ -155,14 +155,10 @@ const GridPopoutEditGenericTemplate: ComponentStory<typeof Grid> = (props: GridP
155
155
  [rowData],
156
156
  );
157
157
 
158
- const [inProgress, setInProgress] = useState(false);
159
-
160
158
  const addRowAction = useCallback(async () => {
161
- setInProgress(true);
162
159
  await wait(1000);
163
160
  const lastRow = rowData[rowData.length - 1];
164
161
  setRowData([...rowData, { id: lastRow.id + 1, name: "?", nameType: "?", numba: "?", plan: "", distance: null }]);
165
- setInProgress(false);
166
162
  }, [rowData]);
167
163
 
168
164
  return (
@@ -175,13 +171,7 @@ const GridPopoutEditGenericTemplate: ComponentStory<typeof Grid> = (props: GridP
175
171
  rowData={rowData}
176
172
  domLayout={"autoHeight"}
177
173
  />
178
- <ActionButton
179
- icon={"ic_add"}
180
- name={"Add new row"}
181
- inProgressName={"Adding..."}
182
- inProgress={inProgress}
183
- onClick={addRowAction}
184
- />
174
+ <ActionButton icon={"ic_add"} name={"Add new row"} inProgressName={"Adding..."} onAction={addRowAction} />
185
175
  </>
186
176
  );
187
177
  };
@@ -13,6 +13,7 @@ import { wait } from "../../utils/util";
13
13
  import { GridSubComponentTextArea } from "../../components/GridSubComponentTextArea";
14
14
  import { ColDefT, GridCell } from "../../components/GridCell";
15
15
  import { GridPopoutEditMultiSelect } from "../../components/gridPopoverEdit/GridPopoutEditMultiSelect";
16
+ import { partition } from "lodash-es";
16
17
 
17
18
  export default {
18
19
  title: "Components / Grids",
@@ -91,11 +92,9 @@ const GridEditMultiSelectTemplate: ComponentStory<typeof Grid> = (props: GridPro
91
92
  console.log("multiSelect result", { selectedRows, selectedOptions });
92
93
 
93
94
  await wait(1000);
94
- const normalValues = selectedOptions.filter((o) => !o.subComponent).map((o) => o.label);
95
- const subValues = selectedOptions.filter((o) => o.subComponent).map((o) => o.subValue);
96
- selectedRows.forEach((row) => {
97
- row.position = [...normalValues, ...subValues].join(", ");
98
- });
95
+ const [subValues, normalValues] = partition(selectedOptions, (o) => o.subComponent);
96
+ const newValue = [...normalValues.map((o) => o.label), ...subValues.map((o) => o.subValue)].join(", ");
97
+ selectedRows.forEach((row) => (row.position = newValue));
99
98
  return true;
100
99
  },
101
100
  },
@@ -159,6 +159,7 @@ const GridReadOnlyTemplate: ComponentStory<typeof Grid> = (props: GridProps) =>
159
159
  return (
160
160
  <Grid
161
161
  {...props}
162
+ selectable={true}
162
163
  externalSelectedItems={externalSelectedItems}
163
164
  setExternalSelectedItems={setExternalSelectedItems}
164
165
  columnDefs={columnDefs}