Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
8d03669
ref: implement onClear by firing an onChange event with `undefined`
TkDodo Nov 20, 2025
8a636b6
ref: set disallowEmptySelection implicitly depending on clearable
TkDodo Nov 20, 2025
6ae2724
typescript needs more help
TkDodo Nov 20, 2025
6ceba45
fix: have clear button re-mount the internal list to clear listSelection
TkDodo Nov 20, 2025
09f0a44
fix: fix clearing values by not passing `undefined` to `selectedItems`
TkDodo Nov 20, 2025
efdb26f
Merge branch 'master' into tkdodo/ref/compactSelect-onClear
TkDodo Nov 20, 2025
1e098f5
test: type-tests for compactSelect onChange param
TkDodo Nov 20, 2025
45e171d
✂️
TkDodo Nov 20, 2025
5adce71
fix stories
TkDodo Nov 20, 2025
22ee87e
test: fix databaseSystemSelector.spec.tsx
TkDodo Nov 20, 2025
7e0a826
test: fix environmentSelector.spec.tsx
TkDodo Nov 20, 2025
67ada78
Merge branch 'master' into tkdodo/ref/compactSelect-onClear
TkDodo Nov 20, 2025
a02aa0f
test: add state to compactSelect tests
TkDodo Nov 20, 2025
fcd355b
Merge branch 'master' into tkdodo/ref/compactSelect-onClear
TkDodo Nov 20, 2025
851a7b4
Merge branch 'master' into tkdodo/ref/compactSelect-onClear
TkDodo Nov 20, 2025
bde40d9
fix: missing call to saveSelectedOptions
TkDodo Nov 20, 2025
19bbd42
fix: restore condition
TkDodo Nov 20, 2025
566704f
test: add state management to composite.spec.tsx
TkDodo Nov 20, 2025
8a4359c
Merge branch 'master' into tkdodo/ref/compactSelect-onClear
TkDodo Nov 20, 2025
f80913d
Merge branch 'master' into tkdodo/ref/compactSelect-onClear
TkDodo Nov 21, 2025
3b7a44c
fix: comments
TkDodo Nov 21, 2025
79352c2
fix: menu should close when `clear` is clicked
TkDodo Nov 21, 2025
d796af9
Merge branch 'master' into tkdodo/ref/compactSelect-onClear
TkDodo Nov 21, 2025
202ed6c
ref: better way to close overlay onClear
TkDodo Nov 21, 2025
cf7e9e2
fix: remove unnecessary check
TkDodo Nov 21, 2025
cfcb1ab
Merge branch 'master' into tkdodo/ref/compactSelect-onClear
TkDodo Nov 21, 2025
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
3 changes: 1 addition & 2 deletions static/app/components/assigneeSelectorDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ export default function AssigneeSelectorDropdown({
}));
};

const handleSelect = (selectedOption: SelectOption<string> | null) => {
const handleSelect = (selectedOption: SelectOption<string> | undefined) => {
// selectedOption is falsey when the option selected is already selected, or when the clear button is clicked
if (!selectedOption) {
if (onClear && group.assignedTo) {
Expand Down Expand Up @@ -565,7 +565,6 @@ export default function AssigneeSelectorDropdown({
className={className}
menuWidth={275}
position="bottom-end"
disallowEmptySelection={false}
onClick={e => e.stopPropagation()}
value={
group.assignedTo
Expand Down
72 changes: 49 additions & 23 deletions static/app/components/charts/optionSelector.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {Fragment, useMemo} from 'react';
import styled from '@emotion/styled';

import type {DistributiveOmit} from '@sentry/scraps/types';

import {FeatureBadge} from 'sentry/components/core/badge';
import type {
MultipleSelectProps,
Expand All @@ -17,28 +19,39 @@ type BaseProps = {
featureType?: 'alpha' | 'beta' | 'new';
};

interface SingleProps
extends Omit<
SingleSelectProps<string>,
'onChange' | 'defaultValue' | 'multiple' | 'title' | 'value'
>,
BaseProps {
onChange: (value: string) => void;
selected: string;
multiple?: false;
}
type SingleUnClearableProps = DistributiveOmit<
SingleSelectProps<string>,
'onChange' | 'multiple' | 'title' | 'value'
> &
BaseProps & {
onChange: (value: string) => void;
selected: string;
clearable?: false;
multiple?: false;
};

interface MultipleProps
extends Omit<
MultipleSelectProps<string>,
'onChange' | 'defaultValue' | 'multiple' | 'title' | 'value'
>,
BaseProps {
multiple: true;
onChange: (value: string[]) => void;
selected: string[];
defaultValue?: string[];
}
type SingleClearableProps = DistributiveOmit<
SingleSelectProps<string>,
'onChange' | 'multiple' | 'title' | 'value'
> &
BaseProps & {
clearable: true;
onChange: (value: string | undefined) => void;
selected: string;
multiple?: false;
};

type SingleProps = SingleClearableProps | SingleUnClearableProps;

type MultipleProps = DistributiveOmit<
MultipleSelectProps<string>,
'onChange' | 'multiple' | 'title' | 'value'
> &
BaseProps & {
multiple: true;
onChange: (value: string[]) => void;
selected: string[];
};

function OptionSelector({
options,
Expand All @@ -48,6 +61,7 @@ function OptionSelector({
featureType,
multiple,
closeOnSelect,
clearable,
...rest
}: SingleProps | MultipleProps) {
const mappedOptions = useMemo(() => {
Expand All @@ -65,6 +79,7 @@ function OptionSelector({
if (multiple) {
return {
multiple,
clearable,
value: selected,
onChange: (sel: Array<SelectOption<string>>) => {
onChange?.(sel.map(o => o.value));
Expand All @@ -73,13 +88,24 @@ function OptionSelector({
};
}

if (clearable) {
return {
multiple,
clearable,
value: selected,
onChange: (opt: SelectOption<string> | undefined) => onChange?.(opt?.value),
closeOnSelect,
};
}

return {
multiple,
clearable,
value: selected,
onChange: (opt: any) => onChange?.(opt.value),
onChange: (opt: SelectOption<string>) => onChange?.(opt.value),
closeOnSelect,
};
}, [multiple, selected, onChange, closeOnSelect]);
}, [clearable, multiple, selected, onChange, closeOnSelect]);

function isOptionDisabled(option: SelectOptionWithKey<string>) {
return Boolean(
Expand Down
Loading
Loading