sanity-plugin-workflow 1.0.0-beta.1 → 1.0.0-beta.10

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.
Files changed (56) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +81 -13
  3. package/lib/{src/index.d.ts → index.d.ts} +4 -3
  4. package/lib/index.esm.js +2106 -1
  5. package/lib/index.esm.js.map +1 -1
  6. package/lib/index.js +2119 -1
  7. package/lib/index.js.map +1 -1
  8. package/package.json +51 -40
  9. package/src/actions/AssignWorkflow.tsx +49 -0
  10. package/src/actions/BeginWorkflow.tsx +63 -0
  11. package/src/actions/CompleteWorkflow.tsx +41 -0
  12. package/src/actions/UpdateWorkflow.tsx +126 -0
  13. package/src/badges/AssigneesBadge.tsx +53 -0
  14. package/src/badges/StateBadge.tsx +28 -0
  15. package/src/components/DocumentCard/AvatarGroup.tsx +12 -8
  16. package/src/components/DocumentCard/CompleteButton.tsx +68 -0
  17. package/src/components/DocumentCard/EditButton.tsx +3 -2
  18. package/src/components/DocumentCard/Field.tsx +38 -0
  19. package/src/components/DocumentCard/Validate.tsx +21 -0
  20. package/src/components/DocumentCard/ValidationStatus.tsx +37 -0
  21. package/src/components/DocumentCard/core/DraftStatus.tsx +32 -0
  22. package/src/components/DocumentCard/core/PublishedStatus.tsx +39 -0
  23. package/src/components/DocumentCard/core/TimeAgo.tsx +11 -0
  24. package/src/components/DocumentCard/index.tsx +177 -68
  25. package/src/components/DocumentList.tsx +169 -0
  26. package/src/components/Filters.tsx +168 -0
  27. package/src/components/FloatingCard.tsx +29 -0
  28. package/src/components/StateTitle/Status.tsx +27 -0
  29. package/src/components/StateTitle/index.tsx +78 -0
  30. package/src/components/UserAssignment.tsx +57 -75
  31. package/src/components/UserAssignmentInput.tsx +27 -0
  32. package/src/components/UserDisplay.tsx +57 -0
  33. package/src/components/Verify.tsx +297 -0
  34. package/src/components/WorkflowContext.tsx +71 -0
  35. package/src/components/WorkflowSignal.tsx +30 -0
  36. package/src/components/WorkflowTool.tsx +373 -162
  37. package/src/constants/index.ts +31 -0
  38. package/src/helpers/arraysContainMatchingString.ts +6 -0
  39. package/src/helpers/filterItemsAndSort.ts +41 -0
  40. package/src/helpers/generateMultipleOrderRanks.ts +80 -0
  41. package/src/helpers/initialRank.ts +13 -0
  42. package/src/hooks/useWorkflowDocuments.tsx +76 -78
  43. package/src/hooks/useWorkflowMetadata.tsx +31 -26
  44. package/src/index.ts +60 -57
  45. package/src/schema/workflow/workflow.metadata.ts +68 -0
  46. package/src/tools/index.ts +15 -0
  47. package/src/types/index.ts +27 -6
  48. package/src/actions/DemoteAction.tsx +0 -62
  49. package/src/actions/PromoteAction.tsx +0 -62
  50. package/src/actions/RequestReviewAction.js +0 -61
  51. package/src/actions/index.js +0 -21
  52. package/src/badges/index.tsx +0 -31
  53. package/src/components/Mutate.tsx +0 -54
  54. package/src/components/StateTimeline.tsx +0 -98
  55. package/src/components/UserSelectInput.tsx +0 -43
  56. package/src/schema/workflow/metadata.ts +0 -38
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2022 Simeon Griggs
3
+ Copyright (c) 2023 Sanity.io
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,17 +1,40 @@
1
1
  > This is a **Sanity Studio v3** plugin.
2
2
 
