Skip to content

Commit

Permalink
fix(dashboard): update props passed to kpi and status components base…
Browse files Browse the repository at this point in the history
…d on new api
  • Loading branch information
jmbuss committed Mar 28, 2023
1 parent 085ab29 commit e2023c9
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 7 deletions.
41 changes: 39 additions & 2 deletions packages/dashboard/src/customization/widgets/kpi/component.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
import React from 'react';
import { useSelector } from 'react-redux';
import pickBy from 'lodash/pickBy';
import { Kpi } from '@iot-app-kit/react-components';
import { computeQueryConfigKey } from '../utils/computeQueryConfigKey';
import type { DashboardState } from '~/store/state';
import type { KPIWidget } from '../types';
import { Box } from '@cloudscape-design/components';
import { useQueries } from '~/components/dashboard/queryContext';
import { isDefined } from '~/util/isDefined';

import './component.css';

const KPIWidgetComponent: React.FC<KPIWidget> = (widget) => {
const viewport = useSelector((state: DashboardState) => state.dashboardConfiguration.viewport);

const { queryConfig, styleSettings, thresholds } = widget.properties;
const {
styleSettings,
queryConfig,
primaryFont,
secondaryFont,
showValue,
showUnit,
showIcon,
showName,
showTimestamp,
thresholds,
} = widget.properties;

const { iotSiteWiseQuery } = useQueries();
const query = iotSiteWiseQuery && queryConfig.query ? iotSiteWiseQuery?.timeSeriesData(queryConfig.query) : undefined;
Expand All @@ -23,7 +36,31 @@ const KPIWidgetComponent: React.FC<KPIWidget> = (widget) => {
if (shouldShowEmptyState) {
return <KPIWidgetEmptyStateComponent />;
}
return <Kpi key={key} query={query} viewport={viewport} styles={styleSettings} thresholds={thresholds} />;

const settings = pickBy(
{
showName,
showIcon,
showValue,
showUnit,
showTimestamp,
fontSize: primaryFont.fontSize,
color: primaryFont.fontColor,
secondaryFontSize: secondaryFont.fontSize,
},
isDefined
);

return (
<Kpi
key={key}
query={query}
viewport={viewport}
styles={styleSettings}
settings={settings}
thresholds={thresholds}
/>
);
};

const KPIWidgetEmptyStateComponent: React.FC = () => {
Expand Down
41 changes: 38 additions & 3 deletions packages/dashboard/src/customization/widgets/status/component.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
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 './component.css';
import { useQueries } from '~/components/dashboard/queryContext';
import { isDefined } from '~/util/isDefined';

import './component.css';

const StatusWidgetComponent: React.FC<StatusWidget> = (widget) => {
const viewport = useSelector((state: DashboardState) => state.dashboardConfiguration.viewport);

const { queryConfig, styleSettings, thresholds } = widget.properties;
const {
styleSettings,
queryConfig,
primaryFont,
secondaryFont,
showValue,
showUnit,
showIcon,
showName,
thresholds,
} = widget.properties;

const { iotSiteWiseQuery } = useQueries();
const query = iotSiteWiseQuery && queryConfig.query ? iotSiteWiseQuery?.timeSeriesData(queryConfig.query) : undefined;
Expand All @@ -23,7 +36,29 @@ const StatusWidgetComponent: React.FC<StatusWidget> = (widget) => {
return <StatusWidgetEmptyStateComponent />;
}

return <Status key={key} query={query} viewport={viewport} styles={styleSettings} thresholds={thresholds} />;
const settings = pickBy(
{
showName,
showIcon,
showValue,
showUnit,
fontSize: primaryFont.fontSize,
color: primaryFont.fontColor,
secondaryFontSize: secondaryFont.fontSize,
},
isDefined
);

return (
<Status
key={key}
query={query}
viewport={viewport}
styles={styleSettings}
settings={settings}
thresholds={thresholds}
/>
);
};

const StatusWidgetEmptyStateComponent: React.FC = () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/react-components/src/components/kpi/kpi.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const Kpi = ({
viewport?: Viewport;
thresholds?: Threshold[];
styles?: StyleSettingsMap;
settings?: KPISettings;
settings?: Partial<KPISettings>;
}) => {
const { dataStreams, thresholds: queryThresholds } = useTimeSeriesData({
viewport: passedInViewport,
Expand Down
2 changes: 1 addition & 1 deletion packages/react-components/src/components/status/status.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const Status = ({
viewport?: Viewport;
thresholds?: Threshold[];
styles?: StyleSettingsMap;
settings?: StatusSettings;
settings?: Partial<StatusSettings>;
}) => {
const { dataStreams, thresholds: queryThresholds } = useTimeSeriesData({
viewport: passedInViewport,
Expand Down

0 comments on commit e2023c9

Please sign in to comment.