Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion frontend/web/components/PageTitle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const PageTitle: FC<PageTitleType> = ({ children, className, cta, title }) => {
</Row>
)}
</div>
{!!cta && <div className='float-end ms-lg-2'>{cta}</div>}
{!!cta && <div className='float-end'>{cta}</div>}
</div>
<hr className='mb-0 mt-3' />
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { FC, useMemo } from 'react'
import { FC, useMemo, useState } from 'react'
import CreatableSelect from 'react-select/creatable'
import { InputActionMeta } from 'react-select'
import {
useGetWarehouseConnectionEventsQuery,
useGetWarehouseConnectionsQuery,
Expand Down Expand Up @@ -33,6 +34,22 @@ const EventNameSelect: FC<EventNameSelectProps> = ({ onChange, value }) => {
)
const options = useMemo(() => buildEventOptions(data?.events), [data?.events])
const showWarning = isSuccess && isUnknownEvent(value, data?.events)
const [inputValue, setInputValue] = useState('')

// Keep the typed text on blur (react-select discards it by default) so
// clicking outside commits the value instead of clearing it.
const handleInputChange = (val: string, meta: InputActionMeta) => {
if (meta.action === 'input-change') setInputValue(val)
}
const handleChange = (option: EventOption | null) => {
setInputValue('')
onChange(option?.value ?? '')
}
const handleBlur = () => {
if (!inputValue) return
onChange(inputValue)
setInputValue('')
}
Comment on lines +37 to +52

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Clear the draft when the user clears the selection.

react-select 5.9.0 sends the clear-indicator action through onChange with action: 'clear'. Option selection uses the separate onInputChange set-value path handled here. (raw.githubusercontent.com)

If the user types a draft, clicks the clear control, and then blurs the field, inputValue remains populated. handleBlur can then call onChange(inputValue) and restore the cleared event.

Handle actionMeta.action === 'clear' in the select onChange callback. Add a regression test for draft input followed by clear and blur.

Suggested fix
-        onChange={(option: EventOption | null) => onChange(option?.value ?? '')}
+        onChange={(option: EventOption | null, actionMeta) => {
+          if (actionMeta.action === 'clear') setInputValue('')
+          onChange(option?.value ?? '')
+        }}
Verification script
#!/bin/bash
set -euo pipefail

select_source="$(
  fd -t f 'Select.tsx' . 2>/dev/null |
    while IFS= read -r file; do
      if rg -q "action: 'clear'|action: 'set-value'" "$file"; then
        printf '%s\n' "$file"
        break
      fi
    done
)"

if [[ -z "$select_source" ]]; then
  printf '%s\n' 'Could not locate the react-select source.' >&2
  exit 2
fi

rg -n -C 3 "action: 'clear'|action: 'set-value'" "$select_source"
rg -n -C 6 'handleInputChange|handleBlur|onChange=' \
  frontend/web/components/experiments/EventNameSelect/EventNameSelect.tsx


return (
<div className='event-name-select'>
Expand All @@ -42,11 +59,14 @@ const EventNameSelect: FC<EventNameSelectProps> = ({ onChange, value }) => {
classNamePrefix='react-select'
isClearable
isLoading={isLoading}
inputValue={inputValue}
onInputChange={handleInputChange}
onBlur={handleBlur}
maxMenuHeight={200}
menuPlacement='auto'
options={options}
value={value ? { label: value, value } : null}
onChange={(option: EventOption | null) => onChange(option?.value ?? '')}
onChange={handleChange}
placeholder='e.g. checkout_completed'
formatCreateLabel={(input: string) => `Use "${input}"`}
noOptionsMessage={() => 'Type to add a new event'}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,12 @@ const ExperimentSummaryScorecard: FC<ExperimentSummaryScorecardProps> = ({
loading={!hasResults}
value={
summary?.winnerName ? (
<span
className={summary.controlWins ? undefined : 'text-success'}
>
<VariantName
fit
colour={summary.winnerColour}
fontSize={24}
name={summary.winnerName}
/>
</span>
<VariantName
fit
colour={summary.winnerColour}
fontSize={24}
name={summary.winnerName}
/>
) : undefined
}
/>
Expand Down
2 changes: 1 addition & 1 deletion frontend/web/components/experiments/steps/SetupStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const SetupStep: FC<SetupStepProps> = ({
search: search || undefined,
type: 'MULTIVARIATE',
},
{ skip: !numericEnvId },
{ refetchOnMountOrArgChange: true, skip: !numericEnvId },
)

const multivariateFeatures = featureList?.results ?? []
Expand Down
Loading