sanity-plugin-workflow 1.0.4 → 1.0.6
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 +0 -2
- package/lib/index.esm.js +24 -17
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +26 -20
- package/lib/index.js.map +1 -1
- package/package.json +11 -11
- package/src/actions/CompleteWorkflow.tsx +29 -6
- package/src/components/DocumentCard/CompleteButton.tsx +2 -14
- package/src/components/FloatingCard.tsx +12 -5
- package/src/components/StateTitle/index.tsx +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sanity-plugin-workflow",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "A demonstration of a custom content publishing workflow using Sanity.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -50,14 +50,15 @@
|
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"@hello-pangea/dnd": "^16.5.0",
|
|
53
|
-
"@sanity/icons": "^
|
|
54
|
-
"@sanity/incompatible-plugin": "^1.0.
|
|
53
|
+
"@sanity/icons": "^3.7.4",
|
|
54
|
+
"@sanity/incompatible-plugin": "^1.0.5",
|
|
55
|
+
"@sanity/ui": "^2.16.4",
|
|
55
56
|
"@tanstack/react-virtual": "^3.0.0-beta.54",
|
|
56
57
|
"framer-motion": "^10.6.1",
|
|
57
|
-
"groq": "^3.
|
|
58
|
+
"groq": "^3.98.1",
|
|
58
59
|
"lexorank": "^1.0.5",
|
|
59
60
|
"react-fast-compare": "^3.2.1",
|
|
60
|
-
"sanity-plugin-utils": "^1.6.
|
|
61
|
+
"sanity-plugin-utils": "^1.6.3"
|
|
61
62
|
},
|
|
62
63
|
"devDependencies": {
|
|
63
64
|
"@commitlint/cli": "^17.4.4",
|
|
@@ -66,7 +67,6 @@
|
|
|
66
67
|
"@sanity/plugin-kit": "^3.1.4",
|
|
67
68
|
"@sanity/semantic-release-preset": "^4.0.1",
|
|
68
69
|
"@types/react": "^18.0.27",
|
|
69
|
-
"@types/styled-components": "^5.1.26",
|
|
70
70
|
"@typescript-eslint/eslint-plugin": "^5.51.0",
|
|
71
71
|
"@typescript-eslint/parser": "^5.51.0",
|
|
72
72
|
"eslint": "^8.33.0",
|
|
@@ -87,14 +87,14 @@
|
|
|
87
87
|
"rimraf": "^4.1.2",
|
|
88
88
|
"sanity": "^3.26.0",
|
|
89
89
|
"semantic-release": "^20.1.3",
|
|
90
|
+
"styled-components": "^6.1.19",
|
|
90
91
|
"typescript": "^5.0.0"
|
|
91
92
|
},
|
|
92
93
|
"peerDependencies": {
|
|
93
|
-
"
|
|
94
|
-
"react": "^18",
|
|
95
|
-
"
|
|
96
|
-
"
|
|
97
|
-
"styled-components": "^5.0 || ^6.0"
|
|
94
|
+
"react": "^18.3 || ^19",
|
|
95
|
+
"react-dom": "^18.3 || ^19",
|
|
96
|
+
"sanity": "^3 || ^4.0.0-0",
|
|
97
|
+
"styled-components": "^6.1"
|
|
98
98
|
},
|
|
99
99
|
"engines": {
|
|
100
100
|
"node": ">=14"
|
|
@@ -1,22 +1,44 @@
|
|
|
1
1
|
import {CheckmarkIcon} from '@sanity/icons'
|
|
2
|
+
import {ToastContextValue, useToast} from '@sanity/ui'
|
|
2
3
|
import {useCallback} from 'react'
|
|
3
|
-
import {DocumentActionProps, useClient} from 'sanity'
|
|
4
|
+
import {DocumentActionProps, SanityClient, useClient} from 'sanity'
|
|
4
5
|
|
|
5
6
|
import {useWorkflowContext} from '../components/WorkflowContext'
|
|
6
7
|
import {API_VERSION} from '../constants'
|
|
7
8
|
|
|
9
|
+
export const handleDeleteMetadata = async (
|
|
10
|
+
client: SanityClient,
|
|
11
|
+
toast: ToastContextValue,
|
|
12
|
+
id: string
|
|
13
|
+
) => {
|
|
14
|
+
try {
|
|
15
|
+
await client.delete(`workflow-metadata.${id}`)
|
|
16
|
+
toast.push({
|
|
17
|
+
status: 'success',
|
|
18
|
+
title: 'Workflow completed',
|
|
19
|
+
})
|
|
20
|
+
} catch (error) {
|
|
21
|
+
console.error(error)
|
|
22
|
+
toast.push({
|
|
23
|
+
status: 'error',
|
|
24
|
+
title: 'Could not complete Workflow',
|
|
25
|
+
})
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
8
29
|
export function CompleteWorkflow(props: DocumentActionProps) {
|
|
9
30
|
const {id} = props
|
|
10
31
|
const {metadata, loading, error, states} = useWorkflowContext(id)
|
|
11
32
|
const client = useClient({apiVersion: API_VERSION})
|
|
33
|
+
const toast = useToast()
|
|
12
34
|
|
|
13
35
|
if (error) {
|
|
14
36
|
console.error(error)
|
|
15
37
|
}
|
|
16
38
|
|
|
17
|
-
const handle = useCallback(() => {
|
|
18
|
-
client
|
|
19
|
-
}, [
|
|
39
|
+
const handle = useCallback(async () => {
|
|
40
|
+
await handleDeleteMetadata(client, toast, id)
|
|
41
|
+
}, [client, toast, id])
|
|
20
42
|
|
|
21
43
|
if (!metadata) {
|
|
22
44
|
return null
|
|
@@ -33,8 +55,9 @@ export function CompleteWorkflow(props: DocumentActionProps) {
|
|
|
33
55
|
title: isLastState
|
|
34
56
|
? `Removes the document from the Workflow process`
|
|
35
57
|
: `Cannot remove from workflow until in the last state`,
|
|
36
|
-
onHandle: () => {
|
|
37
|
-
handle()
|
|
58
|
+
onHandle: async () => {
|
|
59
|
+
await handle()
|
|
60
|
+
props.onComplete()
|
|
38
61
|
},
|
|
39
62
|
color: 'positive',
|
|
40
63
|
}
|
|
@@ -3,6 +3,7 @@ import {Box, Button, Text, Tooltip, useToast} from '@sanity/ui'
|
|
|
3
3
|
import React from 'react'
|
|
4
4
|
import {useClient} from 'sanity'
|
|
5
5
|
|
|
6
|
+
import {handleDeleteMetadata} from '../../actions/CompleteWorkflow'
|
|
6
7
|
import {API_VERSION} from '../../constants'
|
|
7
8
|
|
|
8
9
|
type CompleteButtonProps = {
|
|
@@ -24,20 +25,7 @@ export default function CompleteButton(props: CompleteButtonProps) {
|
|
|
24
25
|
return
|
|
25
26
|
}
|
|
26
27
|
|
|
27
|
-
client
|
|
28
|
-
.delete(`workflow-metadata.${id}`)
|
|
29
|
-
.then(() => {
|
|
30
|
-
toast.push({
|
|
31
|
-
status: 'success',
|
|
32
|
-
title: 'Workflow completed',
|
|
33
|
-
})
|
|
34
|
-
})
|
|
35
|
-
.catch(() => {
|
|
36
|
-
toast.push({
|
|
37
|
-
status: 'error',
|
|
38
|
-
title: 'Could not complete Workflow',
|
|
39
|
-
})
|
|
40
|
-
})
|
|
28
|
+
handleDeleteMetadata(client, toast, id)
|
|
41
29
|
},
|
|
42
30
|
[client, toast]
|
|
43
31
|
)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {PropsWithChildren} from 'react'
|
|
2
|
-
import styled, {css} from 'styled-components'
|
|
3
1
|
import {Card, Grid} from '@sanity/ui'
|
|
4
|
-
import {
|
|
2
|
+
import {AnimatePresence, motion} from 'framer-motion'
|
|
3
|
+
import {PropsWithChildren} from 'react'
|
|
4
|
+
import {css, styled} from 'styled-components'
|
|
5
5
|
|
|
6
6
|
const StyledFloatingCard = styled(Card)(
|
|
7
7
|
() => css`
|
|
@@ -13,12 +13,19 @@ const StyledFloatingCard = styled(Card)(
|
|
|
13
13
|
)
|
|
14
14
|
|
|
15
15
|
export default function FloatingCard({children}: PropsWithChildren) {
|
|
16
|
-
const childrenHaveValues = Array.isArray(children)
|
|
16
|
+
const childrenHaveValues = Array.isArray(children)
|
|
17
|
+
? children.some(Boolean)
|
|
18
|
+
: Boolean(children)
|
|
17
19
|
|
|
18
20
|
return (
|
|
19
21
|
<AnimatePresence>
|
|
20
22
|
{childrenHaveValues ? (
|
|
21
|
-
<motion.div
|
|
23
|
+
<motion.div
|
|
24
|
+
key="floater"
|
|
25
|
+
initial={{opacity: 0}}
|
|
26
|
+
animate={{opacity: 1}}
|
|
27
|
+
exit={{opacity: 0}}
|
|
28
|
+
>
|
|
22
29
|
<StyledFloatingCard shadow={3} padding={3} margin={3} radius={3}>
|
|
23
30
|
<Grid gap={2}>{children}</Grid>
|
|
24
31
|
</StyledFloatingCard>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {InfoOutlineIcon, UserIcon} from '@sanity/icons'
|
|
2
2
|
import {Badge, BadgeTone, Box, Card, Flex, Text} from '@sanity/ui'
|
|
3
|
-
import
|
|
3
|
+
import {css, styled} from 'styled-components'
|
|
4
4
|
|
|
5
5
|
import {State} from '../../types'
|
|
6
6
|
import {Status} from './Status'
|