From 595fb99cb4f26174c41ea232b17294884967275e Mon Sep 17 00:00:00 2001 From: Volodymyr Babak Date: Wed, 8 Sep 2021 13:28:09 +0300 Subject: [PATCH 1/3] Revert allowed entity type for dashboard component - null means show all availabe aliases --- .../components/dashboard-page/dashboard-page.component.ts | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-page.component.ts b/ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-page.component.ts index e77b6a461e..a704c44dc0 100644 --- a/ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-page.component.ts +++ b/ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-page.component.ts @@ -121,7 +121,6 @@ import { DisplayWidgetTypesPanelData } from '@home/components/dashboard-page/widget-types-panel.component'; import { DashboardWidgetSelectComponent } from '@home/components/dashboard-page/dashboard-widget-select.component'; -import { AliasEntityType, EntityType } from '@shared/models/entity-type.models'; import { MobileService } from '@core/services/mobile.service'; import { @@ -193,8 +192,6 @@ export class DashboardPageComponent extends PageComponent implements IDashboardC isToolbarOpenedAnimate = false; isRightLayoutOpened = false; - allowedEntityTypes: Array = null; - editingWidget: Widget = null; editingWidgetLayout: WidgetLayout = null; editingWidgetOriginal: Widget = null; @@ -409,8 +406,6 @@ export class DashboardPageComponent extends PageComponent implements IDashboardC }; this.window.parent.postMessage(JSON.stringify(message), '*'); } - - this.allowedEntityTypes = this.entityService.prepareAllowedEntityTypesList(null, true); } private reset() { @@ -658,8 +653,7 @@ export class DashboardPageComponent extends PageComponent implements IDashboardC data: { entityAliases: deepClone(this.dashboard.configuration.entityAliases), widgets: this.dashboardUtils.getWidgetsArray(this.dashboard), - isSingleEntityAlias: false, - allowedEntityTypes: this.allowedEntityTypes + isSingleEntityAlias: false } }).afterClosed().subscribe((entityAliases) => { if (entityAliases) { From cd78514bc08f3ef2b5411d4fd5db8518734808ae Mon Sep 17 00:00:00 2001 From: Volodymyr Babak Date: Wed, 8 Sep 2021 15:44:31 +0300 Subject: [PATCH 2/3] Added correct alias filtering for edge disabled/enabled events --- ui-ngx/src/app/core/http/entity.service.ts | 31 ++++++++++++++----- .../import-export/import-export.service.ts | 8 ++--- ui-ngx/src/app/shared/models/alias.models.ts | 5 +++ 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/ui-ngx/src/app/core/http/entity.service.ts b/ui-ngx/src/app/core/http/entity.service.ts index 09de886036..704a3dcca9 100644 --- a/ui-ngx/src/app/core/http/entity.service.ts +++ b/ui-ngx/src/app/core/http/entity.service.ts @@ -43,7 +43,13 @@ import { RuleChainService } from '@core/http/rule-chain.service'; import { AliasInfo, StateParams, SubscriptionInfo } from '@core/api/widget-api.models'; import { DataKey, Datasource, DatasourceType, KeyInfo } from '@app/shared/models/widget.models'; import { UtilsService } from '@core/services/utils.service'; -import { AliasFilterType, EntityAlias, EntityAliasFilter, EntityAliasFilterResult } from '@shared/models/alias.models'; +import { + AliasFilterType, + edgeAliasFilterTypes, + EntityAlias, + EntityAliasFilter, + EntityAliasFilterResult +} from '@shared/models/alias.models'; import { EdgeImportEntityData, EntitiesKeysByQuery, @@ -495,7 +501,16 @@ export class EntityService { } public getAliasFilterTypesByEntityTypes(entityTypes: Array): Array { - const allAliasFilterTypes: Array = Object.keys(AliasFilterType).map((key) => AliasFilterType[key]); + const authState = getCurrentAuthState(this.store); + const allAliasFilterTypes: Array = Object.keys(AliasFilterType) + .map((key) => AliasFilterType[key]) + .filter(aft => { + if (authState.edgesSupportEnabled) { + return true; + } else { + return edgeAliasFilterTypes.indexOf(aft) === -1; + } + }); if (!entityTypes || !entityTypes.length) { return allAliasFilterTypes; } @@ -622,14 +637,14 @@ export class EntityService { case Authority.TENANT_ADMIN: entityTypes.push(EntityType.DEVICE); entityTypes.push(EntityType.ASSET); - if (authState.edgesSupportEnabled) { - entityTypes.push(EntityType.EDGE); - } entityTypes.push(EntityType.ENTITY_VIEW); entityTypes.push(EntityType.TENANT); entityTypes.push(EntityType.CUSTOMER); entityTypes.push(EntityType.USER); entityTypes.push(EntityType.DASHBOARD); + if (authState.edgesSupportEnabled) { + entityTypes.push(EntityType.EDGE); + } if (useAliasEntityTypes) { entityTypes.push(AliasEntityType.CURRENT_CUSTOMER); entityTypes.push(AliasEntityType.CURRENT_TENANT); @@ -638,13 +653,13 @@ export class EntityService { case Authority.CUSTOMER_USER: entityTypes.push(EntityType.DEVICE); entityTypes.push(EntityType.ASSET); - if (authState.edgesSupportEnabled) { - entityTypes.push(EntityType.EDGE); - } entityTypes.push(EntityType.ENTITY_VIEW); entityTypes.push(EntityType.CUSTOMER); entityTypes.push(EntityType.USER); entityTypes.push(EntityType.DASHBOARD); + if (authState.edgesSupportEnabled) { + entityTypes.push(EntityType.EDGE); + } if (useAliasEntityTypes) { entityTypes.push(AliasEntityType.CURRENT_CUSTOMER); } diff --git a/ui-ngx/src/app/modules/home/components/import-export/import-export.service.ts b/ui-ngx/src/app/modules/home/components/import-export/import-export.service.ts index 3bd63b046b..1327f23054 100644 --- a/ui-ngx/src/app/modules/home/components/import-export/import-export.service.ts +++ b/ui-ngx/src/app/modules/home/components/import-export/import-export.service.ts @@ -45,7 +45,7 @@ import { } from '@home/components/alias/entity-aliases-dialog.component'; import { ItemBufferService, WidgetItem } from '@core/services/item-buffer.service'; import { FileType, ImportWidgetResult, JSON_TYPE, WidgetsBundleItem, ZIP_TYPE } from './import-export.models'; -import { AliasEntityType, EntityType } from '@shared/models/entity-type.models'; +import { EntityType } from '@shared/models/entity-type.models'; import { UtilsService } from '@core/services/utils.service'; import { WidgetService } from '@core/http/widget.service'; import { NULL_UUID } from '@shared/models/id/has-uuid'; @@ -686,9 +686,6 @@ export class ImportExportService { private editMissingAliases(widgets: Array, isSingleWidget: boolean, customTitle: string, missingEntityAliases: EntityAliases): Observable { - const allowedEntityTypes: Array = - this.entityService.prepareAllowedEntityTypesList(null, true); - return this.dialog.open(EntityAliasesDialogComponent, { disableClose: true, @@ -698,8 +695,7 @@ export class ImportExportService { widgets, customTitle, isSingleWidget, - disableAdd: true, - allowedEntityTypes + disableAdd: true } }).afterClosed().pipe( map((updatedEntityAliases) => { diff --git a/ui-ngx/src/app/shared/models/alias.models.ts b/ui-ngx/src/app/shared/models/alias.models.ts index 1f900d29a1..5df31c2a3c 100644 --- a/ui-ngx/src/app/shared/models/alias.models.ts +++ b/ui-ngx/src/app/shared/models/alias.models.ts @@ -37,6 +37,11 @@ export enum AliasFilterType { entityViewSearchQuery = 'entityViewSearchQuery' } +export const edgeAliasFilterTypes = new Array( + AliasFilterType.edgeType, + AliasFilterType.edgeSearchQuery +); + export const aliasFilterTypeTranslationMap = new Map( [ [ AliasFilterType.singleEntity, 'alias.filter-type-single-entity' ], From 60acd6f56aa5b45f01c99768859d608c793f2ba0 Mon Sep 17 00:00:00 2001 From: Volodymyr Babak Date: Wed, 8 Sep 2021 17:30:25 +0300 Subject: [PATCH 3/3] Code review changes --- ui-ngx/src/app/core/http/entity.service.ts | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/ui-ngx/src/app/core/http/entity.service.ts b/ui-ngx/src/app/core/http/entity.service.ts index 704a3dcca9..78a7dc76df 100644 --- a/ui-ngx/src/app/core/http/entity.service.ts +++ b/ui-ngx/src/app/core/http/entity.service.ts @@ -502,15 +502,10 @@ export class EntityService { public getAliasFilterTypesByEntityTypes(entityTypes: Array): Array { const authState = getCurrentAuthState(this.store); - const allAliasFilterTypes: Array = Object.keys(AliasFilterType) - .map((key) => AliasFilterType[key]) - .filter(aft => { - if (authState.edgesSupportEnabled) { - return true; - } else { - return edgeAliasFilterTypes.indexOf(aft) === -1; - } - }); + let allAliasFilterTypes: Array = Object.values(AliasFilterType); + if (!authState.edgesSupportEnabled) { + allAliasFilterTypes = allAliasFilterTypes.filter(aliasFilterType => !edgeAliasFilterTypes.includes(aliasFilterType)); + } if (!entityTypes || !entityTypes.length) { return allAliasFilterTypes; }