From 4cc01d58c057fc36abcff7da9c52e1cd6a439b06 Mon Sep 17 00:00:00 2001 From: Vladyslav_Prykhodko Date: Tue, 14 Jan 2025 12:43:47 +0200 Subject: [PATCH] UI: Remove rule node config map; Add new function extractComponentsFromModule --- .../src/app/core/http/rule-chain.service.ts | 4 +- .../app/core/services/resources.service.ts | 38 +++++++++++++++++- .../action/action-rule-node-config.module.ts | 26 ------------ .../enrichment-rule-node-core.module.ts | 13 ------ .../external-rule-node-config.module.ts | 16 -------- .../filter/filter-rule-node-config.module.ts | 11 ----- .../flow/flow-rule-node-config.module.ts | 5 --- .../rule-node/rule-node-config.module.ts | 40 ++++--------------- .../transformation-rule-node-config.module.ts | 11 ----- 9 files changed, 45 insertions(+), 119 deletions(-) diff --git a/ui-ngx/src/app/core/http/rule-chain.service.ts b/ui-ngx/src/app/core/http/rule-chain.service.ts index 37a9f8c1af..88bc4286dc 100644 --- a/ui-ngx/src/app/core/http/rule-chain.service.ts +++ b/ui-ngx/src/app/core/http/rule-chain.service.ts @@ -184,8 +184,8 @@ export class RuleChainService { return this.http.post(url, inputParams, defaultHttpOptionsFromConfig(config)); } - public registemSystemRuleNodeConfigComponent(componentMap: Record>) { - this.systemRuleNodeConfigComponents = componentMap; + public registerSystemRuleNodeConfigModule(module: any) { + this.systemRuleNodeConfigComponents = this.resourcesService.extractComponentsFromModule(module, true); } private loadRuleNodeComponents(ruleChainType: RuleChainType, config?: RequestConfig): Observable> { diff --git a/ui-ngx/src/app/core/services/resources.service.ts b/ui-ngx/src/app/core/services/resources.service.ts index f5cba07a47..38bb343aae 100644 --- a/ui-ngx/src/app/core/services/resources.service.ts +++ b/ui-ngx/src/app/core/services/resources.service.ts @@ -31,7 +31,7 @@ import { forkJoin, from, Observable, ReplaySubject, throwError } from 'rxjs'; import { HttpClient } from '@angular/common/http'; import { IModulesMap } from '@modules/common/modules-map.models'; import { TbResourceId } from '@shared/models/id/tb-resource-id'; -import { isObject } from '@core/utils'; +import { camelCase, isObject } from '@core/utils'; import { AuthService } from '@core/auth/auth.service'; import { select, Store } from '@ngrx/store'; import { selectIsAuthenticated } from '@core/auth/auth.selectors'; @@ -51,6 +51,8 @@ export interface ModulesWithComponents { standaloneComponents: ɵComponentDef[]; } +export type ComponentsSelectorMap = Record>; + export const flatModulesWithComponents = (modulesWithComponentsList: ModulesWithComponents[]): ModulesWithComponents => { const modulesWithComponents: ModulesWithComponents = { modules: [], @@ -91,6 +93,17 @@ export const componentTypeBySelector = (modulesWithComponents: ModulesWithCompon const matchesSelector = (selectors: ɵCssSelectorList, selector: string) => selectors.some(s => s.some(s1 => typeof s1 === 'string' && s1 === selector)); +const extractSelectorFromComponent = (comp: ɵComponentDef): string => { + for (const selectors of comp.selectors) { + for (const selector of selectors) { + if (typeof selector === 'string') { + return selector; + } + } + } + return null; +} + @Injectable({ providedIn: 'root' }) @@ -252,6 +265,27 @@ export class ResourcesService { ); } + public extractComponentsFromModule(module: any, isCamelCaseSelector = false): ComponentsSelectorMap { + const modulesWithComponents = this.extractModulesWithComponents(module); + const componentMap = {}; + + const processComponents = (components: Array<ɵComponentDef>) => { + components.forEach(item => { + let selector = extractSelectorFromComponent(item); + if (isCamelCaseSelector) { + selector = camelCase(selector); + } + componentMap[selector] = item.type; + }); + }; + + processComponents(modulesWithComponents.standaloneComponents); + + modulesWithComponents.modules.forEach(module => { + processComponents(module.components); + }) + return componentMap; + } private extractModulesWithComponents(module: any, modulesWithComponents: ModulesWithComponents = { @@ -284,7 +318,7 @@ export class ResourcesService { modulesWithComponents.standaloneComponents.push(component); } } else { - this.extractModulesWithComponents(module, modulesWithComponents, visitedModules); + this.extractModulesWithComponents(element, modulesWithComponents, visitedModules); } } } else if (ɵNG_COMP_DEF in module) { diff --git a/ui-ngx/src/app/modules/home/components/rule-node/action/action-rule-node-config.module.ts b/ui-ngx/src/app/modules/home/components/rule-node/action/action-rule-node-config.module.ts index 3e78ee4c46..17307cb341 100644 --- a/ui-ngx/src/app/modules/home/components/rule-node/action/action-rule-node-config.module.ts +++ b/ui-ngx/src/app/modules/home/components/rule-node/action/action-rule-node-config.module.ts @@ -103,29 +103,3 @@ import { SendRestApiCallReplyConfigComponent } from './send-rest-api-call-reply- }) export class ActionRuleNodeConfigModule { } - -export const actionRuleNodeConfigComponentsMap: Record> = { - 'tbActionNodeAssignToCustomerConfig': AssignCustomerConfigComponent, - 'tbActionNodeAttributesConfig': AttributesConfigComponent, - 'tbActionNodeClearAlarmConfig': ClearAlarmConfigComponent, - 'tbActionNodeCreateAlarmConfig': CreateAlarmConfigComponent, - 'tbActionNodeCreateRelationConfig': CreateRelationConfigComponent, - 'tbActionNodeDeleteAttributesConfig': DeleteAttributesConfigComponent, - 'tbActionNodeDeleteRelationConfig': DeleteRelationConfigComponent, - 'tbActionNodeDeviceProfileConfig': DeviceProfileConfigComponent, - 'tbActionNodeDeviceStateConfig': DeviceStateConfigComponent, - 'tbActionNodeGeneratorConfig': GeneratorConfigComponent, - 'tbActionNodeGpsGeofencingConfig': GpsGeoActionConfigComponent, - 'tbActionNodeLogConfig': LogConfigComponent, - 'tbActionNodeMathFunctionConfig': MathFunctionConfigComponent, - 'tbActionNodeMsgCountConfig': MsgCountConfigComponent, - 'tbActionNodeMsgDelayConfig': MsgDelayConfigComponent, - 'tbActionNodePushToCloudConfig': PushToCloudConfigComponent, - 'tbActionNodePushToEdgeConfig': PushToEdgeConfigComponent, - 'tbActionNodeRpcReplyConfig': RpcReplyConfigComponent, - 'tbActionNodeRpcRequestConfig': RpcRequestConfigComponent, - 'tbActionNodeCustomTableConfig': SaveToCustomTableConfigComponent, - 'tbActionNodeSendRestApiCallReplyConfig': SendRestApiCallReplyConfigComponent, - 'tbActionNodeTimeseriesConfig': TimeseriesConfigComponent, - 'tbActionNodeUnAssignToCustomerConfig': UnassignCustomerConfigComponent -}; diff --git a/ui-ngx/src/app/modules/home/components/rule-node/enrichment/enrichment-rule-node-core.module.ts b/ui-ngx/src/app/modules/home/components/rule-node/enrichment/enrichment-rule-node-core.module.ts index 987389feb8..7d614ecd96 100644 --- a/ui-ngx/src/app/modules/home/components/rule-node/enrichment/enrichment-rule-node-core.module.ts +++ b/ui-ngx/src/app/modules/home/components/rule-node/enrichment/enrichment-rule-node-core.module.ts @@ -62,16 +62,3 @@ import { FetchDeviceCredentialsConfigComponent } from './fetch-device-credential }) export class EnrichmentRuleNodeCoreModule { } - -export const enrichmentRuleNodeConfigComponentsMap: Record> = { - 'tbEnrichmentNodeCalculateDeltaConfig': CalculateDeltaConfigComponent, - 'tbEnrichmentNodeCustomerAttributesConfig': CustomerAttributesConfigComponent, - 'tbEnrichmentNodeDeviceAttributesConfig': DeviceAttributesConfigComponent, - 'tbEnrichmentNodeEntityDetailsConfig': EntityDetailsConfigComponent, - 'tbEnrichmentNodeFetchDeviceCredentialsConfig': FetchDeviceCredentialsConfigComponent, - 'tbEnrichmentNodeGetTelemetryFromDatabase': GetTelemetryFromDatabaseConfigComponent, - 'tbEnrichmentNodeOriginatorAttributesConfig': OriginatorAttributesConfigComponent, - 'tbEnrichmentNodeOriginatorFieldsConfig': OriginatorFieldsConfigComponent, - 'tbEnrichmentNodeRelatedAttributesConfig': RelatedAttributesConfigComponent, - 'tbEnrichmentNodeTenantAttributesConfig': TenantAttributesConfigComponent -} diff --git a/ui-ngx/src/app/modules/home/components/rule-node/external/external-rule-node-config.module.ts b/ui-ngx/src/app/modules/home/components/rule-node/external/external-rule-node-config.module.ts index 38395b9dac..c3c8c2ca2c 100644 --- a/ui-ngx/src/app/modules/home/components/rule-node/external/external-rule-node-config.module.ts +++ b/ui-ngx/src/app/modules/home/components/rule-node/external/external-rule-node-config.module.ts @@ -73,19 +73,3 @@ import { LambdaConfigComponent } from './lambda-config.component'; }) export class ExternalRuleNodeConfigModule { } - -export const externalRuleNodeConfigComponentsMap: Record> = { - 'tbExternalNodeAzureIotHubConfig': AzureIotHubConfigComponent, - 'tbExternalNodeKafkaConfig': KafkaConfigComponent, - 'tbExternalNodeLambdaConfig': LambdaConfigComponent, - 'tbExternalNodeMqttConfig': MqttConfigComponent, - 'tbExternalNodeNotificationConfig': NotificationConfigComponent, - 'tbExternalNodePubSubConfig': PubSubConfigComponent, - 'tbExternalNodeRabbitMqConfig': RabbitMqConfigComponent, - 'tbExternalNodeRestApiCallConfig': RestApiCallConfigComponent, - 'tbExternalNodeSendEmailConfig': SendEmailConfigComponent, - 'tbExternalNodeSendSmsConfig': SendSmsConfigComponent, - 'tbExternalNodeSlackConfig': SlackConfigComponent, - 'tbExternalNodeSnsConfig': SnsConfigComponent, - 'tbExternalNodeSqsConfig': SqsConfigComponent -} diff --git a/ui-ngx/src/app/modules/home/components/rule-node/filter/filter-rule-node-config.module.ts b/ui-ngx/src/app/modules/home/components/rule-node/filter/filter-rule-node-config.module.ts index ca0aaffd71..bb3636811b 100644 --- a/ui-ngx/src/app/modules/home/components/rule-node/filter/filter-rule-node-config.module.ts +++ b/ui-ngx/src/app/modules/home/components/rule-node/filter/filter-rule-node-config.module.ts @@ -56,14 +56,3 @@ import { CommonRuleNodeConfigModule } from '../common/common-rule-node-config.mo }) export class FilterRuleNodeConfigModule { } - -export const filterRuleNodeConfigComponentsMap: Record> = { - 'tbFilterNodeCheckAlarmStatusConfig': CheckAlarmStatusComponent, - 'tbFilterNodeCheckMessageConfig': CheckMessageConfigComponent, - 'tbFilterNodeCheckRelationConfig': CheckRelationConfigComponent, - 'tbFilterNodeGpsGeofencingConfig': GpsGeoFilterConfigComponent, - 'tbFilterNodeMessageTypeConfig': MessageTypeConfigComponent, - 'tbFilterNodeOriginatorTypeConfig': OriginatorTypeConfigComponent, - 'tbFilterNodeScriptConfig': ScriptConfigComponent, - 'tbFilterNodeSwitchConfig': SwitchConfigComponent -} diff --git a/ui-ngx/src/app/modules/home/components/rule-node/flow/flow-rule-node-config.module.ts b/ui-ngx/src/app/modules/home/components/rule-node/flow/flow-rule-node-config.module.ts index 2ee36f71fc..8a703ca9d2 100644 --- a/ui-ngx/src/app/modules/home/components/rule-node/flow/flow-rule-node-config.module.ts +++ b/ui-ngx/src/app/modules/home/components/rule-node/flow/flow-rule-node-config.module.ts @@ -36,8 +36,3 @@ import { RuleChainOutputComponent } from './rule-chain-output.component'; }) export class FlowRuleNodeConfigModule { } - -export const flowRuleNodeConfigComponentsMap: Record> = { - 'tbFlowNodeRuleChainInputConfig': RuleChainInputComponent, - 'tbFlowNodeRuleChainOutputConfig': RuleChainOutputComponent -} diff --git a/ui-ngx/src/app/modules/home/components/rule-node/rule-node-config.module.ts b/ui-ngx/src/app/modules/home/components/rule-node/rule-node-config.module.ts index f960777220..86512eceea 100644 --- a/ui-ngx/src/app/modules/home/components/rule-node/rule-node-config.module.ts +++ b/ui-ngx/src/app/modules/home/components/rule-node/rule-node-config.module.ts @@ -14,35 +14,18 @@ /// limitations under the License. /// -import { NgModule, Type } from '@angular/core'; +import { NgModule } from '@angular/core'; import { EmptyConfigComponent } from './empty-config.component'; import { CommonModule } from '@angular/common'; import { SharedModule } from '@shared/shared.module'; +import { ActionRuleNodeConfigModule } from '@home/components/rule-node/action/action-rule-node-config.module'; +import { FilterRuleNodeConfigModule } from '@home/components/rule-node/filter/filter-rule-node-config.module'; +import { EnrichmentRuleNodeCoreModule } from '@home/components/rule-node/enrichment/enrichment-rule-node-core.module'; +import { ExternalRuleNodeConfigModule } from '@home/components/rule-node/external/external-rule-node-config.module'; import { - actionRuleNodeConfigComponentsMap, - ActionRuleNodeConfigModule -} from '@home/components/rule-node/action/action-rule-node-config.module'; -import { - filterRuleNodeConfigComponentsMap, - FilterRuleNodeConfigModule -} from '@home/components/rule-node/filter/filter-rule-node-config.module'; -import { - enrichmentRuleNodeConfigComponentsMap, - EnrichmentRuleNodeCoreModule -} from '@home/components/rule-node/enrichment/enrichment-rule-node-core.module'; -import { - externalRuleNodeConfigComponentsMap, - ExternalRuleNodeConfigModule -} from '@home/components/rule-node/external/external-rule-node-config.module'; -import { - transformationRuleNodeConfigComponentsMap, TransformationRuleNodeConfigModule } from '@home/components/rule-node/transformation/transformation-rule-node-config.module'; -import { - flowRuleNodeConfigComponentsMap, - FlowRuleNodeConfigModule -} from '@home/components/rule-node/flow/flow-rule-node-config.module'; -import { IRuleNodeConfigurationComponent } from '@shared/models/rule-node.models'; +import { FlowRuleNodeConfigModule } from '@home/components/rule-node/flow/flow-rule-node-config.module'; import { RuleChainService } from '@core/http/rule-chain.service'; @NgModule({ @@ -65,15 +48,6 @@ import { RuleChainService } from '@core/http/rule-chain.service'; }) export class RuleNodeConfigModule { constructor(private ruleChainService: RuleChainService) { - const ruleNodeConfigComponentsMap: Record> = { - ...actionRuleNodeConfigComponentsMap, - ...enrichmentRuleNodeConfigComponentsMap, - ...externalRuleNodeConfigComponentsMap, - ...filterRuleNodeConfigComponentsMap, - ...flowRuleNodeConfigComponentsMap, - ...transformationRuleNodeConfigComponentsMap, - 'tbNodeEmptyConfig': EmptyConfigComponent - }; - this.ruleChainService.registemSystemRuleNodeConfigComponent(ruleNodeConfigComponentsMap); + this.ruleChainService.registerSystemRuleNodeConfigModule(this.constructor); } } diff --git a/ui-ngx/src/app/modules/home/components/rule-node/transformation/transformation-rule-node-config.module.ts b/ui-ngx/src/app/modules/home/components/rule-node/transformation/transformation-rule-node-config.module.ts index a25495d7b4..76ba7934d6 100644 --- a/ui-ngx/src/app/modules/home/components/rule-node/transformation/transformation-rule-node-config.module.ts +++ b/ui-ngx/src/app/modules/home/components/rule-node/transformation/transformation-rule-node-config.module.ts @@ -57,14 +57,3 @@ import { ScriptConfigComponent } from '@home/components/rule-node/filter/script- }) export class TransformationRuleNodeConfigModule { } - -export const transformationRuleNodeConfigComponentsMap: Record> = { - 'tbTransformationNodeChangeOriginatorConfig': ChangeOriginatorConfigComponent, - 'tbTransformationNodeCopyKeysConfig': CopyKeysConfigComponent, - 'tbTransformationNodeDeduplicationConfig': DeduplicationConfigComponent, - 'tbTransformationNodeDeleteKeysConfig': DeleteKeysConfigComponent, - 'tbTransformationNodeJsonPathConfig': NodeJsonPathConfigComponent, - 'tbTransformationNodeRenameKeysConfig': RenameKeysConfigComponent, - 'tbTransformationNodeScriptConfig': ScriptConfigComponent, - 'tbTransformationNodeToEmailConfig': ToEmailConfigComponent -}