@@ -2,6 +2,7 @@ import { getDraftSpecsByDraftId } from 'api/draftSpecs';
2
2
import {
3
3
getLiveSpecsById_writesTo ,
4
4
getLiveSpecsByLiveSpecId ,
5
+ getSchema_Resource ,
5
6
} from 'api/hydration' ;
6
7
import { GlobalSearchParams } from 'hooks/searchParams/useGlobalSearchParams' ;
7
8
import produce from 'immer' ;
@@ -11,6 +12,7 @@ import {
11
12
getStoreWithHydrationSettings ,
12
13
} from 'stores/extensions/Hydration' ;
13
14
import { BindingStoreNames } from 'stores/names' ;
15
+ import { Schema } from 'types' ;
14
16
import { hasLength } from 'utils/misc-utils' ;
15
17
import { devtoolsOptions } from 'utils/store-utils' ;
16
18
import { getCollectionName } from 'utils/workflow-utils' ;
@@ -34,41 +36,23 @@ const getInitialBindingData = (): Pick<BindingState, 'bindings'> => ({
34
36
bindings : { } ,
35
37
} ) ;
36
38
37
- const getInitialStateData = ( ) => ( {
39
+ const getInitialStateData = ( ) : Pick < BindingState , 'resourceSchema' > => ( {
40
+ resourceSchema : { } ,
41
+ } ) ;
42
+
43
+ const getInitialStoreData = ( ) => ( {
38
44
...getInitialBindingData ( ) ,
45
+ ...getInitialStateData ( ) ,
39
46
...getInitialHydrationData ( ) ,
40
47
} ) ;
41
48
42
49
const getInitialState = (
43
50
set : NamedSet < BindingState > ,
44
51
get : StoreApi < BindingState > [ 'getState' ]
45
52
) : BindingState => ( {
46
- ...getInitialStateData ( ) ,
53
+ ...getInitialStoreData ( ) ,
47
54
...getStoreWithHydrationSettings ( STORE_KEY , set ) ,
48
55
49
- prefillBindingDependentState : ( bindings , _referenceBindings ) => {
50
- set (
51
- produce ( ( state : BindingState ) => {
52
- bindings . forEach ( ( binding ) => {
53
- const collection = getCollectionName ( binding ) ;
54
- const UUID = crypto . randomUUID ( ) ;
55
-
56
- const existingBindingIds : string [ ] = Object . hasOwn (
57
- state . bindings ,
58
- collection
59
- )
60
- ? state . bindings [ collection ]
61
- : [ ] ;
62
-
63
- state . bindings [ collection ] =
64
- existingBindingIds . concat ( UUID ) ;
65
- } ) ;
66
- } ) ,
67
- false ,
68
- 'Binding dependent state prefilled'
69
- ) ;
70
- } ,
71
-
72
56
addEmptyBindings : ( data , rehydrating ) => {
73
57
set (
74
58
produce ( ( state : BindingState ) => {
@@ -117,7 +101,7 @@ const getInitialState = (
117
101
118
102
hydrateState : async ( editWorkflow , entityType , rehydrating ) => {
119
103
const searchParams = new URLSearchParams ( window . location . search ) ;
120
- // const connectorId = searchParams.get(GlobalSearchParams.CONNECTOR_ID);
104
+ const connectorId = searchParams . get ( GlobalSearchParams . CONNECTOR_ID ) ;
121
105
const draftId = searchParams . get ( GlobalSearchParams . DRAFT_ID ) ;
122
106
const liveSpecIds = searchParams . getAll (
123
107
GlobalSearchParams . LIVE_SPEC_ID
@@ -134,19 +118,19 @@ const getInitialState = (
134
118
135
119
// resetState(materializationRehydrating);
136
120
137
- // if (connectorId) {
138
- // const { data, error } = await getSchema_Resource(connectorId);
121
+ if ( connectorId ) {
122
+ const { data, error } = await getSchema_Resource ( connectorId ) ;
139
123
140
- // if (error) {
141
- // setHydrationErrorsExist(true);
142
- // } else if (data && data.length > 0) {
143
- // const { setResourceSchema } = get();
124
+ if ( error ) {
125
+ setHydrationErrorsExist ( true ) ;
126
+ } else if ( data && data . length > 0 ) {
127
+ const { setResourceSchema } = get ( ) ;
144
128
145
- // setResourceSchema(
146
- // data[0].resource_spec_schema as unknown as Schema
147
- // );
148
- // }
149
- // }
129
+ setResourceSchema (
130
+ data [ 0 ] . resource_spec_schema as unknown as Schema
131
+ ) ;
132
+ }
133
+ }
150
134
151
135
if ( editWorkflow && liveSpecIds . length > 0 ) {
152
136
const { data : liveSpecs , error : liveSpecError } =
@@ -203,12 +187,35 @@ const getInitialState = (
203
187
return Promise . resolve ( null ) ;
204
188
} ,
205
189
190
+ prefillBindingDependentState : ( bindings , _referenceBindings ) => {
191
+ set (
192
+ produce ( ( state : BindingState ) => {
193
+ bindings . forEach ( ( binding ) => {
194
+ const collection = getCollectionName ( binding ) ;
195
+ const UUID = crypto . randomUUID ( ) ;
196
+
197
+ const existingBindingIds : string [ ] = Object . hasOwn (
198
+ state . bindings ,
199
+ collection
200
+ )
201
+ ? state . bindings [ collection ]
202
+ : [ ] ;
203
+
204
+ state . bindings [ collection ] =
205
+ existingBindingIds . concat ( UUID ) ;
206
+ } ) ;
207
+ } ) ,
208
+ false ,
209
+ 'Binding dependent state prefilled'
210
+ ) ;
211
+ } ,
212
+
206
213
resetState : ( keepCollections ) => {
207
214
const currentState = get ( ) ;
208
215
209
216
const initState = keepCollections
210
217
? getInitialBindingData ( )
211
- : getInitialStateData ( ) ;
218
+ : getInitialStoreData ( ) ;
212
219
213
220
const newState = {
214
221
...currentState ,
@@ -217,6 +224,16 @@ const getInitialState = (
217
224
218
225
set ( newState , false , 'Binding State Reset' ) ;
219
226
} ,
227
+
228
+ setResourceSchema : ( value ) => {
229
+ set (
230
+ produce ( ( state : BindingState ) => {
231
+ state . resourceSchema = value ;
232
+ } ) ,
233
+ false ,
234
+ 'Resource Schema Set'
235
+ ) ;
236
+ } ,
220
237
} ) ;
221
238
222
239
export const bindingStore = create < BindingState > ( ) (
0 commit comments