diff --git a/public/pages/workflow_detail/resizable_workspace.tsx b/public/pages/workflow_detail/resizable_workspace.tsx index 0db6b10f..fac2e65f 100644 --- a/public/pages/workflow_detail/resizable_workspace.tsx +++ b/public/pages/workflow_detail/resizable_workspace.tsx @@ -185,24 +185,7 @@ export function ResizableWorkspace(props: ResizableWorkspaceProps) { // Initialize the form state to an existing workflow, if applicable. useEffect(() => { - // if (workflow?.ui_metadata?.workspace_flow) { - // const initFormValues = {} as WorkspaceFormValues; - // const initSchemaObj = {} as WorkspaceSchemaObj; - // workflow.ui_metadata.workspace_flow.nodes.forEach((node) => { - // initFormValues[node.id] = componentDataToFormik(node.data); - // initSchemaObj[node.id] = getComponentSchema(node.data); - // }); - // const initFormSchema = yup.object(initSchemaObj) as WorkspaceSchema; - // setFormValues(initFormValues); - // setFormSchema(initFormSchema); - // } if (workflow?.ui_metadata?.config) { - // TODO: implement below fns to generate the final form and schema objs. - // Should generate the form and its values on-the-fly - // similar to what we do with ComponentData in above commented-out code. - // This gives us more flexibility and maintainability instead of having to update - // low-level form and schema when making config changes (e.g., if of type 'string', - // automatically generate the default form values, and the default validation schema) const initFormValues = uiConfigToFormik(workflow.ui_metadata.config); const initFormSchema = uiConfigToSchema(workflow.ui_metadata.config); setFormValues(initFormValues); diff --git a/public/pages/workflows/new_workflow/utils.ts b/public/pages/workflows/new_workflow/utils.ts index 06377f9a..2cdde972 100644 --- a/public/pages/workflows/new_workflow/utils.ts +++ b/public/pages/workflows/new_workflow/utils.ts @@ -10,6 +10,7 @@ import { START_FROM_SCRATCH_WORKFLOW_NAME, DEFAULT_NEW_WORKFLOW_NAME, UIState, + IConfig, } from '../../../../common'; // Fn to produce the complete preset template with all necessary UI metadata. @@ -59,8 +60,11 @@ function fetchEmptyMetadata(): UIState { processors: [], }, index: { - id: 'index', - fields: [], + name: { + id: 'indexName', + type: 'string', + label: 'Index name', + }, }, }, search: { @@ -82,49 +86,21 @@ function fetchEmptyMetadata(): UIState { } function fetchSemanticSearchMetadata(): UIState { + // We can reuse the base state. Only need to override a few things, + // such as preset ingest processors. + let baseState = fetchEmptyMetadata(); const processor = new TextEmbeddingProcessor(); - return { - config: { - ingest: { - source: { - id: 'source', - fields: [], - }, - enrich: { - processors: [ - { - id: processor.id, - fields: processor.fields, - metadata: { - label: processor.name, - }, - }, - ], - }, - index: { - name: { - id: 'indexName', - type: 'string', - label: 'Index name', - }, - }, - }, - search: { - request: { - id: 'request', - fields: [], - }, - enrichRequest: { - id: 'enrichRequest', - fields: [], - }, - enrichResponse: { - id: 'enrichResponse', - fields: [], - }, + // @ts-ignore + baseState.config.ingest.enrich.processors = [ + { + id: processor.id, + fields: processor.fields, + metadata: { + label: processor.name, }, }, - }; + ] as IConfig[]; + return baseState; } // function fetchSemanticSearchWorkspaceFlow(): WorkspaceFlowState {