feat: multiselect valve input type with static or dynamic options (#26884)
Adds a multiselect input type for Valves and UserValves so plugin authors can let users pick multiple values from static or runtime-resolved options instead of maintaining comma-separated text fields with hardcoded allowed-value lists in the description.
ENABLED_ITEMS: list[str] = Field(
default=["foo"],
json_schema_extra={"input": {"type": "multiselect", "options": "get_item_options"}},
)
@classmethod
def get_item_options(cls):
return [{"value": "foo", "label": "Foo"}, {"value": "bar", "label": "Bar"}]
Options accept the same shapes as the existing select input: either a static list (strings or {value, label} dicts) or a classmethod name resolved at request time (including __user__ context for UserValves). No backend changes are needed because resolve_valves_schema_options already resolves options independently of the input type.
The new MultiSelect component follows the existing Select portal dropdown pattern and renders checkbox rows that stay open while toggling, with the selected labels shown in the trigger. Values bind as a real string array end to end: the array-to-comma-string conversions in the chat controls valves panel and the valves modal are skipped for multiselect fields, so the stored valve is a native list[str] validated by Pydantic.
Requested in #26848.
This commit is contained in:
1 parent
051a1f6c41
commit
7e96c53a20
4 files changed
+178
-1
No files matched your search
@@ -9,6 +9,7 @@
|
||||
import Switch from './Switch.svelte';
|
||||
import SensitiveInput from './SensitiveInput.svelte';
|
||||
import NativeSelect from './NativeSelect.svelte';
|
||||
import MultiSelect from './MultiSelect.svelte';
|
||||
import MapSelector from './Valves/MapSelector.svelte';
|
||||
|
||||
export let valvesSpec = null;
|
||||
@@ -37,7 +38,11 @@
|
||||
// Initialize to custom value
|
||||
if ((propertySpec?.type ?? null) === 'array') {
|
||||
const defaultArray = propertySpec?.default ?? [];
|
||||
valves[property] = Array.isArray(defaultArray) ? defaultArray.join(', ') : '';
|
||||
if (propertySpec?.input?.type === 'multiselect') {
|
||||
valves[property] = Array.isArray(defaultArray) ? [...defaultArray] : [];
|
||||
} else {
|
||||
valves[property] = Array.isArray(defaultArray) ? defaultArray.join(', ') : '';
|
||||
}
|
||||
} else {
|
||||
valves[property] = propertySpec?.default ?? '';
|
||||
}
|
||||
@@ -95,6 +100,16 @@
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
{:else if valvesSpec.properties[property]?.input?.type === 'multiselect' && valvesSpec.properties[property]?.input?.options}
|
||||
<MultiSelect
|
||||
className="w-full rounded-lg py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-hidden border border-gray-100/30 dark:border-gray-850/30"
|
||||
bind:value={valves[property]}
|
||||
options={valvesSpec.properties[property].input.options}
|
||||
placeholder={$i18n.t('Select options')}
|
||||
on:change={() => {
|
||||
dispatch('change');
|
||||
}}
|
||||
/>
|
||||
{:else if (valvesSpec.properties[property]?.type ?? null) !== 'string'}
|
||||
<input
|
||||
class="w-full rounded-lg py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-hidden border border-gray-100/30 dark:border-gray-850/30"
|
||||
|
||||
Reference in new issue
Block a user