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/lib/index.js CHANGED
@@ -1,7 +1,5 @@
1
1
  'use strict';
2
2
 
3
- var _templateObject, _templateObject2, _templateObject3;
4
- function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
5
3
  Object.defineProperty(exports, '__esModule', {
6
4
  value: true
7
5
  });
@@ -95,7 +93,7 @@ function UserAssignment(props) {
95
93
  title: "Could not find User"
96
94
  });
97
95
  }
98
- return client.patch("workflow-metadata.".concat(documentId)).unset(["assignees[@ == \"".concat(userId, "\"]")]).commit().then(() => {
96
+ return client.patch("workflow-metadata.".concat(documentId)).unset(['assignees[@ == "'.concat(userId, '"]')]).commit().then(() => {
99
97
  return toast.push({
100
98
  title: "Removed ".concat(user.displayName, " from assignees"),
101
99
  status: "success"
@@ -140,7 +138,7 @@ function useWorkflowMetadata(ids) {
140
138
  data: rawData,
141
139
  loading,
142
140
  error
143
- } = sanityPluginUtils.useListeningQuery("*[_type == \"workflow.metadata\" && documentId in $ids]{\n _id,\n _type,\n _rev,\n assignees,\n documentId,\n state,\n orderRank\n }", {
141
+ } = sanityPluginUtils.useListeningQuery('*[_type == "workflow.metadata" && documentId in $ids]{\n _id,\n _type,\n _rev,\n assignees,\n documentId,\n state,\n orderRank\n }', {
144
142
  params: {
145
143
  ids
146
144
  },
@@ -266,7 +264,7 @@ function BeginWorkflow(props) {
266
264
  }
267
265
  const handle = React.useCallback(async () => {
268
266
  setBeginning(true);
269
- const lowestOrderFirstState = await client.fetch("*[_type == \"workflow.metadata\" && state == $state]|order(orderRank)[0].orderRank", {
267
+ const lowestOrderFirstState = await client.fetch('*[_type == "workflow.metadata" && state == $state]|order(orderRank)[0].orderRank', {
270
268
  state: states[0].id
271
269
  });
272
270
  client.createIfNotExists({
@@ -279,7 +277,7 @@ function BeginWorkflow(props) {
279
277
  toast.push({
280
278
  status: "success",
281
279
  title: "Workflow started",
282
- description: "Document is now \"".concat(states[0].title, "\"")
280
+ description: 'Document is now "'.concat(states[0].title, '"')
283
281
  });
284
282
  setBeginning(false);
285
283
  setComplete(true);
@@ -374,7 +372,7 @@ function UpdateWorkflow(props, actionState) {
374
372
  props.onComplete();
375
373
  toast.push({
376
374
  status: "success",
377
- title: "Document state now \"".concat(newState.title, "\"")
375
+ title: 'Document state now "'.concat(newState.title, '"')
378
376
  });
379
377
  }).catch(err => {
380
378
  props.onComplete();
@@ -411,17 +409,17 @@ function UpdateWorkflow(props, actionState) {
411
409
  currentUser && (assignees == null ? void 0 : assignees.length) && assignees.includes(currentUser.id) :
412
410
  // Otherwise this isn't a problem
413
411
  true;
414
- let title = "".concat(directionLabel, " State to \"").concat(actionState.title, "\"");
412
+ let title = "".concat(directionLabel, ' State to "').concat(actionState.title, '"');
415
413
  if (!userRoleCanUpdateState) {
416
- title = "Your User role cannot ".concat(directionLabel, " State to \"").concat(actionState.title, "\"");
414
+ title = "Your User role cannot ".concat(directionLabel, ' State to "').concat(actionState.title, '"');
417
415
  } else if (!actionStateIsAValidTransition) {
418
- title = "You cannot ".concat(directionLabel, " State to \"").concat(actionState.title, "\" from \"").concat(currentState == null ? void 0 : currentState.title, "\"");
416
+ title = "You cannot ".concat(directionLabel, ' State to "').concat(actionState.title, '" from "').concat(currentState == null ? void 0 : currentState.title, '"');
419
417
  } else if (!userAssignmentCanUpdateState) {
420
- title = "You must be assigned to the document to ".concat(directionLabel, " State to \"").concat(actionState.title, "\"");
418
+ title = "You must be assigned to the document to ".concat(directionLabel, ' State to "').concat(actionState.title, '"');
421
419
  } else if ((currentState == null ? void 0 : currentState.requireValidation) && isValidating) {
422
- title = "Document is validating, cannot ".concat(directionLabel, " State to \"").concat(actionState.title, "\"");
420
+ title = "Document is validating, cannot ".concat(directionLabel, ' State to "').concat(actionState.title, '"');
423
421
  } else if (hasValidationErrors) {
424
- title = "Document has validation errors, cannot ".concat(directionLabel, " State to \"").concat(actionState.title, "\"");
422
+ title = "Document has validation errors, cannot ".concat(directionLabel, ' State to "').concat(actionState.title, '"');
425
423
  }
426
424
  return {
427
425
  icon: DirectionIcon,
@@ -609,7 +607,7 @@ var metadata = states => sanity.defineType({
609
607
  liveEdit: true,
610
608
  fields: [sanity.defineField({
611
609
  name: "state",
612
- 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.",
610
+ 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.',
613
611
  readOnly: true,
614
612
  type: "string",
615
613
  options: {
@@ -677,7 +675,13 @@ function filterItemsAndSort(items, stateId) {
677
675
  return aOrderRank.localeCompare(bOrderRank);
678
676
  });
679
677
  }
680
- const QUERY = groq__default.default(_templateObject || (_templateObject = _taggedTemplateLiteral(["*[_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}"])));
678
+ var __freeze$2 = Object.freeze;
679
+ var __defProp$2 = Object.defineProperty;
680
+ var __template$2 = (cooked, raw) => __freeze$2(__defProp$2(cooked, "raw", {
681
+ value: __freeze$2(raw || cooked.slice())
682
+ }));
683
+ var _a$2;
684
+ const QUERY = groq__default.default(_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}'])));
681
685
  function useWorkflowDocuments(schemaTypes) {
682
686
  const toast = ui.useToast();
683
687
  const client = sanity.useClient({
@@ -702,8 +706,8 @@ function useWorkflowDocuments(schemaTypes) {
702
706
  const move = React__default.default.useCallback(async (draggedId, destination, states, newOrder) => {
703
707
  const currentLocalData = localDocuments;
704
708
  const newLocalDocuments = localDocuments.map(item => {
705
- var _a;
706
- if (((_a = item == null ? void 0 : item._metadata) == null ? void 0 : _a.documentId) === draggedId) {
709
+ var _a2;
710
+ if (((_a2 = item == null ? void 0 : item._metadata) == null ? void 0 : _a2.documentId) === draggedId) {
707
711
  return {
708
712
  ...item,
709
713
  _metadata: {
@@ -724,8 +728,8 @@ function useWorkflowDocuments(schemaTypes) {
724
728
  const newStateId = destination.droppableId;
725
729
  const newState = states.find(s => s.id === newStateId);
726
730
  const document = localDocuments.find(d => {
727
- var _a;
728
- return ((_a = d == null ? void 0 : d._metadata) == null ? void 0 : _a.documentId) === draggedId;
731
+ var _a2;
732
+ return ((_a2 = d == null ? void 0 : d._metadata) == null ? void 0 : _a2.documentId) === draggedId;
729
733
  });
730
734
  if (!(newState == null ? void 0 : newState.id)) {
731
735
  toast.push({
@@ -753,17 +757,17 @@ function useWorkflowDocuments(schemaTypes) {
753
757
  state: newStateId,
754
758
  orderRank: newOrder
755
759
  }).commit().then(res => {
756
- var _a, _b;
760
+ var _a2, _b;
757
761
  toast.push({
758
- 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, "\""),
762
+ 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, '"'),
759
763
  status: "success"
760
764
  });
761
765
  return res;
762
766
  }).catch(err => {
763
- var _a;
767
+ var _a2;
764
768
  setLocalDocuments(currentLocalData);
765
769
  toast.push({
766
- title: "Failed to move to \"".concat((_a = newState == null ? void 0 : newState.title) != null ? _a : newStateId, "\""),
770
+ title: 'Failed to move to "'.concat((_a2 = newState == null ? void 0 : newState.title) != null ? _a2 : newStateId, '"'),
767
771
  description: err.message,
768
772
  status: "error"
769
773
  });
@@ -1112,8 +1116,7 @@ function DocumentCard(props) {
1112
1116
  children: [/* @__PURE__ */jsxRuntime.jsx(ui.Card, {
1113
1117
  borderBottom: true,
1114
1118
  radius: 2,
1115
- padding: 3,
1116
- paddingLeft: 2,
1119
+ paddingRight: 2,
1117
1120
  tone: cardTone,
1118
1121
  style: {
1119
1122
  pointerEvents: "none"
@@ -1331,6 +1334,8 @@ function Filters(props) {
1331
1334
  tone: "default",
1332
1335
  children: /* @__PURE__ */jsxRuntime.jsx(ui.MenuButton, {
1333
1336
  button: /* @__PURE__ */jsxRuntime.jsx(ui.Button, {
1337
+ padding: 3,
1338
+ fontSize: 1,
1334
1339
  text: "Filter Assignees",
1335
1340
  tone: "primary",
1336
1341
  icon: icons.UserIcon
@@ -1392,6 +1397,8 @@ function Filters(props) {
1392
1397
  })
1393
1398
  })
1394
1399
  }, user.id)), selectedUserIds.length > 0 ? /* @__PURE__ */jsxRuntime.jsx(ui.Button, {
1400
+ padding: 3,
1401
+ fontSize: 1,
1395
1402
  text: "Clear",
1396
1403
  onClick: resetSelectedUsers,
1397
1404
  mode: "ghost",
@@ -1408,6 +1415,8 @@ function Filters(props) {
1408
1415
  return null;
1409
1416
  }
1410
1417
  return /* @__PURE__ */jsxRuntime.jsx(ui.Button, {
1418
+ padding: 3,
1419
+ fontSize: 1,
1411
1420
  text: (_a = schemaType == null ? void 0 : schemaType.title) != null ? _a : typeName,
1412
1421
  icon: (_b = schemaType == null ? void 0 : schemaType.icon) != null ? _b : void 0,
1413
1422
  mode: selectedSchemaTypes.includes(typeName) ? "default" : "ghost",
@@ -1439,7 +1448,13 @@ function Status(props) {
1439
1448
  })
1440
1449
  });
1441
1450
  }
1442
- const StyledStickyCard = styled__default.default(ui.Card)(() => styled.css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n position: sticky;\n top: 0;\n z-index: 1;\n "]))));
1451
+ var __freeze$1 = Object.freeze;
1452
+ var __defProp$1 = Object.defineProperty;
1453
+ var __template$1 = (cooked, raw) => __freeze$1(__defProp$1(cooked, "raw", {
1454
+ value: __freeze$1(raw || cooked.slice())
1455
+ }));
1456
+ var _a$1;
1457
+ const StyledStickyCard = styled__default.default(ui.Card)(() => styled.css(_a$1 || (_a$1 = __template$1(["\n position: sticky;\n top: 0;\n z-index: 1;\n "]))));
1443
1458
  function StateTitle(props) {
1444
1459
  const {
1445
1460
  state,
@@ -1518,7 +1533,13 @@ function generateMultipleOrderRanks(count, start, end) {
1518
1533
  }
1519
1534
  return ranks.sort((a, b) => a.toString().localeCompare(b.toString()));
1520
1535
  }
1521
- const StyledFloatingCard = styled__default.default(ui.Card)(() => styled.css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n position: fixed;\n bottom: 0;\n left: 0;\n z-index: 1000;\n "]))));
1536
+ var __freeze = Object.freeze;
1537
+ var __defProp = Object.defineProperty;
1538
+ var __template = (cooked, raw) => __freeze(__defProp(cooked, "raw", {
1539
+ value: __freeze(raw || cooked.slice())
1540
+ }));
1541
+ var _a;
1542
+ const StyledFloatingCard = styled__default.default(ui.Card)(() => styled.css(_a || (_a = __template(["\n position: fixed;\n bottom: 0;\n left: 0;\n z-index: 1000;\n "]))));
1522
1543
  function FloatingCard(_ref3) {
1523
1544
  let {
1524
1545
  children
@@ -2054,10 +2075,10 @@ const workflow = sanity.definePlugin(function () {
2054
2075
  ...config
2055
2076
  };
2056
2077
  if (!(states == null ? void 0 : states.length)) {
2057
- throw new Error("Workflow plugin: Missing \"states\" in config");
2078
+ throw new Error('Workflow plugin: Missing "states" in config');
2058
2079
  }
2059
2080
  if (!(schemaTypes == null ? void 0 : schemaTypes.length)) {
2060
- throw new Error("Workflow plugin: Missing \"schemaTypes\" in config");
2081
+ throw new Error('Workflow plugin: Missing "schemaTypes" in config');
2061
2082
  }
2062
2083
  return {
2063
2084
  name: "sanity-plugin-workflow",