Skip to content

Commit

Permalink
add test ids; remove unnecessary try/catch
Browse files Browse the repository at this point in the history
Signed-off-by: Tyler Ohlsen <[email protected]>
  • Loading branch information
ohltyler committed Oct 3, 2024
1 parent 705d663 commit eed68b5
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ export function MLProcessorInputs(props: MLProcessorInputsProps) {
style={{ width: '100px' }}
fill={false}
onClick={() => setIsQueryModalOpen(true)}
data-testid="overrideQueryButton"
>
Override
</EuiSmallButton>
Expand All @@ -328,6 +329,7 @@ export function MLProcessorInputs(props: MLProcessorInputsProps) {
style={{ width: '100px' }}
fill={false}
onClick={() => setIsPromptModalOpen(true)}
data-testid="configurePromptButton"
>
Configure
</EuiSmallButton>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
Expand Down Expand Up @@ -208,7 +206,12 @@ export function OverrideQueryModal(props: OverrideQueryModalProps) {
</EuiFlexGroup>
</EuiModalBody>
<EuiModalFooter>
<EuiSmallButton onClick={props.onClose} fill={false} color="primary">
<EuiSmallButton
onClick={props.onClose}
fill={false}
color="primary"
data-testid="closeModalButton"
>
Close
</EuiSmallButton>
</EuiModalFooter>
Expand Down

0 comments on commit eed68b5

Please sign in to comment.