@linzjs/step-ag-grid 7.13.0 → 7.13.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": "7.13.0",
5
+ "version": "7.13.1",
6
6
  "keywords": [
7
7
  "aggrid",
8
8
  "ag-grid",
@@ -12,7 +12,8 @@
12
12
  "react",
13
13
  "react-component"
14
14
  ],
15
- "main": "dist/index.js",
15
+ "main": "dist/step-ag-grid.esm.js",
16
+ "type": "module",
16
17
  "typings": "dist/src/index.d.ts",
17
18
  "module": "dist/step-ag-grid.esm.js",
18
19
  "files": [
@@ -15,12 +15,16 @@ export const Editor = <FN extends (param: any) => JSX.Element>(props: {
15
15
  params: { ...props.editorParams, multiEdit: props.multiEdit },
16
16
  });
17
17
 
18
+ export interface RowCellEditorParams<RowType extends GridBaseRow> extends ICellEditorParams {
19
+ data: RowType;
20
+ }
21
+
18
22
  /*
19
23
  * All cells should use this
20
24
  */
21
25
  export const GridCellMultiEditor = <RowType extends GridBaseRow>(
22
26
  props: GenericCellColDef<RowType>,
23
- cellEditorSelector: (params: ICellEditorParams) => CellEditorSelectorResult,
27
+ cellEditorSelector: (params: RowCellEditorParams<RowType>) => CellEditorSelectorResult,
24
28
  ): ColDefT<RowType> => {
25
29
  return {
26
30
  colId: props.colId ?? props.field,
@@ -1,8 +1,8 @@
1
1
  import { FocusableItem, MenuDivider, MenuHeader, MenuItem } from "../../react-menu3";
2
- import { useCallback, useEffect, useRef, useState } from "react";
2
+ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
3
3
  import { GridBaseRow } from "../Grid";
4
4
  import { ComponentLoadingWrapper } from "../ComponentLoadingWrapper";
5
- import { delay, isEmpty } from "lodash-es";
5
+ import { isEmpty } from "lodash-es";
6
6
  import debounce from "debounce-promise";
7
7
  import { CellEditorCommon } from "../GridCell";
8
8
  import { useGridPopoverHook } from "../GridPopoverHook";
@@ -49,10 +49,13 @@ export interface GridFormPopoutDropDownProps<RowType extends GridBaseRow> extend
49
49
  filtered?: "local" | "reload";
50
50
  filterPlaceholder?: string;
51
51
  filterHelpText?: string;
52
+ noOptionsMessage?: string;
52
53
  onSelectedItem?: (props: GridPopoutEditDropDownSelectedItem<RowType>) => Promise<void>;
53
54
  onSelectFilter?: (props: GridPopoutEditDropDownSelectedItem<RowType>) => Promise<void>;
54
- options: SelectOption[] | ((selectedRows: RowType[], filter?: string) => Promise<SelectOption[]> | SelectOption[]);
55
- optionsRequestCancel?: () => void;
55
+ options:
56
+ | SelectOption[]
57
+ | ((selectedRows: RowType[], filter?: string) => Promise<SelectOption[] | undefined> | SelectOption[] | undefined)
58
+ | undefined;
56
59
  }
57
60
 
58
61
  const fieldToString = (field: any) => {
@@ -65,7 +68,6 @@ export const GridFormDropDown = <RowType extends GridBaseRow>(props: GridFormPop
65
68
  // Save triggers during async action processing which triggers another selectItem(), this ref blocks that
66
69
  const [filter, setFilter] = useState("");
67
70
  const [filteredValues, setFilteredValues] = useState<any[]>();
68
- const optionsInitialising = useRef(false);
69
71
  const [options, setOptions] = useState<FinalSelectOption[] | null>(null);
70
72
  const subComponentIsValid = useRef(false);
71
73
  const subComponentInitialValue = useRef<string | null>(null);
@@ -92,33 +94,33 @@ export const GridFormDropDown = <RowType extends GridBaseRow>(props: GridFormPop
92
94
 
93
95
  // Load up options list if it's async function
94
96
  useEffect(() => {
95
- if (options || optionsInitialising.current) return;
96
- optionsInitialising.current = true;
97
- let optionsConf = props.options ?? [];
97
+ if (options) return;
98
+ let optionsConf = props.options;
98
99
 
99
100
  (async () => {
100
101
  if (typeof optionsConf == "function") {
101
102
  optionsConf = await optionsConf(selectedRows, filter);
102
103
  }
104
+ if (optionsConf !== undefined) {
105
+ const optionsList = optionsConf?.map((item) =>
106
+ item == null || typeof item == "string"
107
+ ? ({
108
+ value: item,
109
+ label: item,
110
+ disabled: false,
111
+ } as FinalSelectOption)
112
+ : item,
113
+ );
103
114
 
104
- const optionsList = optionsConf?.map((item) =>
105
- item == null || typeof item == "string"
106
- ? ({
107
- value: item,
108
- label: item,
109
- disabled: false,
110
- } as FinalSelectOption)
111
- : item,
112
- );
113
-
114
- if (props.filtered) {
115
- // This is needed otherwise when filter input is rendered and sets autofocus
116
- // the mouse up of the double click edit triggers the cell to cancel editing
117
- delay(() => setOptions(optionsList), 100);
118
- } else {
119
- setOptions(optionsList);
115
+ if (props.filtered) {
116
+ // This is needed otherwise when filter input is rendered and sets autofocus
117
+ // the mouse up of the double click edit triggers the cell to cancel editing
118
+ setOptions(optionsList);
119
+ //delay(() => setOptions(optionsList), 100);
120
+ } else {
121
+ setOptions(optionsList);
122
+ }
120
123
  }
121
- optionsInitialising.current = false;
122
124
  })();
123
125
  }, [filter, options, props, selectedRows]);
124
126
 
@@ -141,11 +143,12 @@ export const GridFormDropDown = <RowType extends GridBaseRow>(props: GridFormPop
141
143
  }
142
144
  }, [props.filtered, filter, options]);
143
145
 
144
- const researchOnFilterChange = debounce(
145
- useCallback(() => {
146
- setOptions(null);
147
- }, []),
148
- 500,
146
+ const researchOnFilterChange = useMemo(
147
+ () =>
148
+ debounce(() => {
149
+ setOptions(null);
150
+ }, 500),
151
+ [],
149
152
  );
150
153
 
151
154
  const previousFilter = useRef<string>(filter);
@@ -154,7 +157,6 @@ export const GridFormDropDown = <RowType extends GridBaseRow>(props: GridFormPop
154
157
  useEffect(() => {
155
158
  if (previousFilter.current != filter && props.filtered == "reload") {
156
159
  previousFilter.current = filter;
157
- props.optionsRequestCancel && props.optionsRequestCancel();
158
160
  researchOnFilterChange().then();
159
161
  }
160
162
  }, [filter, props, researchOnFilterChange]);
@@ -232,7 +234,7 @@ export const GridFormDropDown = <RowType extends GridBaseRow>(props: GridFormPop
232
234
  <>
233
235
  {options && (isEmpty(options) || (filteredValues && isEmpty(filteredValues))) && (
234
236
  <MenuItem key={`${fieldToString(field)}-empty`} className={"GridPopoverEditDropDown-noOptions"}>
235
- No Options
237
+ {props.noOptionsMessage ?? "No Options"}
236
238
  </MenuItem>
237
239
  )}
238
240
  {options?.map((item: FinalSelectOption, index) =>
@@ -1,14 +1,19 @@
1
1
  import { ICellRendererParams } from "ag-grid-community";
2
2
  import { GridBaseRow } from "../Grid";
3
3
  import { ColDefT } from "../GridCell";
4
- import { SuppressKeyboardEventParams } from "ag-grid-community/dist/lib/entities/colDef";
4
+ import { EditableCallbackParams, SuppressKeyboardEventParams } from "ag-grid-community/dist/lib/entities/colDef";
5
5
 
6
6
  export interface RowICellRendererParams<RowType extends GridBaseRow> extends ICellRendererParams {
7
7
  data: RowType;
8
8
  }
9
9
 
10
+ export interface RowEditableCallbackParams<RowType extends GridBaseRow> extends EditableCallbackParams {
11
+ data: RowType;
12
+ }
13
+
10
14
  export interface GenericCellColDef<RowType extends GridBaseRow> extends ColDefT<RowType> {
11
15
  cellRendererParams?: GenericCellRendererParams<RowType>;
16
+ editable?: boolean | ((params: RowEditableCallbackParams<RowType>) => boolean);
12
17
  }
13
18
 
14
19
  export interface GenericCellRendererParams<RowType extends GridBaseRow> {
package/src/index.ts CHANGED
@@ -12,6 +12,8 @@ export * from "./contexts/GridSubComponentContext";
12
12
  export type { GridBaseRow } from "./components/Grid";
13
13
  export { Grid } from "./components/Grid";
14
14
  export * from "./components/GridCell";
15
+ export * from "./components/GridCellMultiEditor";
16
+
15
17
  export { GridIcon } from "./components/GridIcon";
16
18
  export { ComponentLoadingWrapper } from "./components/ComponentLoadingWrapper";
17
19
  export { GridCellMultiSelectClassRules } from "./components/GridCellMultiSelectClassRules";
@@ -34,6 +36,10 @@ export { GridFormSubComponentTextInput } from "./components/gridForm/GridFormSub
34
36
  export * from "./components/gridForm/GridFormDropDown";
35
37
  export * from "./components/gridForm/GridFormMultiSelect";
36
38
  export * from "./components/gridForm/GridFormPopoverMenu";
39
+ export * from "./components/gridForm/GridFormTextInput";
40
+ export * from "./components/gridForm/GridFormTextArea";
41
+ export * from "./components/gridForm/GridFormMessage";
42
+ export * from "./components/gridForm/GridFormEditBearing";
37
43
 
38
44
  export { GridHeaderSelect } from "./components/gridHeader/GridHeaderSelect";
39
45
 
@@ -18,7 +18,6 @@ import { GridPopoverMenu } from "../../components/gridPopoverEdit/GridPopoverMen
18
18
  import { GridContext } from "../../contexts/GridContext";
19
19
  import { Editor, GridCellMultiEditor } from "../../components/GridCellMultiEditor";
20
20
  import { GridFormTextArea } from "../../components/gridForm/GridFormTextArea";
21
- import { ICellEditorParams } from "ag-grid-community/dist/lib/interfaces/iCellEditor";
22
21
  import { GridFormDropDown } from "../../components/gridForm/GridFormDropDown";
23
22
 
24
23
  export default {
@@ -142,7 +141,7 @@ const GridPopoutEditGenericTemplate: ComponentStory<typeof Grid> = (props: GridP
142
141
  headerName: "Multi-editor",
143
142
  maxWidth: 140,
144
143
  },
145
- (_params: ICellEditorParams) =>
144
+ (_params) =>
146
145
  _params.rowIndex == 0
147
146
  ? Editor({
148
147
  multiEdit: true,