Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: api simplification of requestSettings #27

Merged
merged 1 commit into from
Jan 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 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, Request, RequestConfig, SiteWiseAssetTreeQuery } from "@iot-app-kit/core";
import { AnyDataStreamQuery, AssetSummaryQuery, AssetTreeSubscription, DataModule, SiteWiseAssetTreeQuery, TimeSeriesDataRequest, TimeSeriesDataRequestSettings } from "@iot-app-kit/core";
import { DataStream, MinimalViewPortConfig } from "@synchro-charts/core";
import { TableProps } from "@awsui/components-react/table";
import { EmptyStateProps, ITreeNode, UseTreeCollection } from "@iot-app-kit/related-table";
Expand All @@ -23,60 +23,60 @@ export namespace Components {
"appKit": DataModule;
"isEditing": boolean | undefined;
"query": AnyDataStreamQuery;
"requestConfig": RequestConfig | undefined;
"settings": TimeSeriesDataRequestSettings | undefined;
"viewport": MinimalViewPortConfig;
"widgetId": string;
}
interface IotConnector {
"appKit": DataModule;
"query": AnyDataStreamQuery;
"renderFunc": ({ dataStreams }: { dataStreams: DataStream[] }) => unknown;
"requestInfo": Request;
"request": TimeSeriesDataRequest;
}
interface IotKpi {
"appKit": DataModule;
"isEditing": boolean | undefined;
"query": AnyDataStreamQuery;
"requestConfig": RequestConfig | undefined;
"settings": TimeSeriesDataRequestSettings | undefined;
"viewport": MinimalViewPortConfig;
"widgetId": string;
}
interface IotLineChart {
"appKit": DataModule;
"isEditing": boolean | undefined;
"query": AnyDataStreamQuery;
"requestConfig": RequestConfig | undefined;
"settings": TimeSeriesDataRequestSettings | undefined;
"viewport": MinimalViewPortConfig;
"widgetId": string;
}
interface IotScatterChart {
"appKit": DataModule;
"isEditing": boolean | undefined;
"query": AnyDataStreamQuery;
"requestConfig": RequestConfig | undefined;
"settings": TimeSeriesDataRequestSettings | undefined;
"viewport": MinimalViewPortConfig;
"widgetId": string;
}
interface IotStatusGrid {
"appKit": DataModule;
"isEditing": boolean | undefined;
"query": AnyDataStreamQuery;
"requestConfig": RequestConfig | undefined;
"settings": TimeSeriesDataRequestSettings | undefined;
"viewport": MinimalViewPortConfig;
"widgetId": string;
}
interface IotStatusTimeline {
"appKit": DataModule;
"isEditing": boolean | undefined;
"query": AnyDataStreamQuery;
"requestConfig": RequestConfig | undefined;
"settings": TimeSeriesDataRequestSettings | undefined;
"viewport": MinimalViewPortConfig;
"widgetId": string;
}
interface IotTable {
"appKit": DataModule;
"query": AnyDataStreamQuery;
"requestConfig": RequestConfig | undefined;
"settings": TimeSeriesDataRequestSettings | undefined;
"viewport": MinimalViewPortConfig;
"widgetId": string;
}
Expand Down Expand Up @@ -242,60 +242,60 @@ declare namespace LocalJSX {
"appKit"?: DataModule;
"isEditing"?: boolean | undefined;
"query"?: AnyDataStreamQuery;
"requestConfig"?: RequestConfig | undefined;
"settings"?: TimeSeriesDataRequestSettings | undefined;
"viewport"?: MinimalViewPortConfig;
"widgetId"?: string;
}
interface IotConnector {
"appKit"?: DataModule;
"query"?: AnyDataStreamQuery;
"renderFunc"?: ({ dataStreams }: { dataStreams: DataStream[] }) => unknown;
"requestInfo"?: Request;
"request"?: TimeSeriesDataRequest;
}
interface IotKpi {
"appKit"?: DataModule;
"isEditing"?: boolean | undefined;
"query"?: AnyDataStreamQuery;
"requestConfig"?: RequestConfig | undefined;
"settings"?: TimeSeriesDataRequestSettings | undefined;
"viewport"?: MinimalViewPortConfig;
"widgetId"?: string;
}
interface IotLineChart {
"appKit"?: DataModule;
"isEditing"?: boolean | undefined;
"query"?: AnyDataStreamQuery;
"requestConfig"?: RequestConfig | undefined;
"settings"?: TimeSeriesDataRequestSettings | undefined;
"viewport"?: MinimalViewPortConfig;
"widgetId"?: string;
}
interface IotScatterChart {
"appKit"?: DataModule;
"isEditing"?: boolean | undefined;
"query"?: AnyDataStreamQuery;
"requestConfig"?: RequestConfig | undefined;
"settings"?: TimeSeriesDataRequestSettings | undefined;
"viewport"?: MinimalViewPortConfig;
"widgetId"?: string;
}
interface IotStatusGrid {
"appKit"?: DataModule;
"isEditing"?: boolean | undefined;
"query"?: AnyDataStreamQuery;
"requestConfig"?: RequestConfig | undefined;
"settings"?: TimeSeriesDataRequestSettings | undefined;
"viewport"?: MinimalViewPortConfig;
"widgetId"?: string;
}
interface IotStatusTimeline {
"appKit"?: DataModule;
"isEditing"?: boolean | undefined;
"query"?: AnyDataStreamQuery;
"requestConfig"?: RequestConfig | undefined;
"settings"?: TimeSeriesDataRequestSettings | undefined;
"viewport"?: MinimalViewPortConfig;
"widgetId"?: string;
}
interface IotTable {
"appKit"?: DataModule;
"query"?: AnyDataStreamQuery;
"requestConfig"?: RequestConfig | undefined;
"settings"?: TimeSeriesDataRequestSettings | undefined;
"viewport"?: MinimalViewPortConfig;
"widgetId"?: string;
}
Expand Down
20 changes: 11 additions & 9 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,6 @@
import { Component, Prop, h } from '@stencil/core';
import { MinimalViewPortConfig } from '@synchro-charts/core';
import { AnyDataStreamQuery, DataModule, Request, RequestConfig } from '@iot-app-kit/core';
import { AnyDataStreamQuery, DataModule, TimeSeriesDataRequestSettings } from '@iot-app-kit/core';

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

