diff --git a/src/plugins/wizard/public/application/components/data_source_select.tsx b/src/plugins/wizard/public/application/components/data_source_select.tsx index 3bbae08573b9..08c4f86008bf 100644 --- a/src/plugins/wizard/public/application/components/data_source_select.tsx +++ b/src/plugins/wizard/public/application/components/data_source_select.tsx @@ -8,7 +8,6 @@ import { i18n } from '@osd/i18n'; import { EuiIcon } from '@elastic/eui'; import { SearchableDropdown, SearchableDropdownOption } from './searchable_dropdown'; import { useIndexPatterns } from '../utils/use'; -import indexPatternSvg from '../../assets/index_pattern.svg'; import { useTypedDispatch } from '../utils/state_management'; import { setIndexPattern } from '../utils/state_management/visualization_slice'; import { IndexPattern } from '../../../../data/public'; @@ -22,7 +21,7 @@ function toSearchableDropdownOption(indexPattern: IndexPattern): SearchableDropd id: indexPattern.id || '', label: indexPattern.title, searchableLabel: indexPattern.title, - prepend: , + prepend: , }; } diff --git a/src/plugins/wizard/public/application/contributions/containers/data_tab/config_panel.scss b/src/plugins/wizard/public/application/components/data_tab/config_panel.scss similarity index 100% rename from src/plugins/wizard/public/application/contributions/containers/data_tab/config_panel.scss rename to src/plugins/wizard/public/application/components/data_tab/config_panel.scss diff --git a/src/plugins/wizard/public/application/contributions/containers/data_tab/config_panel.tsx b/src/plugins/wizard/public/application/components/data_tab/config_panel.tsx similarity index 79% rename from src/plugins/wizard/public/application/contributions/containers/data_tab/config_panel.tsx rename to src/plugins/wizard/public/application/components/data_tab/config_panel.tsx index 07683666eb79..1c0e67693471 100644 --- a/src/plugins/wizard/public/application/contributions/containers/data_tab/config_panel.tsx +++ b/src/plugins/wizard/public/application/components/data_tab/config_panel.tsx @@ -5,10 +5,10 @@ import { EuiForm } from '@elastic/eui'; import React from 'react'; -import { useVisualizationType } from '../../../utils/use'; -import { useTypedSelector } from '../../../utils/state_management'; +import { useVisualizationType } from '../../utils/use'; +import { useTypedSelector } from '../../utils/state_management'; import './config_panel.scss'; -import { mapSchemaToAggPanel } from './utils/schema_to_dropbox'; +import { mapSchemaToAggPanel } from './schema_to_dropbox'; import { SecondaryPanel } from './secondary_panel'; export function ConfigPanel() { diff --git a/src/plugins/wizard/public/application/contributions/containers/data_tab/items/dropbox.scss b/src/plugins/wizard/public/application/components/data_tab/dropbox.scss similarity index 100% rename from src/plugins/wizard/public/application/contributions/containers/data_tab/items/dropbox.scss rename to src/plugins/wizard/public/application/components/data_tab/dropbox.scss diff --git a/src/plugins/wizard/public/application/contributions/containers/data_tab/items/dropbox.tsx b/src/plugins/wizard/public/application/components/data_tab/dropbox.tsx similarity index 95% rename from src/plugins/wizard/public/application/contributions/containers/data_tab/items/dropbox.tsx rename to src/plugins/wizard/public/application/components/data_tab/dropbox.tsx index 29dda2cfd9c4..451bbe4e52eb 100644 --- a/src/plugins/wizard/public/application/contributions/containers/data_tab/items/dropbox.tsx +++ b/src/plugins/wizard/public/application/components/data_tab/dropbox.tsx @@ -14,12 +14,16 @@ import { DropResult, } from '@elastic/eui'; import React, { useCallback } from 'react'; -import { IDropAttributes, IDropState } from '../../../../utils/drag_drop'; +import { IDropAttributes, IDropState } from '../../utils/drag_drop'; import './dropbox.scss'; -import { DropboxDisplay } from './types'; import { useDropbox } from './use'; import { UseDropboxProps } from './use/use_dropbox'; +export interface DropboxDisplay { + label: string; + id: string; +} + interface DropboxProps extends IDropState { id: string; label: string; diff --git a/src/plugins/wizard/public/application/contributions/containers/data_tab/field_search.tsx b/src/plugins/wizard/public/application/components/data_tab/field_search.tsx similarity index 88% rename from src/plugins/wizard/public/application/contributions/containers/data_tab/field_search.tsx rename to src/plugins/wizard/public/application/components/data_tab/field_search.tsx index 772e308bbc9b..62dcf2c2b953 100644 --- a/src/plugins/wizard/public/application/contributions/containers/data_tab/field_search.tsx +++ b/src/plugins/wizard/public/application/components/data_tab/field_search.tsx @@ -6,8 +6,8 @@ import React from 'react'; import { i18n } from '@osd/i18n'; import { EuiFieldSearch, EuiFlexGroup, EuiFlexItem } from '@elastic/eui'; -import { setSearchField } from '../../../utils/state_management/visualization_slice'; -import { useTypedDispatch } from '../../../utils/state_management'; +import { setSearchField } from '../../utils/state_management/visualization_slice'; +import { useTypedDispatch } from '../../utils/state_management'; export interface Props { /** diff --git a/src/plugins/wizard/public/application/contributions/containers/data_tab/field_selector.scss b/src/plugins/wizard/public/application/components/data_tab/field_selector.scss similarity index 92% rename from src/plugins/wizard/public/application/contributions/containers/data_tab/field_selector.scss rename to src/plugins/wizard/public/application/components/data_tab/field_selector.scss index e2c44387126a..a7d43f6464f7 100644 --- a/src/plugins/wizard/public/application/contributions/containers/data_tab/field_selector.scss +++ b/src/plugins/wizard/public/application/components/data_tab/field_selector.scss @@ -1,11 +1,13 @@ -@import "../../../util"; +@import "../../util"; .wizFieldSelector { @include scrollNavParent(auto 1fr); + padding: $euiSizeS; &__fieldGroups { @include euiYScrollWithShadows; + overflow-y: auto; margin-right: -$euiSizeS; padding-right: $euiSizeS; @@ -14,7 +16,7 @@ &__fieldGroup { margin-top: $euiSizeS; - + &:first-child { margin-top: 0; } diff --git a/src/plugins/wizard/public/application/contributions/containers/data_tab/field_selector.tsx b/src/plugins/wizard/public/application/components/data_tab/field_selector.tsx similarity index 95% rename from src/plugins/wizard/public/application/contributions/containers/data_tab/field_selector.tsx rename to src/plugins/wizard/public/application/components/data_tab/field_selector.tsx index 70dac772a190..2361e8d1d073 100644 --- a/src/plugins/wizard/public/application/contributions/containers/data_tab/field_selector.tsx +++ b/src/plugins/wizard/public/application/components/data_tab/field_selector.tsx @@ -11,12 +11,12 @@ import { IndexPatternField, OPENSEARCH_FIELD_TYPES, OSD_FIELD_TYPES, -} from '../../../../../../data/public'; +} from '../../../../../data/public'; import { FieldSelectorField } from './field_selector_field'; import './field_selector.scss'; -import { useTypedSelector } from '../../../utils/state_management'; -import { useIndexPattern } from '../../../utils/use'; +import { useTypedSelector } from '../../utils/state_management'; +import { useIndexPattern } from '../../utils/use'; interface IFieldCategories { categorical: IndexPatternField[]; diff --git a/src/plugins/wizard/public/application/contributions/containers/data_tab/field_selector_field.scss b/src/plugins/wizard/public/application/components/data_tab/field_selector_field.scss similarity index 99% rename from src/plugins/wizard/public/application/contributions/containers/data_tab/field_selector_field.scss rename to src/plugins/wizard/public/application/components/data_tab/field_selector_field.scss index 0ace9a914b37..e2f9919af3a8 100644 --- a/src/plugins/wizard/public/application/contributions/containers/data_tab/field_selector_field.scss +++ b/src/plugins/wizard/public/application/components/data_tab/field_selector_field.scss @@ -1,5 +1,6 @@ .wizFieldSelectorField { @include euiBottomShadowSmall; + padding: $euiSizeXS; background-color: $euiColorEmptyShade; border: $euiBorderThin; diff --git a/src/plugins/wizard/public/application/contributions/containers/data_tab/field_selector_field.tsx b/src/plugins/wizard/public/application/components/data_tab/field_selector_field.tsx similarity index 92% rename from src/plugins/wizard/public/application/contributions/containers/data_tab/field_selector_field.tsx rename to src/plugins/wizard/public/application/components/data_tab/field_selector_field.tsx index f000f9395280..cfa2220eed6e 100644 --- a/src/plugins/wizard/public/application/contributions/containers/data_tab/field_selector_field.tsx +++ b/src/plugins/wizard/public/application/components/data_tab/field_selector_field.tsx @@ -29,9 +29,9 @@ */ import React, { useState } from 'react'; -import { IndexPatternField } from 'src/plugins/data/public'; -import { FieldButton, FieldIcon } from '../../../../../../opensearch_dashboards_react/public'; -import { useDrag } from '../../../utils/drag_drop/drag_drop_context'; +import { IndexPatternField } from '../../../../../data/public'; +import { FieldButton, FieldIcon } from '../../../../../opensearch_dashboards_react/public'; +import { useDrag } from '../../utils/drag_drop/drag_drop_context'; import './field_selector_field.scss'; diff --git a/src/plugins/wizard/public/application/contributions/containers/data_tab/index.scss b/src/plugins/wizard/public/application/components/data_tab/index.scss similarity index 79% rename from src/plugins/wizard/public/application/contributions/containers/data_tab/index.scss rename to src/plugins/wizard/public/application/components/data_tab/index.scss index 773a12538430..dab7ed4cdda3 100644 --- a/src/plugins/wizard/public/application/contributions/containers/data_tab/index.scss +++ b/src/plugins/wizard/public/application/components/data_tab/index.scss @@ -1,7 +1,8 @@ -@import "../../../util"; +@import "../../util"; .wizDataTab { @include scrollNavParent; + display: grid; grid-template-columns: 50% 50%; } diff --git a/src/plugins/wizard/public/application/contributions/containers/data_tab/index.tsx b/src/plugins/wizard/public/application/components/data_tab/index.tsx similarity index 94% rename from src/plugins/wizard/public/application/contributions/containers/data_tab/index.tsx rename to src/plugins/wizard/public/application/components/data_tab/index.tsx index 9fefef7d8ce9..1f880f20698d 100644 --- a/src/plugins/wizard/public/application/contributions/containers/data_tab/index.tsx +++ b/src/plugins/wizard/public/application/components/data_tab/index.tsx @@ -19,5 +19,3 @@ export const DataTab = () => { ); }; - -export * from './items'; diff --git a/src/plugins/wizard/public/application/contributions/containers/data_tab/utils/schema_to_dropbox.tsx b/src/plugins/wizard/public/application/components/data_tab/schema_to_dropbox.tsx similarity index 77% rename from src/plugins/wizard/public/application/contributions/containers/data_tab/utils/schema_to_dropbox.tsx rename to src/plugins/wizard/public/application/components/data_tab/schema_to_dropbox.tsx index b14a8bd13d85..37c55e25be99 100644 --- a/src/plugins/wizard/public/application/contributions/containers/data_tab/utils/schema_to_dropbox.tsx +++ b/src/plugins/wizard/public/application/components/data_tab/schema_to_dropbox.tsx @@ -4,8 +4,9 @@ */ import React from 'react'; -import { Schemas } from '../../../../../../../vis_default_editor/public'; -import { Title, Dropbox } from '../items'; +import { Schemas } from '../../../../../vis_default_editor/public'; +import { Dropbox } from './dropbox'; +import { Title } from './title'; export const mapSchemaToAggPanel = (schemas: Schemas) => { const panelComponents = schemas.all.map((schema) => { diff --git a/src/plugins/wizard/public/application/contributions/containers/data_tab/secondary_panel.tsx b/src/plugins/wizard/public/application/components/data_tab/secondary_panel.tsx similarity index 75% rename from src/plugins/wizard/public/application/contributions/containers/data_tab/secondary_panel.tsx rename to src/plugins/wizard/public/application/components/data_tab/secondary_panel.tsx index d896116a445d..c897a9b018c5 100644 --- a/src/plugins/wizard/public/application/contributions/containers/data_tab/secondary_panel.tsx +++ b/src/plugins/wizard/public/application/components/data_tab/secondary_panel.tsx @@ -5,14 +5,14 @@ import React, { useCallback, useMemo, useState } from 'react'; import { cloneDeep } from 'lodash'; -import { useTypedDispatch, useTypedSelector } from '../../../utils/state_management'; -import { DefaultEditorAggParams } from '../../../../../../vis_default_editor/public'; -import { Title } from './items'; -import { useIndexPattern, useVisualizationType } from '../../../utils/use'; -import { useOpenSearchDashboards } from '../../../../../../opensearch_dashboards_react/public'; -import { WizardServices } from '../../../../types'; -import { IAggType } from '../../../../../../data/public'; -import { saveAgg, editAgg } from '../../../utils/state_management/visualization_slice'; +import { useTypedDispatch, useTypedSelector } from '../../utils/state_management'; +import { DefaultEditorAggParams } from '../../../../../vis_default_editor/public'; +import { Title } from './title'; +import { useIndexPattern, useVisualizationType } from '../../utils/use'; +import { useOpenSearchDashboards } from '../../../../../opensearch_dashboards_react/public'; +import { WizardServices } from '../../../types'; +import { IAggType } from '../../../../../data/public'; +import { saveAgg, editAgg } from '../../utils/state_management/visualization_slice'; export function SecondaryPanel() { const draftAgg = useTypedSelector((state) => state.visualization.activeVisualization!.draftAgg); @@ -38,8 +38,8 @@ export function SecondaryPanel() { const aggConfig = aggConfigs?.aggs[0]; - const groupName = useMemo( - () => schemas.find((schema) => schema.name === aggConfig?.schema)?.group, + const selectedSchema = useMemo( + () => schemas.find((schema) => schema.name === aggConfig?.schema), [aggConfig?.schema, schemas] ); @@ -52,7 +52,7 @@ export function SecondaryPanel() { return (
- + <Title title={selectedSchema?.title ?? 'Edit'} isSecondary closeMenu={closeMenu} /> {showAggParamEditor && ( <DefaultEditorAggParams className="wizConfig__aggEditor" @@ -62,7 +62,7 @@ export function SecondaryPanel() { setTouched={setTouched} schemas={schemas} formIsTouched={false} - groupName={groupName ?? 'none'} + groupName={selectedSchema?.group ?? 'none'} metricAggs={[]} state={{ data: {}, diff --git a/src/plugins/wizard/public/application/contributions/containers/data_tab/items/title.tsx b/src/plugins/wizard/public/application/components/data_tab/title.tsx similarity index 100% rename from src/plugins/wizard/public/application/contributions/containers/data_tab/items/title.tsx rename to src/plugins/wizard/public/application/components/data_tab/title.tsx diff --git a/src/plugins/wizard/public/application/contributions/containers/data_tab/items/use/index.ts b/src/plugins/wizard/public/application/components/data_tab/use/index.ts similarity index 72% rename from src/plugins/wizard/public/application/contributions/containers/data_tab/items/use/index.ts rename to src/plugins/wizard/public/application/components/data_tab/use/index.ts index 87b259c5a86e..64265e655fa7 100644 --- a/src/plugins/wizard/public/application/contributions/containers/data_tab/items/use/index.ts +++ b/src/plugins/wizard/public/application/components/data_tab/use/index.ts @@ -4,4 +4,3 @@ */ export { useDropbox } from './use_dropbox'; -export { useFormField } from './use_form_field'; diff --git a/src/plugins/wizard/public/application/contributions/containers/data_tab/items/use/use_dropbox.tsx b/src/plugins/wizard/public/application/components/data_tab/use/use_dropbox.tsx similarity index 86% rename from src/plugins/wizard/public/application/contributions/containers/data_tab/items/use/use_dropbox.tsx rename to src/plugins/wizard/public/application/components/data_tab/use/use_dropbox.tsx index ebabb90eccbf..60290fc96e93 100644 --- a/src/plugins/wizard/public/application/contributions/containers/data_tab/items/use/use_dropbox.tsx +++ b/src/plugins/wizard/public/application/components/data_tab/use/use_dropbox.tsx @@ -5,29 +5,24 @@ import { useState, useEffect, useCallback, useMemo } from 'react'; import { cloneDeep } from 'lodash'; -import { BucketAggType, IndexPatternField, propFilter } from '../../../../../../../../data/common'; -import { Schema } from '../../../../../../../../vis_default_editor/public'; -import { FieldDragDataType } from '../../../../../utils/drag_drop/types'; -import { useTypedDispatch, useTypedSelector } from '../../../../../utils/state_management'; -import { DropboxState, DropboxDisplay } from '../types'; -import { DropboxProps } from '../dropbox'; -import { useDrop } from '../../../../../utils/drag_drop'; +import { BucketAggType, IndexPatternField, propFilter } from '../../../../../../data/common'; +import { Schema } from '../../../../../../vis_default_editor/public'; +import { FieldDragDataType } from '../../../utils/drag_drop/types'; +import { useTypedDispatch, useTypedSelector } from '../../../utils/state_management'; +import { DropboxDisplay, DropboxProps } from '../dropbox'; +import { useDrop } from '../../../utils/drag_drop'; import { editAgg, reorderAgg, updateAggConfigParams, -} from '../../../../../utils/state_management/visualization_slice'; -import { useIndexPattern } from '../../../../../../application/utils/use/use_index_pattern'; -import { useOpenSearchDashboards } from '../../../../../../../../opensearch_dashboards_react/public'; -import { WizardServices } from '../../../../../../types'; +} from '../../../utils/state_management/visualization_slice'; +import { useIndexPattern } from '../../../utils/use/use_index_pattern'; +import { useOpenSearchDashboards } from '../../../../../../opensearch_dashboards_react/public'; +import { WizardServices } from '../../../../types'; const filterByName = propFilter('name'); const filterByType = propFilter('type'); -export const INITIAL_STATE: DropboxState = { - instances: [], -}; - export interface UseDropboxProps extends Pick<DropboxProps, 'id' | 'label'> { schema: Schema; } @@ -192,6 +187,8 @@ export const useDropbox = (props: UseDropboxProps): DropboxProps => { }; }, [aggService.types, dragData, indexPattern?.fields, schema.aggFilter, schema.group]); + const canDrop = validAggTypes.length > 0 && schema.max > dropboxAggs.length; + return { id: dropboxId, label, @@ -203,7 +200,7 @@ export const useDropbox = (props: UseDropboxProps): DropboxProps => { onReorderField, ...dropState, dragData, - isValidDropTarget: validAggTypes.length > 0, + isValidDropTarget: canDrop, dropProps, }; }; diff --git a/src/plugins/wizard/public/application/components/searchable_dropdown.scss b/src/plugins/wizard/public/application/components/searchable_dropdown.scss index 6de99e91356d..bd997b5a075d 100644 --- a/src/plugins/wizard/public/application/components/searchable_dropdown.scss +++ b/src/plugins/wizard/public/application/components/searchable_dropdown.scss @@ -10,14 +10,14 @@ } .searchableDropdown--fixedWidthChild { - width: calc(#{$wizSideNavWidth} - #{$euiSizeXL} * 2) ; + width: calc(#{$wizSideNavWidth} - #{$euiSizeXL} * 2); } .searchableDropdown--topDisplay { padding-right: $euiSizeL; + font-size: $euiFontSizeS; } - .searchableDropdown--selectableWrapper .euiSelectableList { // When clicking on the selectable content it will "highlight" itself with a box shadow // This turns that off diff --git a/src/plugins/wizard/public/application/components/searchable_dropdown.tsx b/src/plugins/wizard/public/application/components/searchable_dropdown.tsx index da6795335088..0d489b818167 100644 --- a/src/plugins/wizard/public/application/components/searchable_dropdown.tsx +++ b/src/plugins/wizard/public/application/components/searchable_dropdown.tsx @@ -142,6 +142,7 @@ export const SearchableDropdown = ({ const selectedView = ( <EuiButtonEmpty color="text" + size="s" style={{ textAlign: 'left' }} className="searchableDropdown--topDisplay" onClick={onButtonClick} @@ -150,21 +151,25 @@ export const SearchableDropdown = ({ </EuiButtonEmpty> ); - const formControl = <EuiFormControlLayout - title={selected === undefined ? "Select an option" : selected.label} + const formControl = ( + <EuiFormControlLayout + title={selected === undefined ? 'Select an option' : selected.label} isLoading={loading} fullWidth={true} style={{ cursor: 'pointer' }} prepend={prepend} icon={{ type: 'arrowDown', side: 'right' }} readOnly={true} - >{selectedView}</EuiFormControlLayout> + > + {selectedView} + </EuiFormControlLayout> + ); return ( - <div className="searchableDropdown"> - <EuiPopover button={formControl} isOpen={isPopoverOpen} closePopover={closePopover}> - <div className="searchableDropdown--fixedWidthChild">{selectable}</div> - </EuiPopover> - </div> + <div className="searchableDropdown"> + <EuiPopover button={formControl} isOpen={isPopoverOpen} closePopover={closePopover}> + <div className="searchableDropdown--fixedWidthChild">{selectable}</div> + </EuiPopover> + </div> ); }; diff --git a/src/plugins/wizard/public/application/components/side_nav.tsx b/src/plugins/wizard/public/application/components/side_nav.tsx index c79f63d7b5c0..4e4291f1c447 100644 --- a/src/plugins/wizard/public/application/components/side_nav.tsx +++ b/src/plugins/wizard/public/application/components/side_nav.tsx @@ -8,7 +8,7 @@ import { EuiTabbedContent, EuiTabbedContentTab } from '@elastic/eui'; import './side_nav.scss'; import { useVisualizationType } from '../utils/use'; import { DataSourceSelect } from './data_source_select'; -import { DataTab } from '../contributions'; +import { DataTab } from './data_tab'; import { StyleTabConfig } from '../../services/type_service'; export const SideNav = () => { diff --git a/src/plugins/wizard/public/application/components/workspace.tsx b/src/plugins/wizard/public/application/components/workspace.tsx index 7747eef57cba..94e0d037b4f6 100644 --- a/src/plugins/wizard/public/application/components/workspace.tsx +++ b/src/plugins/wizard/public/application/components/workspace.tsx @@ -17,6 +17,7 @@ import { import React, { FC, useState, useMemo, useEffect } from 'react'; import { useOpenSearchDashboards } from '../../../../opensearch_dashboards_react/public'; import { WizardServices } from '../../types'; +import { validateSchemaState } from '../utils/validate_schema_state'; import { useTypedDispatch, useTypedSelector } from '../utils/state_management'; import { setActiveVisualization } from '../utils/state_management/visualization_slice'; import { useVisualizationType } from '../utils/use'; @@ -27,20 +28,30 @@ export const Workspace: FC = ({ children }) => { const { services: { expressions: { ReactExpressionRenderer }, + notifications: { toasts }, }, } = useOpenSearchDashboards<WizardServices>(); - const { toExpression } = useVisualizationType(); + const { toExpression, ui } = useVisualizationType(); const [expression, setExpression] = useState<string>(); const rootState = useTypedSelector((state) => state); useEffect(() => { async function loadExpression() { + const schemas = ui.containerConfig.data.schemas; + const [valid, errorMsg] = validateSchemaState(schemas, rootState); + + if (!valid) { + if (errorMsg) { + toasts.addWarning(errorMsg); + } + return; + } const exp = await toExpression(rootState); setExpression(exp); } loadExpression(); - }, [rootState, toExpression]); + }, [rootState, toExpression, toasts, ui.containerConfig.data.schemas]); return ( <section className="wizWorkspace"> @@ -94,7 +105,8 @@ const TypeSelectorPopover = () => { icon: <EuiIcon type={icon} />, onClick: () => { closePopover(); - dispatch(setActiveVisualization(name)); + // TODO: Fix changing viz type + // dispatch(setActiveVisualization(name)); }, toolTipContent: description, toolTipPosition: 'right', @@ -102,7 +114,7 @@ const TypeSelectorPopover = () => { ), }, ], - [dispatch, visualizationTypes] + [visualizationTypes] ); const button = ( diff --git a/src/plugins/wizard/public/application/contributions/constants.ts b/src/plugins/wizard/public/application/contributions/constants.ts deleted file mode 100644 index 0a581cabec81..000000000000 --- a/src/plugins/wizard/public/application/contributions/constants.ts +++ /dev/null @@ -1,12 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -import { CommonItemTypes } from './containers/common/items'; -import { DataTabItemTypes } from './containers/data_tab/items'; - -export const ItemTypes = { - ...CommonItemTypes, - ...DataTabItemTypes, -}; diff --git a/src/plugins/wizard/public/application/contributions/containers/common/items/index.tsx b/src/plugins/wizard/public/application/contributions/containers/common/items/index.tsx deleted file mode 100644 index eb081eb2932a..000000000000 --- a/src/plugins/wizard/public/application/contributions/containers/common/items/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -export * from './types'; - -export { Select } from './select'; -export { TextInput } from './text_input'; diff --git a/src/plugins/wizard/public/application/contributions/containers/common/items/select.tsx b/src/plugins/wizard/public/application/contributions/containers/common/items/select.tsx deleted file mode 100644 index cc6c0060c5b0..000000000000 --- a/src/plugins/wizard/public/application/contributions/containers/common/items/select.tsx +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -import React, { useMemo } from 'react'; -import { EuiFormRow, EuiSuperSelect } from '@elastic/eui'; -import { WizardServices } from 'src/plugins/wizard/public'; -import { useOpenSearchDashboards } from '../../../../../../../opensearch_dashboards_react/public'; -import { useTypedSelector } from '../../../../utils/state_management'; -import { SelectContribution } from './types'; - -interface SelectProps extends Omit<SelectContribution<string>, 'type'> { - value: string; -} - -export const Select = ({ label, options, onChange, value, ...rest }: SelectProps) => { - const rootState = useTypedSelector((state) => state); - const { services } = useOpenSearchDashboards<WizardServices>(); - const selectOptions = useMemo( - () => (typeof options === 'function' ? options(rootState, services) : options), - [options, rootState, services] - ); - // const { isInvalid, errorMessage } = getFieldValidityAndErrorMessage(field); - - return ( - <EuiFormRow - label={label} - // error={errorMessage} - // isInvalid={isInvalid} - fullWidth - data-test-subj={rest['data-test-subj']} - describedByIds={rest.idAria ? [rest.idAria] : undefined} - > - <EuiSuperSelect - fullWidth - onChange={(newValue) => { - onChange?.(newValue); - }} - // isInvalid={isInvalid} - valueOfSelected={value || ''} - data-test-subj="select" - options={selectOptions} - /> - </EuiFormRow> - ); -}; diff --git a/src/plugins/wizard/public/application/contributions/containers/common/items/text_input.tsx b/src/plugins/wizard/public/application/contributions/containers/common/items/text_input.tsx deleted file mode 100644 index 91d34a16f072..000000000000 --- a/src/plugins/wizard/public/application/contributions/containers/common/items/text_input.tsx +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -import React from 'react'; -import { EuiFormRow, EuiFieldText } from '@elastic/eui'; -import { InputContribution } from './types'; - -interface InputProps extends Omit<InputContribution, 'type'> { - value: string; -} - -export const TextInput = ({ label, onChange, value, ...rest }: InputProps) => { - // const { isInvalid, errorMessage } = getFieldValidityAndErrorMessage(field); - - return ( - <EuiFormRow - label={label} - // error={errorMessage} - // isInvalid={isInvalid} - fullWidth - data-test-subj={rest['data-test-subj']} - describedByIds={rest.idAria ? [rest.idAria] : undefined} - > - <EuiFieldText - fullWidth - onChange={(event) => { - onChange?.(event.target.value); - }} - // isInvalid={isInvalid} - value={value || ''} - data-test-subj="text_input" - /> - </EuiFormRow> - ); -}; diff --git a/src/plugins/wizard/public/application/contributions/containers/common/items/types.ts b/src/plugins/wizard/public/application/contributions/containers/common/items/types.ts deleted file mode 100644 index 1761a4de2000..000000000000 --- a/src/plugins/wizard/public/application/contributions/containers/common/items/types.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -import { EuiSuperSelectProps } from '@elastic/eui'; -import { WizardServices } from 'src/plugins/wizard/public'; -import { RootState } from '../../../../utils/state_management'; - -/** - * Types for contributions shared across various panels - */ -export enum ITEM_TYPES { - SELECT = 'select', - INPUT = 'input', -} - -export const CommonItemTypes = { - ...ITEM_TYPES, -}; - -export interface SelectContribution<T extends string> { - type: ITEM_TYPES.SELECT; - id: string; - label: string; - options: - | EuiSuperSelectProps<T>['options'] - | ((state: RootState, services: WizardServices) => EuiSuperSelectProps<T>['options']); - onChange?: (option: string) => void; - 'data-test-subj'?: string; - idAria?: string; -} - -export interface InputContribution { - type: ITEM_TYPES.INPUT; - id: string; - label: string; - onChange?: (value: string) => void; - 'data-test-subj'?: string; - idAria?: string; -} - -export type CommonItemContribution = SelectContribution<string> | InputContribution; diff --git a/src/plugins/wizard/public/application/contributions/containers/data_tab/items/form_field.tsx b/src/plugins/wizard/public/application/contributions/containers/data_tab/items/form_field.tsx deleted file mode 100644 index d068474eb267..000000000000 --- a/src/plugins/wizard/public/application/contributions/containers/data_tab/items/form_field.tsx +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ -import React, { ComponentType } from 'react'; -import { Select, TextInput, ITEM_TYPES } from '../../common/items'; -import { FieldContributions } from './types'; -import { useFormField } from './use'; - -const mapItemToFormFieldComponent: { [key in ITEM_TYPES]: ComponentType<any> } = { - [ITEM_TYPES.SELECT]: Select, - [ITEM_TYPES.INPUT]: TextInput, -}; - -export const FormField = ({ type, id, onChange, ...props }: FieldContributions) => { - const FieldComponent = mapItemToFormFieldComponent[type]; - const hookProps = useFormField(id, onChange); - - return <FieldComponent {...props} {...hookProps} />; -}; diff --git a/src/plugins/wizard/public/application/contributions/containers/data_tab/items/index.tsx b/src/plugins/wizard/public/application/contributions/containers/data_tab/items/index.tsx deleted file mode 100644 index 72a3ad62df58..000000000000 --- a/src/plugins/wizard/public/application/contributions/containers/data_tab/items/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -export * from './types'; -export * from './dropbox'; -export { Title } from './title'; -export { FormField } from './form_field'; diff --git a/src/plugins/wizard/public/application/contributions/containers/data_tab/items/types.ts b/src/plugins/wizard/public/application/contributions/containers/data_tab/items/types.ts deleted file mode 100644 index 5a5c14e4e2d1..000000000000 --- a/src/plugins/wizard/public/application/contributions/containers/data_tab/items/types.ts +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -import { IndexPatternField } from 'src/plugins/data/common'; -import { SelectContribution, InputContribution } from '../../common/items'; - -/** - * Types for contributions that relate to the config panel - */ - -export enum ITEM_TYPES { - DROPBOX = 'dropbox', - TITLE = 'title', -} - -export const DataTabItemTypes = { - ...ITEM_TYPES, -}; - -export type FieldContributions = SelectContribution<string> | InputContribution; -export type MainItemContribution = TitleItemContribution | DropboxContribution | FieldContributions; -export type SecondaryItemContribution = TitleItemContribution | FieldContributions; - -export interface TitleItemContribution { - type: ITEM_TYPES.TITLE; - title: string; -} - -export interface DropboxDisplay { - label: string; - id: string; -} -export interface DropboxFieldProps { - fieldName?: string; - [itemId: string]: any; -} - -export interface DropboxContribution { - type: ITEM_TYPES.DROPBOX; - id: string; - label: string; - limit?: number; - items: SecondaryItemContribution[]; - // Define how the IndexPatternField should be displayed on the dropbox - display?: ( - indexField: IndexPatternField, - state: DropboxFieldProps - ) => Pick<DropboxDisplay, 'label'>; - // Defines how the initial state of a field should be set when a field is dropped onto it - onDrop?: (field: IndexPatternField) => DropboxFieldProps; - isDroppable?: (field: IndexPatternField) => boolean; -} - -export interface InstanceState<T> { - instances: Array<{ - id: string; - properties: T; - }>; -} - -export type DropboxState = InstanceState<DropboxFieldProps>; -export type InstanceItemStates = DropboxState; -export type ConfigItemState = InstanceItemStates | string | undefined; diff --git a/src/plugins/wizard/public/application/contributions/containers/data_tab/items/use/use_form_field.tsx b/src/plugins/wizard/public/application/contributions/containers/data_tab/items/use/use_form_field.tsx deleted file mode 100644 index 03d22dd0e7ff..000000000000 --- a/src/plugins/wizard/public/application/contributions/containers/data_tab/items/use/use_form_field.tsx +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -import produce from 'immer'; -import { useCallback, useMemo } from 'react'; -// import { -// ConfigState, -// updateConfigItemState, -// updateInstance, -// } from '../../../../../utils/state_management/config_slice'; -import { useTypedSelector, useTypedDispatch } from '../../../../../utils/state_management'; -import { FieldContributions } from '../types'; - -export const INDEX_FIELD_KEY = 'fieldName'; - -interface FieldProps { - onChange: Function; - value: string; -} - -export const useFormField = (id: string, onChange: FieldContributions['onChange']): FieldProps => { - const configState = useTypedSelector((state) => state.config); - const { activeItem, items } = configState; - const dispatch = useTypedDispatch(); - - const instanceState = useMemo(() => getInstanceState(configState) ?? {}, [configState]); - - const handleChange = useCallback( - (newValue: string) => { - onChange?.(newValue); - - // TODO: Will cleanup once add and edit field support is reintroduced - - // is a MainPanel field value - if (!activeItem) { - // dispatch( - // // updateConfigItemState({ - // // id, - // // itemState: newValue, - // // }) - // ); - return; - } - - const newInstanceState = produce(instanceState, (draftState) => { - draftState[id] = newValue; - }); - - // dispatch( - // updateInstance({ - // id: activeItem.id, - // instanceId: activeItem.instanceId, - // instanceState: newInstanceState, - // }) - // ); - }, - [activeItem, id, instanceState, onChange] - ); - - return { - value: activeItem ? instanceState[id] : items[id], - onChange: handleChange, - }; -}; - -function getInstanceState({ items, activeItem }: ConfigState) { - const { id: parentItemId, instanceId } = activeItem ?? {}; - const configItem = items[parentItemId ?? '']; - - if (!configItem || typeof configItem === 'string') return; - - const instanceItem = configItem.instances.find(({ id }) => id === instanceId); - - if (!instanceItem) return; - - return instanceItem.properties; -} diff --git a/src/plugins/wizard/public/application/contributions/containers/data_tab/utils/item_to_panel.tsx b/src/plugins/wizard/public/application/contributions/containers/data_tab/utils/item_to_panel.tsx deleted file mode 100644 index db9dfdaf7dee..000000000000 --- a/src/plugins/wizard/public/application/contributions/containers/data_tab/utils/item_to_panel.tsx +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -import React from 'react'; -import { ItemTypes } from '../../../constants'; -import { - Title, - Dropbox, - FormField, - MainItemContribution, - SecondaryItemContribution, -} from '../items'; - -export const mapItemToPanelComponents = ( - items: Array<MainItemContribution | SecondaryItemContribution>, - isSecondary = false -) => { - const uniqueDict: { [key: string]: boolean } = {}; - - const [title, ...panelComponents] = items - .filter((item) => { - // Ensure unique item ID - const id = item.type !== ItemTypes.TITLE ? item.id : 'title'; - if (uniqueDict[id]) return false; - - uniqueDict[id] = true; - return true; - }) - .sort((itemA, itemB) => - // Ensure that the title is on top - itemA.type === ItemTypes.TITLE ? -1 : itemB.type === ItemTypes.TITLE ? 1 : 0 - ) - .map((item, index) => { - const { type } = item; - - switch (type) { - case ItemTypes.TITLE: - return <Title key={index} {...item} isSecondary={isSecondary} />; - - case ItemTypes.DROPBOX: - return <Dropbox key={item.id} {...item} />; - - case ItemTypes.SELECT: - case ItemTypes.INPUT: - return <FormField key={item.id} {...item} />; - - default: - break; - } - }); - - return ( - <> - {title} - <div className="wizConfig__content">{panelComponents}</div> - </> - ); -}; diff --git a/src/plugins/wizard/public/application/contributions/containers/index.ts b/src/plugins/wizard/public/application/contributions/containers/index.ts deleted file mode 100644 index 74d0a6b8f76e..000000000000 --- a/src/plugins/wizard/public/application/contributions/containers/index.ts +++ /dev/null @@ -1,7 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -export * from './data_tab'; -export * from './style_tab'; diff --git a/src/plugins/wizard/public/application/contributions/containers/style_tab/index.tsx b/src/plugins/wizard/public/application/contributions/containers/style_tab/index.tsx deleted file mode 100644 index 6da05f6715e7..000000000000 --- a/src/plugins/wizard/public/application/contributions/containers/style_tab/index.tsx +++ /dev/null @@ -1,12 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -import React from 'react'; - -export const STYLE_TAB_ID = 'style_tab'; - -export const StyleTab = () => { - return <div>TODO: Layout styles come here.</div>; -}; diff --git a/src/plugins/wizard/public/application/contributions/index.ts b/src/plugins/wizard/public/application/contributions/index.ts deleted file mode 100644 index 6ea0ec832393..000000000000 --- a/src/plugins/wizard/public/application/contributions/index.ts +++ /dev/null @@ -1,6 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ -export * from './containers'; -export * from './constants'; diff --git a/src/plugins/wizard/public/application/utils/async_search/index.ts b/src/plugins/wizard/public/application/utils/async_search/index.ts deleted file mode 100644 index 9746cde24e4c..000000000000 --- a/src/plugins/wizard/public/application/utils/async_search/index.ts +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -import { CreateAggConfigParams } from 'src/plugins/data/common'; -import { DataPublicPluginStart, IndexPattern } from 'src/plugins/data/public'; - -interface IDoAsyncSearch { - data: DataPublicPluginStart; - indexPattern: IndexPattern | null; - aggs?: CreateAggConfigParams[]; -} - -export const doAsyncSearch = async ({ data, indexPattern, aggs }: IDoAsyncSearch) => { - if (!indexPattern || !aggs || !aggs.length) return; - - // Constuct the query portion of the search request - const query = data.query.getOpenSearchQuery(indexPattern); - - // Constuct the aggregations portion of the search request by using the `data.search.aggs` service. - // const aggs = [{ type: 'avg', params: { field: field.name } }]; - // const aggs = [ - // { type: 'terms', params: { field: 'day_of_week' } }, - // { type: 'avg', params: { field: field.name } }, - // { type: 'terms', params: { field: 'customer_gender' } }, - // ]; - const aggConfigs = data.search.aggs.createAggConfigs(indexPattern, aggs); - const aggsDsl = aggConfigs.toDsl(); - - const request = { - params: { - index: indexPattern.title, - body: { - aggs: aggsDsl, - query, - }, - }, - }; - - // Submit the search request using the `data.search` service. - const { rawResponse } = await data.search.search(request).toPromise(); - - return { - rawResponse, - aggConfigs, - }; -}; diff --git a/src/plugins/wizard/public/application/utils/state_management/visualization_slice.ts b/src/plugins/wizard/public/application/utils/state_management/visualization_slice.ts index d18396197a2f..f7d4d3ff6d49 100644 --- a/src/plugins/wizard/public/application/utils/state_management/visualization_slice.ts +++ b/src/plugins/wizard/public/application/utils/state_management/visualization_slice.ts @@ -4,7 +4,7 @@ */ import { createSlice, PayloadAction } from '@reduxjs/toolkit'; -import { CreateAggConfigParams } from 'src/plugins/data/common'; +import { CreateAggConfigParams } from '../../../../../data/common'; import { WizardServices } from '../../../types'; interface VisualizationState { diff --git a/src/plugins/wizard/public/application/utils/validate_schema_state.ts b/src/plugins/wizard/public/application/utils/validate_schema_state.ts new file mode 100644 index 000000000000..2db3653e2ce3 --- /dev/null +++ b/src/plugins/wizard/public/application/utils/validate_schema_state.ts @@ -0,0 +1,37 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { countBy } from 'lodash'; +import { Schemas } from '../../../../vis_default_editor/public'; +import { RootState } from './state_management'; + +export const validateSchemaState = (schemas: Schemas, state: RootState): [boolean, string?] => { + const activeViz = state.visualization.activeVisualization; + const vizName = activeViz?.name; + const aggs = activeViz?.aggConfigParams; + + // Check if any aggreagations exist + if (aggs?.length === 0) { + return [false]; + } + + // Check if each schema's min agg requirement is met + const aggSchemaCount = countBy(aggs, (agg) => agg.schema); + const invalidsSchemas = schemas.all.filter((schema) => { + if (!schema.min) return false; + if (!aggSchemaCount[schema.name] || aggSchemaCount[schema.name] < schema.min) return true; + + return false; + }); + + if (invalidsSchemas.length > 0) { + return [ + false, + `The ${vizName} visualization needs at least ${invalidsSchemas[0].min} field(s) in the agg type "${invalidsSchemas[0].name}"`, + ]; + } + + return [true, '']; +}; diff --git a/src/plugins/wizard/public/services/type_service/type_service.test.ts b/src/plugins/wizard/public/services/type_service/type_service.test.ts index 7edf38e7e5e0..89e1ecb59154 100644 --- a/src/plugins/wizard/public/services/type_service/type_service.test.ts +++ b/src/plugins/wizard/public/services/type_service/type_service.test.ts @@ -6,11 +6,14 @@ import { VisualizationTypeOptions } from './types'; import { TypeService } from './type_service'; -const DEFAULT_VIZ_PROPS = { +const DEFAULT_VIZ_PROPS: VisualizationTypeOptions = { name: 'some-name', icon: 'some-icon', title: 'Some Title', - contributions: {}, + ui: {} as any, // Not required for this test + toExpression: async (state) => { + return 'test'; + }, }; describe('TypeService', () => { @@ -28,7 +31,7 @@ describe('TypeService', () => { }); describe('#setup', () => { - test('should throw an error if two visualizzations of the same id are registered', () => { + test('should throw an error if two visualizations of the same id are registered', () => { const { createVisualizationType } = service.setup(); createVisualizationType(createVizType({ name: 'viz-type-1' })); diff --git a/src/plugins/wizard/public/services/type_service/types.ts b/src/plugins/wizard/public/services/type_service/types.ts index fae6cdf1c093..b999d66ddf30 100644 --- a/src/plugins/wizard/public/services/type_service/types.ts +++ b/src/plugins/wizard/public/services/type_service/types.ts @@ -7,26 +7,6 @@ import { IconType } from '@elastic/eui'; import { RootState } from '../../application/utils/state_management'; import { Schemas } from '../../../../vis_default_editor/public'; -export enum ContributionTypes { - CONTAINER = 'CONTAINER', - ITEM = 'ITEM', -} - -export enum ContainerLocations { - SIDE_PANEL = 'sidePanel', - TOOLBAR = 'toolbar', -} - -export interface ContainerContribution { - id: string; - name: string; - Component: JSX.Element; -} - -type ContainerSchema = any; - -export type ContainerLocationContribution = { [K in ContainerLocations]: ContainerContribution[] }; - export interface DataTabConfig { schemas: Schemas; } diff --git a/src/plugins/wizard/public/services/type_service/visualization_type.test.tsx b/src/plugins/wizard/public/services/type_service/visualization_type.test.tsx deleted file mode 100644 index 6d362a229d23..000000000000 --- a/src/plugins/wizard/public/services/type_service/visualization_type.test.tsx +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -import React from 'react'; -import { VisualizationTypeOptions } from './types'; -import { VisualizationType } from './visualization_type'; - -// TODO: Update service tests -describe('VisualizationType', () => { - const DEFAULT_VIZ_PROPS = { - name: 'some-name', - icon: 'some-icon', - title: 'Some Title', - contributions: {}, - }; - - // const createVizType = (props?: Partial<VisualizationTypeOptions>): VisualizationTypeOptions => { - // return { - // ...DEFAULT_VIZ_PROPS, - // ...props, - // }; - // }; - - // test('should have default container contributions if none are provided', () => { - // const viz = new VisualizationType(createVizType()); - - // expect(viz.contributions.containers).toEqual(DEFAULT_CONTAINERS); - // }); - - // test('should have replace default container contributions when provided', () => { - // const defaultContainer = DEFAULT_CONTAINERS.sidePanel[0]; - // const viz = new VisualizationType( - // createVizType({ - // contributions: { - // containers: { - // sidePanel: [ - // { - // id: defaultContainer.id, - // name: 'Test', - // Component: <div>Test</div>, - // }, - // ], - // }, - // }, - // }) - // ); - - // const container = viz.contributions.containers.sidePanel.find( - // ({ id }) => id === defaultContainer.id - // ); - // expect(container).toMatchInlineSnapshot(` - // Object { - // "Component": <div> - // Test - // </div>, - // "id": "data_tab", - // "name": "Test", - // } - // `); - // }); - - // test('should register new container if provided', () => { - // const viz = new VisualizationType( - // createVizType({ - // contributions: { - // containers: { - // sidePanel: [ - // { - // id: 'test_id', - // name: 'Test', - // Component: <div>Test</div>, - // }, - // ], - // }, - // }, - // }) - // ); - - // const container = viz.contributions.containers.sidePanel.find(({ id }) => id === 'test_id'); - // const containerNames = viz.contributions.containers.sidePanel.map(({ name }) => name); - // const defaultContainerNames = DEFAULT_CONTAINERS.sidePanel.map(({ name }) => name); - - // expect(containerNames).toEqual([...defaultContainerNames, 'Test']); - // expect(container).toMatchInlineSnapshot(` - // Object { - // "Component": <div> - // Test - // </div>, - // "id": "test_id", - // "name": "Test", - // } - // `); - // }); -}); diff --git a/src/plugins/wizard/public/services/type_service/visualization_type.tsx b/src/plugins/wizard/public/services/type_service/visualization_type.tsx index 2ae1d25a4d96..90f30d8f8a95 100644 --- a/src/plugins/wizard/public/services/type_service/visualization_type.tsx +++ b/src/plugins/wizard/public/services/type_service/visualization_type.tsx @@ -2,18 +2,20 @@ * Copyright OpenSearch Contributors * SPDX-License-Identifier: Apache-2.0 */ +import { IconType } from '@elastic/eui'; +import { RootState } from '../../application/utils/state_management'; import { VisualizationTypeOptions } from './types'; type IVisualizationType = VisualizationTypeOptions; export class VisualizationType implements IVisualizationType { - public readonly name; - public readonly title; - public readonly description; - public readonly icon; - public readonly stage; - public readonly ui; - public readonly toExpression; + public readonly name: string; + public readonly title: string; + public readonly description: string; + public readonly icon: IconType; + public readonly stage: 'beta' | 'production'; + public readonly ui: IVisualizationType['ui']; + public readonly toExpression: (state: RootState) => Promise<string | undefined>; constructor(options: VisualizationTypeOptions) { this.name = options.name; diff --git a/src/plugins/wizard/public/visualizations/bar_chart/index.ts b/src/plugins/wizard/public/visualizations/bar_chart/index.ts deleted file mode 100644 index b135edf48ef6..000000000000 --- a/src/plugins/wizard/public/visualizations/bar_chart/index.ts +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -import { ItemTypes } from '../../application/contributions/constants'; -import { - DATA_TAB_ID, - DropboxContribution, - MainItemContribution as ConfigPanelItem, -} from '../../application/contributions'; -import { VisualizationTypeOptions } from '../../services/type_service'; - -export const createBarChartConfig = (): VisualizationTypeOptions => { - const configPanelItems: ConfigPanelItem[] = [ - { - type: ItemTypes.TITLE, - title: 'Bar Chart Configuration', - }, - createDropboxContribution('x_axis', 'X Axis', {}), - createDropboxContribution('y_axis', 'Y Axis', { limit: 5 }), - // { - // type: ItemTypes.INPUT, - // id: 'testLabel', - // label: 'Test Label', - // }, - ]; - - return { - name: 'bar_chart', - title: 'Bar Chart', - icon: 'visBarVertical', - description: 'This is a bar chart', - contributions: { - items: { - [DATA_TAB_ID]: configPanelItems, - }, - }, - }; -}; - -const createDropboxContribution = ( - id: string, - label: string, - props?: Pick<DropboxContribution, 'limit'> -): DropboxContribution => ({ - type: ItemTypes.DROPBOX, - id, - label, - items: [ - { - type: ItemTypes.SELECT, - id: 'aggregation', - label: 'Select a Function', - options: (state, services) => { - const { config } = state; - // config.items[] - const { buckets } = services.data.search.aggs.types.getAll(); - return buckets.map(({ name, title, type }) => ({ - value: name, - inputDisplay: title, - })); - }, - }, - { - type: ItemTypes.INPUT, - id: 'label', - label: 'Name', - }, - ], - display: (indexField, dropboxState) => { - const dropboxField = { - icon: indexField.type, - label: indexField.displayName, - }; - - if (dropboxState?.label) { - dropboxField.label = dropboxState.label; - } - - return dropboxField; - }, - onDrop: (indexField) => { - return { - // label: indexField.displayName, - }; - }, - // isDroppable: (indexField) => { - // return indexField.displayName === 'geo.srcdest'; - // }, - ...props, -}); diff --git a/src/plugins/wizard/public/visualizations/index.ts b/src/plugins/wizard/public/visualizations/index.ts index b9574fd9a771..44ad05739a74 100644 --- a/src/plugins/wizard/public/visualizations/index.ts +++ b/src/plugins/wizard/public/visualizations/index.ts @@ -5,8 +5,6 @@ import type { TypeServiceSetup } from '../services/type_service'; import { createMetricConfig } from './metric'; -import { createBarChartConfig } from './bar_chart'; -import { createPieChartConfig } from './pie_chart'; import { WizardPluginStartDependencies } from '../types'; export function registerDefaultTypes( diff --git a/src/plugins/wizard/public/visualizations/metric/to_expression.ts b/src/plugins/wizard/public/visualizations/metric/to_expression.ts index f0614801493e..5b787ef5d264 100644 --- a/src/plugins/wizard/public/visualizations/metric/to_expression.ts +++ b/src/plugins/wizard/public/visualizations/metric/to_expression.ts @@ -95,8 +95,6 @@ export const toExpression = async ({ style: styleState, visualization }: MetricR const { activeVisualization, indexPattern: indexId = '' } = visualization; const { aggConfigParams } = activeVisualization || {}; - if (!aggConfigParams || !aggConfigParams.length) return; - const indexPatternsService = getIndexPatterns(); const indexPattern = await indexPatternsService.get(indexId); const aggConfigs = getAggService().createAggConfigs(indexPattern, cloneDeep(aggConfigParams)); diff --git a/src/plugins/wizard/public/visualizations/pie_chart/index.ts b/src/plugins/wizard/public/visualizations/pie_chart/index.ts deleted file mode 100644 index e71540852a32..000000000000 --- a/src/plugins/wizard/public/visualizations/pie_chart/index.ts +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -import { VisualizationTypeOptions } from '../../services/type_service'; - -export const createPieChartConfig = (): VisualizationTypeOptions => { - return { - name: 'pie_chart', - title: 'Pie Chart', - icon: 'visPie', - contributions: {}, - }; -};