-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add gauge component to dashboard
- Loading branch information
1 parent
785a1cd
commit 128cb18
Showing
17 changed files
with
266 additions
and
20 deletions.
There are no files selected for viewing
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
14 changes: 14 additions & 0 deletions
14
packages/dashboard/src/customization/widgets/gauge/component.css
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,14 @@ | ||
.gauge-widget-empty-state { | ||
display: flex; | ||
flex-direction: column; | ||
height: 100%; | ||
} | ||
|
||
.gauge-widget-empty-state-message-container { | ||
align-items: center; | ||
display: flex; | ||
flex-direction: column; | ||
flex-grow: 1; | ||
justify-content: center; | ||
text-align: center; | ||
} |
105 changes: 105 additions & 0 deletions
105
packages/dashboard/src/customization/widgets/gauge/component.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,105 @@ | ||
import React from 'react'; | ||
import { useSelector } from 'react-redux'; | ||
import pickBy from 'lodash/pickBy'; | ||
import { Gauge, useViewport } from '@iot-app-kit/react-components'; | ||
import { createWidgetRenderKey } from '../utils/createWidgetRenderKey'; | ||
import type { DashboardState } from '~/store/state'; | ||
import type { GaugeWidget } from '../types'; | ||
import { Box } from '@cloudscape-design/components'; | ||
import { useQueries } from '~/components/dashboard/queryContext'; | ||
import { isDefined } from '~/util/isDefined'; | ||
|
||
import WidgetTile from '~/components/widgets/tile'; | ||
import { useChartSize } from '~/hooks/useChartSize'; | ||
import './component.css'; | ||
|
||
const GaugeWidgetComponent: React.FC<GaugeWidget> = (widget) => { | ||
const { viewport } = useViewport(); | ||
const dashboardSignificantDigits = useSelector( | ||
(state: DashboardState) => state.significantDigits | ||
); | ||
|
||
const { | ||
styleSettings, | ||
queryConfig, | ||
showUnit, | ||
showName, | ||
thresholds, | ||
significantDigits: widgetSignificantDigits, | ||
yMin, | ||
yMax, | ||
} = widget.properties; | ||
|
||
const queries = useQueries(queryConfig.query); | ||
const key = createWidgetRenderKey(widget.id); | ||
const chartSize = useChartSize(widget); | ||
|
||
const shouldShowEmptyState = queries.length === 0; | ||
|
||
if (shouldShowEmptyState) { | ||
return ( | ||
<WidgetTile widget={widget}> | ||
<GaugeWidgetEmptyStateComponent /> | ||
</WidgetTile> | ||
); | ||
} | ||
|
||
const settings = pickBy( | ||
{ | ||
yMin, | ||
yMax, | ||
showName, | ||
showUnit, | ||
}, | ||
isDefined | ||
); | ||
|
||
const significantDigits = | ||
widgetSignificantDigits ?? dashboardSignificantDigits; | ||
|
||
const size = { width: chartSize.width - 8, height: chartSize.height - 8 }; | ||
|
||
return ( | ||
<WidgetTile widget={widget} key={key}> | ||
<Gauge | ||
size={size} | ||
query={queries[0]} | ||
viewport={viewport} | ||
styles={styleSettings} | ||
settings={settings} | ||
thresholds={thresholds} | ||
significantDigits={significantDigits} | ||
/> | ||
</WidgetTile> | ||
); | ||
}; | ||
|
||
const GaugeWidgetEmptyStateComponent: React.FC = () => { | ||
return ( | ||
<div className='gauge-widget-empty-state'> | ||
<Box variant='strong' color='text-status-inactive' margin='s'> | ||
Gauge | ||
</Box> | ||
|
||
<div className='gauge-widget-empty-state-message-container'> | ||
<Box | ||
variant='strong' | ||
color='text-status-inactive' | ||
margin={{ horizontal: 's' }} | ||
> | ||
No properties or alarms | ||
</Box> | ||
|
||
<Box | ||
variant='p' | ||
color='text-status-inactive' | ||
margin={{ bottom: 's', horizontal: 's' }} | ||
> | ||
Add a property or alarm to populate Gauge | ||
</Box> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default GaugeWidgetComponent; |
12 changes: 12 additions & 0 deletions
12
packages/dashboard/src/customization/widgets/gauge/gauge-dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions
12
packages/dashboard/src/customization/widgets/gauge/gauge.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions
12
packages/dashboard/src/customization/widgets/gauge/icon.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,12 @@ | ||
import React from 'react'; | ||
import { default as GaugeSvg } from './gauge.svg'; | ||
import { default as GaugeSvgDark } from './gauge-dark.svg'; | ||
import WidgetIcon from '../components/widgetIcon'; | ||
|
||
const GaugeIcon = () => { | ||
return ( | ||
<WidgetIcon widget='gauge' defaultIcon={GaugeSvg} darkIcon={GaugeSvgDark} /> | ||
); | ||
}; | ||
|
||
export default GaugeIcon; |
33 changes: 33 additions & 0 deletions
33
packages/dashboard/src/customization/widgets/gauge/plugin.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,33 @@ | ||
import React from 'react'; | ||
import GaugeWidgetComponent from './component'; | ||
import GaugeIcon from './icon'; | ||
import type { DashboardPlugin } from '~/customization/api'; | ||
import type { GaugeWidget } from '../types'; | ||
import { WIDGET_INITIAL_HEIGHT, WIDGET_INITIAL_WIDTH } from '../constants'; | ||
|
||
export const gaugePlugin: DashboardPlugin = { | ||
install: ({ registerWidget }) => { | ||
registerWidget<GaugeWidget>('gauge', { | ||
render: (widget) => <GaugeWidgetComponent {...widget} />, | ||
componentLibrary: { | ||
name: 'Gauge', | ||
icon: GaugeIcon, | ||
}, | ||
properties: () => ({ | ||
queryConfig: { | ||
source: 'iotsitewise', | ||
query: undefined, | ||
}, | ||
showName: true, | ||
showUnit: true, | ||
yMin: 0, | ||
yMax: 100, | ||
thresholds: [], | ||
}), | ||
initialSize: { | ||
height: WIDGET_INITIAL_HEIGHT, | ||
width: WIDGET_INITIAL_WIDTH, | ||
}, | ||
}); | ||
}, | ||
}; |
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
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
Oops, something went wrong.