sanity-plugin-workflow 1.0.2 → 1.0.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/LICENSE +1 -1
- package/lib/index.esm.js +50 -29
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +50 -29
- package/lib/index.js.map +1 -1
- package/package.json +8 -7
- package/src/components/DocumentCard/index.tsx +1 -2
- package/src/components/Filters.tsx +6 -0
package/LICENSE
CHANGED
package/lib/index.esm.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
var _templateObject, _templateObject2, _templateObject3;
|
|
2
|
-
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
3
1
|
import { useClient, useCurrentUser, useValidationStatus, useSchema, Preview, useFormValue, defineType, defineField, UserAvatar, useTimeAgo, TextWithTone, definePlugin, isObjectInputProps } from 'sanity';
|
|
4
2
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
5
3
|
import { UsersIcon, SplitVerticalIcon, CheckmarkIcon, ArrowRightIcon, ArrowLeftIcon, EditIcon, AddIcon, PublishIcon, ErrorOutlineIcon, WarningOutlineIcon, DragHandleIcon, UserIcon, ResetIcon, InfoOutlineIcon } from '@sanity/icons';
|
|
@@ -82,7 +80,7 @@ function UserAssignment(props) {
|
|
|
82
80
|
title: "Could not find User"
|
|
83
81
|
});
|
|
84
82
|
}
|
|
85
|
-
return client.patch("workflow-metadata.".concat(documentId)).unset([
|
|
83
|
+
return client.patch("workflow-metadata.".concat(documentId)).unset(['assignees[@ == "'.concat(userId, '"]')]).commit().then(() => {
|
|
86
84
|
return toast.push({
|
|
87
85
|
title: "Removed ".concat(user.displayName, " from assignees"),
|
|
88
86
|
status: "success"
|
|
@@ -127,7 +125,7 @@ function useWorkflowMetadata(ids) {
|
|
|
127
125
|
data: rawData,
|
|
128
126
|
loading,
|
|
129
127
|
error
|
|
130
|
-
} = useListeningQuery(
|
|
128
|
+
} = useListeningQuery('*[_type == "workflow.metadata" && documentId in $ids]{\n _id,\n _type,\n _rev,\n assignees,\n documentId,\n state,\n orderRank\n }', {
|
|
131
129
|
params: {
|
|
132
130
|
ids
|
|
133
131
|
},
|
|
@@ -253,7 +251,7 @@ function BeginWorkflow(props) {
|
|
|
253
251
|
}
|
|
254
252
|
const handle = useCallback(async () => {
|
|
255
253
|
setBeginning(true);
|
|
256
|
-
const lowestOrderFirstState = await client.fetch(
|
|
254
|
+
const lowestOrderFirstState = await client.fetch('*[_type == "workflow.metadata" && state == $state]|order(orderRank)[0].orderRank', {
|
|
257
255
|
state: states[0].id
|
|
258
256
|
});
|
|
259
257
|
client.createIfNotExists({
|
|
@@ -266,7 +264,7 @@ function BeginWorkflow(props) {
|
|
|
266
264
|
toast.push({
|
|
267
265
|
status: "success",
|
|
268
266
|
title: "Workflow started",
|
|
269
|
-
description:
|
|
267
|
+
description: 'Document is now "'.concat(states[0].title, '"')
|
|
270
268
|
});
|
|
271
269
|
setBeginning(false);
|
|
272
270
|
setComplete(true);
|
|
@@ -361,7 +359,7 @@ function UpdateWorkflow(props, actionState) {
|
|
|
361
359
|
props.onComplete();
|
|
362
360
|
toast.push({
|
|
363
361
|
status: "success",
|
|
364
|
-
title:
|
|
362
|
+
title: 'Document state now "'.concat(newState.title, '"')
|
|
365
363
|
});
|
|
366
364
|
}).catch(err => {
|
|
367
365
|
props.onComplete();
|
|
@@ -398,17 +396,17 @@ function UpdateWorkflow(props, actionState) {
|
|
|
398
396
|
currentUser && (assignees == null ? void 0 : assignees.length) && assignees.includes(currentUser.id) :
|
|
399
397
|
// Otherwise this isn't a problem
|
|
400
398
|
true;
|
|
401
|
-
let title = "".concat(directionLabel,
|
|
399
|
+
let title = "".concat(directionLabel, ' State to "').concat(actionState.title, '"');
|
|
402
400
|
if (!userRoleCanUpdateState) {
|
|
403
|
-
title = "Your User role cannot ".concat(directionLabel,
|
|
401
|
+
title = "Your User role cannot ".concat(directionLabel, ' State to "').concat(actionState.title, '"');
|
|
404
402
|
} else if (!actionStateIsAValidTransition) {
|
|
405
|
-
title = "You cannot ".concat(directionLabel,
|
|
403
|
+
title = "You cannot ".concat(directionLabel, ' State to "').concat(actionState.title, '" from "').concat(currentState == null ? void 0 : currentState.title, '"');
|
|
406
404
|
} else if (!userAssignmentCanUpdateState) {
|
|
407
|
-
title = "You must be assigned to the document to ".concat(directionLabel,
|
|
405
|
+
title = "You must be assigned to the document to ".concat(directionLabel, ' State to "').concat(actionState.title, '"');
|
|
408
406
|
} else if ((currentState == null ? void 0 : currentState.requireValidation) && isValidating) {
|
|
409
|
-
title = "Document is validating, cannot ".concat(directionLabel,
|
|
407
|
+
title = "Document is validating, cannot ".concat(directionLabel, ' State to "').concat(actionState.title, '"');
|
|
410
408
|
} else if (hasValidationErrors) {
|
|
411
|
-
title = "Document has validation errors, cannot ".concat(directionLabel,
|
|
409
|
+
title = "Document has validation errors, cannot ".concat(directionLabel, ' State to "').concat(actionState.title, '"');
|
|
412
410
|
}
|
|
413
411
|
return {
|
|
414
412
|
icon: DirectionIcon,
|
|
@@ -596,7 +594,7 @@ var metadata = states => defineType({
|
|
|
596
594
|
liveEdit: true,
|
|
597
595
|
fields: [defineField({
|
|
598
596
|
name: "state",
|
|
599
|
-
description:
|
|
597
|
+
description: 'The current "State" of the document. Field is read only as changing it would not fire the state\'s "operation" setting. These are fired in the Document Actions and in the custom Tool.',
|
|
600
598
|
readOnly: true,
|
|
601
599
|
type: "string",
|
|
602
600
|
options: {
|
|
@@ -664,7 +662,13 @@ function filterItemsAndSort(items, stateId) {
|
|
|
664
662
|
return aOrderRank.localeCompare(bOrderRank);
|
|
665
663
|
});
|
|
666
664
|
}
|
|
667
|
-
|
|
665
|
+
var __freeze$2 = Object.freeze;
|
|
666
|
+
var __defProp$2 = Object.defineProperty;
|
|
667
|
+
var __template$2 = (cooked, raw) => __freeze$2(__defProp$2(cooked, "raw", {
|
|
668
|
+
value: __freeze$2(raw || cooked.slice())
|
|
669
|
+
}));
|
|
670
|
+
var _a$2;
|
|
671
|
+
const QUERY = groq(_a$2 || (_a$2 = __template$2(['*[_type == "workflow.metadata"]|order(orderRank){\n "_metadata": {\n _rev,\n assignees,\n documentId,\n state,\n orderRank,\n "draftDocumentId": "drafts." + documentId,\n }\n}{\n ...,\n ...(\n *[_id == ^._metadata.documentId || _id == ^._metadata.draftDocumentId]|order(_updatedAt)[0]{ \n _id, \n _type, \n _rev, \n _updatedAt \n }\n )\n}'])));
|
|
668
672
|
function useWorkflowDocuments(schemaTypes) {
|
|
669
673
|
const toast = useToast();
|
|
670
674
|
const client = useClient({
|
|
@@ -689,8 +693,8 @@ function useWorkflowDocuments(schemaTypes) {
|
|
|
689
693
|
const move = React.useCallback(async (draggedId, destination, states, newOrder) => {
|
|
690
694
|
const currentLocalData = localDocuments;
|
|
691
695
|
const newLocalDocuments = localDocuments.map(item => {
|
|
692
|
-
var
|
|
693
|
-
if (((
|
|
696
|
+
var _a2;
|
|
697
|
+
if (((_a2 = item == null ? void 0 : item._metadata) == null ? void 0 : _a2.documentId) === draggedId) {
|
|
694
698
|
return {
|
|
695
699
|
...item,
|
|
696
700
|
_metadata: {
|
|
@@ -711,8 +715,8 @@ function useWorkflowDocuments(schemaTypes) {
|
|
|
711
715
|
const newStateId = destination.droppableId;
|
|
712
716
|
const newState = states.find(s => s.id === newStateId);
|
|
713
717
|
const document = localDocuments.find(d => {
|
|
714
|
-
var
|
|
715
|
-
return ((
|
|
718
|
+
var _a2;
|
|
719
|
+
return ((_a2 = d == null ? void 0 : d._metadata) == null ? void 0 : _a2.documentId) === draggedId;
|
|
716
720
|
});
|
|
717
721
|
if (!(newState == null ? void 0 : newState.id)) {
|
|
718
722
|
toast.push({
|
|
@@ -740,17 +744,17 @@ function useWorkflowDocuments(schemaTypes) {
|
|
|
740
744
|
state: newStateId,
|
|
741
745
|
orderRank: newOrder
|
|
742
746
|
}).commit().then(res => {
|
|
743
|
-
var
|
|
747
|
+
var _a2, _b;
|
|
744
748
|
toast.push({
|
|
745
|
-
title: newState.id === document._metadata.state ?
|
|
749
|
+
title: newState.id === document._metadata.state ? 'Reordered in "'.concat((_a2 = newState == null ? void 0 : newState.title) != null ? _a2 : newStateId, '"') : 'Moved to "'.concat((_b = newState == null ? void 0 : newState.title) != null ? _b : newStateId, '"'),
|
|
746
750
|
status: "success"
|
|
747
751
|
});
|
|
748
752
|
return res;
|
|
749
753
|
}).catch(err => {
|
|
750
|
-
var
|
|
754
|
+
var _a2;
|
|
751
755
|
setLocalDocuments(currentLocalData);
|
|
752
756
|
toast.push({
|
|
753
|
-
title:
|
|
757
|
+
title: 'Failed to move to "'.concat((_a2 = newState == null ? void 0 : newState.title) != null ? _a2 : newStateId, '"'),
|
|
754
758
|
description: err.message,
|
|
755
759
|
status: "error"
|
|
756
760
|
});
|
|
@@ -1099,8 +1103,7 @@ function DocumentCard(props) {
|
|
|
1099
1103
|
children: [/* @__PURE__ */jsx(Card, {
|
|
1100
1104
|
borderBottom: true,
|
|
1101
1105
|
radius: 2,
|
|
1102
|
-
|
|
1103
|
-
paddingLeft: 2,
|
|
1106
|
+
paddingRight: 2,
|
|
1104
1107
|
tone: cardTone,
|
|
1105
1108
|
style: {
|
|
1106
1109
|
pointerEvents: "none"
|
|
@@ -1318,6 +1321,8 @@ function Filters(props) {
|
|
|
1318
1321
|
tone: "default",
|
|
1319
1322
|
children: /* @__PURE__ */jsx(MenuButton, {
|
|
1320
1323
|
button: /* @__PURE__ */jsx(Button, {
|
|
1324
|
+
padding: 3,
|
|
1325
|
+
fontSize: 1,
|
|
1321
1326
|
text: "Filter Assignees",
|
|
1322
1327
|
tone: "primary",
|
|
1323
1328
|
icon: UserIcon
|
|
@@ -1379,6 +1384,8 @@ function Filters(props) {
|
|
|
1379
1384
|
})
|
|
1380
1385
|
})
|
|
1381
1386
|
}, user.id)), selectedUserIds.length > 0 ? /* @__PURE__ */jsx(Button, {
|
|
1387
|
+
padding: 3,
|
|
1388
|
+
fontSize: 1,
|
|
1382
1389
|
text: "Clear",
|
|
1383
1390
|
onClick: resetSelectedUsers,
|
|
1384
1391
|
mode: "ghost",
|
|
@@ -1395,6 +1402,8 @@ function Filters(props) {
|
|
|
1395
1402
|
return null;
|
|
1396
1403
|
}
|
|
1397
1404
|
return /* @__PURE__ */jsx(Button, {
|
|
1405
|
+
padding: 3,
|
|
1406
|
+
fontSize: 1,
|
|
1398
1407
|
text: (_a = schemaType == null ? void 0 : schemaType.title) != null ? _a : typeName,
|
|
1399
1408
|
icon: (_b = schemaType == null ? void 0 : schemaType.icon) != null ? _b : void 0,
|
|
1400
1409
|
mode: selectedSchemaTypes.includes(typeName) ? "default" : "ghost",
|
|
@@ -1426,7 +1435,13 @@ function Status(props) {
|
|
|
1426
1435
|
})
|
|
1427
1436
|
});
|
|
1428
1437
|
}
|
|
1429
|
-
|
|
1438
|
+
var __freeze$1 = Object.freeze;
|
|
1439
|
+
var __defProp$1 = Object.defineProperty;
|
|
1440
|
+
var __template$1 = (cooked, raw) => __freeze$1(__defProp$1(cooked, "raw", {
|
|
1441
|
+
value: __freeze$1(raw || cooked.slice())
|
|
1442
|
+
}));
|
|
1443
|
+
var _a$1;
|
|
1444
|
+
const StyledStickyCard = styled(Card)(() => css(_a$1 || (_a$1 = __template$1(["\n position: sticky;\n top: 0;\n z-index: 1;\n "]))));
|
|
1430
1445
|
function StateTitle(props) {
|
|
1431
1446
|
const {
|
|
1432
1447
|
state,
|
|
@@ -1505,7 +1520,13 @@ function generateMultipleOrderRanks(count, start, end) {
|
|
|
1505
1520
|
}
|
|
1506
1521
|
return ranks.sort((a, b) => a.toString().localeCompare(b.toString()));
|
|
1507
1522
|
}
|
|
1508
|
-
|
|
1523
|
+
var __freeze = Object.freeze;
|
|
1524
|
+
var __defProp = Object.defineProperty;
|
|
1525
|
+
var __template = (cooked, raw) => __freeze(__defProp(cooked, "raw", {
|
|
1526
|
+
value: __freeze(raw || cooked.slice())
|
|
1527
|
+
}));
|
|
1528
|
+
var _a;
|
|
1529
|
+
const StyledFloatingCard = styled(Card)(() => css(_a || (_a = __template(["\n position: fixed;\n bottom: 0;\n left: 0;\n z-index: 1000;\n "]))));
|
|
1509
1530
|
function FloatingCard(_ref3) {
|
|
1510
1531
|
let {
|
|
1511
1532
|
children
|
|
@@ -2041,10 +2062,10 @@ const workflow = definePlugin(function () {
|
|
|
2041
2062
|
...config
|
|
2042
2063
|
};
|
|
2043
2064
|
if (!(states == null ? void 0 : states.length)) {
|
|
2044
|
-
throw new Error(
|
|
2065
|
+
throw new Error('Workflow plugin: Missing "states" in config');
|
|
2045
2066
|
}
|
|
2046
2067
|
if (!(schemaTypes == null ? void 0 : schemaTypes.length)) {
|
|
2047
|
-
throw new Error(
|
|
2068
|
+
throw new Error('Workflow plugin: Missing "schemaTypes" in config');
|
|
2048
2069
|
}
|
|
2049
2070
|
return {
|
|
2050
2071
|
name: "sanity-plugin-workflow",
|