SortPicker: Disable SortPicker by prop (#109083)

This commit is contained in:
Juan Cabanas
2025-08-04 09:17:33 -03:00
committed by GitHub
parent e88b54e9d3
commit 3b96a88aa2

View File

@ -13,13 +13,14 @@ export interface Props {
getSortOptions?: () => Promise<SelectableValue[]>; getSortOptions?: () => Promise<SelectableValue[]>;
filter?: string[]; filter?: string[];
isClearable?: boolean; isClearable?: boolean;
disabled?: boolean;
} }
const defaultSortOptionsGetter = (): Promise<SelectableValue[]> => { const defaultSortOptionsGetter = (): Promise<SelectableValue[]> => {
return getGrafanaSearcher().getSortOptions(); return getGrafanaSearcher().getSortOptions();
}; };
export function SortPicker({ onChange, value, placeholder, filter, getSortOptions, isClearable }: Props) { export function SortPicker({ onChange, value, placeholder, filter, getSortOptions, isClearable, disabled }: Props) {
// Using sync Select and manual options fetching here since we need to find the selected option by value // Using sync Select and manual options fetching here since we need to find the selected option by value
const options = useAsync<() => Promise<SelectableValue[]>>(async () => { const options = useAsync<() => Promise<SelectableValue[]>>(async () => {
const vals = await (getSortOptions ?? defaultSortOptionsGetter)(); const vals = await (getSortOptions ?? defaultSortOptionsGetter)();
@ -45,6 +46,7 @@ export function SortPicker({ onChange, value, placeholder, filter, getSortOption
placeholder={placeholder ?? `Sort (Default ${DEFAULT_SORT.label})`} placeholder={placeholder ?? `Sort (Default ${DEFAULT_SORT.label})`}
prefix={<Icon name={isDesc ? 'sort-amount-down' : 'sort-amount-up'} />} prefix={<Icon name={isDesc ? 'sort-amount-down' : 'sort-amount-up'} />}
isClearable={isClearable} isClearable={isClearable}
disabled={disabled}
/> />
); );
} }