Skip to content

Commit

Permalink
fix: Multiselect broken for single mode (#17453)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjackwhite authored Sep 15, 2023
1 parent 491960d commit d7a97f8
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ export function EditSubscription({
>
{({ value, onChange }) => (
<LemonSelectMultiple
onChange={(val: string[]) => onChange(val)}
onChange={(val: string) => onChange(val)}
value={value}
disabled={slackDisabled}
mode="single"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@ export interface LemonSelectMultipleOptionItem extends LemonSelectMultipleOption

export type LemonSelectMultipleOptions = Record<string, LemonSelectMultipleOption>

export interface LemonSelectMultipleProps {
export type LemonSelectMultipleProps = {
selectClassName?: string
options?: LemonSelectMultipleOptions | LemonSelectMultipleOptionItem[]
value?: string[] | null | LabelInValue[]
value?: string | string[] | null
disabled?: boolean
loading?: boolean
placeholder?: string
labelInValue?: boolean
onChange?: ((newValue: string[]) => void) | ((newValue: LabelInValue[]) => void)
onSearch?: (value: string) => void
onFocus?: () => void
onBlur?: () => void
filterOption?: boolean
mode?: 'single' | 'multiple' | 'multiple-custom'
onChange?: ((newValue: string) => void) | ((newValue: string[]) => void)
'data-attr'?: string
}

Expand Down Expand Up @@ -82,9 +82,10 @@ export function LemonSelectMultiple({
showAction={['focus']}
onChange={(v) => {
if (onChange) {
if (labelInValue) {
const typedValues = v as LabelInValue[]
const typedOnChange = onChange as (newValue: LabelInValue[]) => void
// TRICKY: V is typed poorly and will be a string if the "mode" is undefined
if (!v || typeof v === 'string') {
const typedValues = v as string | null
const typedOnChange = onChange as (newValue: string | null) => void
typedOnChange(typedValues)
} else {
const typedValues = v.map((token) => token.toString().trim()) as string[]
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/scenes/project/Settings/TimezoneConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function TimezoneConfig(): JSX.Element {
loading={currentTeamLoading}
disabled={currentTeamLoading}
value={[currentTeam.timezone]}
onChange={(newTimezone: any): void => {
onChange={(newTimezone: string): void => {
// This is a string for a single-mode select, but typing is poor
if (!preflight?.available_timezones) {
throw new Error('No timezones are available')
Expand Down

0 comments on commit d7a97f8

Please sign in to comment.