Skip to content

Commit

Permalink
hide ML presets for version2.17 and before
Browse files Browse the repository at this point in the history
Signed-off-by: Kama Huang <[email protected]>
  • Loading branch information
Kama Huang committed Nov 24, 2024
1 parent 13b83dc commit 94792d5
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 13 deletions.
3 changes: 3 additions & 0 deletions common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<number>(
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 (
<EuiFlexGroup direction="column">
<ProcessorsTitle
title="Enrich data"
processorCount={props.uiConfig.ingest.enrich.processors?.length || 0}
/>
<ProcessorsTitle title="Enrich data" processorCount={processorCount} />
<EuiFlexItem>
<ProcessorsList
uiConfig={props.uiConfig}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ interface IngestInputsProps {
setUiConfig: (uiConfig: WorkflowConfig) => void;
workflow: Workflow | undefined;
lastIngested: number | undefined;
beforeVersion217: boolean;
}

/**
Expand All @@ -36,7 +37,11 @@ export function IngestInputs(props: IngestInputsProps) {
<EuiHorizontalRule margin="none" />
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EnrichData uiConfig={props.uiConfig} setUiConfig={props.setUiConfig} />
<EnrichData
uiConfig={props.uiConfig}
setUiConfig={props.setUiConfig}
beforeVersion217={props.beforeVersion217}
/>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiHorizontalRule margin="none" />
Expand Down
17 changes: 13 additions & 4 deletions public/pages/workflows/new_workflow/new_workflow.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
22 changes: 20 additions & 2 deletions public/pages/workflows/new_workflow/new_workflow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down
1 change: 0 additions & 1 deletion public/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import {
import { getCore, getDataSourceEnabled } from '../services';
import {
MDSQueryParams,
MapEntry,
ModelInputMap,
ModelOutputMap,
} from '../../common/interfaces';
Expand Down

0 comments on commit 94792d5

Please sign in to comment.