sanity-plugin-workflow 1.0.0-beta.1 → 1.0.0-beta.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.
Files changed (50) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +73 -12
  3. package/lib/{src/index.d.ts → index.d.ts} +3 -3
  4. package/lib/index.esm.js +1800 -1
  5. package/lib/index.esm.js.map +1 -1
  6. package/lib/index.js +1813 -1
  7. package/lib/index.js.map +1 -1
  8. package/package.json +51 -40
  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 +39 -0
  23. package/src/components/DocumentCard/core/TimeAgo.tsx +11 -0
  24. package/src/components/DocumentCard/index.tsx +156 -50
  25. package/src/components/DocumentList.tsx +122 -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 +73 -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/Validators.tsx +229 -0
  34. package/src/components/WorkflowTool.tsx +302 -163
  35. package/src/constants/index.ts +31 -0
  36. package/src/helpers/arraysContainMatchingString.ts +6 -0
  37. package/src/helpers/filterItemsAndSort.ts +41 -0
  38. package/src/helpers/initialRank.ts +13 -0
  39. package/src/hooks/useWorkflowDocuments.tsx +62 -70
  40. package/src/hooks/useWorkflowMetadata.tsx +0 -1
  41. package/src/index.ts +38 -58
  42. package/src/schema/workflow/workflow.metadata.ts +68 -0
  43. package/src/tools/index.ts +15 -0
  44. package/src/types/index.ts +27 -6
  45. package/src/actions/DemoteAction.tsx +0 -62
  46. package/src/actions/PromoteAction.tsx +0 -62
  47. package/src/components/Mutate.tsx +0 -54
  48. package/src/components/StateTimeline.tsx +0 -98
  49. package/src/components/UserSelectInput.tsx +0 -43
  50. package/src/schema/workflow/metadata.ts +0 -38
@@ -1,98 +0,0 @@
1
- import {Button, Card, Text, Inline, Stack, useToast} from '@sanity/ui'
2
- import React, {useEffect} from 'react'
3
- import {ObjectInputProps, useClient} from 'sanity'
4
-
5
- import {useWorkflowMetadata} from '../hooks/useWorkflowMetadata'
6
- import {State} from '../types'
7
-
8
- type StateTimelineProps = ObjectInputProps & {
9
- states: State[]
10
- children: React.ReactNode
11
- }
12
-
13
- export default function StateTimeline(props: StateTimelineProps) {
14
- // return (
15
- // <Stack space={3}>
16
- // <StateTimeline {...props} states={states}>
17
- // {props.renderDefault(props)}
18
- // </StateTimeline>
19
- // </Stack>
20
- // )
21
- console.log(props)
22
- const {value, states, children} = props
23
-
24
- const documentId = String(value?._id)
25
-
26
- const {data, loading, error} = useWorkflowMetadata(documentId, states)
27
- const {state} = data
28
- const [mutatingToState, setMutatingToState] = React.useState<string | null>(
29
- null
30
- )
31
-
32
- const client = useClient()
33
- const toast = useToast()
34
-
35
- // Just because the document is patched ...
36
- // doesn't mean the latest data has been returned from the listener
37
- useEffect(() => {
38
- if (data) {
39
- setMutatingToState(null)
40
- }
41
- }, [data])
42
-
43
- const changeState = React.useCallback(
44
- (publishedId: string, newState: State) => {
45
- setMutatingToState(newState.id)
46
-
47
- client
48
- .patch(`workflow-metadata.${publishedId}`)
49
- .set({state: newState.id})
50
- .commit()
51
- .then(() => {
52
- toast.push({
53
- status: 'success',
54
- title: `Document moved to ${newState.title}`,
55
- })
56
- })
57
- .catch((err) => {
58
- console.error(err)
59
- toast.push({
60
- status: 'error',
61
- title: `Document moved failed`,
62
- })
63
- })
64
- },
65
- [client, toast]
66
- )
67
-
68
- return (
69
- <Stack space={3}>
70
- <Text weight="medium" size={1}>
71
- Workflow State
72
- </Text>
73
- <Card padding={1} radius={3} border tone="primary">
74
- <Inline space={1}>
75
- {states.map((s) => (
76
- <Button
77
- disabled={loading || error || Boolean(mutatingToState)}
78
- fontSize={1}
79
- tone="primary"
80
- mode={
81
- (!mutatingToState && s.id === state?.id) ||
82
- s.id === mutatingToState
83
- ? `default`
84
- : `ghost`
85
- }
86
- key={s.id}
87
- text={s.title}
88
- radius={2}
89
- onClick={() => changeState(documentId, s)}
90
- />
91
- ))}
92
- </Inline>
93
- </Card>
94
-
95
- {children}
96
- </Stack>
97
- )
98
- }
@@ -1,43 +0,0 @@
1
- import {Card} from '@sanity/ui'
2
- import React, {useCallback} from 'react'
3
- import type {ArrayOfPrimitivesInputProps} from 'sanity'
4
- import {setIfMissing, insert, unset} from 'sanity'
5
- import {UserSelectMenu, useProjectUsers} from 'sanity-plugin-utils'
6
-
7
- export default function UserSelectInput(props: ArrayOfPrimitivesInputProps) {
8
- const {value = [], onChange} = props
9
- const userList = useProjectUsers()
10
-
11
- const onAssigneeAdd = useCallback(
12
- (userId: string) => {
13
- onChange([setIfMissing([]), insert([userId], `after`, [-1])])
14
- },
15
- [onChange]
16
- )
17
-
18
- const onAssigneeRemove = useCallback(
19
- (userId: string) => {
20
- const userIdIndex = value.findIndex((v) => v === userId)
21
-
22
- onChange(unset([userIdIndex]))
23
- },
24
- [onChange, value]
25
- )
26
-
27
- const onAssigneesClear = useCallback(() => {
28
- onChange(unset())
29
- }, [onChange])
30
-
31
- return (
32
- <Card border radius={3} padding={1}>
33
- <UserSelectMenu
34
- open
35
- value={value as string[]}
36
- userList={userList}
37
- onAdd={onAssigneeAdd}
38
- onClear={onAssigneesClear}
39
- onRemove={onAssigneeRemove}
40
- />
41
- </Card>
42
- )
43
- }
@@ -1,38 +0,0 @@
1
- import {defineType, defineField, defineArrayMember} from 'sanity'
2
- // import UserSelectInput from '../../components/UserSelectInput'
3
- import {State} from '../../types'
4
-
5
- // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
6
- export default (states: State[]) =>
7
- defineType({
8
- type: 'document',
9
- name: 'workflow.metadata',
10
- title: 'Workflow metadata',
11
- liveEdit: true,
12
- fields: [
13
- defineField({
14
- name: 'state',
15
- type: 'string',
16
- options: {
17
- list: states.map((state) => ({
18
- value: state.id,
19
- title: state.title,
20
- })),
21
- },
22
- }),
23
- defineField({
24
- name: 'documentId',
25
- title: 'Document ID',
26
- type: 'string',
27
- readOnly: true,
28
- }),
29
- defineField({
30
- type: 'array',
31
- name: 'assignees',
32
- description:
33
- 'The people who are assigned to move this further in the workflow.',
34
- of: [defineArrayMember({type: 'string'})],
35
- // components: {input: UserSelectInput},
36
- }),
37
- ],
38
- })