From dff08edc5604985a6414fbb8bbf5bbe7912a9fbf Mon Sep 17 00:00:00 2001 From: Tim Roes Date: Wed, 18 Jul 2018 15:07:32 +0200 Subject: [PATCH 01/12] Refactor vis components to TypeScript --- src/ui/public/persisted_state/index.d.ts | 20 +++ .../persisted_state/persisted_state.d.ts | 22 +++ src/ui/public/vis/index.d.ts | 1 + src/ui/public/vis/update_status.ts | 3 +- src/ui/public/vis/vis.d.ts | 12 +- src/ui/public/vis/vis_types/vis_type.d.ts | 39 +++++ .../visualization_noresults.test.js.snap | 29 ++++ .../components/{index.js => index.ts} | 2 - .../visualize/components/visualization.js | 87 ---------- .../components/visualization.test.js | 8 + .../visualize/components/visualization.tsx | 110 ++++++++++++ .../components/visualization_chart.js | 113 ------------- .../components/visualization_chart.tsx | 156 ++++++++++++++++++ .../visualization_noresults.test.js | 5 + ...results.js => visualization_noresults.tsx} | 8 +- 15 files changed, 408 insertions(+), 207 deletions(-) create mode 100644 src/ui/public/persisted_state/index.d.ts create mode 100644 src/ui/public/persisted_state/persisted_state.d.ts create mode 100644 src/ui/public/vis/vis_types/vis_type.d.ts create mode 100644 src/ui/public/visualize/components/__snapshots__/visualization_noresults.test.js.snap rename src/ui/public/visualize/components/{index.js => index.ts} (91%) delete mode 100644 src/ui/public/visualize/components/visualization.js create mode 100644 src/ui/public/visualize/components/visualization.tsx delete mode 100644 src/ui/public/visualize/components/visualization_chart.js create mode 100644 src/ui/public/visualize/components/visualization_chart.tsx rename src/ui/public/visualize/components/{visualization_noresults.js => visualization_noresults.tsx} (86%) diff --git a/src/ui/public/persisted_state/index.d.ts b/src/ui/public/persisted_state/index.d.ts new file mode 100644 index 0000000000000..ab5a3e7be7d28 --- /dev/null +++ b/src/ui/public/persisted_state/index.d.ts @@ -0,0 +1,20 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +export { PersistedState } from './persisted_state'; diff --git a/src/ui/public/persisted_state/persisted_state.d.ts b/src/ui/public/persisted_state/persisted_state.d.ts new file mode 100644 index 0000000000000..6a02df8f67f7b --- /dev/null +++ b/src/ui/public/persisted_state/persisted_state.d.ts @@ -0,0 +1,22 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +// It's currenty hard to properly type PersistedState, since it dynamically +// inherits the class passed into the constructor. +export type PersistedState = any; diff --git a/src/ui/public/vis/index.d.ts b/src/ui/public/vis/index.d.ts index 0ee214507a9f3..6dddd51132908 100644 --- a/src/ui/public/vis/index.d.ts +++ b/src/ui/public/vis/index.d.ts @@ -19,3 +19,4 @@ export { AggConfig } from './agg_config'; export { Vis, VisProvider } from './vis'; +export { VisualizationController, VisType } from './vis_types/vis_type'; diff --git a/src/ui/public/vis/update_status.ts b/src/ui/public/vis/update_status.ts index 51e26bcc100ad..17b5f968da327 100644 --- a/src/ui/public/vis/update_status.ts +++ b/src/ui/public/vis/update_status.ts @@ -17,6 +17,7 @@ * under the License. */ +import { PersistedState } from '../persisted_state'; import { calculateObjectHash } from './lib/calculate_object_hash'; import { Vis } from './vis'; @@ -57,7 +58,7 @@ function hasSizeChanged(size: Size, oldSize?: Size): boolean { function getUpdateStatus( requiresUpdateStatus: T[] = [], obj: any, - param: { vis: Vis; visData: any; uiState: any } + param: { vis: Vis; visData: any; uiState: PersistedState } ): { [reqStats in T]: boolean } { const status = {} as { [reqStats in T]: boolean }; diff --git a/src/ui/public/vis/vis.d.ts b/src/ui/public/vis/vis.d.ts index 004795920ab41..ef2ac096f27f0 100644 --- a/src/ui/public/vis/vis.d.ts +++ b/src/ui/public/vis/vis.d.ts @@ -17,6 +17,16 @@ * under the License. */ -export type Vis = any; +import { VisType } from './vis_types/vis_type'; + +export interface Vis { + type: VisType; + + // Since we haven't typed everything here yet, we basically "any" the rest + // of that interface. This should be removed as soon as this type definition + // has been completed. But that way we at least have typing for a couple of + // properties on that type. + [key: string]: any; +} export type VisProvider = (...dependencies: any[]) => Vis; diff --git a/src/ui/public/vis/vis_types/vis_type.d.ts b/src/ui/public/vis/vis_types/vis_type.d.ts new file mode 100644 index 0000000000000..e5e0048b7c2e0 --- /dev/null +++ b/src/ui/public/vis/vis_types/vis_type.d.ts @@ -0,0 +1,39 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { Vis } from '..'; +import { Status } from '../update_status'; + +export class VisualizationController { + constructor(element: HTMLElement, vis: Vis); + public render(visData: any, update: { [key in Status]: boolean }): Promise; + public destroy(): void; + public isLoaded?(): Promise | void; +} + +export interface VisType { + visualization: typeof VisualizationController; + isAccessible?: boolean; + + // Since we haven't typed everything here yet, we basically "any" the rest + // of that interface. This should be removed as soon as this type definition + // has been completed. But that way we at least have typing for a couple of + // properties on that type. + [key: string]: any; +} diff --git a/src/ui/public/visualize/components/__snapshots__/visualization_noresults.test.js.snap b/src/ui/public/visualize/components/__snapshots__/visualization_noresults.test.js.snap new file mode 100644 index 0000000000000..332d75e727a22 --- /dev/null +++ b/src/ui/public/visualize/components/__snapshots__/visualization_noresults.test.js.snap @@ -0,0 +1,29 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`VisualizationNoResults should render according to snapshot 1`] = ` +
+
+
+