diff --git a/public/pages/workflow_detail/resizable_workspace.tsx b/public/pages/workflow_detail/resizable_workspace.tsx index 3cfd1daf..801a4ebf 100644 --- a/public/pages/workflow_detail/resizable_workspace.tsx +++ b/public/pages/workflow_detail/resizable_workspace.tsx @@ -5,11 +5,16 @@ import React, { useRef, useState, useEffect } from 'react'; import { useSelector } from 'react-redux'; -import { useHistory } from 'react-router-dom'; import { Form, Formik } from 'formik'; import * as yup from 'yup'; -import { EuiFlexGroup, EuiFlexItem, EuiResizableContainer } from '@elastic/eui'; -import { getCore } from '../../services'; +import { + EuiCodeBlock, + EuiEmptyPrompt, + EuiFlexGroup, + EuiFlexItem, + EuiResizableContainer, + EuiText, +} from '@elastic/eui'; import { Workflow, @@ -17,7 +22,11 @@ import { WorkflowFormValues, WorkflowSchema, } from '../../../common'; -import { APP_PATH, uiConfigToFormik, uiConfigToSchema } from '../../utils'; +import { + reduceToTemplate, + uiConfigToFormik, + uiConfigToSchema, +} from '../../utils'; import { AppState, setDirty, useAppDispatch } from '../../store'; import { WorkflowInputs } from './workflow_inputs'; import { Workspace } from './workspace'; @@ -40,7 +49,6 @@ const TOOLS_PANEL_ID = 'tools_panel_id'; */ export function ResizableWorkspace(props: ResizableWorkspaceProps) { const dispatch = useAppDispatch(); - const history = useHistory(); // Overall workspace state const { isDirty } = useSelector((state: AppState) => state.workspace); @@ -97,20 +105,15 @@ export function ResizableWorkspace(props: ResizableWorkspaceProps) { setIsToolsPanelOpen(!isToolsPanelOpen); }; - // Hook to update some default values for the workflow, if applicable. - // We need to handle different scenarios: - // 1. Rendering backend-only-created workflow / an existing workflow with no ui_metadata. - // In this case, we revert to the home page with a warn toast that we don't support it, for now. - // 2. Rendering a created workflow with ui_metadata. - // In these cases, just render what is persisted, no action needed. + // workflow state + const [isValidWorkflow, setIsValidWorkflow] = useState(true); + + // Hook to check if the workflow is valid or not useEffect(() => { const missingUiFlow = props.workflow && !props.workflow?.ui_metadata?.config; if (missingUiFlow) { - history.replace(APP_PATH.WORKFLOWS); - getCore().notifications.toasts.addWarning( - `There is no ui_metadata for workflow: ${props.workflow?.name}` - ); + setIsValidWorkflow(false); } else { setWorkflow(props.workflow); } @@ -143,7 +146,7 @@ export function ResizableWorkspace(props: ResizableWorkspaceProps) { } } - return ( + return isValidWorkflow ? ( )} + ) : ( + <> + Unable to view workflow details} + titleSize="s" + body={ + <> + + Only valid workflows created from this OpenSearch Dashboards + application are editable and viewable. + + + } + /> + + {JSON.stringify( + reduceToTemplate(props.workflow as Workflow), + undefined, + 2 + )} + + ); } diff --git a/public/pages/workflow_detail/workflow_inputs/ingest_inputs/ingest_inputs.tsx b/public/pages/workflow_detail/workflow_inputs/ingest_inputs/ingest_inputs.tsx index 6a341cc1..aad1d29f 100644 --- a/public/pages/workflow_detail/workflow_inputs/ingest_inputs/ingest_inputs.tsx +++ b/public/pages/workflow_detail/workflow_inputs/ingest_inputs/ingest_inputs.tsx @@ -21,8 +21,6 @@ interface IngestInputsProps { * The base component containing all of the ingest-related inputs */ export function IngestInputs(props: IngestInputsProps) { - // TODO: add some toggle to enable/disable ingest altogether. - // UX not finalized on where that will live currently return ( diff --git a/public/pages/workflow_detail/workflow_inputs/ingest_inputs/source_data.tsx b/public/pages/workflow_detail/workflow_inputs/ingest_inputs/source_data.tsx index b1fa01e6..fce7f7c5 100644 --- a/public/pages/workflow_detail/workflow_inputs/ingest_inputs/source_data.tsx +++ b/public/pages/workflow_detail/workflow_inputs/ingest_inputs/source_data.tsx @@ -5,7 +5,12 @@ import React, { useEffect } from 'react'; import { useFormikContext } from 'formik'; -import { EuiFlexGroup, EuiFlexItem, EuiTitle } from '@elastic/eui'; +import { + EuiFilePicker, + EuiFlexGroup, + EuiFlexItem, + EuiTitle, +} from '@elastic/eui'; import { JsonField } from '../input_fields'; import { IConfigField, WorkspaceFormValues } from '../../../../../common'; @@ -18,7 +23,15 @@ interface SourceDataProps { * Input component for configuring the source data for ingest. */ export function SourceData(props: SourceDataProps) { - const { values } = useFormikContext(); + const { values, setFieldValue } = useFormikContext(); + + // files state. when a file is read, update the form value. + const fileReader = new FileReader(); + fileReader.onload = (e) => { + if (e.target) { + setFieldValue('ingest.docs', e.target.result); + } + }; // Hook to listen when the docs form value changes. // Try to set the ingestDocs if possible @@ -35,6 +48,19 @@ export function SourceData(props: SourceDataProps) {

Source data

+ + { + if (files && files.length > 0) { + fileReader.readAsText(files[0]); + } + }} + display="default" + /> +