diff --git a/projects/natural/src/lib/classes/abstract-detail.ts b/projects/natural/src/lib/classes/abstract-detail.ts index 4a9c4846..50d1c40f 100644 --- a/projects/natural/src/lib/classes/abstract-detail.ts +++ b/projects/natural/src/lib/classes/abstract-detail.ts @@ -11,6 +11,8 @@ import {ifValid, validateAllFormControls} from './validators'; import {PaginatedData} from './data-source'; import {QueryVariables} from './query-variable-manager'; import {CumulativeChanges} from './cumulative-changes'; +import {MAT_DIALOG_DATA} from '@angular/material/dialog'; +import {NaturalDialogTriggerProvidedData} from '../modules/dialog-trigger/dialog-trigger.component'; /** * `Data` contains in `model` either the model fetched from DB or default values (without ID). And besides `model`, @@ -18,6 +20,17 @@ import {CumulativeChanges} from './cumulative-changes'; */ type Data = {model: {id?: string} & ExtractResolve} & Extra; +function isNaturalDialogTriggerProvidedData( + dialogData: unknown, +): dialogData is NaturalDialogTriggerProvidedData { + return ( + !!dialogData && + typeof dialogData === 'object' && + 'activatedRoute' in dialogData && + dialogData.activatedRoute instanceof ActivatedRoute + ); +} + // @dynamic @Directive() export class NaturalAbstractDetail< @@ -78,6 +91,8 @@ export class NaturalAbstractDetail< */ protected readonly route = inject(ActivatedRoute); + #dialogData: unknown = inject(MAT_DIALOG_DATA, {optional: true}); + /** * Once set, this must not change anymore, especially not right after the creation mutation, * so the form does not switch from creation mode to update mode without an actual reload of @@ -97,7 +112,10 @@ export class NaturalAbstractDetail< if (this.isPanel) { this.initForm(); } else { - this.#subscribeToModelFromResolvedData(this.route); + const route = isNaturalDialogTriggerProvidedData(this.#dialogData) + ? this.#dialogData.activatedRoute + : this.route; + this.#subscribeToModelFromResolvedData(route); } }