@linzjs/step-ag-grid 17.4.2 → 17.4.4

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.4.2",
5
+ "version": "17.4.4",
6
6
  "keywords": [
7
7
  "aggrid",
8
8
  "ag-grid",
@@ -1,4 +1,13 @@
1
- import { CellClickedEvent, ColDef, ColGroupDef, ColumnResizedEvent, ModelUpdatedEvent } from "ag-grid-community";
1
+ import {
2
+ CellClickedEvent,
3
+ ColDef,
4
+ ColGroupDef,
5
+ ColumnResizedEvent,
6
+ IClientSideRowModel,
7
+ ModelUpdatedEvent,
8
+ RowHighlightPosition,
9
+ RowNode,
10
+ } from "ag-grid-community";
2
11
  import { CellClassParams, EditableCallback, EditableCallbackParams } from "ag-grid-community/dist/lib/entities/colDef";
3
12
  import { GridOptions } from "ag-grid-community/dist/lib/entities/gridOptions";
4
13
  import {
@@ -7,6 +16,7 @@ import {
7
16
  CellKeyDownEvent,
8
17
  GridReadyEvent,
9
18
  RowDragEndEvent,
19
+ RowDragMoveEvent,
10
20
  SelectionChangedEvent,
11
21
  } from "ag-grid-community/dist/lib/events";
12
22
  import { AgGridReact } from "ag-grid-react";
@@ -50,7 +60,7 @@ export interface GridProps {
50
60
  autoSelectFirstRow?: boolean;
51
61
  onColumnMoved?: GridOptions["onColumnMoved"];
52
62
  rowDragText?: GridOptions["rowDragText"];
53
- onRowDragEnd?: (movedRow: any, targetRow: any, targetIndex: number) => void;
63
+ onRowDragEnd?: (movedRow: any, targetRow: any, targetIndex: number) => Promise<void>;
54
64
  alwaysShowVerticalScroll?: boolean;
55
65
  suppressColumnVirtualization?: GridOptions["suppressColumnVirtualisation"];
56
66
  /**
@@ -339,7 +349,6 @@ export const Grid = ({
339
349
  },
340
350
  checkboxSelection: params.selectable,
341
351
  headerComponent: rowSelection === "multiple" ? GridHeaderSelect : null,
342
- //headerCheckboxSelection:true,
343
352
  suppressHeaderKeyboardEvent: (e) => {
344
353
  if (!params.selectable) return false;
345
354
  if ((e.event.key === "Enter" || e.event.key === " ") && !e.event.repeat) {
@@ -590,15 +599,38 @@ export const Grid = ({
590
599
 
591
600
  const gridContextMenu = useGridContextMenu({ contextMenu: params.contextMenu, contextMenuSelectRow });
592
601
 
602
+ const onRowDragLeave = useCallback((event: RowDragMoveEvent) => {
603
+ const clientSideRowModel = event.api.getModel() as IClientSideRowModel;
604
+ clientSideRowModel.highlightRowAtPixel(null);
605
+ }, []);
606
+
607
+ const onRowDragMove = useCallback((event: RowDragMoveEvent) => {
608
+ const clientSideRowModel = event.api.getModel() as IClientSideRowModel;
609
+ clientSideRowModel.highlightRowAtPixel(event.node as RowNode<any>, event.y);
610
+ }, []);
611
+
593
612
  const onRowDragEnd = useCallback(
594
- (event: RowDragEndEvent) => {
595
- const moved = event.node.data;
596
- const target = event.overNode?.data;
597
-
598
- moved.id != target.id &&
599
- event.node.rowIndex != null &&
600
- params.onRowDragEnd &&
601
- params.onRowDragEnd(moved, target, event.node.rowIndex);
613
+ async (event: RowDragEndEvent) => {
614
+ const clientSideRowModel = event.api.getModel() as IClientSideRowModel;
615
+ if (event.node.rowIndex) {
616
+ const lastHighlightedRowNode = clientSideRowModel.getLastHighlightedRowNode();
617
+ const isBelow = lastHighlightedRowNode && lastHighlightedRowNode.highlighted === RowHighlightPosition.Below;
618
+
619
+ let targetIndex = event.overIndex;
620
+ if (event.node.rowIndex > event.overIndex) {
621
+ targetIndex += isBelow ? 1 : 0;
622
+ } else {
623
+ targetIndex += isBelow ? 0 : -1;
624
+ }
625
+
626
+ const moved = event.node.data;
627
+ const target = event.overNode?.data;
628
+ moved.id != target.id && //moved over a different row
629
+ moved.rowIndex != targetIndex && //moved to a different index
630
+ params.onRowDragEnd &&
631
+ (await params.onRowDragEnd(moved, target, targetIndex));
632
+ }
633
+ clientSideRowModel.highlightRowAtPixel(null);
602
634
  },
603
635
  [params],
604
636
  );
@@ -666,9 +698,9 @@ export const Grid = ({
666
698
  preventDefaultOnContextMenu={true}
667
699
  onCellContextMenu={gridContextMenu.cellContextMenu}
668
700
  rowDragText={params.rowDragText}
669
- rowDragManaged={!!params.onRowDragEnd}
670
- suppressMoveWhenRowDragging={true}
701
+ onRowDragMove={onRowDragMove}
671
702
  onRowDragEnd={onRowDragEnd}
703
+ onRowDragLeave={onRowDragLeave}
672
704
  />
673
705
  </div>
674
706
  </div>
@@ -184,7 +184,7 @@ export const GridFormDropDown = <RowType extends GridBaseRow>(props: GridFormDro
184
184
 
185
185
  const { popoverWrapper } = useGridPopoverHook({
186
186
  className: props.className,
187
- invalid: () => !!(selectedItem && !subComponentIsValid.current),
187
+ invalid: () => !options || !!(selectedItem && !subComponentIsValid.current),
188
188
  save,
189
189
  dontSaveOnExternalClick: true,
190
190
  });
@@ -95,6 +95,7 @@ const GridDragRowTemplate: ComponentStory<typeof Grid> = (props: GridProps) => {
95
95
  { id: 1000, position: "Tester", age: 30, height: `6'4"`, desc: "Tests application", dd: "1" },
96
96
  { id: 1001, position: "Developer", age: 12, height: `5'3"`, desc: "Develops application", dd: "2" },
97
97
  { id: 1002, position: "Manager", age: 65, height: `5'9"`, desc: "Manages", dd: "3" },
98
+ { id: 1003, position: "BA", age: 42, height: `5'7"`, desc: "BAs", dd: "4" },
98
99
  ]);
99
100
 
100
101
  return (
@@ -109,7 +110,7 @@ const GridDragRowTemplate: ComponentStory<typeof Grid> = (props: GridProps) => {
109
110
  defaultColDef={{ sortable: false }}
110
111
  rowData={rowData}
111
112
  onRowDragEnd={(row, _, targetIndex) => {
112
- alert(`Row ${row.id} has been moved to index ${targetIndex}.`);
113
+ alert(`Row ${row.id} request to be moved to index ${targetIndex}.`);
113
114
  }}
114
115
  rowDragText={(params) => `${params.rowNode?.data.id} - ${params.rowNode?.data.position}`}
115
116
  />