@linzjs/step-ag-grid 1.5.4 → 2.0.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.
Files changed (61) hide show
  1. package/dist/index.d.ts +2 -2
  2. package/dist/index.js +241 -200
  3. package/dist/index.js.map +1 -1
  4. package/dist/src/components/GridCell.d.ts +18 -27
  5. package/dist/src/components/GridPopoverHook.d.ts +4 -2
  6. package/dist/src/components/gridForm/GridFormDropDown.d.ts +8 -3
  7. package/dist/src/components/gridForm/GridFormEditBearing.d.ts +3 -4
  8. package/dist/src/components/gridForm/GridFormMessage.d.ts +4 -5
  9. package/dist/src/components/gridForm/GridFormMultiSelect.d.ts +2 -3
  10. package/dist/src/components/gridForm/GridFormPopoutMenu.d.ts +2 -3
  11. package/dist/src/components/gridForm/GridFormTextArea.d.ts +2 -3
  12. package/dist/src/components/gridForm/GridFormTextInput.d.ts +2 -3
  13. package/dist/src/components/gridPopoverEdit/GridPopoutEditMultiSelect.d.ts +3 -2
  14. package/dist/src/components/gridPopoverEdit/GridPopoverEditBearing.d.ts +5 -270
  15. package/dist/src/components/gridPopoverEdit/GridPopoverEditDropDown.d.ts +3 -2
  16. package/dist/src/components/gridPopoverEdit/GridPopoverMenu.d.ts +2 -2
  17. package/dist/src/components/gridPopoverEdit/GridPopoverMessage.d.ts +3 -2
  18. package/dist/src/components/gridPopoverEdit/GridPopoverTextArea.d.ts +3 -2
  19. package/dist/src/components/gridPopoverEdit/GridPopoverTextInput.d.ts +3 -2
  20. package/dist/src/components/gridRender/GridRenderGenericCell.d.ts +1 -3
  21. package/dist/src/contexts/GridPopoverContext.d.ts +17 -0
  22. package/dist/src/contexts/GridPopoverContextProvider.d.ts +6 -0
  23. package/dist/src/contexts/{UpdatingContext.d.ts → GridUpdatingContext.d.ts} +2 -2
  24. package/dist/src/contexts/GridUpdatingContextProvider.d.ts +7 -0
  25. package/dist/src/stories/components/FormTest.d.ts +1 -2
  26. package/dist/step-ag-grid.esm.js +238 -198
  27. package/dist/step-ag-grid.esm.js.map +1 -1
  28. package/package.json +1 -1
  29. package/src/components/Grid.tsx +2 -2
  30. package/src/components/GridCell.tsx +57 -79
  31. package/src/components/GridLoadableCell.tsx +4 -1
  32. package/src/components/GridPopoverHook.tsx +10 -14
  33. package/src/components/gridForm/GridFormDropDown.tsx +41 -30
  34. package/src/components/gridForm/GridFormEditBearing.tsx +13 -13
  35. package/src/components/gridForm/GridFormMessage.tsx +8 -13
  36. package/src/components/gridForm/GridFormMultiSelect.tsx +19 -19
  37. package/src/components/gridForm/GridFormPopoutMenu.tsx +7 -8
  38. package/src/components/gridForm/GridFormTextArea.tsx +16 -17
  39. package/src/components/gridForm/GridFormTextInput.tsx +17 -17
  40. package/src/components/gridPopoverEdit/GridPopoutEditMultiSelect.ts +17 -16
  41. package/src/components/gridPopoverEdit/GridPopoverEditBearing.ts +53 -45
  42. package/src/components/gridPopoverEdit/GridPopoverEditDropDown.ts +17 -16
  43. package/src/components/gridPopoverEdit/GridPopoverMenu.tsx +20 -21
  44. package/src/components/gridPopoverEdit/GridPopoverMessage.ts +18 -16
  45. package/src/components/gridPopoverEdit/GridPopoverTextArea.ts +12 -16
  46. package/src/components/gridPopoverEdit/GridPopoverTextInput.ts +15 -15
  47. package/src/components/gridRender/GridRenderGenericCell.tsx +3 -5
  48. package/src/components/gridRender/GridRenderPopoutMenuCell.tsx +2 -2
  49. package/src/contexts/GridContextProvider.tsx +3 -5
  50. package/src/contexts/GridPopoverContext.tsx +32 -0
  51. package/src/contexts/GridPopoverContextProvider.tsx +53 -0
  52. package/src/contexts/{UpdatingContext.tsx → GridUpdatingContext.tsx} +2 -2
  53. package/src/contexts/{UpdatingContextProvider.tsx → GridUpdatingContextProvider.tsx} +8 -6
  54. package/src/stories/components/FormTest.tsx +4 -3
  55. package/src/stories/components/GridPopoutBearing.stories.tsx +28 -25
  56. package/src/stories/components/GridPopoutEditDropDown.stories.tsx +91 -50
  57. package/src/stories/components/GridPopoutEditGeneric.stories.tsx +18 -13
  58. package/src/stories/components/GridPopoutEditGenericTextArea.stories.tsx +76 -61
  59. package/src/stories/components/GridPopoutEditMultiSelect.stories.tsx +58 -51
  60. package/src/stories/components/GridReadOnly.stories.tsx +73 -57
  61. package/dist/src/contexts/UpdatingContextProvider.d.ts +0 -7