Expand All @@ -19,27 +19,29 @@ export class IotBarChart {

@Prop() isEditing: boolean | undefined;

@Prop() requestConfig: RequestConfig | undefined
@Prop() settings: TimeSeriesDataRequestSettings | undefined;

requestInfo(): Request {
getSettings(): TimeSeriesDataRequestSettings {
return {
viewport: this.viewport,
onlyFetchLatestValue: false,
requestConfig: this.requestConfig,
...this.settings,
fetchFromStartToEnd: true,
};
}

render() {
const requestInfo = this.requestInfo();
const settings = this.getSettings();
return (
<iot-connector
appKit={this.appKit}
query={this.query}
requestInfo={requestInfo}
request={{
settings,
viewport: this.viewport,
}}
renderFunc={({ dataStreams }) => (
<sc-bar-chart
dataStreams={dataStreams}
viewport={requestInfo.viewport}
viewport={this.viewport}
isEditing={this.isEditing}
widgetId={this.widgetId}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const connectorSpecPage = async (propOverrides: Partial<Components.IotConnector>
source: 'test-mock',
assets: [],
} as SiteWiseDataStreamQuery, // static casting because of legacy sw
requestInfo: { viewport, onlyFetchLatestValue: true },
request: { viewport, settings: { fetchMostRecentBeforeEnd: true } },
...propOverrides,
};
update(connector, props);
Expand Down
16 changes: 11 additions & 5 deletions packages/components/src/components/iot-connector/iot-connector.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { Component, Prop, State, Watch } from '@stencil/core';
import { DataStream } from '@synchro-charts/core';
import isEqual from 'lodash.isequal';
import { Request, AnyDataStreamQuery, SubscriptionUpdate, subscribeToDataStreams, DataModule } from '@iot-app-kit/core';
import {
AnyDataStreamQuery,
SubscriptionUpdate,
subscribeToDataStreams,
DataModule,
TimeSeriesDataRequest,
} from '@iot-app-kit/core';

@Component({
tag: 'iot-connector',
Expand All @@ -12,7 +18,7 @@ export class IotConnector {

@Prop() query: AnyDataStreamQuery;

@Prop() requestInfo: Request;
@Prop() request: TimeSeriesDataRequest;

@Prop() renderFunc: ({ dataStreams }: { dataStreams: DataStream[] }) => unknown;

Expand All @@ -28,7 +34,7 @@ export class IotConnector {
this.appKit,
{
query: this.query,
requestInfo: this.requestInfo,
request: this.request,
},
(dataStreams: DataStream[]) => {
this.dataStreams = dataStreams;
Expand All @@ -47,13 +53,13 @@ export class IotConnector {
/**
* Sync subscription to change in queried data
*/
@Watch('requestInfo')
@Watch('request')
@Watch('query')
onUpdateProp(newProp: unknown, oldProp: unknown) {
if (!isEqual(newProp, oldProp) && this.update != null) {
this.update({
query: this.query,
requestInfo: this.requestInfo,
request: this.request,
});
}
}
Expand Down
20 changes: 11 additions & 9 deletions packages/components/src/components/iot-kpi/iot-kpi.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component, Prop, h } from '@stencil/core';
import { MinimalViewPortConfig } from '@synchro-charts/core';
import { AnyDataStreamQuery, DataModule, RequestConfig } from '@iot-app-kit/core';
import { AnyDataStreamQuery, DataModule, TimeSeriesDataRequestSettings } from '@iot-app-kit/core';

const DEFAULT_VIEWPORT = { duration: 10 * 1000 };

Expand All @@ -19,27 +19,29 @@ export class IotKpi {

@Prop() isEditing: boolean | undefined;

@Prop() requestConfig: RequestConfig | undefined
@Prop() settings: TimeSeriesDataRequestSettings | undefined;

requestInfo() {
getSettings(): TimeSeriesDataRequestSettings {
return {
viewport: this.viewport,
onlyFetchLatestValue: true,
requestConfig: this.requestConfig,
...this.settings,
fetchMostRecentBeforeEnd: true,
};
}

render() {
const requestInfo = this.requestInfo();
const settings = this.getSettings();
return (
<iot-connector
appKit={this.appKit}
query={this.query}
requestInfo={requestInfo}
request={{
settings,
viewport: this.viewport,
}}
renderFunc={({ dataStreams }) => (
<sc-kpi
dataStreams={dataStreams}
viewport={requestInfo.viewport}
viewport={this.viewport}
isEditing={this.isEditing}
widgetId={this.widgetId}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component, Prop, h } from '@stencil/core';
import { MinimalViewPortConfig } from '@synchro-charts/core';
import { AnyDataStreamQuery, DataModule, Request, RequestConfig } from '@iot-app-kit/core';
import { AnyDataStreamQuery, DataModule, TimeSeriesDataRequestSettings } from '@iot-app-kit/core';

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

Expand All @@ -19,27 +19,31 @@ export class IotLineChart {

@Prop() isEditing: boolean | undefined;

@Prop() requestConfig: RequestConfig | undefined
@Prop() settings: TimeSeriesDataRequestSettings | undefined;

requestInfo(): Request {
getSettings(): TimeSeriesDataRequestSettings {
return {
viewport: this.viewport,
onlyFetchLatestValue: false,
requestConfig: this.requestConfig,
...this.settings,
fetchFromStartToEnd: true,
// Required to be able to draw line from last point visible, to first point before the viewport.
fetchMostRecentBeforeStart: true,
};
}

render() {
const requestInfo = this.requestInfo();
const settings = this.getSettings();
return (
<iot-connector
appKit={this.appKit}
query={this.query}
requestInfo={requestInfo}
request={{
settings,
viewport: this.viewport,
}}
renderFunc={({ dataStreams }) => (
<sc-line-chart
dataStreams={dataStreams}
viewport={requestInfo.viewport}
viewport={this.viewport}
isEditing={this.isEditing}
widgetId={this.widgetId}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component, Prop, h } from '@stencil/core';
import { MinimalViewPortConfig } from '@synchro-charts/core';
import { AnyDataStreamQuery, DataModule, Request, RequestConfig } from '@iot-app-kit/core';
import { AnyDataStreamQuery, DataModule, TimeSeriesDataRequestSettings } from '@iot-app-kit/core';

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

Expand All @@ -19,27 +19,29 @@ export class IotScatterChart {

@Prop() isEditing: boolean | undefined;

@Prop() requestConfig: RequestConfig | undefined
@Prop() settings: TimeSeriesDataRequestSettings | undefined;

requestInfo(): Request {
getSettings(): TimeSeriesDataRequestSettings {
return {
viewport: this.viewport,
onlyFetchLatestValue: false,
requestConfig: this.requestConfig,
...this.settings,
fetchFromStartToEnd: true,
};
}

render() {
const requestInfo = this.requestInfo();
const settings = this.getSettings();
return (
<iot-connector
appKit={this.appKit}
query={this.query}
requestInfo={requestInfo}
request={{
settings,
viewport: this.viewport,
}}
renderFunc={({ dataStreams }) => (
<sc-scatter-chart
dataStreams={dataStreams}
viewport={requestInfo.viewport}
viewport={this.viewport}
isEditing={this.isEditing}
widgetId={this.widgetId}
/>
Expand Down
Loading