@@ -396,42 +396,57 @@ export class UmbDocumentBlueprintWorkspaceContext
396
396
this . #data. finishPropertyValueChange ( ) ;
397
397
} ;
398
398
399
- async #createOrSave ( ) {
399
+ async #handleSave ( ) {
400
400
const current = this . #data. getCurrent ( ) ;
401
401
if ( ! current ?. unique ) throw new Error ( 'Unique is missing' ) ;
402
402
403
403
if ( this . getIsNew ( ) ) {
404
404
const parent = this . #parent. getValue ( ) ;
405
405
if ( ! parent ) throw new Error ( 'Parent is not set' ) ;
406
406
407
- if ( ( await this . repository . create ( current , parent . unique ) ) . data !== undefined ) {
408
- this . setIsNew ( false ) ;
409
-
410
- // TODO: this might not be the right place to alert the tree, but it works for now
411
- const eventContext = await this . getContext ( UMB_ACTION_EVENT_CONTEXT ) ;
412
- const event = new UmbRequestReloadChildrenOfEntityEvent ( {
413
- entityType : parent . entityType ,
414
- unique : parent . unique ,
415
- } ) ;
416
- eventContext . dispatchEvent ( event ) ;
407
+ const { data, error } = await this . repository . create ( current , parent . unique ) ;
408
+ if ( ! data || error ) {
409
+ console . error ( 'Error creating document' , error ) ;
410
+ throw new Error ( 'Error creating document' ) ;
417
411
}
412
+
413
+ this . setIsNew ( false ) ;
414
+ this . #data. setPersisted ( data ) ;
415
+ // We do not know about the variant IDs, so lets update everything.
416
+ this . #data. setCurrent ( data ) ;
417
+
418
+ const eventContext = await this . getContext ( UMB_ACTION_EVENT_CONTEXT ) ;
419
+ const event = new UmbRequestReloadChildrenOfEntityEvent ( {
420
+ entityType : parent . entityType ,
421
+ unique : parent . unique ,
422
+ } ) ;
423
+ eventContext . dispatchEvent ( event ) ;
418
424
} else {
419
- await this . repository . save ( current ) ;
425
+ // Save:
426
+ const { data, error } = await this . repository . save ( current ) ;
427
+ if ( ! data || error ) {
428
+ console . error ( 'Error saving document' , error ) ;
429
+ throw new Error ( 'Error saving document' ) ;
430
+ }
431
+
432
+ this . #data. setPersisted ( data ) ;
433
+ // We do not know about the variant IDs, so lets update everything.
434
+ this . #data. setCurrent ( data ) ;
420
435
421
- const actionEventContext = await this . getContext ( UMB_ACTION_EVENT_CONTEXT ) ;
436
+ const eventContext = await this . getContext ( UMB_ACTION_EVENT_CONTEXT ) ;
422
437
const event = new UmbRequestReloadStructureForEntityEvent ( {
423
438
unique : this . getUnique ( ) ! ,
424
439
entityType : this . getEntityType ( ) ,
425
440
} ) ;
426
441
427
- actionEventContext . dispatchEvent ( event ) ;
442
+ eventContext . dispatchEvent ( event ) ;
428
443
}
429
444
}
430
445
431
446
async submit ( ) {
432
447
const data = this . getData ( ) ;
433
448
if ( ! data ) throw new Error ( 'Data is missing' ) ;
434
- await this . #createOrSave ( ) ;
449
+ await this . #handleSave ( ) ;
435
450
}
436
451
437
452
async delete ( ) {
@@ -451,6 +466,7 @@ export class UmbDocumentBlueprintWorkspaceContext
451
466
public override destroy ( ) : void {
452
467
this . #data. destroy ( ) ;
453
468
this . structure . destroy ( ) ;
469
+ this . #languageRepository. destroy ( ) ;
454
470
super . destroy ( ) ;
455
471
}
456
472
}
0 commit comments