3
- # sanity-plugin-workflow
3
+ ## Installation
4
+
5
+ ```sh
6
+ npm install sanity-plugin-workflow
7
+ ```
8
+
9
+ # Sanity Workflow Demo Plugin Example
10
+
11
+ With Sanity Studio you can [customize your content tools to support arbitrary workflows like assignment and content pipelines](https://www.sanity.io/docs/custom-workflows).
12
+
13
+ This plugin is distributed as a **reference implementation** of these customization APIs and is not considered to be a feature-complete implementation of what workflow management requires in production. It is a starting point intended to be forked and customized to the needs of your organization and content creators.
14
+
15
+ A key intention of this plugin is that it **does not influence or modify whether a document is in draft or published**. It only tracks the values of a separate "metadata" document. In this implementation, an "Approved" document could be a draft but will still need publishing. "Approving" the document simply removes it from the Workflow process. You will decide if Publishing the document happens in the Studio like normal, using the [Scheduled Publishing plugin](https://www.sanity.io/plugins/scheduled-publishing) or the [Scheduling API](https://www.sanity.io/docs/scheduling-api#fa3bb95f83ed).
16
+
17
+ ![Screenshot 2023-03-21 at 12 11 24](https://user-images.githubusercontent.com/9684022/226602179-5bd3d91a-9c27-431e-be18-3c70f06c6ccb.png)
18
+
19
+ ## Features
20
+
21
+ This work demonstrates how a single plugin can define:
22
+
23
+ - A unique schema to handle workflow metadata
24
+ - Document Actions to promote and demote documents through the workflow
25
+ - Document Badges for visual feedback about the current state of a document
26
+ - A custom Tool for drag-and-drop updating of a document's state
4
27
 
5
28
  ## Installation
6
29
 
7
30
  ```
8
- npm install --save sanity-plugin-workflow
31
+ npm install --save sanity-plugin-workflow@beta
9
32
  ```
10
33
 
11
34
  or
12
35
 
13
36
  ```
14
- yarn add sanity-plugin-workflow
37
+ yarn add sanity-plugin-workflow@beta
15
38
  ```
16
39
 
17
40
  ## Usage
@@ -26,25 +49,70 @@ Add it as a plugin in sanity.config.ts (or .js):
26
49
  // all other settings ...
27
50
  plugins: [
28
51
  workflow({
29
- // Required
52
+ // Required, list of document type names
53
+ // schemaTypes: ['article', 'product'],
30
54
  schemaTypes: [],
31
- // Optional
32
- states: [],
55
+ // Optional, see below
56
+ // states: [],
33
57
  })
34
58
  ]
35
59
  })
36
60
  ```
37
61
 
38
- ## License
62
+ ## Configuring "States"
63
+
64
+ The plugin comes with a default set of "States". These are tracked by the plugin creating a separate "metadata" document for each document that has begun the Workflow.
65
+
66
+ Documents can be promoted and demoted in the Workflow with the provided Document Actions as well as a drag-and-drop custom Tool. The settings below are not enforced by the API, custom access control rules could be used to do so.
67
+
68
+ ```ts
69
+ {
70
+ // Required configuration
71
+ id: 'inReview',
72
+ title: 'In Review',
73
+ // Optional settings:
74
+ // Used for the color of the Document Badge
75
+ color: 'success',
76
+ // Will limit document actions and drag-and-drop for only users with these Role
77
+ roles: ['publisher', 'administrator'],
78
+ // Requires the user to be "assigned" in order to update to this State
79
+ requireAssignment: true,
80
+ // Requires the document to be valid before being promoted out of this State
81
+ // Warning: With many documents in the Kanban view this can negatively impact performance
82
+ requireValidation: true,
83
+ // Defines which States a document can be moved to from this one
84
+ transitions: ['changesRequested', 'approved']
85
+ }
86
+ ```
39
87
 
40
- MIT © Simeon Griggs
41
- See LICENSE
88
+ ### Intended content operations with this plugin
42
89
 
90
+ A content creator composes a new document of one of the configured Schema types. The document is a "Draft", but not automatically added to the Workflow.
43
91
 
44
- ## License
92
+ The creator clicks the "Begin Workflow" Document Action to create a new "metadata" document and add the document to the first State in the Workflow. Using the default States, the document is now "In Review".
93
+
94
+ The document is now visible in the Workflow Tool. The creator can drag and drop the document to the next State in the Workflow, "Changes Requested". Other users may be "assigned" to the document. In the default State configuration, only an assigned user can move the document into the final "Approved" state.
95
+
96
+ An administrator can move the document into Changes Requested or Approved.
97
+
98
+ With the document now Approved, a user may also return to the document and Publish it, by whatever means that make sense to your use case. Such as scheduled publishing or migrating it to a new dataset.
45
99
 
46
- [MIT](LICENSE) © Simeon Griggs
100
+ Once the Workflow is complete, the metadata can be removed by using the "Complete Workflow" document action.
101
+
102
+ ### Differences from the Sanity Studio v2 Workflow Demo
103
+
104
+ This plugin is largely based on the original Workflow Demo built into a Sanity Studio v2 project. The major differences are:
105
+
106
+ * This plugin is not concerned with nor will modify whether a document is in draft or published.
107
+ * This plugin can be more easily installed and configured, not just code examples built into a Studio project.
108
+ * Documents must "opt-in" to and be removed from the Workflow. In the previous version, all documents were in the workflow which would fill up the interface and negatively affect performance.
109
+ * Document validation status can be used as a way to prevent movement through the workflow.
110
+ * User Roles and Assignments can affect the Workflow. Set rules to enforce which States documents can move between and if being assigned to a document is required to move it to a new State.
111
+ * This plugin can filter Schema types and assigned Users.
112
+
113
+ ## License
47
114
 
115
+ [MIT](LICENSE) © Sanity.io
48
116
 
49
117
  ## Develop & test
50
118
 
@@ -52,11 +120,11 @@ This plugin uses [@sanity/plugin-kit](https://github.com/sanity-io/plugin-kit)
52
120
  with default configuration for build & watch scripts.
53
121
 
54
122
  See [Testing a plugin in Sanity Studio](https://github.com/sanity-io/plugin-kit#testing-a-plugin-in-sanity-studio)
55
- on how to run this plugin with hotreload in the studio.
123
+ on how to run this plugin with hot reload in the studio.
56
124
 
57
125
  ### Release new version
58
126
 
59
127
  Run ["CI & Release" workflow](https://github.com/sanity-io/sanity-plugin-workflow/actions/workflows/main.yml).
60
128
  Make sure to select the main branch and check "Release new version".
61
129
 
62
- Semantic release will only release on configured branches, so it is safe to run release on any branch.
130
+ Semantic release will only release on configured branches, so it is safe to run the release on any branch.
@@ -1,12 +1,13 @@
1
1
  import {Plugin as Plugin_2} from 'sanity'
2
- import {default as React_2} from 'react'
3
2
 
4
3
  declare type State = {
5
4
  id: string
5
+ transitions: string[]
6
6
  title: string
7
- operation?: 'publish' | 'unpublish' | null
7
+ roles?: string[]
8
+ requireAssignment?: boolean
9
+ requireValidation?: boolean
8
10
  color?: 'primary' | 'success' | 'warning' | 'danger'
9
- icon?: React_2.ReactNode | React_2.ComponentType
10
11
  }
11
12
 
12
13
  export declare const workflow: Plugin_2<WorkflowConfig>