sanity-plugin-workflow 1.0.0-beta.5 → 1.0.0-beta.6
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 +34 -9
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +34 -9
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/DocumentCard/index.tsx +0 -39
- package/src/components/DocumentList.tsx +1 -1
- package/src/components/StateTitle/index.tsx +31 -26
- package/src/components/Verify.tsx +23 -0
- package/src/components/WorkflowTool.tsx +9 -2
- package/src/hooks/useWorkflowDocuments.tsx +8 -5
- 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,10 +693,9 @@ function useWorkflowDocuments(schemaTypes) {
|
|
|
693
693
|
_type
|
|
694
694
|
} = document;
|
|
695
695
|
const {
|
|
696
|
-
_rev,
|
|
697
696
|
documentId
|
|
698
697
|
} = document._metadata || {};
|
|
699
|
-
client.patch("workflow-metadata.".concat(documentId)).
|
|
698
|
+
await client.patch("workflow-metadata.".concat(documentId)).set({
|
|
700
699
|
state: newStateId,
|
|
701
700
|
orderRank: newOrder
|
|
702
701
|
}).commit().then(() => {
|
|
@@ -705,11 +704,12 @@ function useWorkflowDocuments(schemaTypes) {
|
|
|
705
704
|
title: "Moved to \"".concat((_a = newState == null ? void 0 : newState.title) != null ? _a : newStateId, "\""),
|
|
706
705
|
status: "success"
|
|
707
706
|
});
|
|
708
|
-
}).catch(
|
|
707
|
+
}).catch(err => {
|
|
709
708
|
var _a;
|
|
710
709
|
setLocalDocuments(currentLocalData);
|
|
711
710
|
return toast.push({
|
|
712
711
|
title: "Failed to move to \"".concat((_a = newState == null ? void 0 : newState.title) != null ? _a : newStateId, "\""),
|
|
712
|
+
description: err.message,
|
|
713
713
|
status: "error"
|
|
714
714
|
});
|
|
715
715
|
});
|
|
@@ -1127,7 +1127,7 @@ function DocumentList(props) {
|
|
|
1127
1127
|
return (_c = (_b = (_a = dataFiltered[index]) == null ? void 0 : _a._metadata) == null ? void 0 : _b.documentId) != null ? _c : index;
|
|
1128
1128
|
},
|
|
1129
1129
|
estimateSize: () => 113,
|
|
1130
|
-
overscan:
|
|
1130
|
+
overscan: 10
|
|
1131
1131
|
});
|
|
1132
1132
|
if (!data.length) {
|
|
1133
1133
|
return null;
|
|
@@ -1339,7 +1339,8 @@ function StateTitle(props) {
|
|
|
1339
1339
|
requireAssignment,
|
|
1340
1340
|
userRoleCanDrop,
|
|
1341
1341
|
isDropDisabled,
|
|
1342
|
-
draggingFrom
|
|
1342
|
+
draggingFrom,
|
|
1343
|
+
documentCount
|
|
1343
1344
|
} = props;
|
|
1344
1345
|
let tone = "default";
|
|
1345
1346
|
const isSource = draggingFrom === state.id;
|
|
@@ -1364,7 +1365,15 @@ function StateTitle(props) {
|
|
|
1364
1365
|
}), requireAssignment ? /* @__PURE__ */jsxRuntime.jsx(Status, {
|
|
1365
1366
|
text: "You must be assigned to the document to move documents to this State",
|
|
1366
1367
|
icon: icons.UserIcon
|
|
1367
|
-
}) : null
|
|
1368
|
+
}) : null, /* @__PURE__ */jsxRuntime.jsx(ui.Box, {
|
|
1369
|
+
flex: 1,
|
|
1370
|
+
children: documentCount > 0 ? /* @__PURE__ */jsxRuntime.jsx(ui.Text, {
|
|
1371
|
+
weight: "semibold",
|
|
1372
|
+
align: "right",
|
|
1373
|
+
size: 1,
|
|
1374
|
+
children: documentCount
|
|
1375
|
+
}) : null
|
|
1376
|
+
})]
|
|
1368
1377
|
})
|
|
1369
1378
|
});
|
|
1370
1379
|
}
|
|
@@ -1434,6 +1443,17 @@ function Verify(props) {
|
|
|
1434
1443
|
} = (_a = cur._metadata) != null ? _a : {};
|
|
1435
1444
|
return !orderRank && documentId ? [...acc, documentId] : acc;
|
|
1436
1445
|
}, []) : [];
|
|
1446
|
+
const documentsWithDuplicatedOrderIds = (data == null ? void 0 : data.length) ? data.reduce((acc, cur) => {
|
|
1447
|
+
var _a;
|
|
1448
|
+
const {
|
|
1449
|
+
documentId,
|
|
1450
|
+
orderRank
|
|
1451
|
+
} = (_a = cur._metadata) != null ? _a : {};
|
|
1452
|
+
return orderRank && data.filter(d => {
|
|
1453
|
+
var _a2;
|
|
1454
|
+
return ((_a2 = d._metadata) == null ? void 0 : _a2.orderRank) === orderRank;
|
|
1455
|
+
}).length > 1 && documentId ? [...acc, documentId] : acc;
|
|
1456
|
+
}, []) : [];
|
|
1437
1457
|
const correctDocuments = React__default.default.useCallback(async ids => {
|
|
1438
1458
|
toast.push({
|
|
1439
1459
|
title: "Correcting...",
|
|
@@ -1534,6 +1554,10 @@ function Verify(props) {
|
|
|
1534
1554
|
tone: "caution",
|
|
1535
1555
|
onClick: () => addOrderToDocuments(documentsWithoutOrderIds),
|
|
1536
1556
|
text: documentsWithoutOrderIds.length === 1 ? "Set Order for 1 Document" : "Set Order for ".concat(documentsWithoutOrderIds.length, " Documents")
|
|
1557
|
+
}) : null, documentsWithDuplicatedOrderIds.length > 0 ? /* @__PURE__ */jsxRuntime.jsx(ui.Button, {
|
|
1558
|
+
tone: "caution",
|
|
1559
|
+
onClick: () => addOrderToDocuments(documentsWithDuplicatedOrderIds),
|
|
1560
|
+
text: documentsWithDuplicatedOrderIds.length === 1 ? "Set Unique Order for 1 Document" : "Set Unique Order for ".concat(documentsWithDuplicatedOrderIds.length, " Documents")
|
|
1537
1561
|
}) : null, orphanedMetadataDocumentIds.length > 0 ? /* @__PURE__ */jsxRuntime.jsx(ui.Button, {
|
|
1538
1562
|
text: "Cleanup orphaned metadata",
|
|
1539
1563
|
onClick: handleOrphans,
|
|
@@ -1605,7 +1629,7 @@ function WorkflowTool(props) {
|
|
|
1605
1629
|
setUndroppableStates(undroppableExceptSelf);
|
|
1606
1630
|
}
|
|
1607
1631
|
}, [data, states, user]);
|
|
1608
|
-
const handleDragEnd = React__default.default.useCallback(result => {
|
|
1632
|
+
const handleDragEnd = React__default.default.useCallback(async result => {
|
|
1609
1633
|
var _a2, _b2, _c2, _d, _e, _f;
|
|
1610
1634
|
setUndroppableStates([]);
|
|
1611
1635
|
setDraggingFrom("");
|
|
@@ -1726,7 +1750,8 @@ function WorkflowTool(props) {
|
|
|
1726
1750
|
requireAssignment: (_b2 = state.requireAssignment) != null ? _b2 : false,
|
|
1727
1751
|
userRoleCanDrop,
|
|
1728
1752
|
isDropDisabled,
|
|
1729
|
-
draggingFrom
|
|
1753
|
+
draggingFrom,
|
|
1754
|
+
documentCount: filterItemsAndSort(data, state.id, selectedUserIds, selectedSchemaTypes).length
|
|
1730
1755
|
}), /* @__PURE__ */jsxRuntime.jsx(ui.Box, {
|
|
1731
1756
|
flex: 1,
|
|
1732
1757
|
children: /* @__PURE__ */jsxRuntime.jsx(dnd.Droppable, {
|