sanity-plugin-workflow 1.0.0-beta.1 → 1.0.0-beta.11
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/README.md +81 -13
- package/lib/{src/index.d.ts → index.d.ts} +4 -3
- package/lib/index.esm.js +2107 -1
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +2120 -1
- package/lib/index.js.map +1 -1
- package/package.json +51 -40
- package/src/actions/AssignWorkflow.tsx +47 -0
- package/src/actions/BeginWorkflow.tsx +63 -0
- package/src/actions/CompleteWorkflow.tsx +41 -0
- package/src/actions/UpdateWorkflow.tsx +126 -0
- package/src/badges/AssigneesBadge.tsx +53 -0
- package/src/badges/StateBadge.tsx +28 -0
- package/src/components/DocumentCard/AvatarGroup.tsx +12 -8
- package/src/components/DocumentCard/CompleteButton.tsx +68 -0
- package/src/components/DocumentCard/EditButton.tsx +3 -2
- package/src/components/DocumentCard/Field.tsx +38 -0
- package/src/components/DocumentCard/Validate.tsx +21 -0
- package/src/components/DocumentCard/ValidationStatus.tsx +37 -0
- package/src/components/DocumentCard/core/DraftStatus.tsx +32 -0
- package/src/components/DocumentCard/core/PublishedStatus.tsx +39 -0
- package/src/components/DocumentCard/core/TimeAgo.tsx +11 -0
- package/src/components/DocumentCard/index.tsx +177 -68
- package/src/components/DocumentList.tsx +169 -0
- package/src/components/Filters.tsx +168 -0
- package/src/components/FloatingCard.tsx +29 -0
- package/src/components/StateTitle/Status.tsx +27 -0
- package/src/components/StateTitle/index.tsx +78 -0
- package/src/components/UserAssignment.tsx +57 -75
- package/src/components/UserAssignmentInput.tsx +27 -0
- package/src/components/UserDisplay.tsx +57 -0
- package/src/components/Verify.tsx +297 -0
- package/src/components/WorkflowContext.tsx +71 -0
- package/src/components/WorkflowSignal.tsx +30 -0
- package/src/components/WorkflowTool.tsx +373 -162
- package/src/constants/index.ts +31 -0
- package/src/helpers/arraysContainMatchingString.ts +6 -0
- package/src/helpers/filterItemsAndSort.ts +41 -0
- package/src/helpers/generateMultipleOrderRanks.ts +80 -0
- package/src/helpers/initialRank.ts +13 -0
- package/src/hooks/useWorkflowDocuments.tsx +76 -78
- package/src/hooks/useWorkflowMetadata.tsx +31 -26
- package/src/index.ts +60 -57
- package/src/schema/workflow/workflow.metadata.ts +68 -0
- package/src/tools/index.ts +15 -0
- package/src/types/index.ts +27 -6
- package/src/actions/DemoteAction.tsx +0 -62
- package/src/actions/PromoteAction.tsx +0 -62
- package/src/actions/RequestReviewAction.js +0 -61
- package/src/actions/index.js +0 -21
- package/src/badges/index.tsx +0 -31
- package/src/components/Mutate.tsx +0 -54
- package/src/components/StateTimeline.tsx +0 -98
- package/src/components/UserSelectInput.tsx +0 -43
- package/src/schema/workflow/metadata.ts +0 -38
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import {useCallback, useContext, useState} from 'react'
|
|
2
|
+
import {createContext} from 'react'
|
|
3
|
+
import {LayoutProps} from 'sanity'
|
|
4
|
+
|
|
5
|
+
import {DEFAULT_CONFIG} from '../constants'
|
|
6
|
+
import {useWorkflowMetadata} from '../hooks/useWorkflowMetadata'
|
|
7
|
+
import {KeyedMetadata, WorkflowConfig} from '../types'
|
|
8
|
+
|
|
9
|
+
export type WorkflowContextValue = Required<WorkflowConfig> & {
|
|
10
|
+
data: KeyedMetadata
|
|
11
|
+
loading: boolean
|
|
12
|
+
error: boolean
|
|
13
|
+
ids: string[]
|
|
14
|
+
addId: (id: string) => void
|
|
15
|
+
removeId: (id: string) => void
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const WorkflowContext = createContext<WorkflowContextValue>({
|
|
19
|
+
data: {},
|
|
20
|
+
loading: false,
|
|
21
|
+
error: false,
|
|
22
|
+
ids: [],
|
|
23
|
+
addId: () => null,
|
|
24
|
+
removeId: () => null,
|
|
25
|
+
...DEFAULT_CONFIG,
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
export function useWorkflowContext(id?: string) {
|
|
29
|
+
const current = useContext(WorkflowContext)
|
|
30
|
+
|
|
31
|
+
return {...current, metadata: id ? current.data[id] : null}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
type WorkflowProviderProps = LayoutProps & {workflow: Required<WorkflowConfig>}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* This Provider wraps the Studio and provides the workflow context to document actions and badges.
|
|
38
|
+
* This is so individual actions and badges do not need to all register their own listeners.
|
|
39
|
+
* Instead, each document "signals" its ID up to the provider, which then registers a single listener
|
|
40
|
+
* This is performed inside of a component loaded at the root level of the Document Form
|
|
41
|
+
*/
|
|
42
|
+
export function WorkflowProvider(props: WorkflowProviderProps) {
|
|
43
|
+
const [ids, setIds] = useState<string[]>([])
|
|
44
|
+
const addId = useCallback(
|
|
45
|
+
(id: string) =>
|
|
46
|
+
setIds((current) => (current.includes(id) ? current : [...current, id])),
|
|
47
|
+
[]
|
|
48
|
+
)
|
|
49
|
+
const removeId = useCallback(
|
|
50
|
+
(id: string) => setIds((current) => current.filter((i) => i !== id)),
|
|
51
|
+
[]
|
|
52
|
+
)
|
|
53
|
+
const {data, loading, error} = useWorkflowMetadata(ids)
|
|
54
|
+
|
|
55
|
+
return (
|
|
56
|
+
<WorkflowContext.Provider
|
|
57
|
+
value={{
|
|
58
|
+
data,
|
|
59
|
+
loading,
|
|
60
|
+
error,
|
|
61
|
+
ids,
|
|
62
|
+
addId,
|
|
63
|
+
removeId,
|
|
64
|
+
states: props.workflow.states,
|
|
65
|
+
schemaTypes: props.workflow.schemaTypes,
|
|
66
|
+
}}
|
|
67
|
+
>
|
|
68
|
+
{props.renderDefault(props)}
|
|
69
|
+
</WorkflowContext.Provider>
|
|
70
|
+
)
|
|
71
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import {useEffect} from 'react'
|
|
2
|
+
import {ObjectInputProps} from 'sanity'
|
|
3
|
+
|
|
4
|
+
import {useWorkflowContext} from './WorkflowContext'
|
|
5
|
+
|
|
6
|
+
// This component is loaded at the root level of the Document Form
|
|
7
|
+
// It is used to signal the document ID to the WorkflowProvider
|
|
8
|
+
export default function WorkflowSignal(props: ObjectInputProps) {
|
|
9
|
+
const documentId = props?.value?._id
|
|
10
|
+
? props.value._id.replace(`drafts.`, ``)
|
|
11
|
+
: null
|
|
12
|
+
|
|
13
|
+
const {addId, removeId} = useWorkflowContext()
|
|
14
|
+
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
// On mount, add to the query of listening documents
|
|
17
|
+
if (documentId) {
|
|
18
|
+
addId(documentId)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// On unmount, remove from the query of listening documents
|
|
22
|
+
return () => {
|
|
23
|
+
if (documentId) {
|
|
24
|
+
removeId(documentId)
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}, [documentId, addId, removeId])
|
|
28
|
+
|
|
29
|
+
return props.renderDefault(props)
|
|
30
|
+
}
|