From eed68b56b46b364959b06019a511329c3907da47 Mon Sep 17 00:00:00 2001 From: Tyler Ohlsen Date: Thu, 3 Oct 2024 09:30:08 -0700 Subject: [PATCH] add test ids; remove unnecessary try/catch Signed-off-by: Tyler Ohlsen --- .../processor_inputs/ml_processor_inputs.tsx | 2 + .../modals/override_query_modal.tsx | 87 ++++++++++--------- 2 files changed, 47 insertions(+), 42 deletions(-) diff --git a/public/pages/workflow_detail/workflow_inputs/processor_inputs/ml_processor_inputs.tsx b/public/pages/workflow_detail/workflow_inputs/processor_inputs/ml_processor_inputs.tsx index eeac8dea..3803a2aa 100644 --- a/public/pages/workflow_detail/workflow_inputs/processor_inputs/ml_processor_inputs.tsx +++ b/public/pages/workflow_detail/workflow_inputs/processor_inputs/ml_processor_inputs.tsx @@ -311,6 +311,7 @@ export function MLProcessorInputs(props: MLProcessorInputsProps) { style={{ width: '100px' }} fill={false} onClick={() => setIsQueryModalOpen(true)} + data-testid="overrideQueryButton" > Override @@ -328,6 +329,7 @@ export function MLProcessorInputs(props: MLProcessorInputsProps) { style={{ width: '100px' }} fill={false} onClick={() => setIsPromptModalOpen(true)} + data-testid="configurePromptButton" > Configure diff --git a/public/pages/workflow_detail/workflow_inputs/processor_inputs/modals/override_query_modal.tsx b/public/pages/workflow_detail/workflow_inputs/processor_inputs/modals/override_query_modal.tsx index c30eebb1..edbab46f 100644 --- a/public/pages/workflow_detail/workflow_inputs/processor_inputs/modals/override_query_modal.tsx +++ b/public/pages/workflow_detail/workflow_inputs/processor_inputs/modals/override_query_modal.tsx @@ -119,47 +119,45 @@ export function OverrideQueryModal(props: OverrideQueryModalProps) { items: QUERY_PRESETS.map((preset: QueryPreset) => ({ name: preset.name, onClick: () => { - try { - setFieldValue( - queryFieldPath, - preset.query - // sanitize the query preset string into valid template placeholder format, for - // any placeholder values in the query. - // for example, replacing `"{{vector}}"` with `${vector}` - .replace( - new RegExp(`"${VECTOR_FIELD_PATTERN}"`, 'g'), - `\$\{vector_field\}` - ) - .replace( - new RegExp(`"${VECTOR_PATTERN}"`, 'g'), - `\$\{vector\}` - ) - .replace( - new RegExp(`"${TEXT_FIELD_PATTERN}"`, 'g'), - `\$\{text_field\}` - ) - .replace( - new RegExp(`"${IMAGE_FIELD_PATTERN}"`, 'g'), - `\$\{image_field\}` - ) - .replace( - new RegExp(`"${LABEL_FIELD_PATTERN}"`, 'g'), - `\$\{label_field\}` - ) - .replace( - new RegExp(`"${QUERY_TEXT_PATTERN}"`, 'g'), - `\$\{query_text\}` - ) - .replace( - new RegExp(`"${QUERY_IMAGE_PATTERN}"`, 'g'), - `\$\{query_image\}` - ) - .replace( - new RegExp(`"${MODEL_ID_PATTERN}"`, 'g'), - `\$\{model_id\}` - ) - ); - } catch {} + setFieldValue( + queryFieldPath, + preset.query + // sanitize the query preset string into valid template placeholder format, for + // any placeholder values in the query. + // for example, replacing `"{{vector}}"` with `${vector}` + .replace( + new RegExp(`"${VECTOR_FIELD_PATTERN}"`, 'g'), + `\$\{vector_field\}` + ) + .replace( + new RegExp(`"${VECTOR_PATTERN}"`, 'g'), + `\$\{vector\}` + ) + .replace( + new RegExp(`"${TEXT_FIELD_PATTERN}"`, 'g'), + `\$\{text_field\}` + ) + .replace( + new RegExp(`"${IMAGE_FIELD_PATTERN}"`, 'g'), + `\$\{image_field\}` + ) + .replace( + new RegExp(`"${LABEL_FIELD_PATTERN}"`, 'g'), + `\$\{label_field\}` + ) + .replace( + new RegExp(`"${QUERY_TEXT_PATTERN}"`, 'g'), + `\$\{query_text\}` + ) + .replace( + new RegExp(`"${QUERY_IMAGE_PATTERN}"`, 'g'), + `\$\{query_image\}` + ) + .replace( + new RegExp(`"${MODEL_ID_PATTERN}"`, 'g'), + `\$\{model_id\}` + ) + ); setFieldTouched(queryFieldPath, true); setPresetsPopoverOpen(false); }, @@ -208,7 +206,12 @@ export function OverrideQueryModal(props: OverrideQueryModalProps) { - + Close