mirror of https://github.com/grafana/grafana
Scene: Variables and All value support (#59635)
* Working on the all value * Support for custom allValue * Fixes * More progress * Progress * Updated * Fixed issue with multi and All value * Clarified testspull/60304/head
parent
d2f9d7f39b
commit
ef46761b9a
@ -1,47 +1,62 @@ |
||||
import { isArray } from 'lodash'; |
||||
import React from 'react'; |
||||
|
||||
import { Select, MultiSelect } from '@grafana/ui'; |
||||
import { MultiSelect, Select } from '@grafana/ui'; |
||||
|
||||
import { SceneComponentProps } from '../../core/types'; |
||||
import { MultiValueVariable } from '../variants/MultiValueVariable'; |
||||
|
||||
export function VariableValueSelect({ model }: SceneComponentProps<MultiValueVariable>) { |
||||
const { value, key, loading, isMulti, options } = model.useState(); |
||||
const { value, key, loading } = model.useState(); |
||||
|
||||
if (isMulti) { |
||||
return ( |
||||
<MultiSelect |
||||
<Select |
||||
id={key} |
||||
placeholder="Select value" |
||||
width="auto" |
||||
value={isArray(value) ? value : [value]} |
||||
value={value} |
||||
allowCustomValue |
||||
tabSelectsValue={false} |
||||
isLoading={loading} |
||||
options={options} |
||||
closeMenuOnSelect={false} |
||||
options={model.getOptionsForSelect()} |
||||
onChange={(newValue) => { |
||||
model.changeValueTo( |
||||
newValue.map((v) => v.value!), |
||||
newValue.map((v) => v.label!) |
||||
); |
||||
model.changeValueTo(newValue.value!, newValue.label!); |
||||
}} |
||||
/> |
||||
); |
||||
} |
||||
|
||||
export function VariableValueSelectMulti({ model }: SceneComponentProps<MultiValueVariable>) { |
||||
const { value, key, loading } = model.useState(); |
||||
const arrayValue = isArray(value) ? value : [value]; |
||||
|
||||
return ( |
||||
<Select |
||||
<MultiSelect |
||||
id={key} |
||||
placeholder="Select value" |
||||
width="auto" |
||||
value={value} |
||||
value={arrayValue} |
||||
tabSelectsValue={false} |
||||
allowCustomValue |
||||
isLoading={loading} |
||||
options={options} |
||||
options={model.getOptionsForSelect()} |
||||
closeMenuOnSelect={false} |
||||
isClearable={true} |
||||
onOpenMenu={() => {}} |
||||
onChange={(newValue) => { |
||||
model.changeValueTo(newValue.value!, newValue.label!); |
||||
model.changeValueTo( |
||||
newValue.map((v) => v.value!), |
||||
newValue.map((v) => v.label!) |
||||
); |
||||
}} |
||||
/> |
||||
); |
||||
} |
||||
|
||||
export function renderSelectForVariable(model: MultiValueVariable) { |
||||
if (model.state.isMulti) { |
||||
return <VariableValueSelectMulti model={model} />; |
||||
} else { |
||||
return <VariableValueSelect model={model} />; |
||||
} |
||||
} |
||||
|
Loading…
Reference in new issue