Skip to content

Commit

Permalink
feat!(component): replace table component in @iot-app-kit/components (#…
Browse files Browse the repository at this point in the history
…147)

* feat: Replace iot-table with new version.

* Update autogenerated types

* fix import

* another fix for import

* another fix for import

* Remove unused property for Iot.

* Fix a typo

* Code cleanups.

* Code cleanups.

* update type of `ColumnDefinition.formatter`

also added a few use cases in testing-ground.tsx

* update type of `ColumnDefinition.formatter`

also added a few use cases in testing-ground.tsx

* Update asset/property IDs and table examples.

* update: add formatter to filterOptions

Property filtering options now has the same displayed value as table.

* update formatPropertyFilterOptions function to better handle error & loading states.

* update test examples for table component.

* Disable Customized formatter for property filter options.

* update test cases after disabled formatter for filter options

* Remove unused dependency.

* a few bug fixes
- Split sorting and propertyFiltering
- Remove formatting on property filtering options.

* UI adjustment - center icon and string vertically.

* Update styles and unit tests

* Remove unused imports and statements.

* Reformat css file

* Restore testing ground
  • Loading branch information
square-li committed Sep 13, 2022
1 parent dc0328c commit c75d4f0
Show file tree
Hide file tree
Showing 14 changed files with 392 additions and 268 deletions.
120 changes: 33 additions & 87 deletions packages/components/src/components.d.ts
Expand Up @@ -5,37 +5,27 @@
* It contains typing information for all components that exist in this project.
*/
import { HTMLStencilElement, JSXBase } from "@stencil/core/internal";
import { Annotations } from "@synchro-charts/core";
import { Provider, StyleSettingsMap, TimeQuery, TimeSeriesData, TimeSeriesDataRequest, TimeSeriesDataRequestSettings, TreeQuery, Viewport } from "@iot-app-kit/core";
import { AlarmsConfig, Annotations, Axis, LabelsConfig, LayoutConfig, LegendConfig, MessageOverrides, MinimalSizeConfig, MovementConfig, ScaleConfig, TableColumn, Trend } from "@synchro-charts/core";
import { Item, TableItem, TableProps } from "@iot-app-kit/table";
import { BranchReference, SiteWiseAssetTreeNode } from "@iot-app-kit/source-iotsitewise";
import { ColumnDefinition, FilterTexts } from "./components/iot-resource-explorer/types";
import { TableProps } from "@awsui/components-react/table";
import { TableProps as TableProps1 } from "@awsui/components-react/table";
import { EmptyStateProps, ITreeNode, UseTreeCollection } from "@iot-app-kit/related-table";
import { NonCancelableCustomEvent } from "@awsui/components-react";
export namespace Components {
interface IotBarChart {
"alarms"?: AlarmsConfig;
"annotations": Annotations;
"axis"?: Axis.Options;
"gestures"?: boolean;
"isEditing": boolean | undefined;
"layout"?: LayoutConfig;
"legend"?: LegendConfig;
"messageOverrides"?: MessageOverrides;
"movement"?: MovementConfig;
"queries": TimeQuery<TimeSeriesData[], TimeSeriesDataRequest>[];
"scale"?: ScaleConfig;
"settings": TimeSeriesDataRequestSettings;
"size"?: MinimalSizeConfig;
"styleSettings": StyleSettingsMap | undefined;
"trends": Trend[];
"viewport": Viewport;
"widgetId": string;
}
interface IotKpi {
"annotations": Annotations;
"isEditing": boolean | undefined;
"messageOverrides"?: MessageOverrides;
"queries": TimeQuery<TimeSeriesData[], TimeSeriesDataRequest>[];
"settings": TimeSeriesDataRequestSettings;
"styleSettings": StyleSettingsMap | undefined;
Expand All @@ -44,22 +34,19 @@ export namespace Components {
}
interface IotLineChart {
"annotations": Annotations;
"axis": Axis.Options;
"gestures"?: boolean;
"isEditing": boolean | undefined;
"layout"?: LayoutConfig;
"legend"?: LegendConfig;
"messageOverrides": MessageOverrides;
"movement"?: MovementConfig;
"queries": TimeQuery<TimeSeriesData[], TimeSeriesDataRequest>[];
"scale"?: ScaleConfig;
"settings": TimeSeriesDataRequestSettings;
"size"?: MinimalSizeConfig;
"styleSettings": StyleSettingsMap | undefined;
"trends": Trend[];
"viewport": Viewport;
"widgetId": string;
}
interface IotReactTable {
"columnDefinitions": TableProps['columnDefinitions'];
"items": TableItem[];
"propertyFiltering": TableProps['propertyFiltering'];
"sorting": TableProps['sorting'];
}
interface IotResourceExplorer {
"columnDefinitions": ColumnDefinition<any>[];
"empty"?: EmptyStateProps;
Expand All @@ -78,59 +65,41 @@ export namespace Components {
interface IotResourceExplorerDemo {
}
interface IotScatterChart {
"alarms"?: AlarmsConfig;
"annotations": Annotations;
"axis"?: Axis.Options;
"gestures"?: boolean;
"isEditing": boolean | undefined;
"layout"?: LayoutConfig;
"legend"?: LegendConfig;
"messageOverrides"?: MessageOverrides;
"movement"?: MovementConfig;
"queries": TimeQuery<TimeSeriesData[], TimeSeriesDataRequest>[];
"scale"?: ScaleConfig;
"settings": TimeSeriesDataRequestSettings;
"size"?: MinimalSizeConfig;
"styleSettings": StyleSettingsMap | undefined;
"trends": Trend[];
"viewport": Viewport;
"widgetId": string;
}
interface IotStatusGrid {
"annotations": Annotations;
"isEditing": boolean | undefined;
"labelsConfig": LabelsConfig;
"queries": TimeQuery<TimeSeriesData[], TimeSeriesDataRequest>[];
"settings": TimeSeriesDataRequestSettings;
"styleSettings": StyleSettingsMap | undefined;
"viewport": Viewport;
"widgetId": string;
}
interface IotStatusTimeline {
"alarms"?: AlarmsConfig;
"annotations"?: Annotations;
"axis"?: Axis.Options;
"gestures"?: boolean;
"annotations": Annotations;
"isEditing": boolean | undefined;
"layout"?: LayoutConfig;
"messageOverrides"?: MessageOverrides;
"movement"?: MovementConfig;
"queries": TimeQuery<TimeSeriesData[], TimeSeriesDataRequest>[];
"scale"?: ScaleConfig;
"settings": TimeSeriesDataRequestSettings;
"size"?: MinimalSizeConfig;
"styleSettings": StyleSettingsMap | undefined;
"viewport": Viewport;
"widgetId": string;
}
interface IotTable {
"annotations": Annotations;
"messageOverrides"?: MessageOverrides;
"columnDefinitions": TableProps['columnDefinitions'];
"items": Item[];
"propertyFiltering": TableProps['propertyFiltering'];
"queries": TimeQuery<TimeSeriesData[], TimeSeriesDataRequest>[];
"settings": TimeSeriesDataRequestSettings;
"sorting": TableProps['sorting'];
"styleSettings": StyleSettingsMap | undefined;
"tableColumns": TableColumn[];
"trends": Trend[];
"viewport": Viewport;
"widgetId": string;
}
Expand Down Expand Up @@ -188,6 +157,12 @@ declare global {
prototype: HTMLIotLineChartElement;
new (): HTMLIotLineChartElement;
};
interface HTMLIotReactTableElement extends Components.IotReactTable, HTMLStencilElement {
}
var HTMLIotReactTableElement: {
prototype: HTMLIotReactTableElement;
new (): HTMLIotReactTableElement;
};
interface HTMLIotResourceExplorerElement extends Components.IotResourceExplorer, HTMLStencilElement {
}
var HTMLIotResourceExplorerElement: {
Expand Down Expand Up @@ -264,6 +239,7 @@ declare global {
"iot-bar-chart": HTMLIotBarChartElement;
"iot-kpi": HTMLIotKpiElement;
"iot-line-chart": HTMLIotLineChartElement;
"iot-react-table": HTMLIotReactTableElement;
"iot-resource-explorer": HTMLIotResourceExplorerElement;
"iot-resource-explorer-demo": HTMLIotResourceExplorerDemoElement;
"iot-scatter-chart": HTMLIotScatterChartElement;
Expand All @@ -280,28 +256,17 @@ declare global {
}
declare namespace LocalJSX {
interface IotBarChart {
"alarms"?: AlarmsConfig;
"annotations"?: Annotations;
"axis"?: Axis.Options;
"gestures"?: boolean;
"isEditing"?: boolean | undefined;
"layout"?: LayoutConfig;
"legend"?: LegendConfig;
"messageOverrides"?: MessageOverrides;
"movement"?: MovementConfig;
"queries": TimeQuery<TimeSeriesData[], TimeSeriesDataRequest>[];
"scale"?: ScaleConfig;
"settings"?: TimeSeriesDataRequestSettings;
"size"?: MinimalSizeConfig;
"styleSettings"?: StyleSettingsMap | undefined;
"trends"?: Trend[];
"viewport": Viewport;
"widgetId"?: string;
}
interface IotKpi {
"annotations"?: Annotations;
"isEditing"?: boolean | undefined;
"messageOverrides"?: MessageOverrides;
"queries": TimeQuery<TimeSeriesData[], TimeSeriesDataRequest>[];
"settings"?: TimeSeriesDataRequestSettings;
"styleSettings"?: StyleSettingsMap | undefined;
Expand All @@ -310,22 +275,19 @@ declare namespace LocalJSX {
}
interface IotLineChart {
"annotations"?: Annotations;
"axis"?: Axis.Options;
"gestures"?: boolean;
"isEditing"?: boolean | undefined;
"layout"?: LayoutConfig;
"legend"?: LegendConfig;
"messageOverrides"?: MessageOverrides;
"movement"?: MovementConfig;
"queries": TimeQuery<TimeSeriesData[], TimeSeriesDataRequest>[];
"scale"?: ScaleConfig;
"settings"?: TimeSeriesDataRequestSettings;
"size"?: MinimalSizeConfig;
"styleSettings"?: StyleSettingsMap | undefined;
"trends"?: Trend[];
"viewport": Viewport;
"widgetId"?: string;
}
interface IotReactTable {
"columnDefinitions": TableProps['columnDefinitions'];
"items": TableItem[];
"propertyFiltering"?: TableProps['propertyFiltering'];
"sorting"?: TableProps['sorting'];
}
interface IotResourceExplorer {
"columnDefinitions"?: ColumnDefinition<any>[];
"empty"?: EmptyStateProps;
Expand All @@ -344,59 +306,41 @@ declare namespace LocalJSX {
interface IotResourceExplorerDemo {
}
interface IotScatterChart {
"alarms"?: AlarmsConfig;
"annotations"?: Annotations;
"axis"?: Axis.Options;
"gestures"?: boolean;
"isEditing"?: boolean | undefined;
"layout"?: LayoutConfig;
"legend"?: LegendConfig;
"messageOverrides"?: MessageOverrides;
"movement"?: MovementConfig;
"queries": TimeQuery<TimeSeriesData[], TimeSeriesDataRequest>[];
"scale"?: ScaleConfig;
"settings"?: TimeSeriesDataRequestSettings;
"size"?: MinimalSizeConfig;
"styleSettings"?: StyleSettingsMap | undefined;
"trends"?: Trend[];
"viewport": Viewport;
"widgetId"?: string;
}
interface IotStatusGrid {
"annotations"?: Annotations;
"isEditing"?: boolean | undefined;
"labelsConfig"?: LabelsConfig;
"queries": TimeQuery<TimeSeriesData[], TimeSeriesDataRequest>[];
"settings"?: TimeSeriesDataRequestSettings;
"styleSettings"?: StyleSettingsMap | undefined;
"viewport": Viewport;
"widgetId"?: string;
}
interface IotStatusTimeline {
"alarms"?: AlarmsConfig;
"annotations"?: Annotations;
"axis"?: Axis.Options;
"gestures"?: boolean;
"isEditing"?: boolean | undefined;
"layout"?: LayoutConfig;
"messageOverrides"?: MessageOverrides;
"movement"?: MovementConfig;
"queries": TimeQuery<TimeSeriesData[], TimeSeriesDataRequest>[];
"scale"?: ScaleConfig;
"settings"?: TimeSeriesDataRequestSettings;
"size"?: MinimalSizeConfig;
"styleSettings"?: StyleSettingsMap | undefined;
"viewport": Viewport;
"widgetId"?: string;
}
interface IotTable {
"annotations"?: Annotations;
"messageOverrides"?: MessageOverrides;
"columnDefinitions": TableProps['columnDefinitions'];
"items": Item[];
"propertyFiltering"?: TableProps['propertyFiltering'];
"queries": TimeQuery<TimeSeriesData[], TimeSeriesDataRequest>[];
"settings"?: TimeSeriesDataRequestSettings;
"sorting"?: TableProps['sorting'];
"styleSettings"?: StyleSettingsMap | undefined;
"tableColumns"?: TableColumn[];
"trends"?: Trend[];
"viewport": Viewport;
"widgetId"?: string;
}
Expand Down Expand Up @@ -438,6 +382,7 @@ declare namespace LocalJSX {
"iot-bar-chart": IotBarChart;
"iot-kpi": IotKpi;
"iot-line-chart": IotLineChart;
"iot-react-table": IotReactTable;
"iot-resource-explorer": IotResourceExplorer;
"iot-resource-explorer-demo": IotResourceExplorerDemo;
"iot-scatter-chart": IotScatterChart;
Expand All @@ -459,6 +404,7 @@ declare module "@stencil/core" {
"iot-bar-chart": LocalJSX.IotBarChart & JSXBase.HTMLAttributes<HTMLIotBarChartElement>;
"iot-kpi": LocalJSX.IotKpi & JSXBase.HTMLAttributes<HTMLIotKpiElement>;
"iot-line-chart": LocalJSX.IotLineChart & JSXBase.HTMLAttributes<HTMLIotLineChartElement>;
"iot-react-table": LocalJSX.IotReactTable & JSXBase.HTMLAttributes<HTMLIotReactTableElement>;
"iot-resource-explorer": LocalJSX.IotResourceExplorer & JSXBase.HTMLAttributes<HTMLIotResourceExplorerElement>;
"iot-resource-explorer-demo": LocalJSX.IotResourceExplorerDemo & JSXBase.HTMLAttributes<HTMLIotResourceExplorerDemoElement>;
"iot-scatter-chart": LocalJSX.IotScatterChart & JSXBase.HTMLAttributes<HTMLIotScatterChartElement>;
Expand Down
43 changes: 43 additions & 0 deletions packages/components/src/components/iot-table/iot-react-table.tsx
@@ -0,0 +1,43 @@
import { Component, Element, Host, Prop, State, h } from '@stencil/core';
import React, { FunctionComponent } from 'react';
import { createRoot, Root } from 'react-dom/client';
import { Table, TableItem, TableProps } from '@iot-app-kit/table';

@Component({
tag: 'iot-react-table',
})
export class IotReactTable {
@Prop() items!: TableItem[];

@Prop() columnDefinitions!: TableProps['columnDefinitions'];

@Prop() sorting: TableProps['sorting'];

@Prop() propertyFiltering: TableProps['propertyFiltering'];

@Element() host: HTMLElement;

@State() root: Root;

componentWillLoad() {
this.root = createRoot(this.host);
}

componentDidLoad() {
this.componentDidUpdate();
}

componentDidUpdate() {
const props: TableProps = {
items: this.items,
columnDefinitions: this.columnDefinitions,
sorting: this.sorting,
propertyFiltering: this.propertyFiltering,
};
this.root.render(React.createElement<TableProps>(Table as FunctionComponent<TableProps>, props));
}

render() {
return <Host />;
}
}
21 changes: 20 additions & 1 deletion packages/components/src/components/iot-table/iot-table.spec.tsx
Expand Up @@ -23,9 +23,28 @@ const tableSpecPage = async (propOverrides: Partial<Components.IotKpi> = {}) =>
supportsShadowDom: false,
});
const table = page.doc.createElement('iot-table') as CustomHTMLElement<Components.IotTable>;
const items: Components.IotTable['items'] = [
{
property: {
$cellRef: {
id: 'some-asset-id',
resolution: 0,
},
},
},
];

const columnDefinitions: Components.IotTable['columnDefinitions'] = [
{
header: 'Header',
key: 'property',
},
];
const props: Partial<Components.IotTable> = {
isEditing: false,
viewport,
items,
columnDefinitions,
queries: [
query.timeSeriesData({
assets: [{ assetId: 'some-asset-id', properties: [{ propertyId: 'some-property-id' }] }],
Expand All @@ -44,6 +63,6 @@ const tableSpecPage = async (propOverrides: Partial<Components.IotKpi> = {}) =>

it('renders', async () => {
const { table } = await tableSpecPage();
const tables = table.querySelectorAll('sc-table');
const tables = table.querySelectorAll('iot-react-table');
expect(tables.length).toBe(1);
});

0 comments on commit c75d4f0

Please sign in to comment.