-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(dial): port over DialBase from SynchroCharts (#590)
- Loading branch information
Showing
13 changed files
with
525 additions
and
7 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
packages/react-components/src/components/dial/constants.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { DialSettings } from './types'; | ||
|
||
export enum ColorConfigurations { | ||
BLUE = '#2E72B5', | ||
NORMAL = '#3F7E23', | ||
WARNING = '#F29D38', | ||
CRITICAL = '#C03F25', | ||
GRAY = '#D9D9D9', | ||
PRIMARY_TEXT = '#16191f', | ||
SECONDARY_TEXT = '#687078', | ||
WHITE = '#fff', | ||
} | ||
|
||
export const DEFAULT_DIAL_SETTINGS: DialSettings = { | ||
showName: true, | ||
showUnit: true, | ||
dialThickness: 34, | ||
fontSize: 48, | ||
unitFontSize: 24, | ||
labelFontSize: 24, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import React from 'react'; | ||
import { DialBase } from './dialBase'; | ||
import { TimeQuery, TimeSeriesData, TimeSeriesDataRequest, StyleSettingsMap, Viewport } from '@iot-app-kit/core'; | ||
import { useTimeSeriesData } from '../../hooks/useTimeSeriesData'; | ||
import { widgetPropertiesFromInputs } from '../../common/widgetPropertiesFromInputs'; | ||
import { Annotations } from '../../common/thresholdTypes'; | ||
import { DialSettings } from './types'; | ||
import { useViewport } from '../../hooks/useViewport'; | ||
|
||
export const Dial = ({ | ||
query, | ||
viewport: passedInViewport, | ||
annotations, | ||
styles, | ||
settings, | ||
}: { | ||
query: TimeQuery<TimeSeriesData[], TimeSeriesDataRequest>; | ||
viewport?: Viewport; | ||
annotations?: Annotations; | ||
styles?: StyleSettingsMap; | ||
settings?: DialSettings; | ||
}) => { | ||
const { dataStreams } = useTimeSeriesData({ | ||
viewport: passedInViewport, | ||
query, | ||
settings: { fetchMostRecentBeforeEnd: true }, | ||
styles, | ||
}); | ||
const { viewport } = useViewport(); | ||
|
||
const utilizedViewport = passedInViewport || viewport; // explicitly passed in viewport overrides viewport group | ||
const { propertyPoint, alarmPoint, alarmThreshold, propertyThreshold, alarmStream, propertyStream } = | ||
widgetPropertiesFromInputs({ dataStreams, annotations, viewport: utilizedViewport }); | ||
|
||
const name = propertyStream?.name || alarmStream?.name; | ||
const unit = propertyStream?.unit || alarmStream?.unit; | ||
const color = alarmThreshold?.color || propertyThreshold?.color || propertyStream?.color; | ||
|
||
return ( | ||
<DialBase | ||
propertyPoint={propertyPoint} | ||
alarmPoint={alarmPoint} | ||
settings={settings} | ||
name={name} | ||
unit={unit} | ||
color={color} | ||
/> | ||
); | ||
}; |
127 changes: 127 additions & 0 deletions
127
packages/react-components/src/components/dial/dialBase.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { DialBase } from './dialBase'; | ||
import { DataPoint } from '../../common/dataTypes'; | ||
|
||
describe('name', () => { | ||
it('renders name when showName is true', () => { | ||
const someName = 'some-name'; | ||
render(<DialBase name={someName} settings={{ showName: true }} />); | ||
|
||
expect(screen.queryByText(someName)).not.toBeNull(); | ||
}); | ||
|
||
it('does not render name when showName is false', () => { | ||
const someName = 'some-name'; | ||
render(<DialBase name={someName} settings={{ showName: false }} />); | ||
|
||
expect(screen.queryByText(someName)).toBeNull(); | ||
}); | ||
}); | ||
|
||
describe('unit', () => { | ||
const point: DataPoint = { x: 1213, y: 123 }; | ||
|
||
it('renders unit when showUnit is true and provided a property point', () => { | ||
const someUnit = 'some-Unit'; | ||
render(<DialBase unit={someUnit} propertyPoint={point} settings={{ showUnit: true }} />); | ||
|
||
expect(screen.queryByText(someUnit)).not.toBeNull(); | ||
}); | ||
|
||
it('renders unit when showUnit is true and provided a alarm point', () => { | ||
const someUnit = 'some-Unit'; | ||
render(<DialBase unit={someUnit} alarmPoint={point} settings={{ showUnit: true }} />); | ||
|
||
expect(screen.queryByText(someUnit)).not.toBeNull(); | ||
}); | ||
|
||
it('does not render unit when showUnit is true and is not provided a data point', () => { | ||
const someUnit = 'some-Unit'; | ||
render(<DialBase unit={someUnit} settings={{ showUnit: true }} />); | ||
|
||
expect(screen.queryByText(someUnit)).toBeNull(); | ||
}); | ||
|
||
it('does not render unit when showUnit is false', () => { | ||
const someUnit = 'some-Unit'; | ||
render(<DialBase unit={someUnit} settings={{ showUnit: false }} propertyPoint={point} />); | ||
|
||
expect(screen.queryByText(someUnit)).toBeNull(); | ||
}); | ||
}); | ||
|
||
describe('property value', () => { | ||
it('renders property points y value', () => { | ||
const Y_VALUE = 123445; | ||
render(<DialBase propertyPoint={{ x: new Date().getTime(), y: Y_VALUE }} settings={{ showName: false }} />); | ||
expect(screen.queryByText(Y_VALUE)).not.toBeNull(); | ||
}); | ||
|
||
it('renders alarm points y value', () => { | ||
const Y_VALUE = 123445; | ||
render(<DialBase alarmPoint={{ x: new Date().getTime(), y: Y_VALUE }} settings={{ showName: false }} />); | ||
expect(screen.queryByText(Y_VALUE)).not.toBeNull(); | ||
}); | ||
|
||
it('renders property points y value and alarm points y value when provided both an alarm and a property', () => { | ||
const Y_VALUE_PROPERTY = 123445; | ||
const Y_VALUE_ALARM = 'alarm_value'; | ||
render( | ||
<DialBase | ||
alarmPoint={{ x: new Date().getTime(), y: Y_VALUE_ALARM }} | ||
propertyPoint={{ x: 234324, y: Y_VALUE_PROPERTY }} | ||
settings={{ showName: false }} | ||
/> | ||
); | ||
|
||
expect(screen.queryByText(Y_VALUE_PROPERTY)).not.toBeNull(); | ||
expect(screen.queryByText(Y_VALUE_ALARM)).not.toBeNull(); | ||
}); | ||
}); | ||
|
||
describe('error', () => { | ||
it('renders error', () => { | ||
const someError = 'some-error'; | ||
render(<DialBase error={someError} settings={{}} />); | ||
|
||
expect(screen.queryByText(someError)).not.toBeNull(); | ||
}); | ||
}); | ||
|
||
describe('loading', () => { | ||
it('renders loading spinner while isLoading is true', () => { | ||
render(<DialBase isLoading settings={{}} />); | ||
|
||
expect(screen.queryByTestId('loading')).not.toBeNull(); | ||
}); | ||
|
||
it('does not render loading spinner while isLoading is false', () => { | ||
render(<DialBase isLoading={false} settings={{}} />); | ||
|
||
expect(screen.queryByTestId('loading')).toBeNull(); | ||
}); | ||
|
||
it('renders error while loading', () => { | ||
const someError = 'some-error'; | ||
render(<DialBase error={someError} isLoading settings={{}} />); | ||
|
||
expect(screen.queryByText(someError)).not.toBeNull(); | ||
}); | ||
|
||
it('does not render data point while isLoading is true', () => { | ||
const point = { x: 12341, y: 123213 }; | ||
render(<DialBase propertyPoint={point} isLoading settings={{}} />); | ||
|
||
expect(screen.queryByText(point.y)).toBeNull(); | ||
}); | ||
|
||
it('does not render alarm or property data point while isLoading is true', () => { | ||
const point = { x: 12341, y: 123213 }; | ||
const alarmPoint = { x: 12341, y: 'warning' }; | ||
render(<DialBase propertyPoint={point} alarmPoint={alarmPoint} isLoading settings={{}} />); | ||
|
||
expect(screen.queryByText(point.y)).toBeNull(); | ||
expect(screen.queryByText(alarmPoint.y)).toBeNull(); | ||
}); | ||
}); |
Oops, something went wrong.