From 2aab2ff1527dfe20a912f51e1e15d40d695e22a2 Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Wed, 16 Oct 2024 12:56:32 -0700 Subject: [PATCH] Misc bug fixes and minor UX improvements (#427) (#429) (cherry picked from commit 1f449af4c7330cfc21b3d3d57468781ecad24707) Signed-off-by: Tyler Ohlsen Signed-off-by: github-actions[bot] Co-authored-by: github-actions[bot] --- .../ingest_inputs/ingest_inputs.tsx | 2 + .../ingest_inputs/source_data.tsx | 45 +++-- .../modals/input_transform_modal.tsx | 6 +- .../workflow_inputs/workflow_inputs.tsx | 179 +++++++++--------- .../import_workflow/import_workflow_modal.tsx | 10 +- 5 files changed, 135 insertions(+), 107 deletions(-) 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 527def78..2358003f 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 @@ -15,6 +15,7 @@ interface IngestInputsProps { uiConfig: WorkflowConfig; setUiConfig: (uiConfig: WorkflowConfig) => void; workflow: Workflow | undefined; + lastIngested: number | undefined; } /** @@ -28,6 +29,7 @@ export function IngestInputs(props: IngestInputsProps) { workflow={props.workflow} uiConfig={props.uiConfig} setIngestDocs={props.setIngestDocs} + lastIngested={props.lastIngested} /> 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 d8447804..5c91e643 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 @@ -35,6 +35,7 @@ import { WorkspaceFormValues, customStringify, isVectorSearchUseCase, + toFormattedDate, } from '../../../../../common'; import { AppState, @@ -48,6 +49,7 @@ interface SourceDataProps { workflow: Workflow | undefined; uiConfig: WorkflowConfig; setIngestDocs: (docs: string) => void; + lastIngested: number | undefined; } enum SOURCE_OPTIONS { @@ -65,6 +67,13 @@ export function SourceData(props: SourceDataProps) { const { values, setFieldValue } = useFormikContext(); const indices = useSelector((state: AppState) => state.opensearch.indices); + // empty/populated docs state + let docs = []; + try { + docs = JSON.parse(getIn(values, 'ingest.docs', [])); + } catch {} + const docsPopulated = docs.length > 0; + // selected option state const [selectedOption, setSelectedOption] = useState( SOURCE_OPTIONS.MANUAL @@ -184,7 +193,7 @@ export function SourceData(props: SourceDataProps) { > -

{`Edit source data`}

+

{`Import data`}

@@ -258,7 +267,7 @@ export function SourceData(props: SourceDataProps) { )} -

Source data

+

Import data

