@gridsuite/commons-ui 0.277.0 → 0.278.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.
@@ -270,7 +270,7 @@ import { SelectHeaderCell } from "./network-modification-table/renderers/select-
270
270
  import { SwitchCell } from "./network-modification-table/renderers/switch-cell.js";
271
271
  import { DragCloneRow } from "./network-modification-table/row/drag-row-clone.js";
272
272
  import { ModificationRow } from "./network-modification-table/row/modification-row.js";
273
- import { MAX_COMPOSITE_NESTING_DEPTH, fetchSubModificationsForExpandedRows, findAllLoadedCompositeModifications, findDepth, findModificationInTree, formatToComposedModification, isCompositeModification, isReferenceModification, isTargetChildOfReference, mergeSubModificationsIntoTree, moveSubModificationInTree, removeUuidsFromTree, updateModificationFieldInTree, updateSubModificationsOfACompositeInTree } from "./network-modification-table/utils.js";
273
+ import { MAX_COMPOSITE_NESTING_DEPTH, containsReferenceModification, fetchSubModificationsForExpandedRows, findAllLoadedCompositeModifications, findDepth, findModificationInTree, formatToComposedModification, isCompositeModification, isReferenceModification, mergeSubModificationsIntoTree, moveSubModificationInTree, removeUuidsFromTree, updateModificationFieldInTree, updateSubModificationsOfACompositeInTree } from "./network-modification-table/utils.js";
274
274
  import { AnnouncementBanner } from "./announcement/AnnouncementBanner.js";
275
275
  import { AnnouncementNotification } from "./announcement/AnnouncementNotification.js";
276
276
  import { useGlobalAnnouncement } from "./announcement/useGlobalAnnouncement.js";
