sanity-plugin-workflow 1.0.0-beta.6 → 1.0.0-beta.8

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/lib/index.esm.js CHANGED
@@ -680,25 +680,28 @@ function useWorkflowDocuments(schemaTypes) {
680
680
  _type
681
681
  } = document;
682
682
  const {
683
- documentId
683
+ documentId,
684
+ _rev
684
685
  } = document._metadata || {};
685
- await client.patch("workflow-metadata.".concat(documentId)).set({
686
+ await client.patch("workflow-metadata.".concat(documentId)).ifRevisionId(_rev).set({
686
687
  state: newStateId,
687
688
  orderRank: newOrder
688
- }).commit().then(() => {
689
- var _a;
690
- return toast.push({
691
- title: "Moved to \"".concat((_a = newState == null ? void 0 : newState.title) != null ? _a : newStateId, "\""),
689
+ }).commit().then(res => {
690
+ var _a, _b;
691
+ toast.push({
692
+ title: newState.id === document._metadata.state ? "Reordered in \"".concat((_a = newState == null ? void 0 : newState.title) != null ? _a : newStateId, "\"") : "Moved to \"".concat((_b = newState == null ? void 0 : newState.title) != null ? _b : newStateId, "\""),
692
693
  status: "success"
693
694
  });
695
+ return res;
694
696
  }).catch(err => {
695
697
  var _a;
696
698
  setLocalDocuments(currentLocalData);
697
- return toast.push({
699
+ toast.push({
698
700
  title: "Failed to move to \"".concat((_a = newState == null ? void 0 : newState.title) != null ? _a : newStateId, "\""),
699
701
  description: err.message,
700
702
  status: "error"
701
703
  });
704
+ return null;
702
705
  });
703
706
  return {
704
707
  _id,
@@ -812,31 +815,44 @@ function CompleteButton(props) {
812
815
  apiVersion: API_VERSION
813
816
  });
814
817
  const toast = useToast();
815
- const handleComplete = React.useCallback(id => {
818
+ const handleComplete = React.useCallback(event => {
819
+ const id = event.currentTarget.value;
820
+ if (!id) {
821
+ return;
822
+ }
816
823
  client.delete("workflow-metadata.".concat(id)).then(() => {
817
824
  toast.push({
818
825
  status: "success",
819
- title: "Workflow completed",
820
- description: id
826
+ title: "Workflow completed"
821
827
  });
822
828
  }).catch(() => {
823
829
  toast.push({
824
830
  status: "error",
825
- title: "Could not complete Workflow",
826
- description: id
831
+ title: "Could not complete Workflow"
827
832
  });
828
833
  });
829
834
  }, [client, toast]);
830
- return /* @__PURE__ */jsx(Button, {
831
- onClick: () => handleComplete(documentId),
832
- text: "Complete",
833
- icon: CheckmarkIcon,
834
- tone: "positive",
835
- mode: "ghost",
836
- fontSize: 1,
837
- padding: 2,
838
- tabIndex: -1,
839
- disabled
835
+ return /* @__PURE__ */jsx(Tooltip, {
836
+ portal: true,
837
+ content: /* @__PURE__ */jsx(Box, {
838
+ padding: 2,
839
+ children: /* @__PURE__ */jsx(Text, {
840
+ size: 1,
841
+ children: "Remove this document from Workflow"
842
+ })
843
+ }),
844
+ children: /* @__PURE__ */jsx(Button, {
845
+ value: documentId,
846
+ onClick: handleComplete,
847
+ text: "Complete",
848
+ icon: CheckmarkIcon,
849
+ tone: "positive",
850
+ mode: "ghost",
851
+ fontSize: 1,
852
+ padding: 2,
853
+ tabIndex: -1,
854
+ disabled
855
+ })
840
856
  });
841
857
  }
842
858
  function TimeAgo(_ref2) {
@@ -953,6 +969,7 @@ function DocumentCard(props) {
953
969
  var _a, _b;
954
970
  const {
955
971
  isDragDisabled,
972
+ isPatching,
956
973
  userRoleCanDrop,
957
974
  isDragging,
958
975
  item,
@@ -986,6 +1003,7 @@ function DocumentCard(props) {
986
1003
  let tone = defaultCardTone;
987
1004
  if (!userRoleCanDrop) return isDarkMode ? "default" : "transparent";
988
1005
  if (!documentId) return tone;
1006
+ if (isPatching) tone = isDarkMode ? "default" : "transparent";
989
1007
  if (isDragging) tone = "positive";
990
1008
  if ((state == null ? void 0 : state.requireValidation) && !isValidating && validation.length > 0) {
991
1009
  if (validation.some(v => v.level === "error")) {
@@ -995,7 +1013,7 @@ function DocumentCard(props) {
995
1013
  }
996
1014
  }
997
1015
  return tone;
998
- }, [defaultCardTone, userRoleCanDrop, isDarkMode, documentId, isDragging, isValidating, validation, state == null ? void 0 : state.requireValidation]);
1016
+ }, [defaultCardTone, userRoleCanDrop, isPatching, isDarkMode, documentId, isDragging, isValidating, validation, state == null ? void 0 : state.requireValidation]);
999
1017
  useEffect(() => {
1000
1018
  if (!isValidating && validation.length > 0) {
1001
1019
  if (validation.some(v => v.level === "error")) {
@@ -1041,7 +1059,7 @@ function DocumentCard(props) {
1041
1059
  children: [/* @__PURE__ */jsx(Box, {
1042
1060
  flex: 1,
1043
1061
  children: /* @__PURE__ */jsx(Preview, {
1044
- layout: "default",
1062
+ layout: "block",
1045
1063
  value: item,
1046
1064
  schemaType: schema.get(item._type)
1047
1065
  })
@@ -1049,14 +1067,14 @@ function DocumentCard(props) {
1049
1067
  style: {
1050
1068
  flexShrink: 0
1051
1069
  },
1052
- children: hasError || isDragDisabled ? null : /* @__PURE__ */jsx(DragHandleIcon, {})
1070
+ children: hasError || isDragDisabled || isPatching ? null : /* @__PURE__ */jsx(DragHandleIcon, {})
1053
1071
  })]
1054
1072
  })
1055
- }), /* @__PURE__ */jsx(Card, {
1073
+ }), /* @__PURE__ */jsxs(Card, {
1056
1074
  padding: 2,
1057
1075
  radius: 2,
1058
1076
  tone: "inherit",
1059
- children: /* @__PURE__ */jsxs(Flex, {
1077
+ children: [/* @__PURE__ */jsxs(Flex, {
1060
1078
  align: "center",
1061
1079
  justify: "space-between",
1062
1080
  gap: 3,
@@ -1078,11 +1096,17 @@ function DocumentCard(props) {
1078
1096
  id: item._id,
1079
1097
  type: item._type,
1080
1098
  disabled: !userRoleCanDrop
1081
- }), isLastState ? /* @__PURE__ */jsx(CompleteButton, {
1099
+ }), isLastState && states.length <= 3 ? /* @__PURE__ */jsx(CompleteButton, {
1082
1100
  documentId,
1083
1101
  disabled: !userRoleCanDrop
1084
1102
  }) : null]
1085
- })
1103
+ }), isLastState && states.length > 3 ? /* @__PURE__ */jsx(Stack, {
1104
+ paddingTop: 2,
1105
+ children: /* @__PURE__ */jsx(CompleteButton, {
1106
+ documentId,
1107
+ disabled: !userRoleCanDrop
1108
+ })
1109
+ }) : null]
1086
1110
  })]
1087
1111
  })
1088
1112
  })
@@ -1093,6 +1117,7 @@ function DocumentList(props) {
1093
1117
  const {
1094
1118
  data = [],
1095
1119
  invalidDocumentIds,
1120
+ patchingIds,
1096
1121
  selectedSchemaTypes,
1097
1122
  selectedUserIds,
1098
1123
  state,
@@ -1141,7 +1166,7 @@ function DocumentList(props) {
1141
1166
  }
1142
1167
  const isInvalid = invalidDocumentIds.includes(documentId);
1143
1168
  const meInAssignees = (user == null ? void 0 : user.id) ? assignees == null ? void 0 : assignees.includes(user.id) : false;
1144
- const isDragDisabled = !userRoleCanDrop || isInvalid || !(state.requireAssignment ? state.requireAssignment && meInAssignees : true);
1169
+ const isDragDisabled = patchingIds.includes(documentId) || !userRoleCanDrop || isInvalid || !(state.requireAssignment ? state.requireAssignment && meInAssignees : true);
1145
1170
  return /* @__PURE__ */jsx(Draggable, {
1146
1171
  draggableId: documentId,
1147
1172
  index: virtualItem.index,
@@ -1153,6 +1178,7 @@ function DocumentList(props) {
1153
1178
  children: /* @__PURE__ */jsx(DocumentCard, {
1154
1179
  userRoleCanDrop,
1155
1180
  isDragDisabled,
1181
+ isPatching: patchingIds.includes(documentId),
1156
1182
  isDragging: draggableSnapshot.isDragging,
1157
1183
  item,
1158
1184
  toggleInvalidDocumentId,
@@ -1160,7 +1186,7 @@ function DocumentList(props) {
1160
1186
  states
1161
1187
  })
1162
1188
  })
1163
- }, documentId);
1189
+ }, virtualItem.key);
1164
1190
  })
1165
1191
  });
1166
1192
  }