+ {props.lastIngested !== undefined && ( + + + {`Last ingested: ${toFormattedDate(props.lastIngested)}`} + + + )} + setIsEditModalOpen(true)} > - Edit + {docsPopulated ? `Edit` : `Select data`} - - - + {docsPopulated && ( + + + + )} ); diff --git a/public/pages/workflow_detail/workflow_inputs/processor_inputs/modals/input_transform_modal.tsx b/public/pages/workflow_detail/workflow_inputs/processor_inputs/modals/input_transform_modal.tsx index 624cd0b1..4ef5fee3 100644 --- a/public/pages/workflow_detail/workflow_inputs/processor_inputs/modals/input_transform_modal.tsx +++ b/public/pages/workflow_detail/workflow_inputs/processor_inputs/modals/input_transform_modal.tsx @@ -77,7 +77,7 @@ interface InputTransformModalProps { onClose: () => void; } -// the max number of input docs we use to display & test transforms with +// the max number of input docs we use to display & test transforms with (search response hits) const MAX_INPUT_DOCS = 10; /** @@ -143,7 +143,9 @@ export function InputTransformModal(props: InputTransformModalProps) { const description = props.context === PROCESSOR_CONTEXT.SEARCH_REQUEST ? 'Fetch an input query and see how it is transformed.' - : `Fetch some sample documents (up to ${MAX_INPUT_DOCS}) and see how they are transformed.`; + : props.context === PROCESSOR_CONTEXT.INGEST + ? 'Fetch a sample document and see how it is transformed' + : `Fetch some returned documents (up to ${MAX_INPUT_DOCS}) and see how they are transformed.`; // hook to re-generate the transform when any inputs to the transform are updated useEffect(() => { diff --git a/public/pages/workflow_detail/workflow_inputs/workflow_inputs.tsx b/public/pages/workflow_detail/workflow_inputs/workflow_inputs.tsx index f8087377..3d7e9a79 100644 --- a/public/pages/workflow_detail/workflow_inputs/workflow_inputs.tsx +++ b/public/pages/workflow_detail/workflow_inputs/workflow_inputs.tsx @@ -20,7 +20,6 @@ import { EuiModalHeader, EuiModalHeaderTitle, EuiPanel, - EuiSpacer, EuiStepsHorizontal, EuiText, EuiTitle, @@ -122,6 +121,11 @@ export function WorkflowInputs(props: WorkflowInputsProps) { // confirm modal state const [isModalOpen, setIsModalOpen] = useState(false); + // last ingested state + const [lastIngested, setLastIngested] = useState( + undefined + ); + // maintain global states const onIngest = selectedStep === STEP.INGEST; const onSearch = selectedStep === STEP.SEARCH; @@ -549,6 +553,7 @@ export function WorkflowInputs(props: WorkflowInputsProps) { .unwrap() .then(async (resp) => { props.setIngestResponse(customStringify(resp)); + setLastIngested(Date.now()); }) .catch((error: any) => { props.setIngestResponse(''); @@ -632,7 +637,7 @@ export function WorkflowInputs(props: WorkflowInputsProps) { height: '100%', }} > - + )} - {onIngestAndUnprovisioned && ( - <> - - - - Create an ingest pipeline - - - Configure and ingest data into an index. - - - ), - }} - disabledOption={{ - id: INGEST_OPTION.SKIP, - label: ( - - - Skip ingestion pipeline - - - Use an existing index with data ingested. - - - ), - }} - showLabel={false} - /> - - )} - {!onIngestAndDisabled && ( - <> - - -

- {onIngestAndUnprovisioned ? ( - 'Define ingest pipeline' - ) : onIngestAndProvisioned ? ( - - - Edit ingest pipeline - - - setIsModalOpen(true)} - > - - {` `}Delete resources - - - - ) : ( - 'Define search pipeline' - )} -

-
-
- - {onIngest ? ( + + + +

+ {onIngestAndUnprovisioned ? ( + 'Define ingest pipeline' + ) : onIngestAndProvisioned ? ( + + + Edit ingest pipeline + + + setIsModalOpen(true)} + > + + {` `}Delete resources + + + + ) : ( + 'Define search pipeline' + )} +

+
+
+ {onIngest ? ( + <> + {onIngestAndUnprovisioned && ( + <> + + + Create an ingest pipeline + + + Configure and ingest data into an index. + + + ), + }} + disabledOption={{ + id: INGEST_OPTION.SKIP, + label: ( + + + Skip ingestion pipeline + + + Use an existing index with data ingested. + + + ), + }} + showLabel={false} + /> + + )} + {!onIngestAndDisabled && ( - ) : ( - )} -
- - )} - + + ) : ( + + )} + + diff --git a/public/pages/workflows/import_workflow/import_workflow_modal.tsx b/public/pages/workflows/import_workflow/import_workflow_modal.tsx index 71f8b472..8f8bf9fe 100644 --- a/public/pages/workflows/import_workflow/import_workflow_modal.tsx +++ b/public/pages/workflows/import_workflow/import_workflow_modal.tsx @@ -85,11 +85,7 @@ export function ImportWorkflowModal(props: ImportWorkflowModalProps) { - + {fileContents !== undefined && !isValidWorkflow(fileObj) && ( <> @@ -116,11 +112,15 @@ export function ImportWorkflowModal(props: ImportWorkflowModalProps) { )} { if (files && files.length > 0) { fileReader.readAsText(files[0]); + } else { + setFileContents(undefined); } }} display="large"