From 7e9a693e0f0e1701573099a33ffe23b96f9e2f7d Mon Sep 17 00:00:00 2001 From: Ashwin P Chandran Date: Thu, 21 Jul 2022 18:48:58 -0700 Subject: [PATCH] [D&D] Feature/experimental (#1934) * feat: experimental banner Signed-off-by: Ashwin Pc * feat: experimental embeddable Signed-off-by: Ashwin Pc * fix: experimental banner location Signed-off-by: Ashwin Pc --- .../wizard/type_selection/type_selection.tsx | 18 ++++---- .../components/experimental_info.tsx | 43 +++++++++++++++++++ .../application/components/workspace.tsx | 4 ++ .../public/embeddable/disabled_embeddable.tsx | 34 +++++++++++++++ .../embeddable/disabled_visualization.scss | 8 ++++ .../embeddable/disabled_visualization.tsx | 31 +++++++++++++ .../embeddable/wizard_embeddable_factory.tsx | 28 +++++++++--- src/plugins/wizard/public/plugin.ts | 1 + 8 files changed, 151 insertions(+), 16 deletions(-) create mode 100644 src/plugins/wizard/public/application/components/experimental_info.tsx create mode 100644 src/plugins/wizard/public/embeddable/disabled_embeddable.tsx create mode 100644 src/plugins/wizard/public/embeddable/disabled_visualization.scss create mode 100644 src/plugins/wizard/public/embeddable/disabled_visualization.tsx diff --git a/src/plugins/visualizations/public/wizard/type_selection/type_selection.tsx b/src/plugins/visualizations/public/wizard/type_selection/type_selection.tsx index 27ea53f0f16f..c5c6546c01c0 100644 --- a/src/plugins/visualizations/public/wizard/type_selection/type_selection.tsx +++ b/src/plugins/visualizations/public/wizard/type_selection/type_selection.tsx @@ -182,21 +182,19 @@ class TypeSelection extends React.Component { - // Filter out all lab visualizations if lab mode is not enabled + const filterExperimental = (type: VisType | VisTypeAlias): boolean => { if (!this.props.showExperimental && type.stage === 'experimental') { return false; } - - // Filter out hidden visualizations - if (type.hidden) { - return false; - } - return true; - }); + }; - const allTypes = [...types, ...visTypes.getAliases()]; + const types = visTypes + .all() + .filter(filterExperimental) + .filter((type) => !type.hidden); // Filter out hidden visualizations + const aliasedTypes = visTypes.getAliases().filter(filterExperimental); + const allTypes = [...types, ...aliasedTypes]; let entries: VisTypeListEntry[]; if (!query) { diff --git a/src/plugins/wizard/public/application/components/experimental_info.tsx b/src/plugins/wizard/public/application/components/experimental_info.tsx new file mode 100644 index 000000000000..cc4d0cab1340 --- /dev/null +++ b/src/plugins/wizard/public/application/components/experimental_info.tsx @@ -0,0 +1,43 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import React, { memo } from 'react'; +import { EuiCallOut, EuiLink } from '@elastic/eui'; +import { FormattedMessage } from '@osd/i18n/react'; + +export const InfoComponent = () => { + const title = ( + <> + + GitHub + + ), + }} + /> + + ); + + return ( + + ); +}; + +export const ExperimentalInfo = memo(InfoComponent); diff --git a/src/plugins/wizard/public/application/components/workspace.tsx b/src/plugins/wizard/public/application/components/workspace.tsx index 9a910b51c320..39d75a7c43d2 100644 --- a/src/plugins/wizard/public/application/components/workspace.tsx +++ b/src/plugins/wizard/public/application/components/workspace.tsx @@ -27,6 +27,7 @@ import hand_field from '../../assets/hand_field.svg'; import fields_bg from '../../assets/fields_bg.svg'; import './workspace.scss'; +import { ExperimentalInfo } from './experimental_info'; export const Workspace: FC = ({ children }) => { const { @@ -84,6 +85,9 @@ export const Workspace: FC = ({ children }) => { + + + {expression ? ( diff --git a/src/plugins/wizard/public/embeddable/disabled_embeddable.tsx b/src/plugins/wizard/public/embeddable/disabled_embeddable.tsx new file mode 100644 index 000000000000..5f55859156d0 --- /dev/null +++ b/src/plugins/wizard/public/embeddable/disabled_embeddable.tsx @@ -0,0 +1,34 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import React from 'react'; +import ReactDOM from 'react-dom'; +import { Embeddable, EmbeddableOutput } from '../../../embeddable/public'; + +import { DisabledVisualization } from './disabled_visualization'; +import { WizardInput, WIZARD_EMBEDDABLE } from './wizard_embeddable'; + +export class DisabledEmbeddable extends Embeddable { + private domNode?: HTMLElement; + public readonly type = WIZARD_EMBEDDABLE; + + constructor(private readonly title: string, initialInput: WizardInput) { + super(initialInput, { title }); + } + + public reload() {} + public render(domNode: HTMLElement) { + if (this.title) { + this.domNode = domNode; + ReactDOM.render(, domNode); + } + } + + public destroy() { + if (this.domNode) { + ReactDOM.unmountComponentAtNode(this.domNode); + } + } +} diff --git a/src/plugins/wizard/public/embeddable/disabled_visualization.scss b/src/plugins/wizard/public/embeddable/disabled_visualization.scss new file mode 100644 index 000000000000..73f22386e80e --- /dev/null +++ b/src/plugins/wizard/public/embeddable/disabled_visualization.scss @@ -0,0 +1,8 @@ +.wizDisabledVisualization { + width: 100%; + display: grid; + grid-gap: $euiSize; + place-content: center; + place-items: center; + text-align: center; +} diff --git a/src/plugins/wizard/public/embeddable/disabled_visualization.tsx b/src/plugins/wizard/public/embeddable/disabled_visualization.tsx new file mode 100644 index 000000000000..04b8bf234541 --- /dev/null +++ b/src/plugins/wizard/public/embeddable/disabled_visualization.tsx @@ -0,0 +1,31 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { EuiIcon } from '@elastic/eui'; +import { FormattedMessage } from '@osd/i18n/react'; +import React from 'react'; + +import './disabled_visualization.scss'; + +export function DisabledVisualization({ title }: { title: string }) { + return ( +
+ +
+ {title} }} + /> +
+
+ +
+
+ ); +} diff --git a/src/plugins/wizard/public/embeddable/wizard_embeddable_factory.tsx b/src/plugins/wizard/public/embeddable/wizard_embeddable_factory.tsx index ce1780d0066e..b870687c2d2e 100644 --- a/src/plugins/wizard/public/embeddable/wizard_embeddable_factory.tsx +++ b/src/plugins/wizard/public/embeddable/wizard_embeddable_factory.tsx @@ -4,18 +4,25 @@ */ import { i18n } from '@osd/i18n'; -import { NotificationsStart, SavedObjectsClientContract } from '../../../../core/public'; +import { + IUiSettingsClient, + NotificationsStart, + SavedObjectsClientContract, +} from '../../../../core/public'; import { DataPublicPluginStart } from '../../../data/public'; import { EmbeddableFactory, EmbeddableFactoryDefinition, + EmbeddableOutput, EmbeddableStart, ErrorEmbeddable, IContainer, } from '../../../embeddable/public'; import { ExpressionsStart } from '../../../expressions/public'; +import { VISUALIZE_ENABLE_LABS_SETTING } from '../../../visualizations/public'; import { WizardSavedObjectAttributes } from '../../common'; import { TypeServiceStart } from '../services/type_service'; +import { DisabledEmbeddable } from './disabled_embeddable'; import { WizardEmbeddable, WizardInput, @@ -30,13 +37,14 @@ interface StartServices { savedObjectsClient: SavedObjectsClientContract; notifications: NotificationsStart; types: TypeServiceStart; + uiSettings: IUiSettingsClient; } // TODO: use or remove? export type WizardEmbeddableFactory = EmbeddableFactory< WizardInput, - WizardOutput, - WizardEmbeddable, + WizardOutput | EmbeddableOutput, + WizardEmbeddable | DisabledEmbeddable, WizardSavedObjectAttributes >; @@ -44,8 +52,8 @@ export class WizardEmbeddableFactoryDefinition implements EmbeddableFactoryDefinition< WizardInput, - WizardOutput, - WizardEmbeddable, + WizardOutput | EmbeddableOutput, + WizardEmbeddable | DisabledEmbeddable, WizardSavedObjectAttributes > { public readonly type = WIZARD_EMBEDDABLE; @@ -69,7 +77,7 @@ export class WizardEmbeddableFactoryDefinition savedObjectId: string, input: Partial & { id: string }, parent?: IContainer - ): Promise => { + ): Promise => { return this.create({ ...input, savedObjectId }, parent); }; @@ -81,7 +89,15 @@ export class WizardEmbeddableFactoryDefinition notifications: { toasts }, savedObjectsClient, types, + uiSettings, } = await this.getStartServices(); + + const isLabsEnabled = uiSettings.get(VISUALIZE_ENABLE_LABS_SETTING); + + if (!isLabsEnabled) { + return new DisabledEmbeddable('Wizard', input); + } + return new WizardEmbeddable(input, { parent, data, diff --git a/src/plugins/wizard/public/plugin.ts b/src/plugins/wizard/public/plugin.ts index 422dc78c7d0b..4946c93761e9 100644 --- a/src/plugins/wizard/public/plugin.ts +++ b/src/plugins/wizard/public/plugin.ts @@ -104,6 +104,7 @@ export class WizardPlugin expressions: pluginsStart.expressions, notifications: coreStart.notifications, types: this.typeService.start(), + uiSettings: coreStart.uiSettings, }; }); embeddable.registerEmbeddableFactory(WIZARD_EMBEDDABLE, embeddableFactory);