@@ -10,7 +10,6 @@ import { EntityRegistry } from "../../entity/database-entity.decorator";
1010import { ConfigService } from "../../config/config.service" ;
1111import { EntityMapperService } from "../../entity/entity-mapper/entity-mapper.service" ;
1212import { EntityActionsService } from "../../entity/entity-actions/entity-actions.service" ;
13- import { ViewConfig } from "../../config/dynamic-routing/view-config.interface" ;
1413import { EntityDetailsConfig } from "../../entity-details/EntityDetailsConfig" ;
1514import { EntityConfigService } from "../../entity/entity-config.service" ;
1615import { Config } from "../../config/config" ;
@@ -33,6 +32,7 @@ import { MatListItem, MatNavList } from "@angular/material/list";
3332import { AdminEntityDetailsComponent } from "../admin-entity-details/admin-entity-details/admin-entity-details.component" ;
3433import { AdminEntityGeneralSettingsComponent } from "./admin-entity-general-settings/admin-entity-general-settings.component" ;
3534import { BetaFeatureComponent } from "../../../features/coming-soon/beta-feature/beta-feature.component" ;
35+ import { DynamicComponentConfig } from "../../config/dynamic-components/dynamic-component-config.interface" ;
3636
3737@Component ( {
3838 selector : "app-admin-entity" ,
@@ -63,8 +63,8 @@ export class AdminEntityComponent implements OnInit {
6363 entityConstructor : EntityConstructor ;
6464 private originalEntitySchemaFields : [ string , EntitySchemaField ] [ ] ;
6565
66- configDetailsView : EntityDetailsConfig ;
67- configListView : EntityListConfig ;
66+ configDetailsView : DynamicComponentConfig < EntityDetailsConfig > ;
67+ configListView : DynamicComponentConfig < EntityListConfig > ;
6868 configEntitySettings : EntityConfig ;
6969 protected mode : "details" | "list" | "general" = "details" ;
7070
@@ -93,23 +93,43 @@ export class AdminEntityComponent implements OnInit {
9393 ) ;
9494
9595 this . configDetailsView = this . loadViewConfig (
96- EntityConfigService . getDetailsViewId ( this . entityConstructor ) ,
97- ) ?? { entityType : this . entityType , panels : [ ] } ;
98- this . configListView = this . loadViewConfig (
99- EntityConfigService . getListViewId ( this . entityConstructor ) ,
100- ) ?? { entityType : this . entityType } ;
96+ this . entityConstructor ,
97+ "details" ,
98+ ) ;
99+ this . configListView = this . loadViewConfig ( this . entityConstructor , "list" ) ;
100+
101101 this . configEntitySettings = this . entityConstructor ;
102102 }
103103
104- private loadViewConfig <
105- C = EntityDetailsConfig | EntityListConfig | undefined ,
106- > ( viewId : string ) : C | undefined {
107- const viewConfig : ViewConfig < C > = this . configService . getConfig ( viewId ) ;
104+ private loadViewConfig (
105+ entityType : EntityConstructor ,
106+ viewType : "details" | "list" ,
107+ ) : DynamicComponentConfig {
108+ const viewId =
109+ viewType === "details"
110+ ? EntityConfigService . getDetailsViewId ( entityType )
111+ : EntityConfigService . getListViewId ( entityType ) ;
112+ const viewConfig : DynamicComponentConfig =
113+ this . configService . getConfig ( viewId ) ;
114+
115+ if ( ! viewConfig ) {
116+ // return default view config
117+ if ( viewType === "details" ) {
118+ return {
119+ component : "EntityDetails" ,
120+ config : { entityType : this . entityType , panels : [ ] } ,
121+ } ;
122+ } else {
123+ return {
124+ component : "EntityList" ,
125+ config : { entityType : this . entityType } ,
126+ } ;
127+ }
128+ }
108129
130+ viewConfig . config = viewConfig . config ?? { entityType : this . entityType } ;
109131 // work on a deep copy as we are editing in place (for titles, sections, etc.)
110- return viewConfig ?. config
111- ? JSON . parse ( JSON . stringify ( viewConfig . config ) )
112- : undefined ;
132+ return JSON . parse ( JSON . stringify ( viewConfig ) ) ;
113133 }
114134
115135 cancel ( ) {
@@ -124,18 +144,11 @@ export class AdminEntityComponent implements OnInit {
124144 ) ;
125145 const newConfig = originalConfig . copy ( ) ;
126146
127- this . setViewConfig (
128- newConfig ,
129- EntityConfigService . getDetailsViewId ( this . entityConstructor ) ,
130- this . configDetailsView ,
131- "EntityDetails" ,
132- ) ;
133- this . setViewConfig (
134- newConfig ,
135- EntityConfigService . getListViewId ( this . entityConstructor ) ,
136- this . configListView ,
137- "EntityList" ,
138- ) ;
147+ newConfig . data [
148+ EntityConfigService . getDetailsViewId ( this . entityConstructor )
149+ ] = this . configDetailsView ;
150+ newConfig . data [ EntityConfigService . getListViewId ( this . entityConstructor ) ] =
151+ this . configListView ;
139152 this . setEntityConfig ( newConfig ) ;
140153
141154 await this . entityMapper . save ( newConfig ) ;
@@ -171,22 +184,4 @@ export class AdminEntityComponent implements OnInit {
171184 entitySchemaConfig . hasPII = this . configEntitySettings . hasPII ;
172185 }
173186 }
174-
175- private setViewConfig (
176- targetConfig ,
177- detailsViewId : string ,
178- viewConfig : EntityDetailsConfig | EntityListConfig ,
179- componentForNewConfig : string ,
180- ) {
181- if ( targetConfig . data [ detailsViewId ] ) {
182- targetConfig . data [ detailsViewId ] . config = viewConfig ;
183- } else {
184- // create new config
185- viewConfig . entityType = this . entityType ;
186- targetConfig . data [ detailsViewId ] = {
187- component : componentForNewConfig ,
188- config : viewConfig ,
189- } as ViewConfig < EntityDetailsConfig | EntityListConfig > ;
190- }
191- }
192187}
0 commit comments