@@ -1,20 +1,16 @@
1
- import { GridCell } from "../GridCell";
1
+ import { ColDefT, GenericCellEditorProps, GridCell } from "../GridCell";
2
2
  import { GridBaseRow } from "../Grid";
3
- import { GenericCellColDef } from "../gridRender/GridRenderGenericCell";
4
3
  import { GridFormTextArea, GridFormTextAreaProps } from "../gridForm/GridFormTextArea";
4
+ import { ColDef } from "ag-grid-community";
5
5
 
6
6
  export const GridPopoverTextArea = <RowType extends GridBaseRow>(
7
- colDef: GenericCellColDef<RowType, GridFormTextAreaProps<RowType>>,
8
- ) => {
9
- return GridCell<RowType, GridFormTextAreaProps<RowType>>({
10
- maxWidth: 260,
11
- ...colDef,
12
- ...(colDef?.cellEditorParams && {
13
- cellEditorParams: {
14
- width: 260,
15
- ...colDef.cellEditorParams,
16
- form: GridFormTextArea,
17
- },
18
- }),
19
- });
20
- };
7
+ colDef: ColDef,
8
+ params: GenericCellEditorProps<GridFormTextAreaProps<RowType>>,
9
+ ): ColDefT<RowType> =>
10
+ GridCell(
11
+ {
12
+ maxWidth: 260,
13
+ ...colDef,
14
+ },
15
+ { editor: GridFormTextArea, ...params },
16
+ );
@@ -1,20 +1,20 @@
1
- import { GridCell } from "../GridCell";
1
+ import { ColDefT, GenericCellEditorProps, GridCell } from "../GridCell";
2
2
  import { GridBaseRow } from "../Grid";
3
- import { GenericCellColDef } from "../gridRender/GridRenderGenericCell";
4
3
  import { GridFormTextInput, GridFormTextInputProps } from "../gridForm/GridFormTextInput";
4
+ import { ColDef } from "ag-grid-community";
5
5
 
6
6
  export const GridPopoverTextInput = <RowType extends GridBaseRow>(
7
- colDef: GenericCellColDef<RowType, GridFormTextInputProps<RowType>>,
8
- ) => {
9
- return GridCell<RowType, GridFormTextInputProps<RowType>>({
10
- maxWidth: 140,
11
- ...colDef,
12
- ...(colDef?.cellEditorParams && {
13
- cellEditorParams: {
14
- width: 240,
15
- ...colDef.cellEditorParams,
16
- form: GridFormTextInput,
17
- },
18
- }),
19
- });
7
+ colDef: ColDef,
8
+ params: GenericCellEditorProps<GridFormTextInputProps<RowType>>,
9
+ ): ColDefT<RowType> => {
10
+ return GridCell(
11
+ {
12
+ maxWidth: 140,
13
+ ...colDef,
14
+ },
15
+ {
16
+ editor: GridFormTextInput,
17
+ ...params,
18
+ },
19
+ );
20
20
  };
@@ -1,21 +1,19 @@
1
1
  import "./GridRenderGenericCell.scss";
2
2
 
