Skip to content

Commit

Permalink
fix(dashboard): bugfix for color reset on new property drop
Browse files Browse the repository at this point in the history
  • Loading branch information
jmbuss committed Mar 30, 2023
1 parent 2fa8758 commit 05c04e6
Showing 1 changed file with 9 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { SiteWiseAssetQuery } from '@iot-app-kit/source-iotsitewise';
import { v4 as uuid } from 'uuid';
import type { QueryWidget } from '../types';
import { assignDefaultColor } from '@iot-app-kit/core-util';
import { isDefined } from '~/util/isDefined';

const assignDefaultRefId = (siteWiseAssetQuery: SiteWiseAssetQuery, getId: () => string = uuid) => ({
assets: siteWiseAssetQuery.assets.map(({ properties, ...others }) => ({
Expand All @@ -19,16 +20,13 @@ const assignDefaultColors = (
siteWiseAssetQuery: SiteWiseAssetQuery,
colorIndexOffset = 0
): StyleSettingsMap => {
const properties = siteWiseAssetQuery.assets.flatMap((asset) =>
asset.properties.map(({ refId }) => ({
refId,
}))
);

return properties.reduce((acc: StyleSettingsMap, { refId }, index) => {
if (refId && !styleSettings[refId]) {
acc[refId] = assignDefaultColor({}, index + colorIndexOffset);
}
const refIds = siteWiseAssetQuery.assets
.flatMap((asset) => asset.properties.map(({ refId }) => refId))
.filter(isDefined);

return refIds.reduce((acc: StyleSettingsMap, refId, index) => {
const existing = styleSettings[refId] || {};
acc[refId] = assignDefaultColor(existing, index + colorIndexOffset);
return acc;
}, {});
};
Expand All @@ -38,7 +36,7 @@ export const assignDefaultStyles = (widget: QueryWidget): QueryWidget => {

if (!siteWiseAssetQuery) return widget;

let styleSettings = {};
let styleSettings = widget.properties.styleSettings || {};

const assetQueriesWithRefIds = assignDefaultRefId(siteWiseAssetQuery);
styleSettings = assignDefaultColors(styleSettings, assetQueriesWithRefIds);
Expand Down

0 comments on commit 05c04e6

Please sign in to comment.