@@ -130,39 +130,9 @@ export abstract class UmbEntityDetailWorkspaceContextBase<
130
130
}
131
131
132
132
if ( this . getIsNew ( ) ) {
133
- const parent = this . #parent. getValue ( ) ;
134
- if ( ! parent ) throw new Error ( 'Parent is not set' ) ;
135
- const { error, data } = await this . _detailRepository ! . create ( currentData , parent . unique ) ;
136
- if ( error || ! data ) {
137
- throw error ?. message ?? 'Repository did not return data after create.' ;
138
- }
139
-
140
- this . _data . setPersisted ( data ) ;
141
- this . _data . setCurrent ( data ) ;
142
-
143
- const eventContext = await this . getContext ( UMB_ACTION_EVENT_CONTEXT ) ;
144
- const event = new UmbRequestReloadChildrenOfEntityEvent ( {
145
- entityType : parent . entityType ,
146
- unique : parent . unique ,
147
- } ) ;
148
- eventContext . dispatchEvent ( event ) ;
149
- this . setIsNew ( false ) ;
133
+ this . #create( currentData ) ;
150
134
} else {
151
- const { error, data } = await this . _detailRepository ! . save ( currentData ) ;
152
- if ( error || ! data ) {
153
- throw error ?. message ?? 'Repository did not return data after create.' ;
154
- }
155
-
156
- this . _data . setPersisted ( data ) ;
157
- this . _data . setCurrent ( data ) ;
158
-
159
- const actionEventContext = await this . getContext ( UMB_ACTION_EVENT_CONTEXT ) ;
160
- const event = new UmbRequestReloadStructureForEntityEvent ( {
161
- unique : this . getUnique ( ) ! ,
162
- entityType : this . getEntityType ( ) ,
163
- } ) ;
164
-
165
- actionEventContext . dispatchEvent ( event ) ;
135
+ this . #update( currentData ) ;
166
136
}
167
137
}
168
138
@@ -184,6 +154,44 @@ export abstract class UmbEntityDetailWorkspaceContextBase<
184
154
return ! newUrl . includes ( currentWorkspacePathIdentifier ) ;
185
155
}
186
156
157
+ async #create( currentData : DetailModelType ) {
158
+ const parent = this . #parent. getValue ( ) ;
159
+ if ( ! parent ) throw new Error ( 'Parent is not set' ) ;
160
+ const { error, data } = await this . _detailRepository ! . create ( currentData , parent . unique ) ;
161
+ if ( error || ! data ) {
162
+ throw error ?. message ?? 'Repository did not return data after create.' ;
163
+ }
164
+
165
+ this . _data . setPersisted ( data ) ;
166
+ this . _data . setCurrent ( data ) ;
167
+
168
+ const eventContext = await this . getContext ( UMB_ACTION_EVENT_CONTEXT ) ;
169
+ const event = new UmbRequestReloadChildrenOfEntityEvent ( {
170
+ entityType : parent . entityType ,
171
+ unique : parent . unique ,
172
+ } ) ;
173
+ eventContext . dispatchEvent ( event ) ;
174
+ this . setIsNew ( false ) ;
175
+ }
176
+
177
+ async #update( currentData : DetailModelType ) {
178
+ const { error, data } = await this . _detailRepository ! . save ( currentData ) ;
179
+ if ( error || ! data ) {
180
+ throw error ?. message ?? 'Repository did not return data after create.' ;
181
+ }
182
+
183
+ this . _data . setPersisted ( data ) ;
184
+ this . _data . setCurrent ( data ) ;
185
+
186
+ const actionEventContext = await this . getContext ( UMB_ACTION_EVENT_CONTEXT ) ;
187
+ const event = new UmbRequestReloadStructureForEntityEvent ( {
188
+ unique : this . getUnique ( ) ! ,
189
+ entityType : this . getEntityType ( ) ,
190
+ } ) ;
191
+
192
+ actionEventContext . dispatchEvent ( event ) ;
193
+ }
194
+
187
195
#onWillNavigate = async ( e : CustomEvent ) => {
188
196
const newUrl = e . detail . url ;
189
197
0 commit comments