3
3
  import { useContext } from "react";
4
- import { UpdatingContext } from "@contexts/UpdatingContext";
4
+ import { GridUpdatingContext } from "@contexts/GridUpdatingContext";
5
5
  import { GridLoadableCell } from "../GridLoadableCell";
6
6
  import { GridIcon } from "../GridIcon";
7
7
  import { ColDef, ICellRendererParams } from "ag-grid-community";
8
8
  import { ValueFormatterParams } from "ag-grid-community/dist/lib/entities/colDef";
9
- import { GenericCellEditorParams } from "../GridCell";
10
9
  import { GridBaseRow } from "../Grid";
11
10
 
12
11
  export interface RowICellRendererParams<RowType extends GridBaseRow> extends ICellRendererParams {
13
12
  data: RowType;
14
13
  }
15
14
 
16
- export interface GenericCellColDef<RowType extends GridBaseRow, FormProps extends Record<string, any>> extends ColDef {
15
+ export interface GenericCellColDef<RowType extends GridBaseRow> extends ColDef {
17
16
  cellRendererParams?: GenericCellRendererParams<RowType>;
18
- cellEditorParams?: GenericCellEditorParams<RowType> & FormProps;
19
17
  }
20
18
 
21
19
  export interface GenericCellRendererParams<RowType extends GridBaseRow> {
@@ -25,7 +23,7 @@ export interface GenericCellRendererParams<RowType extends GridBaseRow> {
25
23
  }
26
24
 
27
25
  export const GridRendererGenericCell = <RowType extends GridBaseRow>(props: ICellRendererParams): JSX.Element => {
28
- const { checkUpdating } = useContext(UpdatingContext);
26
+ const { checkUpdating } = useContext(GridUpdatingContext);
29
27
 
30
28
  const colDef = props.colDef as ColDef;
31
29
  const cellRendererParams = colDef.cellRendererParams as GenericCellRendererParams<RowType> | undefined;
@@ -1,12 +1,12 @@
1
1
  import { useContext } from "react";
2
2
  import { ColDef, ICellRendererParams } from "ag-grid-community";
3
- import { UpdatingContext } from "@contexts/UpdatingContext";
3
+ import { GridUpdatingContext } from "@contexts/GridUpdatingContext";
4
4
  import { GridLoadableCell } from "../GridLoadableCell";
5
5
  import { LuiIcon } from "@linzjs/lui";
6
6
  import { Column } from "ag-grid-community/dist/lib/entities/column";
7
7
 
8
8
  export const GridRenderPopoutMenuCell = (props: ICellRendererParams) => {
9
- const { checkUpdating } = useContext(UpdatingContext);
9
+ const { checkUpdating } = useContext(GridUpdatingContext);
10
10
  const isLoading = checkUpdating(props.colDef?.field ?? "", props.data.id);
11
11
  const editable = props.colDef?.editable;
12
12
  const disabled = !(typeof editable === "function"
@@ -3,7 +3,7 @@ import { 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 } from "@utils/util";
6
- import { UpdatingContext } from "./UpdatingContext";
6
+ import { GridUpdatingContext } from "./GridUpdatingContext";
7
7
  import { GridBaseRow } from "@components/Grid";
8
8
 
9
9
  interface GridContextProps {
@@ -16,7 +16,7 @@ interface GridContextProps {
16
16
  * Also, make sure the provider is created in a separate component, otherwise it won't be found.
17
17
  */
18
18
  export const GridContextProvider = (props: GridContextProps): ReactElement => {
19
- const { modifyUpdating } = useContext(UpdatingContext);
19
+ const { modifyUpdating } = useContext(GridUpdatingContext);
20
20
  const gridApiRef = useRef<GridApi>();
21
21
  const idsBeforeUpdate = useRef<number[]>([]);
22
22
 
@@ -48,9 +48,7 @@ export const GridContextProvider = (props: GridContextProps): ReactElement => {
48
48
  noApiFn = (() => {}) as () => R;
49
49
  }
50
50
  const gridApi = gridApiRef.current;
51
- if (gridApi) return hasApiFn(gridApi);
52
- console.error("GridApi not ready");
53
- return noApiFn();
51
+ return gridApi ? hasApiFn(gridApi) : noApiFn();
54
52
  };
55
53
 
56
54
  /**
@@ -0,0 +1,32 @@
1
+ import { createContext, RefObject } from "react";
2
+ import { ICellEditorParams } from "ag-grid-community";
3
+
4
+ export interface PropsType {
5
+ value: any;
6
+ data: any;
7
+ field: string;
8
+ selectedRows: any[];
9
+ }
10
+
11
+ export type GridPopoverContextType = {
12
+ anchorRef: RefObject<Element>;
13
+ updateValueRef: RefObject<(saveFn: (selectedRows: any[]) => Promise<boolean>) => Promise<boolean>>;
14
+ saving: boolean;
15
+ setSaving: (saving: boolean) => void;
16
+ setProps: (props: ICellEditorParams, multiEdit: boolean) => void;
17
+ propsRef: RefObject<PropsType>;
18
+ };
19
+
20
+ export const GridPopoverContext = createContext<GridPopoverContextType>({
21
+ anchorRef: { current: null },
22
+ updateValueRef: {
23
+ current: async () => {
24
+ console.error("Missing GridPopoverContext updateValueRef");
25
+ return false;
26
+ },
27
+ },
28
+ saving: false,
29
+ setSaving: () => {},
30
+ setProps: () => {},
31
+ propsRef: { current: null },
32
+ });
@@ -0,0 +1,53 @@
1
+ import { ReactNode, RefObject, useContext, useRef, useState } from "react";
2
+ import { GridPopoverContext, PropsType } from "./GridPopoverContext";
3
+ import { ICellEditorParams } from "ag-grid-community";
4
+ import { GridBaseRow } from "@components/Grid";
5
+ import { GridContext } from "@contexts/GridContext";
6
+
7
+ interface GridPopoverContextProps {
8
+ children: ReactNode;
9
+ }
10
+
11
+ export const GridPopoverContextProvider = (props: GridPopoverContextProps) => {
12
+ const { getSelectedRows, updatingCells } = useContext(GridContext);
13
+ const anchorRef = useRef<Element>();
14
+ const propsRef = useRef<PropsType>({} as PropsType);
15
+ const updateValueRef = useRef<(saveFn: (selectedRows: any[]) => Promise<boolean>) => Promise<boolean>>(async () => {
16
+ console.error("updateValueRef.current is not set");
17
+ return false;
18
+ });
19
+
20
+ const [saving, setSaving] = useState(false);
21
+
22
+ const setProps = (props: ICellEditorParams, multiEdit: boolean) => {
23
+ const selectedRows = multiEdit ? getSelectedRows<GridBaseRow>() : [props.data];
24
+ const field = props.colDef?.field ?? "";
25
+
26
+ anchorRef.current = props.eGridCell;
27
+ propsRef.current = {
28
+ value: props.value,
29
+ data: props.data,
30
+ field,
31
+ selectedRows,
32
+ };
33
+
34
+ updateValueRef.current = async (saveFn: (selectedRows: any[]) => Promise<boolean>): Promise<boolean> => {
35
+ return !saving && (await updatingCells({ selectedRows, field }, saveFn, setSaving));
36
+ };
37
+ };
38
+
39
+ return (
40
+ <GridPopoverContext.Provider
41
+ value={{
42
+ anchorRef: anchorRef as any as RefObject<Element>,
43
+ saving,
44
+ setSaving,
45
+ updateValueRef,
46
+ propsRef,
47
+ setProps,
48
+ }}
49
+ >
50
+ {props.children}
51
+ </GridPopoverContext.Provider>
52
+ );
53
+ };
@@ -1,11 +1,11 @@
1
1
  import { createContext } from "react";
2
2
 
3
- export type UpdatingContextType = {
3
+ export type GridUpdatingContextType = {
4
4
  checkUpdating: (fields: string | string[], id: number | string) => boolean;
5
5
  modifyUpdating: (field: string, ids: (number | string)[], fn: () => void | Promise<void>) => Promise<void>;
6
6
  };
7
7
 
8
- export const UpdatingContext = createContext<UpdatingContextType>({
8
+ export const GridUpdatingContext = createContext<GridUpdatingContextType>({
9
9
  checkUpdating: () => {
10
10
  console.error("Missing UpdatingContext");
11
11
  return false;
@@ -1,23 +1,23 @@
1
1
  import { ReactNode, useRef } from "react";
2
2
  import { castArray, flatten, remove } from "lodash-es";
3
- import { UpdatingContext } from "./UpdatingContext";
3
+ import { GridUpdatingContext } from "./GridUpdatingContext";
4
4
 
5
5
  interface UpdatingContextProviderProps {
6
6
  children: ReactNode;
7
7
  }
8
8
 
9
- export type UpdatingContextStatus = Record<string, (number | string)[] | undefined>;
9
+ export type GridUpdatingContextStatus = Record<string, (number | string)[] | undefined>;
10
10
 
11
11
  type FieldName = string;
12
12
  type IdList = (number | string)[];
13
13
  type UpdatingBlock = Record<FieldName, IdList[]>;
14
14
 
15
- export const UpdatingContextProvider = (props: UpdatingContextProviderProps) => {
15
+ export const GridUpdatingContextProvider = (props: UpdatingContextProviderProps) => {
16
16
  const updatingBlocks = useRef<UpdatingBlock>({});
17
- const updating = useRef<UpdatingContextStatus>({});
17
+ const updating = useRef<GridUpdatingContextStatus>({});
18
18
 
19
19
  const resetUpdating = () => {
20
- const mergedUpdatingBlocks: UpdatingContextStatus = {};
20
+ const mergedUpdatingBlocks: GridUpdatingContextStatus = {};
21
21
  for (const key in updatingBlocks.current) {
22
22
  mergedUpdatingBlocks[key] = flatten(updatingBlocks.current[key]);
23
23
  }
@@ -38,6 +38,8 @@ export const UpdatingContextProvider = (props: UpdatingContextProviderProps) =>
38
38
  castArray(fields).some((f) => updating.current[f]?.includes(id));
39
39
 
40
40
  return (
41
- <UpdatingContext.Provider value={{ modifyUpdating, checkUpdating }}>{props.children}</UpdatingContext.Provider>
41
+ <GridUpdatingContext.Provider value={{ modifyUpdating, checkUpdating }}>
42
+ {props.children}
43
+ </GridUpdatingContext.Provider>
42
44
  );
43
45
  };
@@ -3,7 +3,7 @@ import "./FormTest.scss";
3
3
  import { useCallback, useState } from "react";
4
4
  import { LuiTextInput } from "@linzjs/lui";
5
5
  import { wait } from "@utils/util";
6
- import { GridFormProps } from "@components/GridCell";
6
+ import { CellParams } from "@components/GridCell";
7
7
  import { useGridPopoverHook } from "@components/GridPopoverHook";
8
8
  import { GridBaseRow } from "@components/Grid";
9
9
 
@@ -16,7 +16,8 @@ export interface IFormTestRow {
16
16
  distance: number | null;
17
17
  }
18
18
 
19
- export const FormTest = <RowType extends GridBaseRow>(props: GridFormProps<RowType>): JSX.Element => {
19
+ export const FormTest = <RowType extends GridBaseRow>(_props: any): JSX.Element => {
20
+ const props = _props as CellParams<RowType>;
20
21
  const [v1, v2, ...v3] = props.value.split(" ");
21
22
 
22
23
  const [nameType, setNameType] = useState(v1);
@@ -34,7 +35,7 @@ export const FormTest = <RowType extends GridBaseRow>(props: GridFormProps<RowTy
34
35
  // Close form
35
36
  return true;
36
37
  }, [nameType, numba, plan, props.selectedRows]);
37
- const { popoverWrapper } = useGridPopoverHook(props, save);
38
+ const { popoverWrapper } = useGridPopoverHook({ save });
38
39
 
39
40
  return popoverWrapper(
40
41
  <div style={{ display: "flex", flexDirection: "row" }} className={"FormTest Grid-popoverContainer"}>
@@ -4,10 +4,10 @@ import "../../lui-overrides.scss";
4
4
 
5
5
  import { ComponentMeta, ComponentStory } from "@storybook/react/dist/ts3.9/client/preview/types-6-3";
6
6
  import { useMemo, useState } from "react";
7
- import { UpdatingContextProvider } from "@contexts/UpdatingContextProvider";
7
+ import { GridUpdatingContextProvider } from "@contexts/GridUpdatingContextProvider";
8
8
  import { GridContextProvider } from "@contexts/GridContextProvider";
9
9
  import { Grid, GridProps } from "@components/Grid";
10
- import { GridCell } from "@components/GridCell";
10
+ import { ColDefT, GridCell } from "@components/GridCell";
11
11
  import {
12
12
  GridPopoverEditBearing,
13
13
  GridPopoverEditBearingCorrection,
@@ -24,11 +24,11 @@ export default {
24
24
  decorators: [
25
25
  (Story) => (
26
26
  <div style={{ width: 1200, height: 400, display: "flex" }}>
27
- <UpdatingContextProvider>
27
+ <GridUpdatingContextProvider>
28
28
  <GridContextProvider>
29
29
  <Story />
30
30
  </GridContextProvider>
31
- </UpdatingContextProvider>
31
+ </GridUpdatingContextProvider>
32
32
  </div>
33
33
  ),
34
34
  ],
@@ -42,7 +42,7 @@ interface ITestRow {
42
42
 
43
43
  const GridReadOnlyTemplate: ComponentStory<typeof Grid> = (props: GridProps) => {
44
44
  const [externalSelectedItems, setExternalSelectedItems] = useState<any[]>([]);
45
- const columnDefs = useMemo(
45
+ const columnDefs: ColDefT<ITestRow>[] = useMemo(
46
46
  () => [
47
47
  GridCell({
48
48
  field: "id",
@@ -50,31 +50,34 @@ const GridReadOnlyTemplate: ComponentStory<typeof Grid> = (props: GridProps) =>
50
50
  initialWidth: 65,
51
51
  maxWidth: 85,
52
52
  }),
53
- GridPopoverEditBearing<ITestRow>({
54
- field: "bearing1",
55
- headerName: "Bearing GCE",
56
- cellRendererParams: {
57
- warning: (props) => props.data.id == 1002 && "Testers are testing",
58
- info: (props) => props.data.id == 1001 && "Developers are developing",
53
+ GridPopoverEditBearing(
54
+ {
55
+ field: "bearing1",
56
+ headerName: "Bearing GCE",
57
+ cellRendererParams: {
58
+ warning: (props: any) => props.data.id == 1002 && "Testers are testing",
59
+ info: (props: any) => props.data.id == 1001 && "Developers are developing",
60
+ },
59
61
  },
60
- cellEditorParams: {
62
+ {
61
63
  multiEdit: false,
62
- placeHolder: "Enter Bearing",
63
64
  },
64
- }),
65
- GridPopoverEditBearingCorrection<ITestRow>({
66
- field: "bearingCorrection",
67
- headerName: "Bearing Correction",
68
- cellEditorParams: {
69
- multiEdit: true,
70
- placeHolder: "Enter Bearing Correction",
71
- onSave: async (selectedRows: ITestRow[], value: ITestRow["bearingCorrection"]) => {
72
- await wait(1000);
73
- selectedRows.forEach((row) => (row["bearingCorrection"] = value));
74
- return true;
65
+ ),
66
+ GridPopoverEditBearingCorrection(
67
+ {
68
+ field: "bearingCorrection",
69
+ headerName: "Bearing Correction",
70
+ },
71
+ {
72
+ editorParams: {
73
+ onSave: async (selectedRows, value: ITestRow["bearingCorrection"]) => {
74
+ await wait(1000);
75
+ selectedRows.forEach((row) => (row["bearingCorrection"] = value));
76
+ return true;
77
+ },
75
78
  },
76
79
  },
77
- }),
80
+ ),
78
81
  ],
79
82
  [],
80
83
  );
@@ -3,19 +3,13 @@ import "@linzjs/lui/dist/fonts";
3
3
  import "../../lui-overrides.scss";
4
4
 
5
5
  import { ComponentMeta, ComponentStory } from "@storybook/react/dist/ts3.9/client/preview/types-6-3";
6
- import { UpdatingContextProvider } from "@contexts/UpdatingContextProvider";
6
+ import { GridUpdatingContextProvider } from "@contexts/GridUpdatingContextProvider";
7
7
  import { GridContextProvider } from "@contexts/GridContextProvider";
8
8
  import { Grid, GridProps } from "@components/Grid";
9
9
  import { useCallback, useMemo, useState } from "react";
10
- import {
11
- GridFormDropDown,
12
- GridFormPopoutDropDownProps,
13
- MenuSeparator,
14
- MenuSeparatorString,
15
- } from "@components/gridForm/GridFormDropDown";
16
- import { ColDef } from "ag-grid-community";
10
+ import { MenuHeaderItem, MenuSeparator, MenuSeparatorString } from "@components/gridForm/GridFormDropDown";
17
11
  import { wait } from "@utils/util";
18
- import { GridCell } from "@components/GridCell";
12
+ import { ColDefT, GridCell } from "@components/GridCell";
19
13
  import { GridPopoverEditDropDown } from "@components/gridPopoverEdit/GridPopoverEditDropDown";
20
14
 
21
15
  export default {
@@ -28,11 +22,11 @@ export default {
28
22
  decorators: [
29
23
  (Story) => (
30
24
  <div style={{ width: 1200, height: 400, display: "flex" }}>
31
- <UpdatingContextProvider>
25
+ <GridUpdatingContextProvider>
32
26
  <GridContextProvider>
33
27
  <Story />
34
28
  </GridContextProvider>
35
- </UpdatingContextProvider>
29
+ </GridUpdatingContextProvider>
36
30
  </div>
37
31
  ),
38
32
  ],
@@ -80,33 +74,39 @@ const GridEditDropDownTemplate: ComponentStory<typeof Grid> = (props: GridProps)
80
74
  [],
81
75
  );
82
76
 
83
- const columnDefs = useMemo(
84
- () =>
85
- [
86
- GridCell({
87
- field: "id",
88
- headerName: "Id",
89
- initialWidth: 65,
90
- maxWidth: 85,
91
- }),
92
- GridCell<ITestRow, GridFormPopoutDropDownProps<ITestRow, ITestRow["position"]>>({
77
+ const columnDefs: ColDefT<ITestRow>[] = useMemo(
78
+ () => [
79
+ GridCell({
80
+ field: "id",
81
+ headerName: "Id",
82
+ initialWidth: 65,
83
+ maxWidth: 85,
84
+ }),
85
+ GridPopoverEditDropDown(
86
+ {
93
87
  field: "position",
94
88
  initialWidth: 65,
95
89
  maxWidth: 150,
96
90
  headerName: "Position",
97
- cellEditorParams: {
98
- form: GridFormDropDown,
91
+ },
92
+ {
93
+ multiEdit: false,
94
+ editorParams: {
99
95
  options: ["Architect", "Developer", "Product Owner", "Scrum Master", "Tester", MenuSeparator, "(other)"],
100
- multiEdit: false,
101
96
  },
102
- }),
103
- GridPopoverEditDropDown<ITestRow, ITestRow["position2"]>({
97
+ },
98
+ ),
99
+ GridPopoverEditDropDown(
100
+ {
104
101
  field: "position2",
105
102
  maxWidth: 100,
106
103
  headerName: "Multi-edit",
107
- cellEditorParams: {
108
- multiEdit: true,
104
+ },
105
+ {
106
+ multiEdit: true,
107
+ editorParams: {
109
108
  options: [
109
+ MenuHeaderItem("Header"),
110
110
  {
111
111
  value: "1",
112
112
  label: "One",
@@ -117,27 +117,36 @@ const GridEditDropDownTemplate: ComponentStory<typeof Grid> = (props: GridProps)
117
117
  { value: "3", label: "Three" },
118
118
  ],
119
119
  },
120
- }),
121
- GridPopoverEditDropDown<ITestRow, ITestRow["position3"]>({
120
+ },
121
+ ),
122
+ GridPopoverEditDropDown(
123
+ {
122
124
  field: "position3",
123
125
  initialWidth: 65,
124
126
  maxWidth: 150,
125
127
  headerName: "Custom callback",
126
- cellEditorParams: {
127
- multiEdit: true,
128
+ },
129
+ {
130
+ multiEdit: true,
131
+ editorParams: {
128
132
  options: [null, "Architect", "Developer", "Product Owner", "Scrum Master", "Tester", "(other)"],
129
133
  onSelectedItem: async (selected) => {
130
134
  await wait(2000);
131
135
  selected.selectedRows.forEach((row) => (row.position3 = selected.value));
132
136
  },
133
137
  },
134
- }),
135
- GridPopoverEditDropDown<ITestRow, ITestRow["position"]>({
138
+ },
139
+ ),
140
+ GridPopoverEditDropDown(
141
+ {
136
142
  field: "position",
137
143
  initialWidth: 65,
138
144
  maxWidth: 150,
139
145
  headerName: "Options Fn",
140
- cellEditorParams: {
146
+ },
147
+ {
148
+ multiEdit: false,
149
+ editorParams: {
141
150
  filtered: "reload",
142
151
  filterPlaceholder: "Search me...",
143
152
  options: optionsFn,
@@ -148,44 +157,75 @@ const GridEditDropDownTemplate: ComponentStory<typeof Grid> = (props: GridProps)
148
157
  // eslint-disable-next-line no-console
149
158
  console.log("optionsRequestCancelled");
150
159
  },
151
- multiEdit: false,
152
160
  },
153
- }),
154
- GridPopoverEditDropDown<ITestRow, ITestRow["position3"]>({
161
+ },
162
+ ),
163
+ GridPopoverEditDropDown(
164
+ {
155
165
  field: "position3",
156
166
  initialWidth: 65,
157
167
  maxWidth: 150,
158
168
  headerName: "Filtered",
159
- cellEditorParams: {
160
- multiEdit: true,
169
+ },
170
+ {
171
+ multiEdit: true,
172
+ editorParams: {
161
173
  filtered: "local",
162
174
  filterPlaceholder: "Filter this",
163
175
  options: [null, "Architect", "Developer", "Product Owner", "Scrum Master", "Tester", "(other)"],
164
176
  },
165
- }),
166
- GridPopoverEditDropDown<ITestRow, ITestRow["position4"]>({
177
+ },
178
+ ),
179
+ GridPopoverEditDropDown(
180
+ {
167
181
  field: "position4",
168
182
  initialWidth: 65,
169
183
  maxWidth: 150,
170
184
  headerName: "Filtered (object)",
171
185
  valueGetter: (params) => params.data.position4?.desc,
172
- cellEditorParams: {
173
- multiEdit: true,
186
+ },
187
+ {
188
+ multiEdit: true,
189
+ editorParams: {
174
190
  filtered: "local",
175
191
  filterPlaceholder: "Filter this",
176
192
  options: optionsObjects.map((o) => {
177
193
  return { value: o, label: o.desc, disabled: false };
178
194
  }),
179
195
  },
180
- }),
181
- GridPopoverEditDropDown<ITestRow, ICode>({
196
+ },
197
+ ),
198
+ GridPopoverEditDropDown(
199
+ {
200
+ field: "code",
201
+ initialWidth: 65,
202
+ maxWidth: 150,
203
+ headerName: "Max height",
204
+ valueGetter: (params) => params.data.code,
205
+ },
206
+ {
207
+ multiEdit: true,
208
+ editorParams: {
209
+ maxRows: 2,
210
+ filtered: "local",
211
+ filterPlaceholder: "Filter this",
212
+ options: Array.from(Array(30).keys()).map((o) => {
213
+ return { value: o, label: `${o}` };
214
+ }),
215
+ },
216
+ },
217
+ ),
218
+ GridPopoverEditDropDown(
219
+ {
182
220
  field: "code",
183
221
  initialWidth: 65,
184
222
  maxWidth: 150,
185
223
  headerName: "Filter Selectable",
186
224
  valueGetter: (params) => params.data.code,
187
- cellEditorParams: {
188
- multiEdit: true,
225
+ },
226
+ {
227
+ multiEdit: true,
228
+ editorParams: {
189
229
  filtered: "local",
190
230
  filterPlaceholder: "Filter this",
191
231
  options: optionsObjects.map((o) => {
@@ -198,8 +238,9 @@ const GridEditDropDownTemplate: ComponentStory<typeof Grid> = (props: GridProps)
198
238
  selected.selectedRows.forEach((row) => (row.code = selected.value));
199
239
  },
200
240
  },
201
- }),
202
- ] as ColDef[],
241
+ },
242
+ ),
243
+ ],
203
244
  [optionsFn, optionsObjects],
204
245
  );
205
246