UI: Add lazy-load rulechain page components

This commit is contained in:
Vladyslav_Prykhodko 2025-01-09 13:04:40 +02:00
parent f57d46af37
commit 0de0479177
7 changed files with 89 additions and 44 deletions

View File

@ -53,6 +53,7 @@ export class RuleChainService {
private ruleNodeComponentsMap: Map<RuleChainType, Array<RuleNodeComponentDescriptor>> = private ruleNodeComponentsMap: Map<RuleChainType, Array<RuleNodeComponentDescriptor>> =
new Map<RuleChainType, Array<RuleNodeComponentDescriptor>>(); new Map<RuleChainType, Array<RuleNodeComponentDescriptor>>();
private ruleNodeConfigComponents: {[directive: string]: Type<IRuleNodeConfigurationComponent>} = {}; private ruleNodeConfigComponents: {[directive: string]: Type<IRuleNodeConfigurationComponent>} = {};
private systemRuleNodeConfigComponents: {[directive: string]: Type<IRuleNodeConfigurationComponent>} = {};
constructor( constructor(
private http: HttpClient, private http: HttpClient,
@ -128,7 +129,10 @@ export class RuleChainService {
} }
} }
public getRuleNodeConfigComponent(directive: string): Type<IRuleNodeConfigurationComponent> { public getRuleNodeConfigComponent(directive: string, isSystemComponent = false): Type<IRuleNodeConfigurationComponent> {
if (isSystemComponent) {
return this.systemRuleNodeConfigComponents[directive];
}
return this.ruleNodeConfigComponents[directive]; return this.ruleNodeConfigComponents[directive];
} }
@ -180,6 +184,10 @@ export class RuleChainService {
return this.http.post<TestScriptResult>(url, inputParams, defaultHttpOptionsFromConfig(config)); return this.http.post<TestScriptResult>(url, inputParams, defaultHttpOptionsFromConfig(config));
} }
public registemSystemRuleNodeConfigComponent(componentMap: Record<string, Type<IRuleNodeConfigurationComponent>>) {
this.systemRuleNodeConfigComponents = componentMap;
}
private loadRuleNodeComponents(ruleChainType: RuleChainType, config?: RequestConfig): Observable<Array<RuleNodeComponentDescriptor>> { private loadRuleNodeComponents(ruleChainType: RuleChainType, config?: RequestConfig): Observable<Array<RuleNodeComponentDescriptor>> {
return this.componentDescriptorService.getComponentDescriptorsByTypes(ruleNodeTypeComponentTypes, ruleChainType, config).pipe( return this.componentDescriptorService.getComponentDescriptorsByTypes(ruleNodeTypeComponentTypes, ruleChainType, config).pipe(
map((components) => { map((components) => {

View File

@ -43,6 +43,7 @@ import {
FlowRuleNodeConfigModule FlowRuleNodeConfigModule
} from '@home/components/rule-node/flow/flow-rule-node-config.module'; } from '@home/components/rule-node/flow/flow-rule-node-config.module';
import { IRuleNodeConfigurationComponent } from '@shared/models/rule-node.models'; import { IRuleNodeConfigurationComponent } from '@shared/models/rule-node.models';
import { RuleChainService } from '@core/http/rule-chain.service';
@NgModule({ @NgModule({
declarations: [ declarations: [
@ -62,14 +63,17 @@ import { IRuleNodeConfigurationComponent } from '@shared/models/rule-node.models
EmptyConfigComponent EmptyConfigComponent
] ]
}) })
export class RuleNodeConfigModule {} export class RuleNodeConfigModule {
constructor(private ruleChainService: RuleChainService) {
export const ruleNodeConfigComponentsMap: Record<string, Type<IRuleNodeConfigurationComponent>> = { const ruleNodeConfigComponentsMap: Record<string, Type<IRuleNodeConfigurationComponent>> = {
...actionRuleNodeConfigComponentsMap, ...actionRuleNodeConfigComponentsMap,
...enrichmentRuleNodeConfigComponentsMap, ...enrichmentRuleNodeConfigComponentsMap,
...externalRuleNodeConfigComponentsMap, ...externalRuleNodeConfigComponentsMap,
...filterRuleNodeConfigComponentsMap, ...filterRuleNodeConfigComponentsMap,
...flowRuleNodeConfigComponentsMap, ...flowRuleNodeConfigComponentsMap,
...transformationRuleNodeConfigComponentsMap, ...transformationRuleNodeConfigComponentsMap,
'tbNodeEmptyConfig': EmptyConfigComponent 'tbNodeEmptyConfig': EmptyConfigComponent
}; };
this.ruleChainService.registemSystemRuleNodeConfigComponent(ruleNodeConfigComponentsMap);
}
}

View File

@ -291,6 +291,7 @@ const routes: Routes = [
import: false, import: false,
ruleChainType: RuleChainType.EDGE ruleChainType: RuleChainType.EDGE
}, },
loadChildren: () => import('../rulechain/rulechain-page.module').then(m => m.RuleChainPageModule),
resolve: { resolve: {
ruleChain: RuleChainResolver, ruleChain: RuleChainResolver,
ruleChainMetaData: RuleChainMetaDataResolver, ruleChainMetaData: RuleChainMetaDataResolver,
@ -336,6 +337,7 @@ const routes: Routes = [
import: false, import: false,
ruleChainType: RuleChainType.EDGE ruleChainType: RuleChainType.EDGE
}, },
loadChildren: () => import('../rulechain/rulechain-page.module').then(m => m.RuleChainPageModule),
resolve: { resolve: {
ruleChain: RuleChainResolver, ruleChain: RuleChainResolver,
ruleChainMetaData: RuleChainMetaDataResolver, ruleChainMetaData: RuleChainMetaDataResolver,
@ -358,6 +360,7 @@ const routes: Routes = [
import: true, import: true,
ruleChainType: RuleChainType.EDGE ruleChainType: RuleChainType.EDGE
}, },
loadChildren: () => import('../rulechain/rulechain-page.module').then(m => m.RuleChainPageModule),
resolve: { resolve: {
ruleNodeComponents: RuleNodeComponentsResolver, ruleNodeComponents: RuleNodeComponentsResolver,
tooltipster: TooltipsterResolver tooltipster: TooltipsterResolver

View File

@ -21,7 +21,7 @@ import {
forwardRef, forwardRef,
Input, Input,
OnDestroy, OnDestroy,
Output, Type, Output,
ViewChild, ViewChild,
ViewContainerRef ViewContainerRef
} from '@angular/core'; } from '@angular/core';
@ -43,7 +43,6 @@ import { coerceBooleanProperty } from '@angular/cdk/coercion';
import { JsonObjectEditComponent } from '@shared/components/json-object-edit.component'; import { JsonObjectEditComponent } from '@shared/components/json-object-edit.component';
import { deepClone } from '@core/utils'; import { deepClone } from '@core/utils';
import { RuleChainType } from '@shared/models/rule-chain.models'; import { RuleChainType } from '@shared/models/rule-chain.models';
import { ruleNodeConfigComponentsMap } from '@home/components/rule-node/rule-node-config.module';
@Component({ @Component({
selector: 'tb-rule-node-config', selector: 'tb-rule-node-config',
@ -213,12 +212,7 @@ export class RuleNodeConfigComponent implements ControlValueAccessor, OnDestroy
this.changeScriptSubscription = null; this.changeScriptSubscription = null;
} }
this.definedConfigContainer.clear(); this.definedConfigContainer.clear();
let component: Type<IRuleNodeConfigurationComponent>; const component = this.ruleChainService.getRuleNodeConfigComponent(this.nodeDefinition.configDirective, !this.nodeDefinition.uiResources?.length);
if (!this.nodeDefinition.uiResources?.length) {
component = ruleNodeConfigComponentsMap[this.nodeDefinition.configDirective];
} else {
component = this.ruleChainService.getRuleNodeConfigComponent(this.nodeDefinition.configDirective);
}
this.definedConfigComponentRef = this.definedConfigContainer.createComponent(component); this.definedConfigComponentRef = this.definedConfigContainer.createComponent(component);
this.definedConfigComponent = this.definedConfigComponentRef.instance; this.definedConfigComponent = this.definedConfigComponentRef.instance;
this.definedConfigComponent.ruleNodeId = this.ruleNodeId; this.definedConfigComponent.ruleNodeId = this.ruleNodeId;

View File

@ -0,0 +1,57 @@
///
/// Copyright © 2016-2024 The Thingsboard Authors
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
/// http://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
///
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { SharedModule } from '@shared/shared.module';
import { HomeComponentsModule } from '@home/components/home-components.module';
import { DurationLeftPipe } from '@shared/pipe/duration-left.pipe';
import {
EntityDebugSettingsButtonComponent
} from '@home/components/entity/debug/entity-debug-settings-button.component';
import { RuleNodeConfigModule } from '@home/components/rule-node/rule-node-config.module';
import {
AddRuleNodeDialogComponent,
AddRuleNodeLinkDialogComponent,
CreateNestedRuleChainDialogComponent,
RuleChainPageComponent
} from '@home/pages/rulechain/rulechain-page.component';
import { RuleNodeDetailsComponent } from '@home/pages/rulechain/rule-node-details.component';
import { RuleNodeConfigComponent } from '@home/pages/rulechain/rule-node-config.component';
import { LinkLabelsComponent } from '@home/pages/rulechain/link-labels.component';
import { RuleNodeLinkComponent } from '@home/pages/rulechain/rule-node-link.component';
@NgModule({
declarations: [
RuleChainPageComponent,
RuleNodeDetailsComponent,
LinkLabelsComponent,
RuleNodeLinkComponent,
RuleNodeConfigComponent,
AddRuleNodeLinkDialogComponent,
AddRuleNodeDialogComponent,
CreateNestedRuleChainDialogComponent
],
imports: [
CommonModule,
SharedModule,
DurationLeftPipe,
EntityDebugSettingsButtonComponent,
RuleNodeConfigModule,
HomeComponentsModule,
]
})
export class RuleChainPageModule {}

View File

@ -148,6 +148,7 @@ const routes: Routes = [
import: false, import: false,
ruleChainType: RuleChainType.CORE ruleChainType: RuleChainType.CORE
}, },
loadChildren: () => import('./rulechain-page.module').then(m => m.RuleChainPageModule),
resolve: { resolve: {
ruleChain: RuleChainResolver, ruleChain: RuleChainResolver,
ruleChainMetaData: RuleChainMetaDataResolver, ruleChainMetaData: RuleChainMetaDataResolver,
@ -170,6 +171,7 @@ const routes: Routes = [
import: true, import: true,
ruleChainType: RuleChainType.CORE ruleChainType: RuleChainType.CORE
}, },
loadChildren: () => import('./rulechain-page.module').then(m => m.RuleChainPageModule),
resolve: { resolve: {
ruleNodeComponents: RuleNodeComponentsResolver, ruleNodeComponents: RuleNodeComponentsResolver,
tooltipster: TooltipsterResolver tooltipster: TooltipsterResolver

View File

@ -21,34 +21,14 @@ import { RuleChainComponent } from '@modules/home/pages/rulechain/rulechain.comp
import { RuleChainRoutingModule } from '@modules/home/pages/rulechain/rulechain-routing.module'; import { RuleChainRoutingModule } from '@modules/home/pages/rulechain/rulechain-routing.module';
import { HomeComponentsModule } from '@modules/home/components/home-components.module'; import { HomeComponentsModule } from '@modules/home/components/home-components.module';
import { RuleChainTabsComponent } from '@home/pages/rulechain/rulechain-tabs.component'; import { RuleChainTabsComponent } from '@home/pages/rulechain/rulechain-tabs.component';
import {
AddRuleNodeDialogComponent,
AddRuleNodeLinkDialogComponent, CreateNestedRuleChainDialogComponent,
RuleChainPageComponent
} from './rulechain-page.component';
import { RuleNodeComponent } from '@home/pages/rulechain/rulenode.component'; import { RuleNodeComponent } from '@home/pages/rulechain/rulenode.component';
import { FC_NODE_COMPONENT_CONFIG } from 'ngx-flowchart'; import { FC_NODE_COMPONENT_CONFIG } from 'ngx-flowchart';
import { RuleNodeDetailsComponent } from './rule-node-details.component';
import { RuleNodeLinkComponent } from './rule-node-link.component';
import { LinkLabelsComponent } from '@home/pages/rulechain/link-labels.component';
import { RuleNodeConfigComponent } from './rule-node-config.component';
import { DurationLeftPipe } from '@shared/pipe/duration-left.pipe';
import { EntityDebugSettingsButtonComponent } from '@home/components/entity/debug/entity-debug-settings-button.component';
import { RuleNodeConfigModule } from '@home/components/rule-node/rule-node-config.module';
@NgModule({ @NgModule({
declarations: [ declarations: [
RuleChainComponent, RuleChainComponent,
RuleChainTabsComponent, RuleChainTabsComponent,
RuleChainPageComponent,
RuleNodeComponent, RuleNodeComponent,
RuleNodeDetailsComponent,
RuleNodeConfigComponent,
LinkLabelsComponent,
RuleNodeLinkComponent,
AddRuleNodeLinkDialogComponent,
AddRuleNodeDialogComponent,
CreateNestedRuleChainDialogComponent
], ],
providers: [ providers: [
{ {
@ -56,16 +36,13 @@ import { RuleNodeConfigModule } from '@home/components/rule-node/rule-node-confi
useValue: { useValue: {
nodeComponentType: RuleNodeComponent nodeComponentType: RuleNodeComponent
} }
} },
], ],
imports: [ imports: [
CommonModule, CommonModule,
SharedModule, SharedModule,
HomeComponentsModule, HomeComponentsModule,
RuleChainRoutingModule, RuleChainRoutingModule,
DurationLeftPipe,
EntityDebugSettingsButtonComponent,
RuleNodeConfigModule,
] ]
}) })
export class RuleChainModule { } export class RuleChainModule { }