sanity-plugin-workflow 1.0.0-beta.5 → 1.0.0-beta.7
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/README.md +9 -5
- package/lib/index.esm.js +171 -71
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +171 -71
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/DocumentCard/CompleteButton.tsx +47 -32
- package/src/components/DocumentCard/index.tsx +20 -42
- package/src/components/DocumentList.tsx +5 -2
- package/src/components/Filters.tsx +1 -1
- package/src/components/StateTitle/index.tsx +31 -26
- package/src/components/Verify.tsx +36 -4
- package/src/components/WorkflowTool.tsx +122 -51
- package/src/hooks/useWorkflowDocuments.tsx +11 -8
- package/src/types/index.ts +0 -3
package/lib/index.js
CHANGED
|
@@ -646,7 +646,7 @@ function useWorkflowDocuments(schemaTypes) {
|
|
|
646
646
|
setLocalDocuments(data);
|
|
647
647
|
}
|
|
648
648
|
}, [data]);
|
|
649
|
-
const move = React__default.default.useCallback((draggedId, destination, states, newOrder) => {
|
|
649
|
+
const move = React__default.default.useCallback(async (draggedId, destination, states, newOrder) => {
|
|
650
650
|
const currentLocalData = localDocuments;
|
|
651
651
|
const newLocalDocuments = localDocuments.map(item => {
|
|
652
652
|
var _a;
|
|
@@ -693,25 +693,28 @@ function useWorkflowDocuments(schemaTypes) {
|
|
|
693
693
|
_type
|
|
694
694
|
} = document;
|
|
695
695
|
const {
|
|
696
|
-
|
|
697
|
-
|
|
696
|
+
documentId,
|
|
697
|
+
_rev
|
|
698
698
|
} = document._metadata || {};
|
|
699
|
-
client.patch("workflow-metadata.".concat(documentId)).ifRevisionId(_rev).set({
|
|
699
|
+
await client.patch("workflow-metadata.".concat(documentId)).ifRevisionId(_rev).set({
|
|
700
700
|
state: newStateId,
|
|
701
701
|
orderRank: newOrder
|
|
702
|
-
}).commit().then(
|
|
702
|
+
}).commit().then(res => {
|
|
703
703
|
var _a;
|
|
704
|
-
|
|
704
|
+
toast.push({
|
|
705
705
|
title: "Moved to \"".concat((_a = newState == null ? void 0 : newState.title) != null ? _a : newStateId, "\""),
|
|
706
706
|
status: "success"
|
|
707
707
|
});
|
|
708
|
-
|
|
708
|
+
return res;
|
|
709
|
+
}).catch(err => {
|
|
709
710
|
var _a;
|
|
710
711
|
setLocalDocuments(currentLocalData);
|
|
711
|
-
|
|
712
|
+
toast.push({
|
|
712
713
|
title: "Failed to move to \"".concat((_a = newState == null ? void 0 : newState.title) != null ? _a : newStateId, "\""),
|
|
714
|
+
description: err.message,
|
|
713
715
|
status: "error"
|
|
714
716
|
});
|
|
717
|
+
return null;
|
|
715
718
|
});
|
|
716
719
|
return {
|
|
717
720
|
_id,
|
|
@@ -825,31 +828,44 @@ function CompleteButton(props) {
|
|
|
825
828
|
apiVersion: API_VERSION
|
|
826
829
|
});
|
|
827
830
|
const toast = ui.useToast();
|
|
828
|
-
const handleComplete = React__default.default.useCallback(
|
|
831
|
+
const handleComplete = React__default.default.useCallback(event => {
|
|
832
|
+
const id = event.currentTarget.value;
|
|
833
|
+
if (!id) {
|
|
834
|
+
return;
|
|
835
|
+
}
|
|
829
836
|
client.delete("workflow-metadata.".concat(id)).then(() => {
|
|
830
837
|
toast.push({
|
|
831
838
|
status: "success",
|
|
832
|
-
title: "Workflow completed"
|
|
833
|
-
description: id
|
|
839
|
+
title: "Workflow completed"
|
|
834
840
|
});
|
|
835
841
|
}).catch(() => {
|
|
836
842
|
toast.push({
|
|
837
843
|
status: "error",
|
|
838
|
-
title: "Could not complete Workflow"
|
|
839
|
-
description: id
|
|
844
|
+
title: "Could not complete Workflow"
|
|
840
845
|
});
|
|
841
846
|
});
|
|
842
847
|
}, [client, toast]);
|
|
843
|
-
return /* @__PURE__ */jsxRuntime.jsx(ui.
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
848
|
+
return /* @__PURE__ */jsxRuntime.jsx(ui.Tooltip, {
|
|
849
|
+
portal: true,
|
|
850
|
+
content: /* @__PURE__ */jsxRuntime.jsx(ui.Box, {
|
|
851
|
+
padding: 2,
|
|
852
|
+
children: /* @__PURE__ */jsxRuntime.jsx(ui.Text, {
|
|
853
|
+
size: 1,
|
|
854
|
+
children: "Remove this document from Workflow"
|
|
855
|
+
})
|
|
856
|
+
}),
|
|
857
|
+
children: /* @__PURE__ */jsxRuntime.jsx(ui.Button, {
|
|
858
|
+
value: documentId,
|
|
859
|
+
onClick: handleComplete,
|
|
860
|
+
text: "Complete",
|
|
861
|
+
icon: icons.CheckmarkIcon,
|
|
862
|
+
tone: "positive",
|
|
863
|
+
mode: "ghost",
|
|
864
|
+
fontSize: 1,
|
|
865
|
+
padding: 2,
|
|
866
|
+
tabIndex: -1,
|
|
867
|
+
disabled
|
|
868
|
+
})
|
|
853
869
|
});
|
|
854
870
|
}
|
|
855
871
|
function TimeAgo(_ref2) {
|
|
@@ -966,6 +982,7 @@ function DocumentCard(props) {
|
|
|
966
982
|
var _a, _b;
|
|
967
983
|
const {
|
|
968
984
|
isDragDisabled,
|
|
985
|
+
isPatching,
|
|
969
986
|
userRoleCanDrop,
|
|
970
987
|
isDragging,
|
|
971
988
|
item,
|
|
@@ -999,6 +1016,7 @@ function DocumentCard(props) {
|
|
|
999
1016
|
let tone = defaultCardTone;
|
|
1000
1017
|
if (!userRoleCanDrop) return isDarkMode ? "default" : "transparent";
|
|
1001
1018
|
if (!documentId) return tone;
|
|
1019
|
+
if (isPatching) tone = isDarkMode ? "default" : "transparent";
|
|
1002
1020
|
if (isDragging) tone = "positive";
|
|
1003
1021
|
if ((state == null ? void 0 : state.requireValidation) && !isValidating && validation.length > 0) {
|
|
1004
1022
|
if (validation.some(v => v.level === "error")) {
|
|
@@ -1008,7 +1026,7 @@ function DocumentCard(props) {
|
|
|
1008
1026
|
}
|
|
1009
1027
|
}
|
|
1010
1028
|
return tone;
|
|
1011
|
-
}, [defaultCardTone, userRoleCanDrop, isDarkMode, documentId, isDragging, isValidating, validation, state == null ? void 0 : state.requireValidation]);
|
|
1029
|
+
}, [defaultCardTone, userRoleCanDrop, isPatching, isDarkMode, documentId, isDragging, isValidating, validation, state == null ? void 0 : state.requireValidation]);
|
|
1012
1030
|
React.useEffect(() => {
|
|
1013
1031
|
if (!isValidating && validation.length > 0) {
|
|
1014
1032
|
if (validation.some(v => v.level === "error")) {
|
|
@@ -1054,7 +1072,7 @@ function DocumentCard(props) {
|
|
|
1054
1072
|
children: [/* @__PURE__ */jsxRuntime.jsx(ui.Box, {
|
|
1055
1073
|
flex: 1,
|
|
1056
1074
|
children: /* @__PURE__ */jsxRuntime.jsx(sanity.Preview, {
|
|
1057
|
-
layout: "
|
|
1075
|
+
layout: "block",
|
|
1058
1076
|
value: item,
|
|
1059
1077
|
schemaType: schema.get(item._type)
|
|
1060
1078
|
})
|
|
@@ -1062,14 +1080,14 @@ function DocumentCard(props) {
|
|
|
1062
1080
|
style: {
|
|
1063
1081
|
flexShrink: 0
|
|
1064
1082
|
},
|
|
1065
|
-
children: hasError || isDragDisabled ? null : /* @__PURE__ */jsxRuntime.jsx(icons.DragHandleIcon, {})
|
|
1083
|
+
children: hasError || isDragDisabled || isPatching ? null : /* @__PURE__ */jsxRuntime.jsx(icons.DragHandleIcon, {})
|
|
1066
1084
|
})]
|
|
1067
1085
|
})
|
|
1068
|
-
}), /* @__PURE__ */jsxRuntime.
|
|
1086
|
+
}), /* @__PURE__ */jsxRuntime.jsxs(ui.Card, {
|
|
1069
1087
|
padding: 2,
|
|
1070
1088
|
radius: 2,
|
|
1071
1089
|
tone: "inherit",
|
|
1072
|
-
children: /* @__PURE__ */jsxRuntime.jsxs(ui.Flex, {
|
|
1090
|
+
children: [/* @__PURE__ */jsxRuntime.jsxs(ui.Flex, {
|
|
1073
1091
|
align: "center",
|
|
1074
1092
|
justify: "space-between",
|
|
1075
1093
|
gap: 3,
|
|
@@ -1091,11 +1109,17 @@ function DocumentCard(props) {
|
|
|
1091
1109
|
id: item._id,
|
|
1092
1110
|
type: item._type,
|
|
1093
1111
|
disabled: !userRoleCanDrop
|
|
1094
|
-
}), isLastState ? /* @__PURE__ */jsxRuntime.jsx(CompleteButton, {
|
|
1112
|
+
}), isLastState && states.length <= 3 ? /* @__PURE__ */jsxRuntime.jsx(CompleteButton, {
|
|
1095
1113
|
documentId,
|
|
1096
1114
|
disabled: !userRoleCanDrop
|
|
1097
1115
|
}) : null]
|
|
1098
|
-
})
|
|
1116
|
+
}), isLastState && states.length > 3 ? /* @__PURE__ */jsxRuntime.jsx(ui.Stack, {
|
|
1117
|
+
paddingTop: 2,
|
|
1118
|
+
children: /* @__PURE__ */jsxRuntime.jsx(CompleteButton, {
|
|
1119
|
+
documentId,
|
|
1120
|
+
disabled: !userRoleCanDrop
|
|
1121
|
+
})
|
|
1122
|
+
}) : null]
|
|
1099
1123
|
})]
|
|
1100
1124
|
})
|
|
1101
1125
|
})
|
|
@@ -1106,6 +1130,7 @@ function DocumentList(props) {
|
|
|
1106
1130
|
const {
|
|
1107
1131
|
data = [],
|
|
1108
1132
|
invalidDocumentIds,
|
|
1133
|
+
patchingIds,
|
|
1109
1134
|
selectedSchemaTypes,
|
|
1110
1135
|
selectedUserIds,
|
|
1111
1136
|
state,
|
|
@@ -1127,7 +1152,7 @@ function DocumentList(props) {
|
|
|
1127
1152
|
return (_c = (_b = (_a = dataFiltered[index]) == null ? void 0 : _a._metadata) == null ? void 0 : _b.documentId) != null ? _c : index;
|
|
1128
1153
|
},
|
|
1129
1154
|
estimateSize: () => 113,
|
|
1130
|
-
overscan:
|
|
1155
|
+
overscan: 10
|
|
1131
1156
|
});
|
|
1132
1157
|
if (!data.length) {
|
|
1133
1158
|
return null;
|
|
@@ -1154,7 +1179,7 @@ function DocumentList(props) {
|
|
|
1154
1179
|
}
|
|
1155
1180
|
const isInvalid = invalidDocumentIds.includes(documentId);
|
|
1156
1181
|
const meInAssignees = (user == null ? void 0 : user.id) ? assignees == null ? void 0 : assignees.includes(user.id) : false;
|
|
1157
|
-
const isDragDisabled = !userRoleCanDrop || isInvalid || !(state.requireAssignment ? state.requireAssignment && meInAssignees : true);
|
|
1182
|
+
const isDragDisabled = patchingIds.includes(documentId) || !userRoleCanDrop || isInvalid || !(state.requireAssignment ? state.requireAssignment && meInAssignees : true);
|
|
1158
1183
|
return /* @__PURE__ */jsxRuntime.jsx(dnd.Draggable, {
|
|
1159
1184
|
draggableId: documentId,
|
|
1160
1185
|
index: virtualItem.index,
|
|
@@ -1166,6 +1191,7 @@ function DocumentList(props) {
|
|
|
1166
1191
|
children: /* @__PURE__ */jsxRuntime.jsx(DocumentCard, {
|
|
1167
1192
|
userRoleCanDrop,
|
|
1168
1193
|
isDragDisabled,
|
|
1194
|
+
isPatching: patchingIds.includes(documentId),
|
|
1169
1195
|
isDragging: draggableSnapshot.isDragging,
|
|
1170
1196
|
item,
|
|
1171
1197
|
toggleInvalidDocumentId,
|
|
@@ -1291,7 +1317,7 @@ function Filters(props) {
|
|
|
1291
1317
|
icon: icons.ResetIcon
|
|
1292
1318
|
}) : null]
|
|
1293
1319
|
})
|
|
1294
|
-
}), schemaTypes.length >
|
|
1320
|
+
}), schemaTypes.length > 1 ? /* @__PURE__ */jsxRuntime.jsx(ui.Flex, {
|
|
1295
1321
|
align: "center",
|
|
1296
1322
|
gap: 1,
|
|
1297
1323
|
children: schemaTypes.map(typeName => {
|
|
@@ -1339,7 +1365,8 @@ function StateTitle(props) {
|
|
|
1339
1365
|
requireAssignment,
|
|
1340
1366
|
userRoleCanDrop,
|
|
1341
1367
|
isDropDisabled,
|
|
1342
|
-
draggingFrom
|
|
1368
|
+
draggingFrom,
|
|
1369
|
+
documentCount
|
|
1343
1370
|
} = props;
|
|
1344
1371
|
let tone = "default";
|
|
1345
1372
|
const isSource = draggingFrom === state.id;
|
|
@@ -1364,7 +1391,15 @@ function StateTitle(props) {
|
|
|
1364
1391
|
}), requireAssignment ? /* @__PURE__ */jsxRuntime.jsx(Status, {
|
|
1365
1392
|
text: "You must be assigned to the document to move documents to this State",
|
|
1366
1393
|
icon: icons.UserIcon
|
|
1367
|
-
}) : null
|
|
1394
|
+
}) : null, /* @__PURE__ */jsxRuntime.jsx(ui.Box, {
|
|
1395
|
+
flex: 1,
|
|
1396
|
+
children: documentCount > 0 ? /* @__PURE__ */jsxRuntime.jsx(ui.Text, {
|
|
1397
|
+
weight: "semibold",
|
|
1398
|
+
align: "right",
|
|
1399
|
+
size: 1,
|
|
1400
|
+
children: documentCount
|
|
1401
|
+
}) : null
|
|
1402
|
+
})]
|
|
1368
1403
|
})
|
|
1369
1404
|
});
|
|
1370
1405
|
}
|
|
@@ -1434,6 +1469,17 @@ function Verify(props) {
|
|
|
1434
1469
|
} = (_a = cur._metadata) != null ? _a : {};
|
|
1435
1470
|
return !orderRank && documentId ? [...acc, documentId] : acc;
|
|
1436
1471
|
}, []) : [];
|
|
1472
|
+
const documentsWithDuplicatedOrderIds = (data == null ? void 0 : data.length) ? data.reduce((acc, cur) => {
|
|
1473
|
+
var _a;
|
|
1474
|
+
const {
|
|
1475
|
+
documentId,
|
|
1476
|
+
orderRank
|
|
1477
|
+
} = (_a = cur._metadata) != null ? _a : {};
|
|
1478
|
+
return orderRank && data.filter(d => {
|
|
1479
|
+
var _a2;
|
|
1480
|
+
return ((_a2 = d._metadata) == null ? void 0 : _a2.orderRank) === orderRank;
|
|
1481
|
+
}).length > 1 && documentId ? [...acc, documentId] : acc;
|
|
1482
|
+
}, []) : [];
|
|
1437
1483
|
const correctDocuments = React__default.default.useCallback(async ids => {
|
|
1438
1484
|
toast.push({
|
|
1439
1485
|
title: "Correcting...",
|
|
@@ -1481,16 +1527,21 @@ function Verify(props) {
|
|
|
1481
1527
|
});
|
|
1482
1528
|
}, [client, data, toast, userList]);
|
|
1483
1529
|
const addOrderToDocuments = React__default.default.useCallback(async ids => {
|
|
1484
|
-
var _a, _b;
|
|
1485
1530
|
toast.push({
|
|
1486
1531
|
title: "Adding ordering...",
|
|
1487
1532
|
status: "info"
|
|
1488
1533
|
});
|
|
1489
|
-
const firstOrder
|
|
1490
|
-
|
|
1534
|
+
const [firstOrder, secondOrder] = [...data].slice(0, 2).map(d => {
|
|
1535
|
+
var _a;
|
|
1536
|
+
return (_a = d._metadata) == null ? void 0 : _a.orderRank;
|
|
1537
|
+
});
|
|
1538
|
+
const minLexo = firstOrder && data.length !== ids.length ? lexorank.LexoRank.parse(firstOrder) : lexorank.LexoRank.min();
|
|
1539
|
+
const maxLexo = secondOrder && data.length !== ids.length ? lexorank.LexoRank.parse(secondOrder) : lexorank.LexoRank.max();
|
|
1540
|
+
let newLexo = minLexo.between(maxLexo);
|
|
1541
|
+
const lastLexo = maxLexo;
|
|
1491
1542
|
const tx = client.transaction();
|
|
1492
1543
|
for (let index = 0; index < ids.length; index += 1) {
|
|
1493
|
-
newLexo = newLexo.
|
|
1544
|
+
newLexo = newLexo.between(lastLexo);
|
|
1494
1545
|
tx.patch("workflow-metadata.".concat(ids[index]), {
|
|
1495
1546
|
set: {
|
|
1496
1547
|
orderRank: newLexo.toString()
|
|
@@ -1534,6 +1585,10 @@ function Verify(props) {
|
|
|
1534
1585
|
tone: "caution",
|
|
1535
1586
|
onClick: () => addOrderToDocuments(documentsWithoutOrderIds),
|
|
1536
1587
|
text: documentsWithoutOrderIds.length === 1 ? "Set Order for 1 Document" : "Set Order for ".concat(documentsWithoutOrderIds.length, " Documents")
|
|
1588
|
+
}) : null, documentsWithDuplicatedOrderIds.length > 0 ? /* @__PURE__ */jsxRuntime.jsx(ui.Button, {
|
|
1589
|
+
tone: "caution",
|
|
1590
|
+
onClick: () => addOrderToDocuments(documentsWithDuplicatedOrderIds),
|
|
1591
|
+
text: documentsWithDuplicatedOrderIds.length === 1 ? "Set Unique Order for 1 Document" : "Set Unique Order for ".concat(documentsWithDuplicatedOrderIds.length, " Documents")
|
|
1537
1592
|
}) : null, orphanedMetadataDocumentIds.length > 0 ? /* @__PURE__ */jsxRuntime.jsx(ui.Button, {
|
|
1538
1593
|
text: "Cleanup orphaned metadata",
|
|
1539
1594
|
onClick: handleOrphans,
|
|
@@ -1549,6 +1604,7 @@ function WorkflowTool(props) {
|
|
|
1549
1604
|
} = (_b = (_a = props == null ? void 0 : props.tool) == null ? void 0 : _a.options) != null ? _b : {};
|
|
1550
1605
|
const isDarkMode = ui.useTheme().sanity.color.dark;
|
|
1551
1606
|
const defaultCardTone = isDarkMode ? "default" : "transparent";
|
|
1607
|
+
const toast = ui.useToast();
|
|
1552
1608
|
const userList = sanityPluginUtils.useProjectUsers({
|
|
1553
1609
|
apiVersion: API_VERSION
|
|
1554
1610
|
});
|
|
@@ -1558,6 +1614,7 @@ function WorkflowTool(props) {
|
|
|
1558
1614
|
workflowData,
|
|
1559
1615
|
operations
|
|
1560
1616
|
} = useWorkflowDocuments(schemaTypes);
|
|
1617
|
+
const [patchingIds, setPatchingIds] = React__default.default.useState([]);
|
|
1561
1618
|
const {
|
|
1562
1619
|
data,
|
|
1563
1620
|
loading,
|
|
@@ -1605,7 +1662,7 @@ function WorkflowTool(props) {
|
|
|
1605
1662
|
setUndroppableStates(undroppableExceptSelf);
|
|
1606
1663
|
}
|
|
1607
1664
|
}, [data, states, user]);
|
|
1608
|
-
const handleDragEnd = React__default.default.useCallback(result => {
|
|
1665
|
+
const handleDragEnd = React__default.default.useCallback(async result => {
|
|
1609
1666
|
var _a2, _b2, _c2, _d, _e, _f;
|
|
1610
1667
|
setUndroppableStates([]);
|
|
1611
1668
|
setDraggingFrom("");
|
|
@@ -1622,26 +1679,65 @@ function WorkflowTool(props) {
|
|
|
1622
1679
|
return;
|
|
1623
1680
|
}
|
|
1624
1681
|
const destinationStateItems = [...filterItemsAndSort(data, destination.droppableId, [], null)];
|
|
1682
|
+
const destinationStateIndex = states.findIndex(s => s.id === destination.droppableId);
|
|
1683
|
+
const globalStateMinimumRank = data[0]._metadata.orderRank;
|
|
1684
|
+
const globalStateMaximumRank = data[data.length - 1]._metadata.orderRank;
|
|
1625
1685
|
let newOrder;
|
|
1626
1686
|
if (!destinationStateItems.length) {
|
|
1627
|
-
|
|
1687
|
+
if (destinationStateIndex === 0) {
|
|
1688
|
+
newOrder = lexorank.LexoRank.min().toString();
|
|
1689
|
+
} else {
|
|
1690
|
+
newOrder = lexorank.LexoRank.parse(globalStateMinimumRank).between(lexorank.LexoRank.min()).toString();
|
|
1691
|
+
}
|
|
1628
1692
|
} else if (destination.index === 0) {
|
|
1629
1693
|
const firstItemOrderRank = (_b2 = (_a2 = [...destinationStateItems].shift()) == null ? void 0 : _a2._metadata) == null ? void 0 : _b2.orderRank;
|
|
1630
|
-
|
|
1694
|
+
if (firstItemOrderRank && typeof firstItemOrderRank === "string") {
|
|
1695
|
+
newOrder = lexorank.LexoRank.parse(firstItemOrderRank).genPrev().toString();
|
|
1696
|
+
} else if (destinationStateIndex === 0) {
|
|
1697
|
+
newOrder = lexorank.LexoRank.min().toString();
|
|
1698
|
+
} else {
|
|
1699
|
+
newOrder = lexorank.LexoRank.parse(globalStateMinimumRank).between(lexorank.LexoRank.min()).toString();
|
|
1700
|
+
}
|
|
1631
1701
|
} else if (destination.index + 1 === destinationStateItems.length) {
|
|
1632
1702
|
const lastItemOrderRank = (_d = (_c2 = [...destinationStateItems].pop()) == null ? void 0 : _c2._metadata) == null ? void 0 : _d.orderRank;
|
|
1633
|
-
|
|
1703
|
+
if (lastItemOrderRank && typeof lastItemOrderRank === "string") {
|
|
1704
|
+
newOrder = lexorank.LexoRank.parse(lastItemOrderRank).genNext().toString();
|
|
1705
|
+
} else if (destinationStateIndex === states.length - 1) {
|
|
1706
|
+
newOrder = lexorank.LexoRank.max().toString();
|
|
1707
|
+
} else {
|
|
1708
|
+
newOrder = lexorank.LexoRank.parse(globalStateMaximumRank).between(lexorank.LexoRank.min()).toString();
|
|
1709
|
+
}
|
|
1634
1710
|
} else {
|
|
1635
1711
|
const itemBefore = destinationStateItems[destination.index - 1];
|
|
1636
1712
|
const itemBeforeRank = (_e = itemBefore == null ? void 0 : itemBefore._metadata) == null ? void 0 : _e.orderRank;
|
|
1637
|
-
|
|
1713
|
+
let itemBeforeRankParsed;
|
|
1714
|
+
if (itemBeforeRank) {
|
|
1715
|
+
itemBeforeRankParsed = lexorank.LexoRank.parse(itemBeforeRank);
|
|
1716
|
+
} else if (destinationStateIndex === 0) {
|
|
1717
|
+
itemBeforeRankParsed = lexorank.LexoRank.min();
|
|
1718
|
+
} else {
|
|
1719
|
+
itemBeforeRankParsed = lexorank.LexoRank.parse(globalStateMinimumRank);
|
|
1720
|
+
}
|
|
1638
1721
|
const itemAfter = destinationStateItems[destination.index];
|
|
1639
1722
|
const itemAfterRank = (_f = itemAfter == null ? void 0 : itemAfter._metadata) == null ? void 0 : _f.orderRank;
|
|
1640
|
-
|
|
1723
|
+
let itemAfterRankParsed;
|
|
1724
|
+
if (itemAfterRank) {
|
|
1725
|
+
itemAfterRankParsed = lexorank.LexoRank.parse(itemAfterRank);
|
|
1726
|
+
} else if (destinationStateIndex === states.length - 1) {
|
|
1727
|
+
itemAfterRankParsed = lexorank.LexoRank.max();
|
|
1728
|
+
} else {
|
|
1729
|
+
itemAfterRankParsed = lexorank.LexoRank.parse(globalStateMaximumRank);
|
|
1730
|
+
}
|
|
1641
1731
|
newOrder = itemBeforeRankParsed.between(itemAfterRankParsed).toString();
|
|
1642
1732
|
}
|
|
1643
|
-
|
|
1644
|
-
|
|
1733
|
+
setPatchingIds([...patchingIds, draggableId]);
|
|
1734
|
+
toast.push({
|
|
1735
|
+
status: "info",
|
|
1736
|
+
title: "Updating document state..."
|
|
1737
|
+
});
|
|
1738
|
+
await move(draggableId, destination, states, newOrder);
|
|
1739
|
+
setPatchingIds(ids => ids.filter(id => id !== draggableId));
|
|
1740
|
+
}, [data, patchingIds, toast, move, states]);
|
|
1645
1741
|
const uniqueAssignedUsers = React__default.default.useMemo(() => {
|
|
1646
1742
|
const uniqueUserIds = data.reduce((acc, item) => {
|
|
1647
1743
|
var _a2;
|
|
@@ -1668,6 +1764,30 @@ function WorkflowTool(props) {
|
|
|
1668
1764
|
const toggleInvalidDocumentId = React__default.default.useCallback((docId, action) => {
|
|
1669
1765
|
setInvalidDocumentIds(prev => action === "ADD" ? [...prev, docId] : prev.filter(id => id !== docId));
|
|
1670
1766
|
}, []);
|
|
1767
|
+
const Clone = React__default.default.useCallback((provided, snapshot, rubric) => {
|
|
1768
|
+
const item = data.find(doc => {
|
|
1769
|
+
var _a2;
|
|
1770
|
+
return ((_a2 = doc == null ? void 0 : doc._metadata) == null ? void 0 : _a2.documentId) === rubric.draggableId;
|
|
1771
|
+
});
|
|
1772
|
+
return /* @__PURE__ */jsxRuntime.jsx("div", {
|
|
1773
|
+
...provided.draggableProps,
|
|
1774
|
+
...provided.dragHandleProps,
|
|
1775
|
+
ref: provided.innerRef,
|
|
1776
|
+
children: item ? /* @__PURE__ */jsxRuntime.jsx(DocumentCard, {
|
|
1777
|
+
isDragDisabled: false,
|
|
1778
|
+
isPatching: false,
|
|
1779
|
+
userRoleCanDrop: true,
|
|
1780
|
+
isDragging: snapshot.isDragging,
|
|
1781
|
+
item,
|
|
1782
|
+
states,
|
|
1783
|
+
toggleInvalidDocumentId,
|
|
1784
|
+
userList
|
|
1785
|
+
}) : /* @__PURE__ */jsxRuntime.jsx(sanityPluginUtils.Feedback, {
|
|
1786
|
+
title: "Item not found",
|
|
1787
|
+
tone: "caution"
|
|
1788
|
+
})
|
|
1789
|
+
});
|
|
1790
|
+
}, [data, states, toggleInvalidDocumentId, userList]);
|
|
1671
1791
|
if (!(states == null ? void 0 : states.length)) {
|
|
1672
1792
|
return /* @__PURE__ */jsxRuntime.jsx(ui.Container, {
|
|
1673
1793
|
width: 1,
|
|
@@ -1726,36 +1846,15 @@ function WorkflowTool(props) {
|
|
|
1726
1846
|
requireAssignment: (_b2 = state.requireAssignment) != null ? _b2 : false,
|
|
1727
1847
|
userRoleCanDrop,
|
|
1728
1848
|
isDropDisabled,
|
|
1729
|
-
draggingFrom
|
|
1849
|
+
draggingFrom,
|
|
1850
|
+
documentCount: filterItemsAndSort(data, state.id, selectedUserIds, selectedSchemaTypes).length
|
|
1730
1851
|
}), /* @__PURE__ */jsxRuntime.jsx(ui.Box, {
|
|
1731
1852
|
flex: 1,
|
|
1732
1853
|
children: /* @__PURE__ */jsxRuntime.jsx(dnd.Droppable, {
|
|
1733
1854
|
droppableId: state.id,
|
|
1734
1855
|
isDropDisabled,
|
|
1735
1856
|
mode: "virtual",
|
|
1736
|
-
renderClone:
|
|
1737
|
-
const item = data.find(doc => {
|
|
1738
|
-
var _a3;
|
|
1739
|
-
return ((_a3 = doc == null ? void 0 : doc._metadata) == null ? void 0 : _a3.documentId) === rubric.draggableId;
|
|
1740
|
-
});
|
|
1741
|
-
return /* @__PURE__ */jsxRuntime.jsx("div", {
|
|
1742
|
-
...provided.draggableProps,
|
|
1743
|
-
...provided.dragHandleProps,
|
|
1744
|
-
ref: provided.innerRef,
|
|
1745
|
-
children: item ? /* @__PURE__ */jsxRuntime.jsx(DocumentCard, {
|
|
1746
|
-
isDragDisabled: false,
|
|
1747
|
-
userRoleCanDrop,
|
|
1748
|
-
isDragging: snapshot.isDragging,
|
|
1749
|
-
item,
|
|
1750
|
-
states,
|
|
1751
|
-
toggleInvalidDocumentId,
|
|
1752
|
-
userList
|
|
1753
|
-
}) : /* @__PURE__ */jsxRuntime.jsx(sanityPluginUtils.Feedback, {
|
|
1754
|
-
title: "Item not found",
|
|
1755
|
-
tone: "caution"
|
|
1756
|
-
})
|
|
1757
|
-
});
|
|
1758
|
-
},
|
|
1857
|
+
renderClone: Clone,
|
|
1759
1858
|
children: (provided, snapshot) => /* @__PURE__ */jsxRuntime.jsxs(ui.Card, {
|
|
1760
1859
|
ref: provided.innerRef,
|
|
1761
1860
|
tone: snapshot.isDraggingOver ? "primary" : defaultCardTone,
|
|
@@ -1771,6 +1870,7 @@ function WorkflowTool(props) {
|
|
|
1771
1870
|
}) : null, /* @__PURE__ */jsxRuntime.jsx(DocumentList, {
|
|
1772
1871
|
data,
|
|
1773
1872
|
invalidDocumentIds,
|
|
1873
|
+
patchingIds,
|
|
1774
1874
|
selectedSchemaTypes,
|
|
1775
1875
|
selectedUserIds,
|
|
1776
1876
|
state,
|