@@ -1278,7 +1304,7 @@ function Filters(props) {
1278
1304
  icon: ResetIcon
1279
1305
  }) : null]
1280
1306
  })
1281
- }), schemaTypes.length > 0 ? /* @__PURE__ */jsx(Flex, {
1307
+ }), schemaTypes.length > 1 ? /* @__PURE__ */jsx(Flex, {
1282
1308
  align: "center",
1283
1309
  gap: 1,
1284
1310
  children: schemaTypes.map(typeName => {
@@ -1364,6 +1390,40 @@ function StateTitle(props) {
1364
1390
  })
1365
1391
  });
1366
1392
  }
1393
+ function generateMiddleValue(ranks) {
1394
+ if (!ranks.some(rank => !rank)) {
1395
+ return ranks;
1396
+ }
1397
+ const firstUndefined = ranks.findIndex(rank => !rank);
1398
+ const firstDefinedAfter = ranks.findIndex((rank, index) => rank && index > firstUndefined);
1399
+ const firstDefinedBefore = ranks.findLastIndex((rank, index) => rank && index < firstUndefined);
1400
+ if (firstDefinedAfter === -1 || firstDefinedBefore === -1) {
1401
+ throw new Error("Unable to generate middle value between indexes ".concat(firstDefinedBefore, " and ").concat(firstDefinedAfter));
1402
+ }
1403
+ const beforeRank = ranks[firstDefinedBefore];
1404
+ const afterRank = ranks[firstDefinedAfter];
1405
+ if (!beforeRank || typeof beforeRank === "undefined" || !afterRank || typeof afterRank === "undefined") {
1406
+ throw new Error("Unable to generate middle value between indexes ".concat(firstDefinedBefore, " and ").concat(firstDefinedAfter));
1407
+ }
1408
+ const between = beforeRank.between(afterRank);
1409
+ const middle = Math.floor((firstDefinedAfter + firstDefinedBefore) / 2);
1410
+ if (ranks[middle]) {
1411
+ throw new Error("Should not have overwritten value at index ".concat(middle));
1412
+ }
1413
+ ranks[middle] = between;
1414
+ return ranks;
1415
+ }
1416
+ function generateMultipleOrderRanks(count, start, end) {
1417
+ let ranks = [...Array(count)];
1418
+ const rankStart = start != null ? start : LexoRank.min().genNext().genNext();
1419
+ const rankEnd = end != null ? end : LexoRank.max().genPrev().genPrev();
1420
+ ranks[0] = rankStart;
1421
+ ranks[count - 1] = rankEnd;
1422
+ for (let i = 0; i < count; i++) {
1423
+ ranks = generateMiddleValue(ranks);
1424
+ }
1425
+ return ranks.sort((a, b) => a.toString().localeCompare(b.toString()));
1426
+ }
1367
1427
  const StyledFloatingCard = styled(Card)(() => css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n position: fixed;\n bottom: 0;\n left: 0;\n z-index: 1000;\n "]))));
1368
1428
  function FloatingCard(_ref3) {
1369
1429
  let {
@@ -1413,7 +1473,7 @@ function Verify(props) {
1413
1473
  const stateExists = states.find(s => s.id === state);
1414
1474
  return !stateExists && documentId ? [...acc, documentId] : acc;
1415
1475
  }, []) : [];
1416
- const documentsWithInvalidUserIds = (data == null ? void 0 : data.length) ? data.reduce((acc, cur) => {
1476
+ const documentsWithInvalidUserIds = (data == null ? void 0 : data.length) && (userList == null ? void 0 : userList.length) ? data.reduce((acc, cur) => {
1417
1477
  var _a;
1418
1478
  const {
1419
1479
  documentId,
@@ -1488,19 +1548,42 @@ function Verify(props) {
1488
1548
  });
1489
1549
  }, [client, data, toast, userList]);
1490
1550
  const addOrderToDocuments = React.useCallback(async ids => {
1491
- var _a, _b;
1492
1551
  toast.push({
1493
1552
  title: "Adding ordering...",
1494
1553
  status: "info"
1495
1554
  });
1496
- const firstOrder = (_b = (_a = data[0]) == null ? void 0 : _a._metadata) == null ? void 0 : _b.orderRank;
1497
- let newLexo = firstOrder && data.length !== ids.length ? LexoRank.parse(firstOrder) : LexoRank.min();
1555
+ const [firstOrder, secondOrder] = [...data].slice(0, 2).map(d => {
1556
+ var _a;
1557
+ return (_a = d._metadata) == null ? void 0 : _a.orderRank;
1558
+ });
1559
+ const minLexo = firstOrder ? LexoRank.parse(firstOrder) : void 0;
1560
+ const maxLexo = secondOrder ? LexoRank.parse(secondOrder) : void 0;
1561
+ const ranks = generateMultipleOrderRanks(ids.length, minLexo, maxLexo);
1498
1562
  const tx = client.transaction();
1499
1563
  for (let index = 0; index < ids.length; index += 1) {
1500
- newLexo = newLexo.genNext().genNext();
1501
1564
  tx.patch("workflow-metadata.".concat(ids[index]), {
1502
1565
  set: {
1503
- orderRank: newLexo.toString()
1566
+ orderRank: ranks[index].toString()
1567
+ }
1568
+ });
1569
+ }
1570
+ await tx.commit();
1571
+ toast.push({
1572
+ title: "Added order to ".concat(ids.length === 1 ? "1 Document" : "".concat(ids.length, " Documents")),
1573
+ status: "success"
1574
+ });
1575
+ }, [data, client, toast]);
1576
+ const resetOrderOfAllDocuments = React.useCallback(async ids => {
1577
+ toast.push({
1578
+ title: "Adding ordering...",
1579
+ status: "info"
1580
+ });
1581
+ const ranks = generateMultipleOrderRanks(ids.length);
1582
+ const tx = client.transaction();
1583
+ for (let index = 0; index < ids.length; index += 1) {
1584
+ tx.patch("workflow-metadata.".concat(ids[index]), {
1585
+ set: {
1586
+ orderRank: ranks[index].toString()
1504
1587
  }
1505
1588
  });
1506
1589
  }
@@ -1531,24 +1614,39 @@ function Verify(props) {
1531
1614
  return /* @__PURE__ */jsxs(FloatingCard, {
1532
1615
  children: [documentsWithoutValidMetadataIds.length > 0 ? /* @__PURE__ */jsx(Button, {
1533
1616
  tone: "caution",
1617
+ mode: "ghost",
1534
1618
  onClick: () => correctDocuments(documentsWithoutValidMetadataIds),
1535
1619
  text: documentsWithoutValidMetadataIds.length === 1 ? "Correct 1 Document State" : "Correct ".concat(documentsWithoutValidMetadataIds.length, " Document States")
1536
1620
  }) : null, documentsWithInvalidUserIds.length > 0 ? /* @__PURE__ */jsx(Button, {
1537
1621
  tone: "caution",
1622
+ mode: "ghost",
1538
1623
  onClick: () => removeUsersFromDocuments(documentsWithInvalidUserIds),
1539
1624
  text: documentsWithInvalidUserIds.length === 1 ? "Remove Invalid Users from 1 Document" : "Remove Invalid Users from ".concat(documentsWithInvalidUserIds.length, " Documents")
1540
1625
  }) : null, documentsWithoutOrderIds.length > 0 ? /* @__PURE__ */jsx(Button, {
1541
1626
  tone: "caution",
1627
+ mode: "ghost",
1542
1628
  onClick: () => addOrderToDocuments(documentsWithoutOrderIds),
1543
1629
  text: documentsWithoutOrderIds.length === 1 ? "Set Order for 1 Document" : "Set Order for ".concat(documentsWithoutOrderIds.length, " Documents")
1544
- }) : null, documentsWithDuplicatedOrderIds.length > 0 ? /* @__PURE__ */jsx(Button, {
1545
- tone: "caution",
1546
- onClick: () => addOrderToDocuments(documentsWithDuplicatedOrderIds),
1547
- text: documentsWithDuplicatedOrderIds.length === 1 ? "Set Unique Order for 1 Document" : "Set Unique Order for ".concat(documentsWithDuplicatedOrderIds.length, " Documents")
1630
+ }) : null, documentsWithDuplicatedOrderIds.length > 0 ? /* @__PURE__ */jsxs(Fragment, {
1631
+ children: [/* @__PURE__ */jsx(Button, {
1632
+ tone: "caution",
1633
+ mode: "ghost",
1634
+ onClick: () => addOrderToDocuments(documentsWithDuplicatedOrderIds),
1635
+ text: documentsWithDuplicatedOrderIds.length === 1 ? "Set Unique Order for 1 Document" : "Set Unique Order for ".concat(documentsWithDuplicatedOrderIds.length, " Documents")
1636
+ }), /* @__PURE__ */jsx(Button, {
1637
+ tone: "caution",
1638
+ mode: "ghost",
1639
+ onClick: () => resetOrderOfAllDocuments(data.map(doc => {
1640
+ var _a;
1641
+ return String((_a = doc._metadata) == null ? void 0 : _a.documentId);
1642
+ })),
1643
+ text: data.length === 1 ? "Reset Order for 1 Document" : "Reset Order for all ".concat(data.length, " Documents")
1644
+ })]
1548
1645
  }) : null, orphanedMetadataDocumentIds.length > 0 ? /* @__PURE__ */jsx(Button, {
1549
1646
  text: "Cleanup orphaned metadata",
1550
1647
  onClick: handleOrphans,
1551
- tone: "caution"
1648
+ tone: "caution",
1649
+ mode: "ghost"
1552
1650
  }) : null]
1553
1651
  });
1554
1652
  }
@@ -1560,6 +1658,7 @@ function WorkflowTool(props) {
1560
1658
  } = (_b = (_a = props == null ? void 0 : props.tool) == null ? void 0 : _a.options) != null ? _b : {};
1561
1659
  const isDarkMode = useTheme().sanity.color.dark;
1562
1660
  const defaultCardTone = isDarkMode ? "default" : "transparent";
1661
+ const toast = useToast();
1563
1662
  const userList = useProjectUsers({
1564
1663
  apiVersion: API_VERSION
1565
1664
  });
@@ -1569,6 +1668,7 @@ function WorkflowTool(props) {
1569
1668
  workflowData,
1570
1669
  operations
1571
1670
  } = useWorkflowDocuments(schemaTypes);
1671
+ const [patchingIds, setPatchingIds] = React.useState([]);
1572
1672
  const {
1573
1673
  data,
1574
1674
  loading,
@@ -1633,26 +1733,65 @@ function WorkflowTool(props) {
1633
1733
  return;
1634
1734
  }
1635
1735
  const destinationStateItems = [...filterItemsAndSort(data, destination.droppableId, [], null)];
1736
+ const destinationStateIndex = states.findIndex(s => s.id === destination.droppableId);
1737
+ const globalStateMinimumRank = data[0]._metadata.orderRank;
1738
+ const globalStateMaximumRank = data[data.length - 1]._metadata.orderRank;
1636
1739
  let newOrder;
1637
1740
  if (!destinationStateItems.length) {
1638
- newOrder = LexoRank.min().toString();
1741
+ if (destinationStateIndex === 0) {
1742
+ newOrder = LexoRank.min().toString();
1743
+ } else {
1744
+ newOrder = LexoRank.parse(globalStateMinimumRank).between(LexoRank.min()).toString();
1745
+ }
1639
1746
  } else if (destination.index === 0) {
1640
1747
  const firstItemOrderRank = (_b2 = (_a2 = [...destinationStateItems].shift()) == null ? void 0 : _a2._metadata) == null ? void 0 : _b2.orderRank;
1641
- newOrder = firstItemOrderRank && typeof firstItemOrderRank === "string" ? LexoRank.parse(firstItemOrderRank).genPrev().toString() : LexoRank.min().toString();
1748
+ if (firstItemOrderRank && typeof firstItemOrderRank === "string") {
1749
+ newOrder = LexoRank.parse(firstItemOrderRank).genPrev().toString();
1750
+ } else if (destinationStateIndex === 0) {
1751
+ newOrder = LexoRank.min().toString();
1752
+ } else {
1753
+ newOrder = LexoRank.parse(globalStateMinimumRank).between(LexoRank.min()).toString();
1754
+ }
1642
1755
  } else if (destination.index + 1 === destinationStateItems.length) {
1643
1756
  const lastItemOrderRank = (_d = (_c2 = [...destinationStateItems].pop()) == null ? void 0 : _c2._metadata) == null ? void 0 : _d.orderRank;
1644
- newOrder = lastItemOrderRank && typeof lastItemOrderRank === "string" ? LexoRank.parse(lastItemOrderRank).genNext().toString() : LexoRank.min().toString();
1757
+ if (lastItemOrderRank && typeof lastItemOrderRank === "string") {
1758
+ newOrder = LexoRank.parse(lastItemOrderRank).genNext().toString();
1759
+ } else if (destinationStateIndex === states.length - 1) {
1760
+ newOrder = LexoRank.max().toString();
1761
+ } else {
1762
+ newOrder = LexoRank.parse(globalStateMaximumRank).between(LexoRank.min()).toString();
1763
+ }
1645
1764
  } else {
1646
1765
  const itemBefore = destinationStateItems[destination.index - 1];
1647
1766
  const itemBeforeRank = (_e = itemBefore == null ? void 0 : itemBefore._metadata) == null ? void 0 : _e.orderRank;
1648
- const itemBeforeRankParsed = itemBeforeRank ? LexoRank.parse(itemBeforeRank) : LexoRank.min();
1767
+ let itemBeforeRankParsed;
1768
+ if (itemBeforeRank) {
1769
+ itemBeforeRankParsed = LexoRank.parse(itemBeforeRank);
1770
+ } else if (destinationStateIndex === 0) {
1771
+ itemBeforeRankParsed = LexoRank.min();
1772
+ } else {
1773
+ itemBeforeRankParsed = LexoRank.parse(globalStateMinimumRank);
1774
+ }
1649
1775
  const itemAfter = destinationStateItems[destination.index];
1650
1776
  const itemAfterRank = (_f = itemAfter == null ? void 0 : itemAfter._metadata) == null ? void 0 : _f.orderRank;
1651
- const itemAfterRankParsed = itemAfterRank ? LexoRank.parse(itemAfterRank) : LexoRank.max();
1777
+ let itemAfterRankParsed;
1778
+ if (itemAfterRank) {
1779
+ itemAfterRankParsed = LexoRank.parse(itemAfterRank);
1780
+ } else if (destinationStateIndex === states.length - 1) {
1781
+ itemAfterRankParsed = LexoRank.max();
1782
+ } else {
1783
+ itemAfterRankParsed = LexoRank.parse(globalStateMaximumRank);
1784
+ }
1652
1785
  newOrder = itemBeforeRankParsed.between(itemAfterRankParsed).toString();
1653
1786
  }
1654
- move(draggableId, destination, states, newOrder);
1655
- }, [data, move, states]);
1787
+ setPatchingIds([...patchingIds, draggableId]);
1788
+ toast.push({
1789
+ status: "info",
1790
+ title: "Updating document state..."
1791
+ });
1792
+ await move(draggableId, destination, states, newOrder);
1793
+ setPatchingIds(ids => ids.filter(id => id !== draggableId));
1794
+ }, [data, patchingIds, toast, move, states]);
1656
1795
  const uniqueAssignedUsers = React.useMemo(() => {
1657
1796
  const uniqueUserIds = data.reduce((acc, item) => {
1658
1797
  var _a2;
@@ -1679,6 +1818,30 @@ function WorkflowTool(props) {
1679
1818
  const toggleInvalidDocumentId = React.useCallback((docId, action) => {
1680
1819
  setInvalidDocumentIds(prev => action === "ADD" ? [...prev, docId] : prev.filter(id => id !== docId));
1681
1820
  }, []);
1821
+ const Clone = React.useCallback((provided, snapshot, rubric) => {
1822
+ const item = data.find(doc => {
1823
+ var _a2;
1824
+ return ((_a2 = doc == null ? void 0 : doc._metadata) == null ? void 0 : _a2.documentId) === rubric.draggableId;
1825
+ });
1826
+ return /* @__PURE__ */jsx("div", {
1827
+ ...provided.draggableProps,
1828
+ ...provided.dragHandleProps,
1829
+ ref: provided.innerRef,
1830
+ children: item ? /* @__PURE__ */jsx(DocumentCard, {
1831
+ isDragDisabled: false,
1832
+ isPatching: false,
1833
+ userRoleCanDrop: true,
1834
+ isDragging: snapshot.isDragging,
1835
+ item,
1836
+ states,
1837
+ toggleInvalidDocumentId,
1838
+ userList
1839
+ }) : /* @__PURE__ */jsx(Feedback, {
1840
+ title: "Item not found",
1841
+ tone: "caution"
1842
+ })
1843
+ });
1844
+ }, [data, states, toggleInvalidDocumentId, userList]);
1682
1845
  if (!(states == null ? void 0 : states.length)) {
1683
1846
  return /* @__PURE__ */jsx(Container, {
1684
1847
  width: 1,
@@ -1745,29 +1908,7 @@ function WorkflowTool(props) {
1745
1908
  droppableId: state.id,
1746
1909
  isDropDisabled,
1747
1910
  mode: "virtual",
1748
- renderClone: (provided, snapshot, rubric) => {
1749
- const item = data.find(doc => {
1750
- var _a3;
1751
- return ((_a3 = doc == null ? void 0 : doc._metadata) == null ? void 0 : _a3.documentId) === rubric.draggableId;
1752
- });
1753
- return /* @__PURE__ */jsx("div", {
1754
- ...provided.draggableProps,
1755
- ...provided.dragHandleProps,
1756
- ref: provided.innerRef,
1757
- children: item ? /* @__PURE__ */jsx(DocumentCard, {
1758
- isDragDisabled: false,
1759
- userRoleCanDrop,
1760
- isDragging: snapshot.isDragging,
1761
- item,
1762
- states,
1763
- toggleInvalidDocumentId,
1764
- userList
1765
- }) : /* @__PURE__ */jsx(Feedback, {
1766
- title: "Item not found",
1767
- tone: "caution"
1768
- })
1769
- });
1770
- },
1911
+ renderClone: Clone,
1771
1912
  children: (provided, snapshot) => /* @__PURE__ */jsxs(Card, {
1772
1913
  ref: provided.innerRef,
1773
1914
  tone: snapshot.isDraggingOver ? "primary" : defaultCardTone,
@@ -1783,6 +1924,7 @@ function WorkflowTool(props) {
1783
1924
  }) : null, /* @__PURE__ */jsx(DocumentList, {
1784
1925
  data,
1785
1926
  invalidDocumentIds,
1927
+ patchingIds,
1786
1928
  selectedSchemaTypes,
1787
1929
  selectedUserIds,
1788
1930
  state,