Skip to content

Commit

Permalink
refactor(dashboard): refactor constant types to help enforce static t…
Browse files Browse the repository at this point in the history
…yping checks
  • Loading branch information
square-li committed Mar 22, 2023
1 parent 5fb120e commit a03042f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
10 changes: 5 additions & 5 deletions packages/core/src/common/constants.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import type { DataType, StreamType, ComparisonOperator, StatusIconType } from '../data-module/types';
import type { ComparisonOperator, DataType, StatusIconType, StreamType } from '../data-module/types';

export const DATA_TYPE: { [dataType: string]: DataType } = {
export const DATA_TYPE: { [dataType in DataType]: DataType } = {
NUMBER: 'NUMBER',
BOOLEAN: 'BOOLEAN',
STRING: 'STRING',
};

export const STREAM_TYPE: { [streamType: string]: StreamType } = {
export const STREAM_TYPE: { [streamType in StreamType]: StreamType } = {
ALARM: 'ALARM',
ANOMALY: 'ANOMALY',
ALARM_THRESHOLD: 'ALARM_THRESHOLD',
};

export const COMPARISON_OPERATOR: { [comparisonOperator: string]: ComparisonOperator } = {
export const COMPARISON_OPERATOR: { [comparisonOperator in ComparisonOperator]: ComparisonOperator } = {
LT: 'LT',
GT: 'GT',
LTE: 'LTE',
Expand All @@ -21,7 +21,7 @@ export const COMPARISON_OPERATOR: { [comparisonOperator: string]: ComparisonOper
CONTAINS: 'CONTAINS',
};

export const STATUS_ICON_TYPE: { [statusIconType: string]: StatusIconType } = {
export const STATUS_ICON_TYPE: { [statusIconType in StatusIconType]: StatusIconType } = {
error: 'error',
active: 'active',
normal: 'normal',
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/mockWidgetProperties.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { STATUS_ICON_TYPE, COMPARISON_OPERATOR, DATA_TYPE, STREAM_TYPE } from './common/constants';
import { COMPARISON_OPERATOR, DATA_TYPE, STATUS_ICON_TYPE, STREAM_TYPE } from './common/constants';
import { DAY_IN_MS } from './common/time';
import type { Threshold } from './common/types';
import type { DataStream } from './data-module/types';
Expand Down Expand Up @@ -54,7 +54,7 @@ export const ALARM_STREAM: DataStream<string> = {
dataType: DATA_TYPE.STRING,
name: 'alarm stream',
color: 'red',
streamType: STREAM_TYPE.alarm,
streamType: STREAM_TYPE.ALARM,
resolution: 0,
data: [
{
Expand All @@ -67,8 +67,8 @@ export const ALARM_STREAM: DataStream<string> = {
export const ALARM_THRESHOLD: Threshold<string> = {
value: ALARM,
color: 'orange',
comparisonOperator: COMPARISON_OPERATOR.EQUAL,
icon: STATUS_ICON_TYPE.ACTIVE,
comparisonOperator: COMPARISON_OPERATOR.EQ,
icon: STATUS_ICON_TYPE.active,
};

export const STRING_STREAM_1: DataStream<string> = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ export const StatusIcon: React.FC<{
name: StatusIconType;
color?: string; // hex color
size?: number; // pixels
}> = ({ name = STATUS_ICON_TYPE.NORMAL, color, size }) => (
}> = ({ name = STATUS_ICON_TYPE.normal, color, size }) => (
<Icon data-testid={`status-icon-${name}`}>{getIcons(name, color, size)}</Icon>
);
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React from 'react';
import type { DataStream, Viewport } from '@iot-app-kit/core';
import { COMPARISON_OPERATOR, STATUS_ICON_TYPE } from '@iot-app-kit/core';
import { createTableItems } from './createTableItems';
import { TableBase } from './tableBase';
import { DEFAULT_TABLE_MESSAGES } from './messages';
import { render } from '@testing-library/react';
import type { DataStream, Viewport } from '@iot-app-kit/core';
import type { TableColumnDefinition, TableItem } from './types';

const dataStreamId = 'datastream-1';
Expand Down Expand Up @@ -100,7 +100,7 @@ it('renders icon and applies style when a datastream breaches threshold', async
color: 'red',
value: 30,
comparisonOperator: COMPARISON_OPERATOR.GT,
icon: STATUS_ICON_TYPE.ERROR,
icon: STATUS_ICON_TYPE.error,
dataStreamIds: [dataStreamId],
},
],
Expand Down

0 comments on commit a03042f

Please sign in to comment.