From 94792d594966f3ef63abe7f00894e4fae1fc6283 Mon Sep 17 00:00:00 2001 From: Kama Huang Date: Thu, 21 Nov 2024 00:59:27 -0800 Subject: [PATCH] hide ML presets for version2.17 and before Signed-off-by: Kama Huang --- common/constants.ts | 3 ++ .../ingest_inputs/enrich_data.tsx | 43 ++++++++++++++++--- .../ingest_inputs/ingest_inputs.tsx | 7 ++- .../new_workflow/new_workflow.test.tsx | 17 ++++++-- .../workflows/new_workflow/new_workflow.tsx | 22 +++++++++- public/utils/utils.ts | 1 - 6 files changed, 80 insertions(+), 13 deletions(-) diff --git a/common/constants.ts b/common/constants.ts index 69826bc7..a02f2862 100644 --- a/common/constants.ts +++ b/common/constants.ts @@ -128,6 +128,9 @@ export enum PROCESSOR_TYPE { NORMALIZATION = 'normalization-processor', COLLAPSE = 'collapse', RERANK = 'rerank', + TEXT_EMBEDDING = 'text-embedding-processor', + TEXT_IMAGE_EMBEDDING = 'text-image-embedding-processor', + } export enum MODEL_TYPE { diff --git a/public/pages/workflow_detail/workflow_inputs/ingest_inputs/enrich_data.tsx b/public/pages/workflow_detail/workflow_inputs/ingest_inputs/enrich_data.tsx index 4cb03de7..d14fc86f 100644 --- a/public/pages/workflow_detail/workflow_inputs/ingest_inputs/enrich_data.tsx +++ b/public/pages/workflow_detail/workflow_inputs/ingest_inputs/enrich_data.tsx @@ -6,24 +6,57 @@ import React from 'react'; import { EuiFlexGroup, EuiFlexItem } from '@elastic/eui'; import { ProcessorsList } from '../processors_list'; -import { PROCESSOR_CONTEXT, WorkflowConfig } from '../../../../../common'; +import { + PROCESSOR_CONTEXT, + PROCESSOR_TYPE, + WorkflowConfig, +} from '../../../../../common'; import { ProcessorsTitle } from '../../../../general_components'; +import { useState, useEffect } from 'react'; interface EnrichDataProps { uiConfig: WorkflowConfig; setUiConfig: (uiConfig: WorkflowConfig) => void; + beforeVersion217: boolean; } /** * Base component for configuring any data enrichment */ export function EnrichData(props: EnrichDataProps) { + const { uiConfig, setUiConfig } = props; + // const beforeVersion217 = true; + const initialProcessorCount = uiConfig.ingest.enrich.processors?.filter( + (processor) => processor.type !== PROCESSOR_TYPE.ML + ).length; + const [processorCount, setProcessorCount] = useState( + initialProcessorCount + ); + + // useEffect(() => { + // var processors = uiConfig.ingest.enrich.processors; + // if (beforeVersion217) { + // processors = uiConfig.ingest.enrich.processors.filter( + // (processor) => processor.type !== PROCESSOR_TYPE.ML + // ); + // } + // setProcessorCount(processors.length); + + // setUiConfig({ + // ...uiConfig, + // ingest: { + // ...uiConfig.ingest, + // enrich: { + // ...uiConfig.ingest.enrich, + // processors: processors, + // }, + // }, + // }); + // }, [beforeVersion217]); + return ( - + void; workflow: Workflow | undefined; lastIngested: number | undefined; + beforeVersion217: boolean; } /** @@ -36,7 +37,11 @@ export function IngestInputs(props: IngestInputsProps) { - + diff --git a/public/pages/workflows/new_workflow/new_workflow.test.tsx b/public/pages/workflows/new_workflow/new_workflow.test.tsx index 14a609f9..422d0a5d 100644 --- a/public/pages/workflows/new_workflow/new_workflow.test.tsx +++ b/public/pages/workflows/new_workflow/new_workflow.test.tsx @@ -52,14 +52,23 @@ describe('NewWorkflow', () => { jest.spyOn(ReactReduxHooks, 'useAppDispatch').mockReturnValue(mockDispatch); }); - test('renders the preset workflow names & descriptions', () => { + test('renders the preset workflow names & descriptions when version is before 2.17', () => { const presetWorkflows = loadPresetWorkflowTemplates(); + const allowedPresets = [ + 'Semantic Search', + 'Hybrid Search', + 'Multimodal Search', + ]; const { getByPlaceholderText, getAllByText } = renderWithRouter(); expect(getByPlaceholderText('Search')).toBeInTheDocument(); - presetWorkflows.forEach((workflow) => { - expect(getAllByText(workflow.name)).toHaveLength(1); - expect(getAllByText(workflow.description)).toHaveLength(1); + allowedPresets.forEach((workflowName) => { + expect(getAllByText(workflowName)).toHaveLength(1); }); + presetWorkflows + .filter((workflow) => !allowedPresets.includes(workflow.name)) + .forEach((workflow) => { + expect(() => getAllByText(workflow.name)).toThrow(); + }); }); test('renders the quick configure for preset workflow templates', async () => { diff --git a/public/pages/workflows/new_workflow/new_workflow.tsx b/public/pages/workflows/new_workflow/new_workflow.tsx index f0c2a537..fdaa8fd7 100644 --- a/public/pages/workflows/new_workflow/new_workflow.tsx +++ b/public/pages/workflows/new_workflow/new_workflow.tsx @@ -67,15 +67,33 @@ export function NewWorkflow(props: NewWorkflowProps) { // initial hook to populate all workflows // enrich them with dynamically-generated UI flows based on use case + + const beforeVersion217 = true; useEffect(() => { if (presetWorkflows) { + const ALLOWED_PRESETS_FOR_BEFORE_217 = [ + 'Semantic Search', + 'Hybrid Search', + 'Multimodal Search', + ]; + + let filteredPresets = presetWorkflows; + + if (beforeVersion217) { + filteredPresets = presetWorkflows.filter( + (presetWorkflow) => + presetWorkflow.name && + ALLOWED_PRESETS_FOR_BEFORE_217.includes(presetWorkflow.name) + ); + } + setAllWorkflows( - presetWorkflows.map((presetWorkflow) => + filteredPresets.map((presetWorkflow) => enrichPresetWorkflowWithUiMetadata(presetWorkflow) ) ); } - }, [presetWorkflows]); + }, [presetWorkflows, beforeVersion217]); // initial hook to populate filtered workflows useEffect(() => { diff --git a/public/utils/utils.ts b/public/utils/utils.ts index f750bddd..3f023f26 100644 --- a/public/utils/utils.ts +++ b/public/utils/utils.ts @@ -29,7 +29,6 @@ import { import { getCore, getDataSourceEnabled } from '../services'; import { MDSQueryParams, - MapEntry, ModelInputMap, ModelOutputMap, } from '../../common/interfaces';