-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: dashboard: re-introduce status widget icon #1977
- Loading branch information
1 parent
a7cefce
commit 0b62042
Showing
9 changed files
with
173 additions
and
0 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
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/status/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 @@ | ||
.status-widget-empty-state { | ||
display: flex; | ||
flex-direction: column; | ||
height: 100%; | ||
} | ||
|
||
.status-widget-empty-state-message-container { | ||
align-items: center; | ||
display: flex; | ||
flex-direction: column; | ||
flex-grow: 1; | ||
justify-content: center; | ||
text-align: center; | ||
} |
97 changes: 97 additions & 0 deletions
97
packages/dashboard/src/customization/widgets/status/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,97 @@ | ||
import React from 'react'; | ||
import { useSelector } from 'react-redux'; | ||
import pickBy from 'lodash/pickBy'; | ||
import { Status } from '@iot-app-kit/react-components'; | ||
import { computeQueryConfigKey } from '../utils/computeQueryConfigKey'; | ||
import type { DashboardState } from '~/store/state'; | ||
import type { StatusWidget } from '../types'; | ||
import { Box } from '@cloudscape-design/components'; | ||
import { useQueries } from '~/components/dashboard/queryContext'; | ||
import { isDefined } from '~/util/isDefined'; | ||
import { aggregateToString } from '~/customization/propertiesSections/aggregationSettings/helpers'; | ||
import { getAggregation } from '../utils/widgetAggregationUtils'; | ||
import { SiteWiseAssetQuery } from '@iot-app-kit/source-iotsitewise'; | ||
import './component.css'; | ||
|
||
const StatusWidgetComponent: React.FC<StatusWidget> = (widget) => { | ||
const viewport = useSelector((state: DashboardState) => state.dashboardConfiguration.viewport); | ||
const dashboardSignificantDigits = useSelector((state: DashboardState) => state.significantDigits); | ||
|
||
const { | ||
styleSettings, | ||
queryConfig, | ||
primaryFont, | ||
secondaryFont, | ||
showValue, | ||
showUnit, | ||
showIcon, | ||
showName, | ||
thresholds, | ||
significantDigits: widgetSignificantDigits, | ||
} = widget.properties; | ||
|
||
const { iotSiteWiseQuery } = useQueries(); | ||
// const query = iotSiteWiseQuery && queryConfig.query ? iotSiteWiseQuery?.timeSeriesData(queryConfig.query) : undefined; | ||
const query = | ||
iotSiteWiseQuery && queryConfig.query | ||
? iotSiteWiseQuery?.timeSeriesData(queryConfig.query as SiteWiseAssetQuery) | ||
: undefined; | ||
|
||
const shouldShowEmptyState = query == null || !iotSiteWiseQuery; | ||
const key = computeQueryConfigKey(viewport, queryConfig); | ||
const aggregation = getAggregation(widget); | ||
|
||
if (shouldShowEmptyState) { | ||
return <StatusWidgetEmptyStateComponent />; | ||
} | ||
|
||
const settings = pickBy( | ||
{ | ||
showName, | ||
showIcon, | ||
showValue, | ||
showUnit, | ||
fontSize: primaryFont.fontSize, | ||
color: primaryFont.fontColor, | ||
secondaryFontSize: secondaryFont.fontSize, | ||
}, | ||
isDefined | ||
); | ||
|
||
const significantDigits = widgetSignificantDigits ?? dashboardSignificantDigits; | ||
|
||
return ( | ||
<Status | ||
key={key} | ||
query={query} | ||
viewport={viewport} | ||
styles={styleSettings} | ||
settings={settings} | ||
thresholds={thresholds} | ||
aggregationType={aggregateToString(aggregation)} | ||
significantDigits={significantDigits} | ||
/> | ||
); | ||
}; | ||
|
||
const StatusWidgetEmptyStateComponent: React.FC = () => { | ||
return ( | ||
<div className='status-widget-empty-state'> | ||
<Box variant='strong' color='text-status-inactive' margin='s'> | ||
Status | ||
</Box> | ||
|
||
<div className='status-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 status | ||
</Box> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default StatusWidgetComponent; |
12 changes: 12 additions & 0 deletions
12
packages/dashboard/src/customization/widgets/status/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 statusSvg } from './status.svg'; | ||
import { default as statusSvgDark } from './status-dark.svg'; | ||
|
||
const StatusIcon: React.FC = () => ( | ||
<span> | ||
<img src={statusSvg} alt='Status widget light icon' /> | ||
<img src={statusSvgDark} alt='Status widget dark icon' /> | ||
</span> | ||
); | ||
|
||
export default StatusIcon; |
30 changes: 30 additions & 0 deletions
30
packages/dashboard/src/customization/widgets/status/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,30 @@ | ||
import React from 'react'; | ||
import StatusWidgetComponent from './component'; | ||
import StatusIcon from './icon'; | ||
import type { DashboardPlugin } from '~/customization/api'; | ||
import type { StatusWidget } from '../types'; | ||
import { STATUS_WIDGET_INITIAL_HEIGHT, STATUS_WIDGET_INITIAL_WIDTH } from '../constants'; | ||
|
||
export const statusPlugin: DashboardPlugin = { | ||
install: ({ registerWidget }) => { | ||
registerWidget<StatusWidget>('status', { | ||
render: (widget) => <StatusWidgetComponent {...widget} />, | ||
componentLibrary: { | ||
name: 'Status', | ||
icon: StatusIcon, | ||
}, | ||
properties: () => ({ | ||
queryConfig: { | ||
source: 'iotsitewise', | ||
query: undefined, | ||
}, | ||
primaryFont: {}, | ||
secondaryFont: {}, | ||
}), | ||
initialSize: { | ||
height: STATUS_WIDGET_INITIAL_HEIGHT, | ||
width: STATUS_WIDGET_INITIAL_WIDTH, | ||
}, | ||
}); | ||
}, | ||
}; |
7 changes: 7 additions & 0 deletions
7
packages/dashboard/src/customization/widgets/status/status-dark.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions
7
packages/dashboard/src/customization/widgets/status/status.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.