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

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 (49) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +71 -12
  3. package/lib/{src/index.d.ts → index.d.ts} +3 -3
  4. package/lib/index.esm.js +1691 -1
  5. package/lib/index.esm.js.map +1 -1
  6. package/lib/index.js +1704 -1
  7. package/lib/index.js.map +1 -1
  8. package/package.json +48 -38
  9. package/src/actions/AssignWorkflow.tsx +48 -0
  10. package/src/actions/BeginWorkflow.tsx +68 -0
  11. package/src/actions/CompleteWorkflow.tsx +41 -0
  12. package/src/actions/RequestReviewAction.js +1 -7
  13. package/src/actions/UpdateWorkflow.tsx +142 -0
  14. package/src/badges/AssigneesBadge.tsx +52 -0
  15. package/src/badges/{index.tsx → StateBadge.tsx} +4 -8
  16. package/src/components/DocumentCard/AvatarGroup.tsx +12 -8
  17. package/src/components/DocumentCard/CompleteButton.tsx +53 -0
  18. package/src/components/DocumentCard/EditButton.tsx +3 -2
  19. package/src/components/DocumentCard/Field.tsx +38 -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 +32 -0
  23. package/src/components/DocumentCard/core/TimeAgo.tsx +11 -0
  24. package/src/components/DocumentCard/index.tsx +156 -50
  25. package/src/components/Filters.tsx +168 -0
  26. package/src/components/FloatingCard.tsx +29 -0
  27. package/src/components/StateTitle/Status.tsx +27 -0
  28. package/src/components/StateTitle/index.tsx +73 -0
  29. package/src/components/UserAssignment.tsx +57 -75
  30. package/src/components/UserAssignmentInput.tsx +27 -0
  31. package/src/components/UserDisplay.tsx +57 -0
  32. package/src/components/Validators.tsx +196 -0
  33. package/src/components/WorkflowTool.tsx +301 -160
  34. package/src/constants/index.ts +31 -0
  35. package/src/helpers/arraysContainMatchingString.ts +6 -0
  36. package/src/helpers/filterItemsAndSort.ts +39 -0
  37. package/src/helpers/initialRank.ts +13 -0
  38. package/src/hooks/useWorkflowDocuments.tsx +62 -70
  39. package/src/hooks/useWorkflowMetadata.tsx +0 -1
  40. package/src/index.ts +38 -58
  41. package/src/schema/workflow/workflow.metadata.ts +68 -0
  42. package/src/tools/index.ts +15 -0
  43. package/src/types/index.ts +27 -6
  44. package/src/actions/DemoteAction.tsx +0 -62
  45. package/src/actions/PromoteAction.tsx +0 -62
  46. package/src/components/Mutate.tsx +0 -54
  47. package/src/components/StateTimeline.tsx +0 -98
  48. package/src/components/UserSelectInput.tsx +0 -43
  49. 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,36 @@
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
+ ## Features
16
+
17
+ This work demonstrates how a single plugin can define:
18
+
19
+ - A unique schema to handle workflow metadata
20
+ - Document Actions to promote and demote documents through the workflow
21
+ - Document Badges for visual feedback about the current state of a document
22
+ - A custom Tool for drag-and-drop updating of a document's state
4
23
 
5
24
  ## Installation
6
25
 
7
26
  ```
8
- npm install --save sanity-plugin-workflow
27
+ npm install --save sanity-plugin-workflow@beta
9
28
  ```
10
29
 
11
30
  or
12
31
 
13
32
  ```
14
- yarn add sanity-plugin-workflow
33
+ yarn add sanity-plugin-workflow@beta
15
34
  ```
16
35
 
17
36
  ## Usage
@@ -26,25 +45,65 @@ Add it as a plugin in sanity.config.ts (or .js):
26
45
  // all other settings ...
27
46
  plugins: [
28
47
  workflow({
29
- // Required
48
+ // Required, list of document type names
49
+ // schemaTypes: ['article', 'product'],
30
50
  schemaTypes: [],
31
- // Optional
51
+ // Optional, see below
32
52
  states: [],
33
53
  })
34
54
  ]
35
55
  })
36
56
  ```
37
57
 
38
- ## License
58
+ ## Configuring "States"
59
+
60
+ 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.
61
+
62
+ 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.
63
+
64
+ ```ts
65
+ {
66
+ // Required configuration
67
+ id: 'inReview',
68
+ title: 'In Review',
69
+ // Optional settings:
70
+ // Used for the color of the Document Badge
71
+ color: 'success',
72
+ // Will enable document actions and drag-and-drop for only users with these Role
73
+ roles: ['publisher', 'administrator'],
74
+ // Requires the user to be "assigned" in order to update to this State
75
+ requireAssignment: true,
76
+ // Defines which States a document can be moved to from this one
77
+ transitions: ['changesRequested', 'approved']
78
+ }
79
+ ```
39
80
 
40
- MIT © Simeon Griggs
41
- See LICENSE
81
+ ### Intended content operations with this plugin
42
82
 
83
+ 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
84
 
44
- ## License
85
+ 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".
86
+
87
+ 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.
88
+
89
+ An administrator can move the document into Changes Requested or Approved.
90
+
91
+ 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
92
 
46
- [MIT](LICENSE) © Simeon Griggs
93
+ Once the Workflow is complete, the metadata can be removed by using the "Complete Workflow" document action.
94
+
95
+ ### Differences from the Sanity Studio v2 Workflow Demo
96
+
97
+ This plugin is largely based on the original Workflow Demo built into a Sanity Studio v2 project. The major differences are:
98
+
99
+ * This plugin can be more easily installed and configured, not just code examples built into a Studio project
100
+ * Documents must "opt-in" to and removed from the Workflow, in the previous version all documents were in the workflow which would fill up the interface
101
+ * 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
102
+ * Ability to filter Schema types and assigned Users
103
+
104
+ ## License
47
105
 
106
+ [MIT](LICENSE) © Sanity.io
48
107
 
49
108
  ## Develop & test
50
109
 
@@ -52,11 +111,11 @@ This plugin uses [@sanity/plugin-kit](https://github.com/sanity-io/plugin-kit)
52
111
  with default configuration for build & watch scripts.
53
112
 
54
113
  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.
114
+ on how to run this plugin with hot reload in the studio.
56
115
 
57
116
  ### Release new version
58
117
 
59
118
  Run ["CI & Release" workflow](https://github.com/sanity-io/sanity-plugin-workflow/actions/workflows/main.yml).
60
119
  Make sure to select the main branch and check "Release new version".
61
120
 
62
- Semantic release will only release on configured branches, so it is safe to run release on any branch.
121
+ Semantic release will only release on configured branches, so it is safe to run the release on any branch.
@@ -1,12 +1,12 @@
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
8
9
  color?: 'primary' | 'success' | 'warning' | 'danger'
9
- icon?: React_2.ReactNode | React_2.ComponentType
10
10
  }
11
11
 
12
12
  export declare const workflow: Plugin_2<WorkflowConfig>