@@ -719,6 +719,7 @@ export {
719
719
  computeRatioTapChangerRegulationMode,
720
720
  computeSwitchedOnValue,
721
721
  computeTagMinSize,
722
+ containsReferenceModification,
722
723
  convertFilterValues,
723
724
  convertLimitsToOperationalLimitsGroupFormSchema,
724
725
  convertToLineSegmentInfos,
@@ -924,7 +925,6 @@ export {
924
925
  isEditingGlobalFilter,
925
926
  isProcessType,
926
927
  isReferenceModification,
927
- isTargetChildOfReference,
928
928
  isValidComputingType,
929
929
  isValidContingencyRow,
930
930
  italicFontTextField,
@@ -14,7 +14,7 @@ import { SelectHeaderCell } from "./renderers/select-header-cell.js";
14
14
  import { SwitchCell } from "./renderers/switch-cell.js";
15
15
  import { DragCloneRow } from "./row/drag-row-clone.js";
16
16
  import { ModificationRow } from "./row/modification-row.js";
17
- import { MAX_COMPOSITE_NESTING_DEPTH, fetchSubModificationsForExpandedRows, findAllLoadedCompositeModifications, findDepth, findModificationInTree, formatToComposedModification, isCompositeModification, isReferenceModification, isTargetChildOfReference, mergeSubModificationsIntoTree, moveSubModificationInTree, removeUuidsFromTree, updateModificationFieldInTree, updateSubModificationsOfACompositeInTree } from "./utils.js";
17
+ import { MAX_COMPOSITE_NESTING_DEPTH, containsReferenceModification, fetchSubModificationsForExpandedRows, findAllLoadedCompositeModifications, findDepth, findModificationInTree, formatToComposedModification, isCompositeModification, isReferenceModification, mergeSubModificationsIntoTree, moveSubModificationInTree, removeUuidsFromTree, updateModificationFieldInTree, updateSubModificationsOfACompositeInTree } from "./utils.js";
18
18
  export {
19
19
  AUTO_EXTENSIBLE_COLUMNS,
20
20
  BASE_MODIFICATION_TABLE_COLUMNS,
@@ -49,6 +49,7 @@ export {
49
49
  SwitchCell,
50
50
  SwitchCellRenderer,
51
51
  computeTagMinSize,
52
+ containsReferenceModification,
52
53
  createCellBorderColor,
53
54
  createCellContentWrapperSx,
54
55
  createCellStyle,
@@ -66,7 +67,6 @@ export {
66
67
  formatToComposedModification,
67
68
  isCompositeModification,
68
69
  isReferenceModification,
69
- isTargetChildOfReference,
70
70
  mergeSubModificationsIntoTree,
71
71
  moveSubModificationInTree,
72
72
  networkModificationTableStyles,
@@ -6,7 +6,7 @@ import { Draggable } from "@hello-pangea/dnd";
6
6
  import { useIntl } from "react-intl";
7
7
  import { BASE_MODIFICATION_TABLE_COLUMNS, AUTO_EXTENSIBLE_COLUMNS } from "../columns-definition.js";
8
8
  import { COLUMNS_WITHOUT_BORDER, createCellContentWrapperSx, createCellStyle, createRowSx, networkModificationTableStyles } from "../network-modification-table-styles.js";
9
- import { isCompositeModification, isReferenceModification, isTargetChildOfReference } from "../utils.js";
9
+ import { isCompositeModification, isReferenceModification } from "../utils.js";
10
10
  import "../../../utils/conversionUtils.js";
11
11
  import "../../../utils/types/equipmentType.js";
12
12
  import "@mui/icons-material";
@@ -30,84 +30,76 @@ function ModificationRow({
30
30
  },
31
31
  [handleCellClick, row.original]
32
32
  );
33
- return /* @__PURE__ */ jsx(
34
- Draggable,
35
- {
36
- draggableId: row.id,
37
- index: virtualRow.index,
38
- isDragDisabled: isRowDragDisabled || isTargetChildOfReference(row),
39
- children: (provided, snapshot) => {
40
- const { style, ...draggablePropsWithoutStyle } = provided.draggableProps;
41
- return /* @__PURE__ */ jsx(
42
- TableRow,
43
- {
44
- ref: provided.innerRef,
45
- ...draggablePropsWithoutStyle,
46
- "data-row-id": row.id,
47
- sx: mergeSx(
48
- networkModificationTableStyles.tableRow,
49
- createRowSx(
50
- theme,
51
- isHighlighted,
52
- snapshot.isDragging,
53
- virtualRow,
54
- row.depth,
55
- isCompositeModification(row.original) || isReferenceModification(row.original)
56
- )
57
- ),
58
- children: row.getVisibleCells().map((cell) => {
59
- const isNameColumn = cell.column.id === BASE_MODIFICATION_TABLE_COLUMNS.NAME.id;
60
- const isDragHandle = cell.column.id === BASE_MODIFICATION_TABLE_COLUMNS.DRAG_HANDLE.id;
61
- const isCheckboxColumn = cell.column.id === BASE_MODIFICATION_TABLE_COLUMNS.SELECT.id;
62
- const cellContent = flexRender(cell.column.columnDef.cell, cell.getContext());
63
- const cellWithoutBorders = (isExpanded || row.depth > 0) && COLUMNS_WITHOUT_BORDER.has(cell.column.columnDef.id ?? "");
64
- if (isDragHandle) {
65
- return /* @__PURE__ */ jsx(
66
- TableCell,
33
+ return /* @__PURE__ */ jsx(Draggable, { draggableId: row.id, index: virtualRow.index, isDragDisabled: isRowDragDisabled, children: (provided, snapshot) => {
34
+ const { style, ...draggablePropsWithoutStyle } = provided.draggableProps;
35
+ return /* @__PURE__ */ jsx(
36
+ TableRow,
37
+ {
38
+ ref: provided.innerRef,
39
+ ...draggablePropsWithoutStyle,
40
+ "data-row-id": row.id,
41
+ sx: mergeSx(
42
+ networkModificationTableStyles.tableRow,
43
+ createRowSx(
44
+ theme,
45
+ isHighlighted,
46
+ snapshot.isDragging,
47
+ virtualRow,
48
+ row.depth,
49
+ isCompositeModification(row.original) || isReferenceModification(row.original)
50
+ )
51
+ ),
52
+ children: row.getVisibleCells().map((cell) => {
53
+ const isNameColumn = cell.column.id === BASE_MODIFICATION_TABLE_COLUMNS.NAME.id;
54
+ const isDragHandle = cell.column.id === BASE_MODIFICATION_TABLE_COLUMNS.DRAG_HANDLE.id;
55
+ const isCheckboxColumn = cell.column.id === BASE_MODIFICATION_TABLE_COLUMNS.SELECT.id;
56
+ const cellContent = flexRender(cell.column.columnDef.cell, cell.getContext());
57
+ const cellWithoutBorders = (isExpanded || row.depth > 0) && COLUMNS_WITHOUT_BORDER.has(cell.column.columnDef.id ?? "");
58
+ if (isDragHandle) {
59
+ return /* @__PURE__ */ jsx(
60
+ TableCell,
61
+ {
62
+ sx: createCellStyle(cell, AUTO_EXTENSIBLE_COLUMNS.includes(cell.column.id)),
63
+ children: /* @__PURE__ */ jsx(
64
+ Box,
67
65
  {
68
- sx: createCellStyle(cell, AUTO_EXTENSIBLE_COLUMNS.includes(cell.column.id)),
69
- children: /* @__PURE__ */ jsx(
70
- Box,
71
- {
72
- sx: createCellContentWrapperSx(theme, cellWithoutBorders),
73
- ...provided.dragHandleProps,
74
- "aria-label": intl.formatMessage({ id: "moveModification" }),
75
- children: cellContent
76
- }
77
- )
78
- },
79
- cell.id
80
- );
81
- }
82
- if (isCheckboxColumn) {
83
- return /* @__PURE__ */ jsx(
84
- TableCell,
85
- {
86
- sx: createCellStyle(cell, AUTO_EXTENSIBLE_COLUMNS.includes(cell.column.id)),
87
- onClick: () => handleCellClickCallback(cell.column.id),
88
- children: /* @__PURE__ */ jsx(Box, { sx: createCellContentWrapperSx(theme, cellWithoutBorders), children: cellContent })
89
- },
90
- cell.id
91
- );
92
- }
93
- return /* @__PURE__ */ jsx(
94
- TableCell,
95
- {
96
- sx: createCellStyle(cell, AUTO_EXTENSIBLE_COLUMNS.includes(cell.column.id)),
97
- onClick: () => handleCellClickCallback(cell.column.id),
98
- children: isNameColumn ? (
99
- // NameCell owns its own borders entirely
100
- flexRender(cell.column.columnDef.cell, cell.getContext())
101
- ) : /* @__PURE__ */ jsx(Box, { sx: createCellContentWrapperSx(theme, cellWithoutBorders), children: cellContent })
102
- },
103
- cell.id
104
- );
105
- })
66
+ sx: createCellContentWrapperSx(theme, cellWithoutBorders),
67
+ ...provided.dragHandleProps,
68
+ "aria-label": intl.formatMessage({ id: "moveModification" }),
69
+ children: cellContent
70
+ }
71
+ )
72
+ },
73
+ cell.id
74
+ );
75
+ }
76
+ if (isCheckboxColumn) {
77
+ return /* @__PURE__ */ jsx(
78
+ TableCell,
79
+ {
80
+ sx: createCellStyle(cell, AUTO_EXTENSIBLE_COLUMNS.includes(cell.column.id)),
81
+ onClick: () => handleCellClickCallback(cell.column.id),
82
+ children: /* @__PURE__ */ jsx(Box, { sx: createCellContentWrapperSx(theme, cellWithoutBorders), children: cellContent })
83
+ },
84
+ cell.id
85
+ );
106
86
  }
107
- );
87
+ return /* @__PURE__ */ jsx(
88
+ TableCell,
89
+ {
90
+ sx: createCellStyle(cell, AUTO_EXTENSIBLE_COLUMNS.includes(cell.column.id)),
91
+ onClick: () => handleCellClickCallback(cell.column.id),
92
+ children: isNameColumn ? (
93
+ // NameCell owns its own borders entirely
94
+ flexRender(cell.column.columnDef.cell, cell.getContext())
95
+ ) : /* @__PURE__ */ jsx(Box, { sx: createCellContentWrapperSx(theme, cellWithoutBorders), children: cellContent })
96
+ },
97
+ cell.id
98
+ );
99
+ })
108
100
  }
109
- }
110
- );
101
+ );
102
+ } });
111
103
  }
112
104
  export {
113
105
  ModificationRow
@@ -7,7 +7,7 @@ import "@hello-pangea/dnd";
7
7
  import "react-intl";
8
8
  import "./columns-definition.js";
9
9
  import { DROP_FORBIDDEN_INDICATOR_BOTTOM, DROP_FORBIDDEN_INDICATOR_TOP, DROP_INDICATOR_BOTTOM, DROP_INDICATOR_TOP } from "./network-modification-table-styles.js";
10
- import { isCompositeModification, isReferenceModification, isTargetChildOfReference, MAX_COMPOSITE_NESTING_DEPTH, findModificationInTree, moveSubModificationInTree } from "./utils.js";
10
+ import { isCompositeModification, isReferenceModification, MAX_COMPOSITE_NESTING_DEPTH, findModificationInTree, containsReferenceModification, moveSubModificationInTree } from "./utils.js";
11
11
  import "../../utils/conversionUtils.js";
12
12
  import { snackWithFallback } from "../../utils/error.js";
13
13
  import "../../utils/types/equipmentType.js";
@@ -55,7 +55,7 @@ const useModificationsDragAndDrop = ({
55
55
  }) => {
56
56
  const { snackError } = useSnackMessage();
57
57
  const { rows } = table.getRowModel();
58
- const computeTargetDepth = useCallback(
58
+ const computeIsDraggingDown = useCallback(
59
59
  (sourceRow, targetRow) => {
60
60
  const sourceRowIndex = table.getRowModel().flatRows.findIndex((row) => {
61
61
  return row.id === sourceRow.id;
@@ -63,26 +63,35 @@ const useModificationsDragAndDrop = ({
63
63
  const targetRowIndex = table.getRowModel().flatRows.findIndex((row) => {
64
64
  return row.id === targetRow.id;
65
65
  });
66
- const isDraggingDown = sourceRowIndex < targetRowIndex;
67
- return isCompositeModification(targetRow.original) && targetRow.getIsExpanded() && isDraggingDown ? targetRow.depth + 1 : targetRow.depth;
66
+ return sourceRowIndex < targetRowIndex;
68
67
  },
69
68
  [table]
70
69
  );
70
+ const computeTargetDepth = useCallback(
71
+ (sourceRow, targetRow) => {
72
+ const isDraggingDown = computeIsDraggingDown(sourceRow, targetRow);
73
+ return isCompositeModification(targetRow.original) && targetRow.getIsExpanded() && isDraggingDown ? targetRow.depth + 1 : targetRow.depth;
74
+ },
75
+ [computeIsDraggingDown]
76
+ );
71
77
  const isDropForbidden = useCallback(
72
78
  (sourceRow, targetRow) => {
73
- if (isCompositeModification(sourceRow.original)) {
74
- if (isReferenceModification(targetRow.original) || isTargetChildOfReference(targetRow)) {
75
- return true;
76
- }
79
+ const sourceIsCompositeOrReference = isCompositeModification(sourceRow.original) || isReferenceModification(sourceRow.original);
80
+ if (sourceIsCompositeOrReference) {
77
81
  const targetDepth = computeTargetDepth(sourceRow, targetRow);
78
- return (sourceRow.original.maxDepth ?? 0) + targetDepth > MAX_COMPOSITE_NESTING_DEPTH || !!(isCompositeModification(sourceRow.original) && findModificationInTree(targetRow.id, [sourceRow.original]));
79
- }
80
- if (isReferenceModification(sourceRow.original) || isReferenceModification(targetRow.original) || isTargetChildOfReference(targetRow)) {
81
- return true;
82
+ const exceedsNestingLimit = (sourceRow.original.maxDepth ?? 0) + targetDepth > MAX_COMPOSITE_NESTING_DEPTH;
83
+ const isSelfDrop = !!findModificationInTree(targetRow.id, [sourceRow.original]);
84
+ const isDraggingDown = computeIsDraggingDown(sourceRow, targetRow);
85
+ const entersTargetRowItself = (isCompositeModification(targetRow.original) || isReferenceModification(targetRow.original)) && targetRow.getIsExpanded() && isDraggingDown;
86
+ const enteringParent = entersTargetRowItself ? targetRow.original : targetRow.getParentRow()?.original;
87
+ const sourceCarriesReference = isReferenceModification(sourceRow.original) || containsReferenceModification(sourceRow.original);
88
+ const enteringSharedSubtree = isReferenceModification(enteringParent) || enteringParent?.childFromShared === true;
89
+ const isReferenceIntoReference = sourceCarriesReference && enteringSharedSubtree;
90
+ return exceedsNestingLimit || isSelfDrop || isReferenceIntoReference;
82
91
  }
83
92
  return false;
84
93
  },
85
- [computeTargetDepth]
94
+ [computeTargetDepth, computeIsDraggingDown]
86
95
  );
87
96
  const handleDragUpdate = useCallback(
88
97
  (update) => {
@@ -125,7 +134,7 @@ const useModificationsDragAndDrop = ({
125
134
  const sourceCompositeRowKey = sourceParent?.id ?? null;
126
135
  const sourceContainerId = sourceParent?.original.uuid ?? null;
127
136
  const isDraggingDown = destination.index > source.index;
128
- const droppingIntoExpandedComposite = isDraggingDown && targetRow.getIsExpanded();
137
+ const droppingIntoExpandedComposite = isDraggingDown && isCompositeModification(targetRow.original) && targetRow.getIsExpanded();
129
138
  const isSubRowInvolved = sourceRow.depth > 0 || targetRow.depth > 0;
130
139
  const targetComposite = resolveTargetComposite(droppingIntoExpandedComposite, targetRow);
131
140
  const targetContainerId = targetComposite.uuid;
@@ -5,9 +5,7 @@ export declare const MAX_COMPOSITE_NESTING_DEPTH = 5;
5
5
  export declare const formatToComposedModification: (modifications: NetworkModificationMetadata[]) => ComposedModificationMetadata[];
6
6
  export declare function isCompositeModification(modification: ComposedModificationMetadata | undefined): boolean;
7
7
  export declare function isReferenceModification(modification: ComposedModificationMetadata | undefined): boolean;
8
- export declare function isTargetChildOfReference(targetRow: {
9
- original: ComposedModificationMetadata;
10
- }): boolean;
8
+ export declare function containsReferenceModification(modification: ComposedModificationMetadata | undefined): boolean;
11
9
  export declare function findDepth(mods: ComposedModificationMetadata[], uuid: UUID, currentDepth?: number): number;
12
10
  export declare function removeUuidsFromTree(mods: ComposedModificationMetadata[], uuidsToRemove: Set<string>): ComposedModificationMetadata[];
13
11
  /**
@@ -18,6 +18,14 @@ function isCompositeModification(modification) {
18
18
  function isReferenceModification(modification) {
19
19
  return modification?.type === MODIFICATION_TYPES.MODIFICATION_REFERENCE.type;
20
20
  }
21
+ function containsReferenceModification(modification) {
22
+ if (!modification) {
23
+ return false;
24
+ }
25
+ return modification.subModifications.some(
26
+ (sub) => isReferenceModification(sub) || containsReferenceModification(sub)
27
+ );
28
+ }
21
29
  function normalizeReferenceChild(child) {
22
30
  return {
23
31
  ...child,
@@ -25,12 +33,6 @@ function normalizeReferenceChild(child) {
25
33
  messageValues: child.messageValues ?? "{}"
26
34
  };
27
35
  }
28
- function isTargetChildOfReference(targetRow) {
29
- if (targetRow.original.childFromShared === true) {
30
- return true;
31
- }
32
- return false;
33
- }
34
36
  function extractReferenceChildren(detail) {
35
37
  const referenceInfos = detail?.referenceInfos;
36
38
  if (!referenceInfos) {
@@ -224,6 +226,7 @@ async function fetchSubModificationsForExpandedRows(expandedRowKeys, mods, setMo
224
226
  }
225
227
  export {
226
228
  MAX_COMPOSITE_NESTING_DEPTH,
229
+ containsReferenceModification,
227
230
  fetchSubModificationsForExpandedRows,
228
231
  findAllLoadedCompositeModifications,
229
232
  findDepth,
@@ -231,7 +234,6 @@ export {
231
234
  formatToComposedModification,
232
235
  isCompositeModification,
233
236
  isReferenceModification,
234
- isTargetChildOfReference,
235
237
  mergeSubModificationsIntoTree,
236
238
  moveSubModificationInTree,
237
239
  removeUuidsFromTree,
package/dist/index.js CHANGED
@@ -466,7 +466,7 @@ import { SelectHeaderCell } from "./features/network-modification-table/renderer
466
466
  import { SwitchCell } from "./features/network-modification-table/renderers/switch-cell.js";
467
467
  import { DragCloneRow } from "./features/network-modification-table/row/drag-row-clone.js";
468
468
  import { ModificationRow } from "./features/network-modification-table/row/modification-row.js";
469
- import { MAX_COMPOSITE_NESTING_DEPTH, fetchSubModificationsForExpandedRows, findAllLoadedCompositeModifications, findDepth, findModificationInTree, formatToComposedModification, isCompositeModification, isReferenceModification, isTargetChildOfReference, mergeSubModificationsIntoTree, moveSubModificationInTree, removeUuidsFromTree, updateModificationFieldInTree, updateSubModificationsOfACompositeInTree } from "./features/network-modification-table/utils.js";
469
+ import { MAX_COMPOSITE_NESTING_DEPTH, containsReferenceModification, fetchSubModificationsForExpandedRows, findAllLoadedCompositeModifications, findDepth, findModificationInTree, formatToComposedModification, isCompositeModification, isReferenceModification, mergeSubModificationsIntoTree, moveSubModificationInTree, removeUuidsFromTree, updateModificationFieldInTree, updateSubModificationsOfACompositeInTree } from "./features/network-modification-table/utils.js";
470
470
  import { AnnouncementBanner } from "./features/announcement/AnnouncementBanner.js";
471
471
  import { AnnouncementNotification } from "./features/announcement/AnnouncementNotification.js";
472
472
  import { useGlobalAnnouncement } from "./features/announcement/useGlobalAnnouncement.js";
@@ -1348,6 +1348,7 @@ export {
1348
1348
  computeSwitchedOnValue,
1349
1349
  computeTagMinSize,
1350
1350
  computeTolerance,
1351
+ containsReferenceModification,
1351
1352
  convertFilterValues,
1352
1353
  convertInputValue,
1353
1354
  convertLimitsToOperationalLimitsGroupFormSchema,
@@ -1712,7 +1713,6 @@ export {
1712
1713
  isProcessType,
1713
1714
  isReferenceModification,
1714
1715
  isStudyMetadata,
1715
- isTargetChildOfReference,
1716
1716
  isValidComputingType,
1717
1717
  isValidContingencyRow,
1718
1718
  italicFontTextField,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gridsuite/commons-ui",
3
- "version": "0.277.0",
3
+ "version": "0.278.0",
4
4
  "description": "common react components for gridsuite applications",
5
5
  "author": "gridsuite team",
6
6
  "homepage": "https://github.com/gridsuite",