Skip to content

Commit

Permalink
fix(dashboard): bar chart default aggregation+resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
corteggiano authored and tracy-french committed Oct 9, 2023
1 parent 4e305d4 commit 44fd991
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,31 @@ import type { QueryWidget } from '../types';
import { assignDefaultColor } from '@iot-app-kit/core-util';
import { isDefined } from '~/util/isDefined';
import { IoTSiteWiseDataStreamQuery } from '~/types';
import { getCurrentAggregationResolution } from './widgetAggregationUtils';
import { AggregateType } from '@aws-sdk/client-iotsitewise';

type Query = NonNullable<QueryWidget['properties']['queryConfig']['query']>;

const assignDefaultRefId = (
// Assigns default RefID to each property and defauly aggregations+resolutions to each property
const assignDefaults = (
{ assets = [], properties = [] }: IoTSiteWiseDataStreamQuery,
resAndAggr: { aggregation?: AggregateType; resolution?: string },
getId: () => string = uuid
) => ({
assets: assets.map(({ properties, ...others }) => ({
...others,
properties: properties.map((propertyQuery) => ({
...propertyQuery,
resolution: resAndAggr.resolution,
aggregationType: resAndAggr.aggregation,
refId: propertyQuery.refId || getId(),
})),
})),
properties: properties.map((propertyQuery) => ({
...propertyQuery,
refId: propertyQuery.refId || getId(),
resolution: resAndAggr.resolution,
aggregationType: resAndAggr.aggregation,
})),
});

Expand Down Expand Up @@ -48,7 +56,8 @@ export const assignDefaultStyles = (widget: QueryWidget): QueryWidget => {

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

const assetQueriesWithRefIds = assignDefaultRefId(siteWiseAssetQuery);
const defaultResolutionAndAggregation = getCurrentAggregationResolution(widget);
const assetQueriesWithRefIds = assignDefaults(siteWiseAssetQuery, defaultResolutionAndAggregation);
styleSettings = assignDefaultColors(styleSettings, assetQueriesWithRefIds);

const updated = {
Expand Down

0 comments on commit 44fd991

Please sign in to comment.