sanity-plugin-dashboard-widget-vercel 3.1.2 → 3.1.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.
- package/lib/index.js +364 -328
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +365 -330
- package/lib/index.mjs.map +1 -1
- package/package.json +22 -23
- package/src/app.tsx +22 -30
- package/src/components/DeployButton/index.tsx +8 -7
- package/src/components/DialogForm/index.tsx +78 -96
- package/src/machines/deploy.ts +94 -91
- package/src/machines/deploymentTargetList.ts +113 -90
- package/src/machines/dialog.ts +44 -44
- package/src/machines/form.ts +136 -91
- package/src/machines/refresh.ts +22 -18
- package/src/utils/fetcher.ts +0 -1
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import {assign,
|
|
1
|
+
import {assign, setup, fromPromise, assertEvent} from 'xstate'
|
|
2
2
|
import {Sanity} from '../types'
|
|
3
|
+
import type {SanityClient} from 'sanity'
|
|
4
|
+
import {DEPLOYMENT_TARGET_DOCUMENT_TYPE} from '../constants'
|
|
3
5
|
|
|
4
6
|
type Context = {
|
|
5
|
-
|
|
7
|
+
client: SanityClient
|
|
6
8
|
results: Sanity.DeploymentTarget[] // TODO: type correctly
|
|
7
9
|
}
|
|
8
10
|
|
|
@@ -11,22 +13,10 @@ type Event =
|
|
|
11
13
|
| {type: 'CREATE'; deploymentTarget: Sanity.DeploymentTarget}
|
|
12
14
|
| {type: 'DELETE'; id: string}
|
|
13
15
|
| {type: 'FETCH'}
|
|
14
|
-
| {type: '
|
|
15
|
-
| {type: 'RESOLVE'; results: any[]}
|
|
16
|
-
| {type: 'UPDATE'}
|
|
16
|
+
| {type: 'UPDATE'; deploymentTarget: Sanity.DeploymentTarget}
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
failed: {}
|
|
21
|
-
pending: {}
|
|
22
|
-
ready: {
|
|
23
|
-
states: {
|
|
24
|
-
unknown: {}
|
|
25
|
-
withData: {}
|
|
26
|
-
withoutData: {}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
18
|
+
interface Input {
|
|
19
|
+
client: SanityClient
|
|
30
20
|
}
|
|
31
21
|
|
|
32
22
|
const sortByTargetName = (items: Sanity.DeploymentTarget[]) => {
|
|
@@ -34,93 +24,126 @@ const sortByTargetName = (items: Sanity.DeploymentTarget[]) => {
|
|
|
34
24
|
if (a.name > b.name) {
|
|
35
25
|
return 1
|
|
36
26
|
}
|
|
37
|
-
|
|
38
27
|
if (a.name < b.name) {
|
|
39
28
|
return -1
|
|
40
29
|
}
|
|
41
|
-
|
|
42
30
|
return 0
|
|
43
31
|
})
|
|
44
32
|
}
|
|
45
33
|
|
|
46
|
-
const deploymentTargetListMachine = (
|
|
47
|
-
|
|
48
|
-
{
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
34
|
+
export const deploymentTargetListMachine = setup({
|
|
35
|
+
types: {} as {
|
|
36
|
+
children: {fetchData: 'fetch data'}
|
|
37
|
+
context: Context
|
|
38
|
+
events: Event
|
|
39
|
+
input: Input
|
|
40
|
+
},
|
|
41
|
+
actions: {
|
|
42
|
+
targetCreate: assign({
|
|
43
|
+
results: ({context, event}) => {
|
|
44
|
+
assertEvent(event, 'CREATE')
|
|
45
|
+
return sortByTargetName([...context.results, event.deploymentTarget])
|
|
52
46
|
},
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
47
|
+
}),
|
|
48
|
+
targetDelete: assign({
|
|
49
|
+
results: ({context, event}) => {
|
|
50
|
+
assertEvent(event, 'DELETE')
|
|
51
|
+
return context.results.filter((target) => target._id !== event.id)
|
|
52
|
+
},
|
|
53
|
+
}),
|
|
54
|
+
targetUpdate: assign({
|
|
55
|
+
results: ({context, event}) => {
|
|
56
|
+
assertEvent(event, 'UPDATE')
|
|
57
|
+
const {deploymentTarget} = event
|
|
58
|
+
const index = context.results.findIndex((target) => target._id === deploymentTarget._id)
|
|
59
|
+
const updatedResults = Object.assign([], context.results, {
|
|
60
|
+
[index]: deploymentTarget,
|
|
61
|
+
})
|
|
62
|
+
return sortByTargetName(updatedResults)
|
|
63
|
+
},
|
|
64
|
+
}),
|
|
65
|
+
},
|
|
66
|
+
guards: {
|
|
67
|
+
hasData: ({context}) => {
|
|
68
|
+
return context?.results?.length > 0
|
|
69
|
+
},
|
|
70
|
+
hasNoData: ({context}) => {
|
|
71
|
+
return context?.results?.length === 0
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
actors: {
|
|
75
|
+
'fetch data': fromPromise(
|
|
76
|
+
({input, signal}: {input: {client: SanityClient}; signal: AbortSignal}) => {
|
|
77
|
+
return input.client
|
|
78
|
+
.fetch<Sanity.DeploymentTarget[]>(
|
|
79
|
+
'*[_type == $type] | order(name asc)',
|
|
80
|
+
{
|
|
81
|
+
type: DEPLOYMENT_TARGET_DOCUMENT_TYPE,
|
|
81
82
|
},
|
|
82
|
-
|
|
83
|
+
{signal}
|
|
84
|
+
)
|
|
85
|
+
.catch((error) => {
|
|
86
|
+
if (error instanceof Error && error.name === 'AbortError') {
|
|
87
|
+
return []
|
|
88
|
+
}
|
|
89
|
+
console.error('Failed to fetch deployment targets', error)
|
|
90
|
+
throw error
|
|
91
|
+
})
|
|
92
|
+
}
|
|
93
|
+
),
|
|
94
|
+
},
|
|
95
|
+
}).createMachine({
|
|
96
|
+
/** @xstate-layout N4IgpgJg5mDOIC5QAoC2BDAxgCwJYDswBKAOgAcx8ICoBiCAe0JIIDcGBrMEgMzABccAEXT90AbQAMAXUSgyDWLn64mckAA9EAZkkBOEgHYAjAA5DAFgBsFgEwnJAVkMAaEAE9Ep4yUeT-klbGesbaoYaGAL6RbmhYeISkFFQ0tGAATukM6eQANqI82ai8AsKiEjLqCkoqakiaOvpGZpY29sZOrh6IxpYkFo5h2oaOpnqOxraSFtGxGDgExCTpYOgQ7rQAwgBKAKIAggAqu1Ky9dXKqvjqWggWHSS9eoaS9ibao6aObp4IVh8kL56OzGII2PT-WYgOILRLLVbrWhCXYAGV2x1OVUUlzqoFu90kRm8tlM2gsL1eJJ+iEGBj0gVsFm0YWmVkctihMISSxWaw2AFUAApCI4nSrnbG1a71fGSUz9WzBezTFWvb7dO5MkjjMITZykwxjTnzbmkXnrEgAV3wHHwDAA7vhaJiJTUrjces9fFZGc9TLYrGqA9SEM9CcT7sznH5HHpjfFFmaEe4rTa7Y7ncYzvJJe6ZZ7DN7fYaA0GrCHvD4xs4S+yPnGYtCTYn4XySPblNgRGJneKc27cQ0EI4BiQ2T77noAzXyxrTIESGFGd4rP9DONTPHYTzk+3OwxLfxu+he9mQBcpR7h6Px4ylWyIrPfl9bIvJhZJIYA-7zFZoo27QgOB1C5RMsQHaU8UQABaYIQ2gv9G1AuFkmofAoHAnFIKHOwQz0bRtUMcd-j8WwpnuLdTVbdZMMvfMEFsPQQxMeViQmZkLC+f0oiQ5s4XNFNrVtB1sIvPMoIQCIK1BIsmXXWxtFJcZKJbAS934Ltylo8ShysfDHl9PRxjlekrC6Z9BhIBk5MkXpzFBFT+N3DsNIPI8tNdLCr20L0Wmscw5V0e5pMJYwBiI8kwrDRC5gTOEeHQXBckgbTB1uZwQw6RwrEBd9bEcQZYzsRDoiAA */
|
|
97
|
+
context: ({input}) => ({
|
|
98
|
+
client: input.client,
|
|
99
|
+
results: [],
|
|
100
|
+
}),
|
|
101
|
+
initial: 'pending',
|
|
102
|
+
states: {
|
|
103
|
+
pending: {
|
|
104
|
+
invoke: {
|
|
105
|
+
src: 'fetch data',
|
|
106
|
+
id: 'fetchData',
|
|
107
|
+
input: ({context}) => ({client: context.client}),
|
|
108
|
+
onDone: {
|
|
109
|
+
actions: assign({results: ({event}) => event.output}),
|
|
110
|
+
target: 'ready',
|
|
83
111
|
},
|
|
84
|
-
|
|
85
|
-
|
|
112
|
+
onError: {
|
|
113
|
+
target: 'failed',
|
|
86
114
|
},
|
|
87
115
|
},
|
|
88
116
|
},
|
|
89
|
-
{
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
results: context.results.filter((target) => target._id !== event.id),
|
|
102
|
-
})),
|
|
103
|
-
targetUpdate: assign((context, event: any) => {
|
|
104
|
-
const {deploymentTarget} = event
|
|
105
|
-
const index = context.results.findIndex((target) => target._id === deploymentTarget._id)
|
|
106
|
-
const updatedResults = Object.assign([], context.results, {
|
|
107
|
-
[index]: event.deploymentTarget,
|
|
108
|
-
})
|
|
109
|
-
|
|
110
|
-
return {
|
|
111
|
-
results: sortByTargetName(updatedResults),
|
|
112
|
-
}
|
|
113
|
-
}),
|
|
117
|
+
ready: {
|
|
118
|
+
initial: 'unknown',
|
|
119
|
+
on: {
|
|
120
|
+
CREATE: {
|
|
121
|
+
actions: 'targetCreate',
|
|
122
|
+
},
|
|
123
|
+
DELETE: {
|
|
124
|
+
actions: 'targetDelete',
|
|
125
|
+
},
|
|
126
|
+
UPDATE: {
|
|
127
|
+
actions: 'targetUpdate',
|
|
128
|
+
},
|
|
114
129
|
},
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
130
|
+
states: {
|
|
131
|
+
unknown: {
|
|
132
|
+
always: [
|
|
133
|
+
{target: 'withData', guard: 'hasData'},
|
|
134
|
+
{target: 'withoutData', guard: 'hasNoData'},
|
|
135
|
+
],
|
|
118
136
|
},
|
|
119
|
-
|
|
120
|
-
|
|
137
|
+
withData: {
|
|
138
|
+
always: [{target: 'withoutData', guard: 'hasNoData'}],
|
|
139
|
+
},
|
|
140
|
+
withoutData: {
|
|
141
|
+
always: [{target: 'withData', guard: 'hasData'}],
|
|
121
142
|
},
|
|
122
143
|
},
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
144
|
+
},
|
|
145
|
+
failed: {
|
|
146
|
+
type: 'final',
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
})
|
package/src/machines/dialog.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {assign,
|
|
1
|
+
import {assertEvent, assign, setup} from 'xstate'
|
|
2
2
|
import {Sanity} from '../types'
|
|
3
3
|
|
|
4
4
|
type Context = {
|
|
@@ -10,53 +10,53 @@ type Event =
|
|
|
10
10
|
| {type: 'CLOSE'}
|
|
11
11
|
| {type: 'EDIT'; deploymentTarget: Sanity.DeploymentTarget}
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
{
|
|
24
|
-
context: {
|
|
25
|
-
editDeploymentTarget: undefined,
|
|
13
|
+
export const dialogMachine = setup({
|
|
14
|
+
types: {
|
|
15
|
+
context: {} as Context,
|
|
16
|
+
events: {} as Event,
|
|
17
|
+
},
|
|
18
|
+
actions: {
|
|
19
|
+
setEditDeploymentTarget: assign({
|
|
20
|
+
editDeploymentTarget: ({event}) => {
|
|
21
|
+
assertEvent(event, 'EDIT')
|
|
22
|
+
return event.deploymentTarget
|
|
26
23
|
},
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
24
|
+
}),
|
|
25
|
+
},
|
|
26
|
+
}).createMachine({
|
|
27
|
+
/** @xstate-layout N4IgpgJg5mDOIC5QAoC2BDAxgCwJYDswBKAOlwgBswBiAYQCUBRAQQBVGBtABgF1FQADgHtYuAC64h+fiAAeiAEwKArCQCcANgAcAdmUbNOhVx0BGLQBoQAT0SmAzApJcXXexoAsW5fbWaFAL4BVmhYeISk5FTUjAAiAJKs3HxIIMKiElIy8ghKqpq6+obGZpY2ivb2zq4e5moeXKZc3kEhGDgExCSQ4nQAMgDyAMqcvDLp4pLSqTn2DSQefn7uyq5aWvZWtgjmTqsuvnU6XMoK9q0goR0RJJgATmDoYjS0gyPJ4yKTWTOIc1wLJZqFZrDZbRBaUwkfZuew6SFcepuILBED4IQQOAyK7hYifDJTbKIAC0GnBCFJFxxnUilDA+O+01AOQ8CnJGxIGn29lMpjUxhcCh0VPauNIPTEDMyTLkiA8PhIxh5Cg8DS8pgM5L5UOalSMah0cP05hFYRptweT3pqQm0qJCHlVSVphVashmvKCDUAN17j0XNMqrUyhRASAA */
|
|
28
|
+
context: {
|
|
29
|
+
editDeploymentTarget: undefined,
|
|
30
|
+
},
|
|
31
|
+
initial: 'idle',
|
|
32
|
+
states: {
|
|
33
|
+
idle: {
|
|
34
|
+
entry: assign({
|
|
35
|
+
editDeploymentTarget: () => undefined,
|
|
36
|
+
}),
|
|
37
|
+
on: {
|
|
38
|
+
CREATE: {
|
|
39
|
+
target: 'create',
|
|
40
40
|
},
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
},
|
|
41
|
+
EDIT: {
|
|
42
|
+
actions: 'setEditDeploymentTarget',
|
|
43
|
+
target: 'edit',
|
|
45
44
|
},
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
edit: {
|
|
48
|
+
on: {
|
|
49
|
+
CLOSE: {
|
|
50
|
+
target: 'idle',
|
|
50
51
|
},
|
|
51
52
|
},
|
|
52
53
|
},
|
|
53
|
-
{
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
54
|
+
create: {
|
|
55
|
+
on: {
|
|
56
|
+
CLOSE: {
|
|
57
|
+
target: 'idle',
|
|
58
|
+
},
|
|
58
59
|
},
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
export default dialogMachine
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
})
|
package/src/machines/form.ts
CHANGED
|
@@ -1,110 +1,155 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {SanityClient} from 'sanity'
|
|
2
|
+
import {uuid} from '@sanity/uuid'
|
|
3
|
+
import {assertEvent, assign, fromPromise, setup} from 'xstate'
|
|
4
|
+
import type {Sanity} from '../types'
|
|
5
|
+
import {DEPLOYMENT_TARGET_DOCUMENT_TYPE} from '../constants'
|
|
2
6
|
|
|
3
7
|
type Context = {
|
|
8
|
+
client: SanityClient
|
|
9
|
+
document?: Sanity.DeploymentTarget
|
|
10
|
+
id?: string
|
|
4
11
|
formData?: Record<string, any>
|
|
5
12
|
message: string
|
|
6
13
|
}
|
|
7
14
|
|
|
8
15
|
type Event =
|
|
9
|
-
| {type: 'CREATE'}
|
|
10
|
-
| {type: '
|
|
11
|
-
| {type: '
|
|
12
|
-
| {type: 'RESOLVE'}
|
|
13
|
-
| {type: 'SUBMIT'}
|
|
14
|
-
| {type: 'UPDATE'}
|
|
16
|
+
| {type: 'CREATE'; formData: Record<string, any>}
|
|
17
|
+
| {type: 'UPDATE'; id: string; formData: Record<string, any>}
|
|
18
|
+
| {type: 'DELETE'; id: string}
|
|
15
19
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
idle: {}
|
|
19
|
-
creating: {}
|
|
20
|
-
updating: {}
|
|
21
|
-
deleting: {}
|
|
22
|
-
success: {}
|
|
23
|
-
error: {}
|
|
24
|
-
}
|
|
20
|
+
interface Input {
|
|
21
|
+
client: SanityClient
|
|
25
22
|
}
|
|
26
23
|
|
|
27
|
-
const formMachine =
|
|
28
|
-
{
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
},
|
|
45
|
-
UPDATE: {
|
|
46
|
-
actions: ['updateDocument'],
|
|
47
|
-
target: 'updating',
|
|
48
|
-
},
|
|
49
|
-
},
|
|
24
|
+
export const formMachine = setup({
|
|
25
|
+
types: {} as {
|
|
26
|
+
children: {
|
|
27
|
+
createDocumentActor: 'create document'
|
|
28
|
+
updateDocumentActor: 'update document'
|
|
29
|
+
deleteDocumentActor: 'delete document'
|
|
30
|
+
}
|
|
31
|
+
context: Context
|
|
32
|
+
events: Event
|
|
33
|
+
input: Input
|
|
34
|
+
tags: 'busy'
|
|
35
|
+
},
|
|
36
|
+
actions: {
|
|
37
|
+
setId: assign({
|
|
38
|
+
id: ({event}) => {
|
|
39
|
+
assertEvent(event, ['UPDATE', 'DELETE'])
|
|
40
|
+
return event.id
|
|
50
41
|
},
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
},
|
|
57
|
-
on: {
|
|
58
|
-
RESOLVE: 'success',
|
|
59
|
-
REJECT: 'error',
|
|
60
|
-
},
|
|
42
|
+
}),
|
|
43
|
+
setFormData: assign({
|
|
44
|
+
formData: ({event}) => {
|
|
45
|
+
assertEvent(event, ['CREATE', 'UPDATE'])
|
|
46
|
+
return event.formData
|
|
61
47
|
},
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
48
|
+
}),
|
|
49
|
+
setMessage: assign({
|
|
50
|
+
message: ({event}) => {
|
|
51
|
+
if (
|
|
52
|
+
'data' in event &&
|
|
53
|
+
event.data &&
|
|
54
|
+
typeof event.data === 'object' &&
|
|
55
|
+
'details' in event.data &&
|
|
56
|
+
event.data.details &&
|
|
57
|
+
typeof event.data.details === 'object' &&
|
|
58
|
+
'description' in event.data.details
|
|
59
|
+
) {
|
|
60
|
+
return event.data.details.description as string
|
|
61
|
+
}
|
|
62
|
+
return 'An error occurred'
|
|
63
|
+
},
|
|
64
|
+
}),
|
|
65
|
+
setDocument: assign({
|
|
66
|
+
document: ({event}) => {
|
|
67
|
+
// @ts-expect-error - fix typings later
|
|
68
|
+
return event.output
|
|
72
69
|
},
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
70
|
+
}),
|
|
71
|
+
},
|
|
72
|
+
actors: {
|
|
73
|
+
'create document': fromPromise(
|
|
74
|
+
({input}: {input: Required<Pick<Context, 'client' | 'formData'>>}) => {
|
|
75
|
+
return input.client.create({
|
|
76
|
+
_id: `vercel.${uuid()}`,
|
|
77
|
+
_type: DEPLOYMENT_TARGET_DOCUMENT_TYPE,
|
|
78
|
+
...input.formData,
|
|
79
|
+
})
|
|
80
|
+
}
|
|
81
|
+
),
|
|
82
|
+
'update document': fromPromise(
|
|
83
|
+
({input}: {input: Required<Pick<Context, 'client' | 'id' | 'formData'>>}) => {
|
|
84
|
+
return input.client.patch(input.id).set(input.formData).commit()
|
|
85
|
+
}
|
|
86
|
+
),
|
|
87
|
+
'delete document': fromPromise(({input}: {input: Required<Pick<Context, 'client' | 'id'>>}) => {
|
|
88
|
+
return input.client.delete(input.id)
|
|
89
|
+
}),
|
|
90
|
+
},
|
|
91
|
+
}).createMachine({
|
|
92
|
+
/** @xstate-layout N4IgpgJg5mDOIC5QAoC2BDAxgCwJYDswBKAOlwgBswBiAYQCUBRAQQBVGBtABgF1FQADgHtYuAC64h+fiAAeiAIwBmAGwkuGjQFYALAE4AHACYdWgwYA0IAJ6IjKgOwkdXFUYVa9h-Ua5KAvv5WaFh4hKTkVNQAqgAKACJsnLwywqISUjLyCMpqmtr6xqbmVrYIBgokWvlGWkpaCgZeKoHBGDgExGSUNPGMADKM7Nx8SCBp4pLSY9m56vm6hiZmljaIOipqdXpcDk1aWiYqBlqtICEd4SSYAE5g6BL4UNQQUmBk+ABuQgDW77f3MRgeJCTAAV1QYHwYmYmDEQhuI1SIkmmRmiGOShIDiUOh0SiaCgUegcDj0pTsjhI5iMewUpPsTSMZwuYS6AIeBGeYBuNwRJAEFAeADMEahrncHsDQRCoTC4QikWMJhlpqBspjsbj8YTiaTyWsEKouNT6noiX5zUpiQEgud2mzSGCBBBOU8Xm8Pt8-iRna6gSDwZDobD4YiUsqUaqshiDFicXiCea9WSKeVKiSVIclEYlIY-BUWQ7Ok6XW7ubz+YKRWLfWWAzLg-Kw0rBFGpjGEJqEzrkyTU4b6ToSHojHos7VXEc6kXQiWSBAwFRHs9XoQvb93ovl9Kg3LQ4qI230h30V241rE7r+wayro1A4dO4VHotA5fPTTnbWfPt2AV9QPJ8jcApCmIoo3OKf4NnuIYKuGozHqiapyLG8bakmRI3mmpjxk0XAuEoXAHI+DgtGc+BCIu8BjD+4TIieaLqogAC0Khpmxs6XF0kRgAxyGdk+aYKLSVR7Fweg6A4IkGFwChcY6EqAly-HRmeY7DnSY5GHGL4qFwRhpjpJpmriDjVMRLgGAp84ckCECqaezEIHoObUuZuwKH4xGPgoRnmCQpmOAcqhmPJ37Flcfrlo5TGoQgY4mgYHkeAS+iqH5hqSc4dSuCo+I6SoSjvjZUX1pAsUodkrlGO51TSd5b46JlZRebVuG7IcjRmA05FtHOVzQSpkaMVVdivs4CibHGxg6biSg4ZsJD2AccaFEVGwOKVXTQRVI0CWeNV1Z5jW+WmujDj4HjmMRnhEttpBAQilWdkdyX1V5RFNS1iAEpU1pHER9JWjogSBEAA */
|
|
93
|
+
context: ({input}) => ({
|
|
94
|
+
client: input.client,
|
|
95
|
+
formData: {},
|
|
96
|
+
message: '',
|
|
97
|
+
}),
|
|
98
|
+
initial: 'idle',
|
|
99
|
+
states: {
|
|
100
|
+
idle: {
|
|
101
|
+
on: {
|
|
102
|
+
CREATE: {
|
|
103
|
+
actions: ['setFormData'],
|
|
104
|
+
target: 'creating',
|
|
78
105
|
},
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
106
|
+
UPDATE: {
|
|
107
|
+
actions: ['setId', 'setFormData'],
|
|
108
|
+
target: 'updating',
|
|
82
109
|
},
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
src: 'formSubmittedService',
|
|
110
|
+
DELETE: {
|
|
111
|
+
actions: 'setId',
|
|
112
|
+
target: 'deleting',
|
|
87
113
|
},
|
|
88
114
|
},
|
|
89
|
-
error: {},
|
|
90
115
|
},
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
deleteDocument: assign(() => ({
|
|
101
|
-
// id: event.id,
|
|
102
|
-
})),
|
|
103
|
-
updateDocument: assign((_context, event: any) => ({
|
|
104
|
-
formData: event.formData,
|
|
105
|
-
})),
|
|
116
|
+
creating: {
|
|
117
|
+
tags: ['busy'],
|
|
118
|
+
invoke: {
|
|
119
|
+
src: 'create document',
|
|
120
|
+
id: 'createDocumentActor',
|
|
121
|
+
input: ({context}) => ({client: context.client, formData: context.formData!}),
|
|
122
|
+
onDone: {actions: 'setDocument', target: 'created'},
|
|
123
|
+
onError: {actions: 'setMessage', target: 'error'},
|
|
124
|
+
},
|
|
106
125
|
},
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
126
|
+
created: {type: 'final'},
|
|
127
|
+
updating: {
|
|
128
|
+
tags: ['busy'],
|
|
129
|
+
invoke: {
|
|
130
|
+
src: 'update document',
|
|
131
|
+
id: 'updateDocumentActor',
|
|
132
|
+
input: ({context}) => ({
|
|
133
|
+
client: context.client,
|
|
134
|
+
id: context.id!,
|
|
135
|
+
formData: context.formData!,
|
|
136
|
+
}),
|
|
137
|
+
onDone: {actions: 'setDocument', target: 'updated'},
|
|
138
|
+
onError: {actions: 'setMessage', target: 'error'},
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
updated: {type: 'final'},
|
|
142
|
+
deleting: {
|
|
143
|
+
tags: ['busy'],
|
|
144
|
+
invoke: {
|
|
145
|
+
src: 'delete document',
|
|
146
|
+
id: 'deleteDocumentActor',
|
|
147
|
+
input: ({context}) => ({client: context.client, id: context.id!}),
|
|
148
|
+
onDone: {target: 'deleted'},
|
|
149
|
+
onError: {actions: 'setMessage', target: 'error'},
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
deleted: {type: 'final'},
|
|
153
|
+
error: {type: 'final'},
|
|
154
|
+
},
|
|
155
|
+
})
|
package/src/machines/refresh.ts
CHANGED
|
@@ -1,40 +1,44 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
type Context = {}
|
|
1
|
+
import {setup} from 'xstate'
|
|
4
2
|
|
|
5
3
|
type Event = {type: 'ERROR'} | {type: 'REFRESH'} | {type: 'REFRESHED'} | {type: 'RETRY'}
|
|
6
4
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const refreshMachine = Machine<Context, Schema, Event>({
|
|
5
|
+
const refreshMachine = setup({
|
|
6
|
+
types: {
|
|
7
|
+
events: {} as Event,
|
|
8
|
+
},
|
|
9
|
+
}).createMachine({
|
|
10
|
+
/** @xstate-layout N4IgpgJg5mDOIC5QAoC2BDAxgCwJYDswBKAOlwgBswBiAJQFEAxBgZQAkBtABgF1FQADgHtYuAC64h+fiAAeiAIwAmAGwkuGrkoAsAZhVKlAVm0KAHABoQAT0QBOJSRN27XFXaMmz2twF9fVmhYeISkAE5gAGYRsCFQ1PS0tADytNx8SCDCohJSMvIIPnYkxhpKXGZ22kY6xla2CAq6CiQudgDsRnYqKroVfe3+gRg4BMQkEdFwcXRMrGz0ACLpMtniktKZBUUlRmUVVTXadTaISrqObUY97QodvWa6QyBBo6ETUTHYkLPM9OwrTJrXKbUDbJTFLjtMzmWraOx3doqeqKMyOeHdXp3BTHXTVZ6vELjMBhMJCMK-eaAwQidZ5LaIY6Q6Gw47wxHI04IGEkDFma5NbTtY7ufwBED4IQQOAyQljIirWkg-KIAC0nIa6oJIyJpHIVEVOQ2KsKShRCDsunUGLcHi8PhU2uC8o+U1iBCghrpoLkZ2uTk0XCq7SRRl0Zg19itXHhIZ85lMEaUTre40mX0gXuVDIQnmKRhZKk6PmaVXN2PUaLsZhj2hUOJU-JTupIJLJYSzxpzeacheLXFL2nNrkrfW8SKFnhDYt8QA */
|
|
17
11
|
initial: 'idle',
|
|
18
12
|
states: {
|
|
19
13
|
idle: {
|
|
20
14
|
on: {
|
|
21
|
-
REFRESH:
|
|
15
|
+
REFRESH: {
|
|
16
|
+
target: 'refreshing',
|
|
17
|
+
},
|
|
22
18
|
},
|
|
23
19
|
},
|
|
24
20
|
refreshing: {
|
|
25
21
|
on: {
|
|
26
|
-
ERROR:
|
|
27
|
-
|
|
22
|
+
ERROR: {
|
|
23
|
+
target: 'error',
|
|
24
|
+
},
|
|
25
|
+
REFRESHED: {
|
|
26
|
+
target: 'refreshed',
|
|
27
|
+
},
|
|
28
28
|
},
|
|
29
29
|
},
|
|
30
30
|
refreshed: {
|
|
31
31
|
on: {
|
|
32
|
-
REFRESH:
|
|
32
|
+
REFRESH: {
|
|
33
|
+
target: 'refreshing',
|
|
34
|
+
},
|
|
33
35
|
},
|
|
34
36
|
},
|
|
35
37
|
error: {
|
|
36
38
|
on: {
|
|
37
|
-
REFRESH:
|
|
39
|
+
REFRESH: {
|
|
40
|
+
target: 'refreshing',
|
|
41
|
+
},
|
|
38
42
|
},
|
|
39
43
|
},
|
|
40
44
|
},
|
package/src/utils/fetcher.ts
CHANGED