Skip to content

Commit

Permalink
feat: introduce module coordinator (#47)
Browse files Browse the repository at this point in the history
* fix aggregated data parsing
* remove unused styles in core
* mark deprecated mocks as deprecated within core
* move mock data source into testing
* refactor the data source into source specific folders
* add some tests in asset session
  • Loading branch information
diehbria authored Feb 4, 2022
1 parent f2d1011 commit 36684eb
Show file tree
Hide file tree
Showing 97 changed files with 1,208 additions and 735 deletions.
40 changes: 21 additions & 19 deletions packages/components/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* It contains typing information for all components that exist in this project.
*/
import { HTMLStencilElement, JSXBase } from "@stencil/core/internal";
import { AnyDataStreamQuery, AssetSummaryQuery, AssetTreeSubscription, DataModule, DataStream, SiteWiseAssetTreeQuery, StyleSettingsMap, TimeSeriesDataRequest, TimeSeriesDataRequestSettings } from "@iot-app-kit/core";
import { AnyDataStreamQuery, AssetSummaryQuery, AssetTreeSubscription, DataStream, IoTAppKitSession, SiteWiseAssetTreeQuery, StyleSettingsMap, TimeSeriesDataRequest, TimeSeriesDataRequestSettings } from "@iot-app-kit/core";
import { MinimalViewPortConfig } from "@synchro-charts/core";
import { ColumnDefinition, FilterTexts, ResourceExplorerQuery, SitewiseAssetResource } from "./components/iot-resource-explorer/types";
import { TableProps } from "@awsui/components-react/table";
Expand All @@ -20,7 +20,7 @@ export namespace Components {
"subscription": AssetTreeSubscription;
}
interface IotBarChart {
"appKit": DataModule;
"appKitSession": IoTAppKitSession;
"isEditing": boolean | undefined;
"queries": AnyDataStreamQuery[];
"settings": TimeSeriesDataRequestSettings | undefined;
Expand All @@ -29,14 +29,14 @@ export namespace Components {
"widgetId": string;
}
interface IotConnector {
"appKit": DataModule;
"appKitSession": IoTAppKitSession;
"queries": AnyDataStreamQuery[];
"renderFunc": ({ dataStreams }: { dataStreams: DataStream[] }) => unknown;
"request": TimeSeriesDataRequest;
"styleSettings": StyleSettingsMap | undefined;
}
interface IotKpi {
"appKit": DataModule;
"appKitSession": IoTAppKitSession;
"isEditing": boolean | undefined;
"queries": AnyDataStreamQuery[];
"settings": TimeSeriesDataRequestSettings | undefined;
Expand All @@ -45,7 +45,7 @@ export namespace Components {
"widgetId": string;
}
interface IotLineChart {
"appKit": DataModule;
"appKitSession": IoTAppKitSession;
"isEditing": boolean | undefined;
"queries": AnyDataStreamQuery[];
"settings": TimeSeriesDataRequestSettings | undefined;
Expand All @@ -55,7 +55,7 @@ export namespace Components {
"widgetId": string;
}
interface IotResourceExplorer {
"appKit": DataModule;
"appKitSession": IoTAppKitSession;
"columnDefinitions"?: ColumnDefinition<SitewiseAssetResource>[];
"empty"?: EmptyStateProps;
"filterEnabled": boolean;
Expand All @@ -71,7 +71,7 @@ export namespace Components {
interface IotResourceExplorerDemo {
}
interface IotScatterChart {
"appKit": DataModule;
"appKitSession": IoTAppKitSession;
"isEditing": boolean | undefined;
"queries": AnyDataStreamQuery[];
"settings": TimeSeriesDataRequestSettings | undefined;
Expand All @@ -80,7 +80,7 @@ export namespace Components {
"widgetId": string;
}
interface IotStatusGrid {
"appKit": DataModule;
"appKitSession": IoTAppKitSession;
"isEditing": boolean | undefined;
"queries": AnyDataStreamQuery[];
"settings": TimeSeriesDataRequestSettings | undefined;
Expand All @@ -89,7 +89,7 @@ export namespace Components {
"widgetId": string;
}
interface IotStatusTimeline {
"appKit": DataModule;
"appKitSession": IoTAppKitSession;
"isEditing": boolean | undefined;
"queries": AnyDataStreamQuery[];
"settings": TimeSeriesDataRequestSettings | undefined;
Expand All @@ -98,7 +98,7 @@ export namespace Components {
"widgetId": string;
}
interface IotTable {
"appKit": DataModule;
"appKitSession": IoTAppKitSession;
"queries": AnyDataStreamQuery[];
"settings": TimeSeriesDataRequestSettings | undefined;
"styleSettings": StyleSettingsMap | undefined;
Expand Down Expand Up @@ -128,6 +128,7 @@ export namespace Components {
interface IotTreeTableDemo {
}
interface SitewiseResourceExplorer {
"appKitSession": IoTAppKitSession;
"columnDefinitions": ColumnDefinition<any>[];
"empty"?: EmptyStateProps;
"filterEnabled": boolean;
Expand Down Expand Up @@ -275,7 +276,7 @@ declare namespace LocalJSX {
"subscription"?: AssetTreeSubscription;
}
interface IotBarChart {
"appKit"?: DataModule;
"appKitSession"?: IoTAppKitSession;
"isEditing"?: boolean | undefined;
"queries"?: AnyDataStreamQuery[];
"settings"?: TimeSeriesDataRequestSettings | undefined;
Expand All @@ -284,14 +285,14 @@ declare namespace LocalJSX {
"widgetId"?: string;
}
interface IotConnector {
"appKit"?: DataModule;
"appKitSession"?: IoTAppKitSession;
"queries"?: AnyDataStreamQuery[];
"renderFunc"?: ({ dataStreams }: { dataStreams: DataStream[] }) => unknown;
"request"?: TimeSeriesDataRequest;
"styleSettings"?: StyleSettingsMap | undefined;
}
interface IotKpi {
"appKit"?: DataModule;
"appKitSession"?: IoTAppKitSession;
"isEditing"?: boolean | undefined;
"queries"?: AnyDataStreamQuery[];
"settings"?: TimeSeriesDataRequestSettings | undefined;
Expand All @@ -300,7 +301,7 @@ declare namespace LocalJSX {
"widgetId"?: string;
}
interface IotLineChart {
"appKit"?: DataModule;
"appKitSession"?: IoTAppKitSession;
"isEditing"?: boolean | undefined;
"queries"?: AnyDataStreamQuery[];
"settings"?: TimeSeriesDataRequestSettings | undefined;
Expand All @@ -310,7 +311,7 @@ declare namespace LocalJSX {
"widgetId"?: string;
}
interface IotResourceExplorer {
"appKit"?: DataModule;
"appKitSession"?: IoTAppKitSession;
"columnDefinitions"?: ColumnDefinition<SitewiseAssetResource>[];
"empty"?: EmptyStateProps;
"filterEnabled"?: boolean;
Expand All @@ -326,7 +327,7 @@ declare namespace LocalJSX {
interface IotResourceExplorerDemo {
}
interface IotScatterChart {
"appKit"?: DataModule;
"appKitSession"?: IoTAppKitSession;
"isEditing"?: boolean | undefined;
"queries"?: AnyDataStreamQuery[];
"settings"?: TimeSeriesDataRequestSettings | undefined;
Expand All @@ -335,7 +336,7 @@ declare namespace LocalJSX {
"widgetId"?: string;
}
interface IotStatusGrid {
"appKit"?: DataModule;
"appKitSession"?: IoTAppKitSession;
"isEditing"?: boolean | undefined;
"queries"?: AnyDataStreamQuery[];
"settings"?: TimeSeriesDataRequestSettings | undefined;
Expand All @@ -344,7 +345,7 @@ declare namespace LocalJSX {
"widgetId"?: string;
}
interface IotStatusTimeline {
"appKit"?: DataModule;
"appKitSession"?: IoTAppKitSession;
"isEditing"?: boolean | undefined;
"queries"?: AnyDataStreamQuery[];
"settings"?: TimeSeriesDataRequestSettings | undefined;
Expand All @@ -353,7 +354,7 @@ declare namespace LocalJSX {
"widgetId"?: string;
}
interface IotTable {
"appKit"?: DataModule;
"appKitSession"?: IoTAppKitSession;
"queries"?: AnyDataStreamQuery[];
"settings"?: TimeSeriesDataRequestSettings | undefined;
"styleSettings"?: StyleSettingsMap | undefined;
Expand Down Expand Up @@ -383,6 +384,7 @@ declare namespace LocalJSX {
interface IotTreeTableDemo {
}
interface SitewiseResourceExplorer {
"appKitSession"?: IoTAppKitSession;
"columnDefinitions"?: ColumnDefinition<any>[];
"empty"?: EmptyStateProps;
"filterEnabled"?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { newSpecPage } from '@stencil/core/testing';
import { MinimalLiveViewport } from '@synchro-charts/core';
import { IotBarChart } from './iot-bar-chart';
import { Components } from '../../components.d';
import { registerDataSource, initialize, SiteWiseDataStreamQuery } from '@iot-app-kit/core';
import { initialize, SiteWiseDataStreamQuery } from '@iot-app-kit/core';
import { createMockSource } from '../../testing/createMockSource';
import { DATA_STREAM } from '../../testing/mockWidgetProperties';
import { IotConnector } from '../iot-connector/iot-connector';
Expand All @@ -14,8 +14,8 @@ const viewport: MinimalLiveViewport = {
};

const barChartSpecPage = async (propOverrides: Partial<Components.IotBarChart> = {}) => {
const appKit = initialize({ registerDataSources: false });
registerDataSource(appKit, createMockSource([DATA_STREAM]));
const appKitSession = initialize({ registerDataSources: false }).session();
appKitSession.registerDataSource(createMockSource([DATA_STREAM]));

const page = await newSpecPage({
components: [IotBarChart, IotConnector],
Expand All @@ -24,7 +24,7 @@ const barChartSpecPage = async (propOverrides: Partial<Components.IotBarChart> =
});
const barChart = page.doc.createElement('iot-bar-chart') as CustomHTMLElement<Components.IotBarChart>;
const props: Partial<Components.IotBarChart> = {
appKit,
appKitSession,
widgetId: 'test-bar-chart-widget',
isEditing: false,
queries: [
Expand Down
15 changes: 10 additions & 5 deletions packages/components/src/components/iot-bar-chart/iot-bar-chart.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { Component, Prop, h } from '@stencil/core';
import { MinimalViewPortConfig } from '@synchro-charts/core';
import { AnyDataStreamQuery, DataModule, TimeSeriesDataRequestSettings, StyleSettingsMap } from '@iot-app-kit/core';
import { MinimalViewPortConfig, DataStream as SynchroChartsDataStream } from '@synchro-charts/core';
import {
AnyDataStreamQuery,
TimeSeriesDataRequestSettings,
StyleSettingsMap,
IoTAppKitSession,
} from '@iot-app-kit/core';

const DEFAULT_VIEWPORT = { duration: 10 * 1000 * 60 };

Expand All @@ -9,7 +14,7 @@ const DEFAULT_VIEWPORT = { duration: 10 * 1000 * 60 };
shadow: false,
})
export class IotBarChart {
@Prop() appKit: DataModule;
@Prop() appKitSession: IoTAppKitSession;

@Prop() queries: AnyDataStreamQuery[];

Expand All @@ -34,7 +39,7 @@ export class IotBarChart {
const settings = this.getSettings();
return (
<iot-connector
appKit={this.appKit}
appKitSession={this.appKitSession}
queries={this.queries}
styleSettings={this.styleSettings}
request={{
Expand All @@ -43,7 +48,7 @@ export class IotBarChart {
}}
renderFunc={({ dataStreams }) => (
<sc-bar-chart
dataStreams={dataStreams}
dataStreams={dataStreams as SynchroChartsDataStream[]}
viewport={this.viewport}
isEditing={this.isEditing}
widgetId={this.widgetId}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,35 @@
import { renderChart, testChartContainerClassNameSelector } from '@iot-app-kit/components/src/testing/renderChart';
import { SECOND_IN_MS } from '@iot-app-kit/core/src/common/time';
import { mockDataResponse } from '../../testing/mocks/response';
import { mockGetAggregatedOrRawResponse } from '../../testing/mocks/mockGetAggregatedOrRawResponse';
import { mockGetAssetSummary } from '../../testing/mocks/mockGetAssetSummaries';

describe('handles gestures', () => {
const assetId = 'some-asset-id';
const assetModelId = 'some-asset-model-id';

before(() => {
cy.intercept('/properties/history?*', (req) => {
req.reply(mockDataResponse(new Date(req.query.startDate), new Date(req.query.endDate)));
req.reply(
mockGetAggregatedOrRawResponse({
startDate: new Date(req.query.startDate),
endDate: new Date(req.query.endDate),
})
);
});

cy.intercept('/properties/aggregates?*', (req) => {
req.reply(
mockDataResponse(new Date(req.query.startDate), new Date(req.query.endDate), req.query.resolution as string)
mockGetAggregatedOrRawResponse({
startDate: new Date(req.query.startDate),
endDate: new Date(req.query.endDate),
resolution: req.query.resolution as string,
})
);
});

cy.intercept(`/assets/${assetId}`, (req) => {
req.reply(mockGetAssetSummary({ assetModelId, id: assetId }));
});
});

it('zooms in and out', () => {
Expand Down
Loading

0 comments on commit 36684eb

Please sign in to comment.