Browse Source

style(iot-hub): polish getInstalledItemUrl readability

- Guard the helper against a missing descriptor by short-circuiting
  to null up front instead of letting the switch crash on
  `undefined.type`.
- Expand the inline single-line `case 'X': … break;` arms in the
  switch so each branch reads on its own line, matching the
  formatting of the already-multi-line CALCULATED_FIELD /
  ALARM_RULE arms.
pull/15772/head
Igor Kulikov 4 months ago
parent
commit
8861bc6c90
  1. 23
      ui-ngx/src/app/shared/models/iot-hub/iot-hub-installed-item.models.ts

23
ui-ngx/src/app/shared/models/iot-hub/iot-hub-installed-item.models.ts

@ -101,12 +101,21 @@ export interface IotHubInstalledItem extends BaseData<{id: string}> {
} }
export const getInstalledItemUrl = (descriptor?: IotHubInstalledItemDescriptor): string | null => { export const getInstalledItemUrl = (descriptor?: IotHubInstalledItemDescriptor): string | null => {
if (!descriptor) {
return null;
}
let entityId: string | null = null; let entityId: string | null = null;
let entityType: EntityType | null = null; let entityType: EntityType | null = null;
let query: string | null = null; let query: string | null = null;
switch (descriptor.type) { switch (descriptor.type) {
case 'WIDGET': entityId = descriptor.widgetTypeId?.id; entityType = EntityType.WIDGET_TYPE; break; case 'WIDGET':
case 'DASHBOARD': entityId = descriptor.dashboardId?.id; entityType = EntityType.DASHBOARD; break; entityId = descriptor.widgetTypeId?.id;
entityType = EntityType.WIDGET_TYPE;
break;
case 'DASHBOARD':
entityId = descriptor.dashboardId?.id;
entityType = EntityType.DASHBOARD;
break;
case 'CALCULATED_FIELD': case 'CALCULATED_FIELD':
case 'ALARM_RULE': case 'ALARM_RULE':
entityId = descriptor.entityId?.id; entityId = descriptor.entityId?.id;
@ -115,8 +124,14 @@ export const getInstalledItemUrl = (descriptor?: IotHubInstalledItemDescriptor):
query = 'selectedTab=cf'; query = 'selectedTab=cf';
} }
break; break;
case 'RULE_CHAIN': entityId = descriptor.ruleChainId?.id; entityType = EntityType.RULE_CHAIN; break; case 'RULE_CHAIN':
case 'SOLUTION_TEMPLATE': entityId = descriptor.dashboardId?.id; entityType = EntityType.DASHBOARD; break; entityId = descriptor.ruleChainId?.id;
entityType = EntityType.RULE_CHAIN;
break;
case 'SOLUTION_TEMPLATE':
entityId = descriptor.dashboardId?.id;
entityType = EntityType.DASHBOARD;
break;
} }
if (entityType && entityId) { if (entityType && entityId) {
let url = getEntityDetailsPageURL(entityId, entityType); let url = getEntityDetailsPageURL(entityId, entityType);

Loading…
Cancel
Save