Skip to content

Commit

Permalink
fix(dashboard): better empty thresholds pane
Browse files Browse the repository at this point in the history
  • Loading branch information
corteggiano committed Apr 3, 2023
1 parent 791c036 commit 493b9f2
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { FC, MouseEventHandler } from 'react';
import React from 'react';
import React, { useState } from 'react';
import type { SelectProps, ToggleProps } from '@cloudscape-design/components';
import { ExpandableSection, SpaceBetween, Toggle } from '@cloudscape-design/components';
import ExpandableSectionHeader from '../../shared/expandableSectionHeader';
Expand All @@ -18,6 +18,7 @@ import type {
import type { DashboardWidget } from '~/types';
import type { ThresholdWithId } from '~/customization/settings';
import { COMPARISON_OPERATOR, ThresholdSettings } from '@iot-app-kit/core';
import { isEmpty } from 'lodash';

export type ThresholdWidget =
| KPIWidget
Expand Down Expand Up @@ -46,6 +47,7 @@ const defaultMessages = {
};

const ThresholdsSection: FC<ThresholdWidget> = (widget) => {
const [isExpanded, setIsExpanded] = useState<boolean>(true);
const [thresholds = [], updateThresholds] = useWidgetLense<ThresholdWidget, ThresholdWithId[] | undefined>(
widget,
(w) => w.properties.thresholds,
Expand All @@ -72,6 +74,7 @@ const ThresholdsSection: FC<ThresholdWidget> = (widget) => {

const onAddNewThreshold: MouseEventHandler = (e) => {
e.stopPropagation();
!isExpanded && setIsExpanded(true);
const newThreshold: ThresholdWithId = {
value: '',
id: nanoid(),
Expand Down Expand Up @@ -153,9 +156,11 @@ const ThresholdsSection: FC<ThresholdWidget> = (widget) => {
<ExpandableSectionHeader onClickButton={onAddNewThreshold}>{defaultMessages.header}</ExpandableSectionHeader>
}
defaultExpanded
expanded={isExpanded}
onChange={(event) => setIsExpanded(event.detail.expanded)}
>
<SpaceBetween size='m' direction='vertical'>
{isAnnotationsSupported(widget) && (
{isAnnotationsSupported(widget) && !isEmpty(thresholds) && (
<Toggle checked={thresholdSettings?.colorBreachedData ?? true} onChange={onCheckColorData}>
{defaultMessages.colorDataToggle}
</Toggle>
Expand Down

0 comments on commit 493b9f2

Please sign in to comment.