@linzjs/step-ag-grid 17.8.0 → 17.9.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": "17.8.0",
5
+ "version": "17.9.0",
6
6
  "keywords": [
7
7
  "aggrid",
8
8
  "ag-grid",
@@ -101,6 +101,8 @@ export interface GridProps {
101
101
  * Defaults to false.
102
102
  */
103
103
  singleClickEdit?: boolean;
104
+
105
+ loading?: boolean;
104
106
  }
105
107
 
106
108
  /**
@@ -136,9 +138,11 @@ export const Grid = ({
136
138
  doesExternalFilterPass,
137
139
  setOnCellEditingComplete,
138
140
  getColDef,
141
+ showNoRowsOverlay,
142
+ prePopupOps,
143
+ stopEditing,
139
144
  } = useContext(GridContext);
140
145
  const { checkUpdating, updatedDep, updatingCols } = useContext(GridUpdatingContext);
141
- const { prePopupOps } = useContext(GridContext);
142
146
 
143
147
  const gridDivRef = useRef<HTMLDivElement>(null);
144
148
  const lastSelectedIds = useRef<number[]>([]);
@@ -323,7 +327,11 @@ export const Grid = ({
323
327
  const columnDefs = useMemo((): (ColDef | ColGroupDef)[] => {
324
328
  const adjustColDefs = params.columnDefs.map((colDef) => {
325
329
  const colDefEditable = colDef.editable;
326
- const editable = combineEditables(params.readOnly !== true, params.defaultColDef?.editable, colDefEditable);
330
+ const editable = combineEditables(
331
+ params.loading !== true && params.readOnly !== true,
332
+ params.defaultColDef?.editable,
333
+ colDefEditable,
334
+ );
327
335
  return {
328
336
  ...colDef,
329
337
  editable,
@@ -369,6 +377,7 @@ export const Grid = ({
369
377
  params.columnDefs,
370
378
  params.selectable,
371
379
  params.onRowDragEnd,
380
+ params.loading,
372
381
  params.readOnly,
373
382
  params.defaultColDef?.editable,
374
383
  selectColumnPinned,
@@ -566,6 +575,16 @@ export const Grid = ({
566
575
  }
567
576
  }, [autoSizeColumns, getColDef, sizeColumns, updatedDep, updatingCols]);
568
577
 
578
+ const prevLoading = useRef(false);
579
+ useEffect(() => {
580
+ const newLoading = !rowData || params.loading === true;
581
+ if (newLoading && !prevLoading.current) {
582
+ stopEditing();
583
+ showNoRowsOverlay();
584
+ }
585
+ prevLoading.current = newLoading;
586
+ }, [params.loading, rowData, showNoRowsOverlay, stopEditing]);
587
+
569
588
  /**
570
589
  * Resize columns to fit if required on window/container resize
571
590
  */
@@ -691,7 +710,7 @@ export const Grid = ({
691
710
  event.api.forEachNode(() => rowCount++);
692
711
  return (
693
712
  <GridNoRowsOverlay
694
- loading={!rowData}
713
+ loading={!rowData || params.loading === true}
695
714
  rowCount={rowCount}
696
715
  headerRowHeight={headerRowCount * rowHeight}
697
716
  filteredRowCount={event.api.getDisplayedRowCount()}
@@ -65,6 +65,7 @@ export interface GridContextType<RowType extends GridBaseRow> {
65
65
  setInvisibleColumnIds: (colIds: string[]) => void;
66
66
  downloadCsv: (csvExportParams?: CsvExportParams) => void;
67
67
  setOnCellEditingComplete: (callback: (() => void) | undefined) => void;
68
+ showNoRowsOverlay: () => void;
68
69
  }
69
70
 
70
71
  export const GridContext = createContext<GridContextType<any>>({
@@ -201,6 +202,9 @@ export const GridContext = createContext<GridContextType<any>>({
201
202
  setOnCellEditingComplete: () => {
202
203
  console.error("no context provider for setOnCellEditingComplete");
203
204
  },
205
+ showNoRowsOverlay: () => {
206
+ console.error("no context provider for showLoadingOverlay");
207
+ },
204
208
  });
205
209
 
206
210
  export const useGridContext = <RowType extends GridBaseRow>() => useContext<GridContextType<RowType>>(GridContext);
@@ -659,6 +659,10 @@ export const GridContextProvider = <RowType extends GridBaseRow>(props: PropsWit
659
659
  [gridApi],
660
660
  );
661
661
 
662
+ const showNoRowsOverlay = useCallback((): void => {
663
+ gridApi?.showNoRowsOverlay();
664
+ }, [gridApi]);
665
+
662
666
  /**
663
667
  * Apply column visibility
664
668
  */
@@ -755,6 +759,7 @@ export const GridContextProvider = <RowType extends GridBaseRow>(props: PropsWit
755
759
  doesExternalFilterPass,
756
760
  downloadCsv,
757
761
  setOnCellEditingComplete,
762
+ showNoRowsOverlay,
758
763
  }}
759
764
  >
760
765
  {props.children}
@@ -215,6 +215,25 @@ const GridReadOnlyTemplate: StoryFn<typeof Grid> = (props: GridProps) => {
215
215
  { id: 1001, position: "Developer", age: 12, height: `5'3"`, desc: "Develops application", dd: "2" },
216
216
  { id: 1002, position: "Manager", age: 65, height: `5'9"`, desc: "Manages", dd: "3" },
217
217
  ]);
218
+ /*
219
+ Testing
220
+ const [loading, setLoading] = useState(false);
221
+
222
+ useTimeout(() => {
223
+ setRowData([
224
+ { id: 1000, position: "Tester", age: 30, height: `6'4"`, desc: "Tests application", dd: "1" },
225
+ { id: 1001, position: "Developer", age: 12, height: `5'3"`, desc: "Develops application", dd: "2" },
226
+ { id: 1002, position: "Manager", age: 65, height: `5'9"`, desc: "Manages", dd: "3" },
227
+ ]);
228
+ }, 5000);
229
+
230
+ useTimeout(() => {
231
+ setLoading(true);
232
+ }, 7000);
233
+
234
+ useTimeout(() => {
235
+ setLoading(false);
236
+ }, 9000);*/
218
237
 
219
238
  return (
220
239
  <GridWrapper maxHeight={400}>