From fdb2544c8e6f666ed082d7f2728675b37688ade5 Mon Sep 17 00:00:00 2001 From: Ashwin Pc Date: Mon, 4 Jul 2022 03:41:39 +0000 Subject: [PATCH 1/6] adds min/max validation Signed-off-by: Ashwin Pc --- .../application/components/workspace.tsx | 20 ++++++++-- .../data_tab/items/use/use_dropbox.tsx | 4 +- .../data_tab/utils/validate_schema_state.ts | 37 +++++++++++++++++++ .../state_management/visualization_slice.ts | 2 +- .../public/services/type_service/types.ts | 2 - .../type_service/visualization_type.tsx | 16 ++++---- .../visualizations/metric/to_expression.ts | 2 - 7 files changed, 66 insertions(+), 17 deletions(-) create mode 100644 src/plugins/wizard/public/application/contributions/containers/data_tab/utils/validate_schema_state.ts diff --git a/src/plugins/wizard/public/application/components/workspace.tsx b/src/plugins/wizard/public/application/components/workspace.tsx index 7747eef57cba..3ceb345f7393 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 '../contributions/containers/data_tab/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(); - const { toExpression } = useVisualizationType(); + const { toExpression, ui } = useVisualizationType(); const [expression, setExpression] = useState(); 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 (
@@ -94,7 +105,8 @@ const TypeSelectorPopover = () => { 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/containers/data_tab/items/use/use_dropbox.tsx b/src/plugins/wizard/public/application/contributions/containers/data_tab/items/use/use_dropbox.tsx index ebabb90eccbf..6ad4b93a6620 100644 --- a/src/plugins/wizard/public/application/contributions/containers/data_tab/items/use/use_dropbox.tsx +++ b/src/plugins/wizard/public/application/contributions/containers/data_tab/items/use/use_dropbox.tsx @@ -192,6 +192,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 +205,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/contributions/containers/data_tab/utils/validate_schema_state.ts b/src/plugins/wizard/public/application/contributions/containers/data_tab/utils/validate_schema_state.ts new file mode 100644 index 000000000000..2bee606e2b3e --- /dev/null +++ b/src/plugins/wizard/public/application/contributions/containers/data_tab/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 '../../../../utils/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/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/services/type_service/types.ts b/src/plugins/wizard/public/services/type_service/types.ts index fae6cdf1c093..054d22fe54ec 100644 --- a/src/plugins/wizard/public/services/type_service/types.ts +++ b/src/plugins/wizard/public/services/type_service/types.ts @@ -23,8 +23,6 @@ export interface ContainerContribution { Component: JSX.Element; } -type ContainerSchema = any; - export type ContainerLocationContribution = { [K in ContainerLocations]: ContainerContribution[] }; export interface DataTabConfig { 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; constructor(options: VisualizationTypeOptions) { this.name = options.name; 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)); From 9b635d9fbd2bd3996521eff8f83e8176d39203c7 Mon Sep 17 00:00:00 2001 From: Ashwin Pc Date: Mon, 4 Jul 2022 03:54:21 +0000 Subject: [PATCH 2/6] relocated contributions Signed-off-by: Ashwin Pc --- .../data_tab/config_panel.scss | 0 .../data_tab/config_panel.tsx | 4 +- .../data_tab/field_search.tsx | 4 +- .../data_tab/field_selector.scss | 6 +- .../data_tab/field_selector.tsx | 6 +- .../data_tab/field_selector_field.scss | 1 + .../data_tab/field_selector_field.tsx | 6 +- .../data_tab/index.scss | 3 +- .../data_tab/index.tsx | 0 .../data_tab/items/dropbox.scss | 0 .../data_tab/items/dropbox.tsx | 8 +- .../data_tab/items/index.tsx | 2 - .../data_tab/items/title.tsx | 0 .../data_tab/items/use/index.ts | 1 - .../data_tab/items/use/use_dropbox.tsx | 18 ++--- .../data_tab/secondary_panel.tsx | 14 ++-- .../data_tab/utils/schema_to_dropbox.tsx | 2 +- .../data_tab/utils/validate_schema_state.ts | 4 +- .../application/components/side_nav.tsx | 2 +- .../application/components/workspace.tsx | 2 +- .../application/contributions/constants.ts | 12 --- .../containers/common/items/index.tsx | 9 --- .../containers/common/items/select.tsx | 47 ----------- .../containers/common/items/text_input.tsx | 37 --------- .../containers/common/items/types.ts | 43 ---------- .../containers/data_tab/items/form_field.tsx | 20 ----- .../containers/data_tab/items/types.ts | 65 --------------- .../data_tab/items/use/use_form_field.tsx | 79 ------------------- .../data_tab/utils/item_to_panel.tsx | 60 -------------- .../contributions/containers/index.ts | 7 -- .../containers/style_tab/index.tsx | 12 --- .../public/application/contributions/index.ts | 6 -- 32 files changed, 44 insertions(+), 436 deletions(-) rename src/plugins/wizard/public/application/{contributions/containers => components}/data_tab/config_panel.scss (100%) rename src/plugins/wizard/public/application/{contributions/containers => components}/data_tab/config_panel.tsx (86%) rename src/plugins/wizard/public/application/{contributions/containers => components}/data_tab/field_search.tsx (88%) rename src/plugins/wizard/public/application/{contributions/containers => components}/data_tab/field_selector.scss (92%) rename src/plugins/wizard/public/application/{contributions/containers => components}/data_tab/field_selector.tsx (95%) rename src/plugins/wizard/public/application/{contributions/containers => components}/data_tab/field_selector_field.scss (99%) rename src/plugins/wizard/public/application/{contributions/containers => components}/data_tab/field_selector_field.tsx (92%) rename src/plugins/wizard/public/application/{contributions/containers => components}/data_tab/index.scss (79%) rename src/plugins/wizard/public/application/{contributions/containers => components}/data_tab/index.tsx (100%) rename src/plugins/wizard/public/application/{contributions/containers => components}/data_tab/items/dropbox.scss (100%) rename src/plugins/wizard/public/application/{contributions/containers => components}/data_tab/items/dropbox.tsx (95%) rename src/plugins/wizard/public/application/{contributions/containers => components}/data_tab/items/index.tsx (68%) rename src/plugins/wizard/public/application/{contributions/containers => components}/data_tab/items/title.tsx (100%) rename src/plugins/wizard/public/application/{contributions/containers => components}/data_tab/items/use/index.ts (72%) rename src/plugins/wizard/public/application/{contributions/containers => components}/data_tab/items/use/use_dropbox.tsx (91%) rename src/plugins/wizard/public/application/{contributions/containers => components}/data_tab/secondary_panel.tsx (82%) rename src/plugins/wizard/public/application/{contributions/containers => components}/data_tab/utils/schema_to_dropbox.tsx (87%) rename src/plugins/wizard/public/application/{contributions/containers => components}/data_tab/utils/validate_schema_state.ts (87%) delete mode 100644 src/plugins/wizard/public/application/contributions/constants.ts delete mode 100644 src/plugins/wizard/public/application/contributions/containers/common/items/index.tsx delete mode 100644 src/plugins/wizard/public/application/contributions/containers/common/items/select.tsx delete mode 100644 src/plugins/wizard/public/application/contributions/containers/common/items/text_input.tsx delete mode 100644 src/plugins/wizard/public/application/contributions/containers/common/items/types.ts delete mode 100644 src/plugins/wizard/public/application/contributions/containers/data_tab/items/form_field.tsx delete mode 100644 src/plugins/wizard/public/application/contributions/containers/data_tab/items/types.ts delete mode 100644 src/plugins/wizard/public/application/contributions/containers/data_tab/items/use/use_form_field.tsx delete mode 100644 src/plugins/wizard/public/application/contributions/containers/data_tab/utils/item_to_panel.tsx delete mode 100644 src/plugins/wizard/public/application/contributions/containers/index.ts delete mode 100644 src/plugins/wizard/public/application/contributions/containers/style_tab/index.tsx delete mode 100644 src/plugins/wizard/public/application/contributions/index.ts 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 86% 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..eaf8b1c3ef80 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,8 +5,8 @@ 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 { SecondaryPanel } from './secondary_panel'; 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 100% 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 diff --git a/src/plugins/wizard/public/application/contributions/containers/data_tab/items/dropbox.scss b/src/plugins/wizard/public/application/components/data_tab/items/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/items/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/items/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/items/dropbox.tsx index 29dda2cfd9c4..7d8d99617d58 100644 --- a/src/plugins/wizard/public/application/contributions/containers/data_tab/items/dropbox.tsx +++ b/src/plugins/wizard/public/application/components/data_tab/items/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/items/index.tsx b/src/plugins/wizard/public/application/components/data_tab/items/index.tsx similarity index 68% rename from src/plugins/wizard/public/application/contributions/containers/data_tab/items/index.tsx rename to src/plugins/wizard/public/application/components/data_tab/items/index.tsx index 72a3ad62df58..cba9a7530982 100644 --- a/src/plugins/wizard/public/application/contributions/containers/data_tab/items/index.tsx +++ b/src/plugins/wizard/public/application/components/data_tab/items/index.tsx @@ -3,7 +3,5 @@ * 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/title.tsx b/src/plugins/wizard/public/application/components/data_tab/items/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/items/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/items/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/items/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/items/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/items/use/use_dropbox.tsx similarity index 91% 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/items/use/use_dropbox.tsx index 6ad4b93a6620..f730498229d0 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/items/use/use_dropbox.tsx @@ -5,21 +5,21 @@ 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 { 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 { 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'); 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 82% 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..e5f95214eaa2 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 { 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 { 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); 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/utils/schema_to_dropbox.tsx similarity index 87% 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/utils/schema_to_dropbox.tsx index b14a8bd13d85..970f002b6ccb 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/utils/schema_to_dropbox.tsx @@ -4,7 +4,7 @@ */ import React from 'react'; -import { Schemas } from '../../../../../../../vis_default_editor/public'; +import { Schemas } from '../../../../../../vis_default_editor/public'; import { Title, Dropbox } from '../items'; export const mapSchemaToAggPanel = (schemas: Schemas) => { diff --git a/src/plugins/wizard/public/application/contributions/containers/data_tab/utils/validate_schema_state.ts b/src/plugins/wizard/public/application/components/data_tab/utils/validate_schema_state.ts similarity index 87% rename from src/plugins/wizard/public/application/contributions/containers/data_tab/utils/validate_schema_state.ts rename to src/plugins/wizard/public/application/components/data_tab/utils/validate_schema_state.ts index 2bee606e2b3e..9ba9e8f2f539 100644 --- a/src/plugins/wizard/public/application/contributions/containers/data_tab/utils/validate_schema_state.ts +++ b/src/plugins/wizard/public/application/components/data_tab/utils/validate_schema_state.ts @@ -4,8 +4,8 @@ */ import { countBy } from 'lodash'; -import { Schemas } from '../../../../../../../vis_default_editor/public'; -import { RootState } from '../../../../utils/state_management'; +import { Schemas } from '../../../../../../vis_default_editor/public'; +import { RootState } from '../../../utils/state_management'; export const validateSchemaState = (schemas: Schemas, state: RootState): [boolean, string?] => { const activeViz = state.visualization.activeVisualization; 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 3ceb345f7393..8d752a4949ce 100644 --- a/src/plugins/wizard/public/application/components/workspace.tsx +++ b/src/plugins/wizard/public/application/components/workspace.tsx @@ -17,7 +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 '../contributions/containers/data_tab/utils/validate_schema_state'; +import { validateSchemaState } from './data_tab/utils/validate_schema_state'; import { useTypedDispatch, useTypedSelector } from '../utils/state_management'; import { setActiveVisualization } from '../utils/state_management/visualization_slice'; import { useVisualizationType } from '../utils/use'; 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, 'type'> { - value: string; -} - -export const Select = ({ label, options, onChange, value, ...rest }: SelectProps) => { - const rootState = useTypedSelector((state) => state); - const { services } = useOpenSearchDashboards(); - const selectOptions = useMemo( - () => (typeof options === 'function' ? options(rootState, services) : options), - [options, rootState, services] - ); - // const { isInvalid, errorMessage } = getFieldValidityAndErrorMessage(field); - - return ( - - { - onChange?.(newValue); - }} - // isInvalid={isInvalid} - valueOfSelected={value || ''} - data-test-subj="select" - options={selectOptions} - /> - - ); -}; 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 { - value: string; -} - -export const TextInput = ({ label, onChange, value, ...rest }: InputProps) => { - // const { isInvalid, errorMessage } = getFieldValidityAndErrorMessage(field); - - return ( - - { - onChange?.(event.target.value); - }} - // isInvalid={isInvalid} - value={value || ''} - data-test-subj="text_input" - /> - - ); -}; 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 { - type: ITEM_TYPES.SELECT; - id: string; - label: string; - options: - | EuiSuperSelectProps['options'] - | ((state: RootState, services: WizardServices) => EuiSuperSelectProps['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 | 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 } = { - [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 ; -}; 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 | 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; - // 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 { - instances: Array<{ - id: string; - properties: T; - }>; -} - -export type DropboxState = InstanceState; -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, - 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 ; - - 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'; From 63d71375e96af69916bf59bfbdf11c90f448271a Mon Sep 17 00:00:00 2001 From: Ashwin Pc <ashwinpc@amazon.com> Date: Mon, 4 Jul 2022 05:12:30 +0000 Subject: [PATCH 3/6] Some more cleanup Signed-off-by: Ashwin Pc <ashwinpc@amazon.com> --- .../components/data_tab/config_panel.tsx | 2 +- .../data_tab/{items => }/dropbox.scss | 0 .../data_tab/{items => }/dropbox.tsx | 2 +- .../application/components/data_tab/index.tsx | 2 -- .../components/data_tab/items/index.tsx | 7 ------ .../{utils => }/schema_to_dropbox.tsx | 5 ++-- .../components/data_tab/secondary_panel.tsx | 2 +- .../components/data_tab/{items => }/title.tsx | 0 .../data_tab/{items => }/use/index.ts | 0 .../data_tab/{items => }/use/use_dropbox.tsx | 25 ++++++++----------- .../application/components/workspace.tsx | 2 +- .../utils/validate_schema_state.ts | 4 +-- 12 files changed, 19 insertions(+), 32 deletions(-) rename src/plugins/wizard/public/application/components/data_tab/{items => }/dropbox.scss (100%) rename src/plugins/wizard/public/application/components/data_tab/{items => }/dropbox.tsx (97%) delete mode 100644 src/plugins/wizard/public/application/components/data_tab/items/index.tsx rename src/plugins/wizard/public/application/components/data_tab/{utils => }/schema_to_dropbox.tsx (77%) rename src/plugins/wizard/public/application/components/data_tab/{items => }/title.tsx (100%) rename src/plugins/wizard/public/application/components/data_tab/{items => }/use/index.ts (100%) rename src/plugins/wizard/public/application/components/data_tab/{items => }/use/use_dropbox.tsx (88%) rename src/plugins/wizard/public/application/{components/data_tab => }/utils/validate_schema_state.ts (88%) diff --git a/src/plugins/wizard/public/application/components/data_tab/config_panel.tsx b/src/plugins/wizard/public/application/components/data_tab/config_panel.tsx index eaf8b1c3ef80..1c0e67693471 100644 --- a/src/plugins/wizard/public/application/components/data_tab/config_panel.tsx +++ b/src/plugins/wizard/public/application/components/data_tab/config_panel.tsx @@ -8,7 +8,7 @@ import React from 'react'; 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/components/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/components/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/components/data_tab/items/dropbox.tsx b/src/plugins/wizard/public/application/components/data_tab/dropbox.tsx similarity index 97% rename from src/plugins/wizard/public/application/components/data_tab/items/dropbox.tsx rename to src/plugins/wizard/public/application/components/data_tab/dropbox.tsx index 7d8d99617d58..451bbe4e52eb 100644 --- a/src/plugins/wizard/public/application/components/data_tab/items/dropbox.tsx +++ b/src/plugins/wizard/public/application/components/data_tab/dropbox.tsx @@ -14,7 +14,7 @@ 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 { useDropbox } from './use'; import { UseDropboxProps } from './use/use_dropbox'; diff --git a/src/plugins/wizard/public/application/components/data_tab/index.tsx b/src/plugins/wizard/public/application/components/data_tab/index.tsx index 9fefef7d8ce9..1f880f20698d 100644 --- a/src/plugins/wizard/public/application/components/data_tab/index.tsx +++ b/src/plugins/wizard/public/application/components/data_tab/index.tsx @@ -19,5 +19,3 @@ export const DataTab = () => { </div> ); }; - -export * from './items'; diff --git a/src/plugins/wizard/public/application/components/data_tab/items/index.tsx b/src/plugins/wizard/public/application/components/data_tab/items/index.tsx deleted file mode 100644 index cba9a7530982..000000000000 --- a/src/plugins/wizard/public/application/components/data_tab/items/index.tsx +++ /dev/null @@ -1,7 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -export * from './dropbox'; -export { Title } from './title'; diff --git a/src/plugins/wizard/public/application/components/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/components/data_tab/utils/schema_to_dropbox.tsx rename to src/plugins/wizard/public/application/components/data_tab/schema_to_dropbox.tsx index 970f002b6ccb..37c55e25be99 100644 --- a/src/plugins/wizard/public/application/components/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/components/data_tab/secondary_panel.tsx b/src/plugins/wizard/public/application/components/data_tab/secondary_panel.tsx index e5f95214eaa2..00d57289e1bd 100644 --- a/src/plugins/wizard/public/application/components/data_tab/secondary_panel.tsx +++ b/src/plugins/wizard/public/application/components/data_tab/secondary_panel.tsx @@ -7,7 +7,7 @@ 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 { Title } from './title'; import { useIndexPattern, useVisualizationType } from '../../utils/use'; import { useOpenSearchDashboards } from '../../../../../opensearch_dashboards_react/public'; import { WizardServices } from '../../../types'; diff --git a/src/plugins/wizard/public/application/components/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/components/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/components/data_tab/items/use/index.ts b/src/plugins/wizard/public/application/components/data_tab/use/index.ts similarity index 100% rename from src/plugins/wizard/public/application/components/data_tab/items/use/index.ts rename to src/plugins/wizard/public/application/components/data_tab/use/index.ts diff --git a/src/plugins/wizard/public/application/components/data_tab/items/use/use_dropbox.tsx b/src/plugins/wizard/public/application/components/data_tab/use/use_dropbox.tsx similarity index 88% rename from src/plugins/wizard/public/application/components/data_tab/items/use/use_dropbox.tsx rename to src/plugins/wizard/public/application/components/data_tab/use/use_dropbox.tsx index f730498229d0..60290fc96e93 100644 --- a/src/plugins/wizard/public/application/components/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 '../../../../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; } diff --git a/src/plugins/wizard/public/application/components/workspace.tsx b/src/plugins/wizard/public/application/components/workspace.tsx index 8d752a4949ce..94e0d037b4f6 100644 --- a/src/plugins/wizard/public/application/components/workspace.tsx +++ b/src/plugins/wizard/public/application/components/workspace.tsx @@ -17,7 +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 './data_tab/utils/validate_schema_state'; +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'; diff --git a/src/plugins/wizard/public/application/components/data_tab/utils/validate_schema_state.ts b/src/plugins/wizard/public/application/utils/validate_schema_state.ts similarity index 88% rename from src/plugins/wizard/public/application/components/data_tab/utils/validate_schema_state.ts rename to src/plugins/wizard/public/application/utils/validate_schema_state.ts index 9ba9e8f2f539..2db3653e2ce3 100644 --- a/src/plugins/wizard/public/application/components/data_tab/utils/validate_schema_state.ts +++ b/src/plugins/wizard/public/application/utils/validate_schema_state.ts @@ -4,8 +4,8 @@ */ import { countBy } from 'lodash'; -import { Schemas } from '../../../../../../vis_default_editor/public'; -import { RootState } from '../../../utils/state_management'; +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; From 0912724ac8ac3263b91ffa31ba748f460c3b3748 Mon Sep 17 00:00:00 2001 From: Ashwin Pc <ashwinpc@amazon.com> Date: Mon, 4 Jul 2022 05:59:59 +0000 Subject: [PATCH 4/6] minor fixes Signed-off-by: Ashwin Pc <ashwinpc@amazon.com> --- .../components/data_source_select.tsx | 3 +- .../components/searchable_dropdown.scss | 4 +- .../components/searchable_dropdown.tsx | 21 ++-- .../type_service/type_service.test.ts | 9 +- .../public/services/type_service/types.ts | 18 ---- .../type_service/visualization_type.test.tsx | 96 ------------------- .../public/visualizations/bar_chart/index.ts | 92 ------------------ .../wizard/public/visualizations/index.ts | 2 - .../public/visualizations/pie_chart/index.ts | 15 --- 9 files changed, 22 insertions(+), 238 deletions(-) delete mode 100644 src/plugins/wizard/public/services/type_service/visualization_type.test.tsx delete mode 100644 src/plugins/wizard/public/visualizations/bar_chart/index.ts delete mode 100644 src/plugins/wizard/public/visualizations/pie_chart/index.ts 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: <EuiIcon type={indexPatternSvg} />, + prepend: <EuiIcon type="indexPatternApp" />, }; } 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/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 054d22fe54ec..b999d66ddf30 100644 --- a/src/plugins/wizard/public/services/type_service/types.ts +++ b/src/plugins/wizard/public/services/type_service/types.ts @@ -7,24 +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; -} - -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/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/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: {}, - }; -}; From 1fbe9593fd5cbb518b0299ae7815cf299c125dc1 Mon Sep 17 00:00:00 2001 From: Ashwin Pc <ashwinpc@amazon.com> Date: Mon, 4 Jul 2022 06:20:15 +0000 Subject: [PATCH 5/6] one more unnecessary file Signed-off-by: Ashwin Pc <ashwinpc@amazon.com> --- .../application/utils/async_search/index.ts | 48 ------------------- 1 file changed, 48 deletions(-) delete mode 100644 src/plugins/wizard/public/application/utils/async_search/index.ts 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, - }; -}; From efe98f0bd71a4b8ed35aa73680ef4e5bcfb64395 Mon Sep 17 00:00:00 2001 From: Ashwin Pc <ashwinpc@amazon.com> Date: Mon, 4 Jul 2022 10:37:59 +0000 Subject: [PATCH 6/6] fix: Seconday panel title Signed-off-by: Ashwin Pc <ashwinpc@amazon.com> --- .../application/components/data_tab/secondary_panel.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/plugins/wizard/public/application/components/data_tab/secondary_panel.tsx b/src/plugins/wizard/public/application/components/data_tab/secondary_panel.tsx index 00d57289e1bd..c897a9b018c5 100644 --- a/src/plugins/wizard/public/application/components/data_tab/secondary_panel.tsx +++ b/src/plugins/wizard/public/application/components/data_tab/secondary_panel.tsx @@ -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 ( <div className="wizConfig__section wizConfig--secondary"> - <Title title="Test" isSecondary closeMenu={closeMenu} /> + <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: {},