Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 12 additions & 0 deletions contracts/api/v2/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -16879,6 +16879,10 @@
},
"type": "array"
},
"ordered": {
"description": "The order of a multi-select's values matters. The form shows the chosen values as a list that can be put in order.",
"type": "boolean"
},
"placeholder": {
"type": "string"
},
Expand Down Expand Up @@ -16919,6 +16923,14 @@
"AdminPluginFormSection": {
"additionalProperties": false,
"properties": {
"add_group": {
"description": "Sections with the same add_group are the slots of one list. The form shows the slots in use and a button that reveals the next.",
"type": "string"
},
"add_label": {
"description": "The text of the button that reveals the next slot.",
"type": "string"
},
"collapsed_default": {
"type": "boolean"
},
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,4 @@ require (

replace github.com/zishang520/webtransport-go => ./internal/compat/zishang520-webtransport-go

replace github.com/Silo-Server/silo-plugin-sdk => github.com/grtn91/silo-plugin-sdk v0.32.2-0.20261111162054-6349f38bd415
replace github.com/Silo-Server/silo-plugin-sdk => github.com/grtn91/silo-plugin-sdk v0.32.2-0.20261111220705-65c53aada4d3
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aN
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.29.0 h1:5VipnvEpbqr2gA2VbM+nYVbkIF28c5ZQfqCBQ5g2xfk=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.29.0/go.mod h1:Hyl3n6Twe1hvtd9XUXDec4pTvgMSEixRuQKPTMH2bNs=
github.com/grtn91/silo-plugin-sdk v0.32.2-0.20261111162054-6349f38bd415 h1:Hd76ckWisVLd+q/+SCyVKACQrq128i+gQS1b+p3IyyE=
github.com/grtn91/silo-plugin-sdk v0.32.2-0.20261111162054-6349f38bd415/go.mod h1:+r4X2TAiB9Gk22sUj1gFWUj65lll1P1/dMS+Ncvy3Y0=
github.com/grtn91/silo-plugin-sdk v0.32.2-0.20261111220705-65c53aada4d3 h1:Hm3wz12BcA9RxImughmC1VLmu5fGJ8JAV2gsshyIGUA=
github.com/grtn91/silo-plugin-sdk v0.32.2-0.20261111220705-65c53aada4d3/go.mod h1:+r4X2TAiB9Gk22sUj1gFWUj65lll1P1/dMS+Ncvy3Y0=
github.com/h2non/bimg v1.1.9 h1:WH20Nxko9l/HFm4kZCA3Phbgu2cbHvYzxwxn9YROEGg=
github.com/h2non/bimg v1.1.9/go.mod h1:R3+UiYwkK4rQl6KVFTOFJHitgLbZXBZNFh2cv3AEbp8=
github.com/hashicorp/go-hclog v1.6.3 h1:Qr2kF+eVWjTiYmU7Y31tYlP1h0q/X3Nl3tPGdaB11/k=
Expand Down
7 changes: 5 additions & 2 deletions internal/apiv2/admin_plugin_installations.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ type AdminPluginFormField struct {
ShowWhen []AdminFormCondition `json:"show_when"`
Validation *AdminPluginFormValidation `json:"validation,omitempty"`
ExclusiveGroupField string `json:"exclusive_group_field,omitempty"`
Ordered bool `json:"ordered,omitempty" doc:"The order of a multi-select's values matters. The form shows the chosen values as a list that can be put in order."`
}
type AdminPluginFormSection struct {
Key string `json:"key"`
Expand All @@ -108,6 +109,8 @@ type AdminPluginFormSection struct {
CollapsedDefault bool `json:"collapsed_default"`
FieldKeys []string `json:"field_keys"`
ShowWhen []AdminFormCondition `json:"show_when"`
AddGroup string `json:"add_group,omitempty" doc:"Sections with the same add_group are the slots of one list. The form shows the slots in use and a button that reveals the next."`
AddLabel string `json:"add_label,omitempty" doc:"The text of the button that reveals the next slot."`
}
type AdminPluginForm struct {
Fields []AdminPluginFormField `json:"fields"`
Expand Down Expand Up @@ -285,7 +288,7 @@ func adminPluginFormOf(f *plugins.AdminFormView) (*AdminPluginForm, error) {
}
out := &AdminPluginForm{Fields: make([]AdminPluginFormField, 0, len(f.Fields)), SubmitLabel: f.SubmitLabel, Sections: make([]AdminPluginFormSection, 0, len(f.Sections))}
for _, fld := range f.Fields {
item := AdminPluginFormField{Key: fld.Key, Label: fld.Label, Description: fld.Description, Control: fld.Control, Placeholder: fld.Placeholder, Required: fld.Required, Secret: fld.Secret, Multiline: fld.Multiline, Options: make([]AdminFormOption, 0, len(fld.Options)), Rows: fld.Rows, DynamicOptions: fld.DynamicOptions, ShowWhen: adminPluginFormConditionsOf(fld.ShowWhen), ExclusiveGroupField: fld.ExclusiveGroupField}
item := AdminPluginFormField{Key: fld.Key, Label: fld.Label, Description: fld.Description, Control: fld.Control, Placeholder: fld.Placeholder, Required: fld.Required, Secret: fld.Secret, Multiline: fld.Multiline, Options: make([]AdminFormOption, 0, len(fld.Options)), Rows: fld.Rows, DynamicOptions: fld.DynamicOptions, ShowWhen: adminPluginFormConditionsOf(fld.ShowWhen), ExclusiveGroupField: fld.ExclusiveGroupField, Ordered: fld.Ordered}
if fld.DefaultValue != nil {
raw, err := json.Marshal(fld.DefaultValue)
if err != nil {
Expand All @@ -302,7 +305,7 @@ func adminPluginFormOf(f *plugins.AdminFormView) (*AdminPluginForm, error) {
out.Fields = append(out.Fields, item)
}
for _, s := range f.Sections {
out.Sections = append(out.Sections, AdminPluginFormSection{Key: s.Key, Title: s.Title, Description: s.Description, Collapsible: s.Collapsible, CollapsedDefault: s.CollapsedDefault, FieldKeys: NonNil(s.FieldKeys), ShowWhen: adminPluginFormConditionsOf(s.ShowWhen)})
out.Sections = append(out.Sections, AdminPluginFormSection{Key: s.Key, Title: s.Title, Description: s.Description, Collapsible: s.Collapsible, CollapsedDefault: s.CollapsedDefault, FieldKeys: NonNil(s.FieldKeys), ShowWhen: adminPluginFormConditionsOf(s.ShowWhen), AddGroup: s.AddGroup, AddLabel: s.AddLabel})
}
return out, nil
}
Expand Down
9 changes: 8 additions & 1 deletion internal/plugins/config_schema_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ type AdminFormFieldView struct {
ShowWhen []AdminFormConditionView `json:"show_when,omitempty"`
Validation *AdminFormValidationView `json:"validation,omitempty"`
ExclusiveGroupField string `json:"exclusive_group_field,omitempty"`
// Ordered says the order of a multi-select's values matters.
Ordered bool `json:"ordered,omitempty"`
}

type AdminFormOptionView struct {
Expand Down Expand Up @@ -70,6 +72,10 @@ type AdminFormSectionView struct {
CollapsedDefault bool `json:"collapsed_default"`
FieldKeys []string `json:"field_keys"`
ShowWhen []AdminFormConditionView `json:"show_when,omitempty"`
// AddGroup names the list this section is one slot of, and AddLabel the
// button that reveals the next slot. Empty for an ordinary section.
AddGroup string `json:"add_group,omitempty"`
AddLabel string `json:"add_label,omitempty"`
}

func ConfigSchemaViews(schemas []*pluginv1.ConfigSchema) []ConfigSchemaView {
Expand Down Expand Up @@ -122,7 +128,7 @@ func AdminFormViewFromProto(form *pluginv1.AdminFormDescriptor) *AdminFormView {
Placeholder: field.GetPlaceholder(), Required: field.GetRequired(), Secret: field.GetSecret(),
Multiline: field.GetMultiline(), DefaultValue: defaultValue, Options: options, Rows: field.GetRows(),
DynamicOptions: field.GetDynamicOptions(), ShowWhen: adminFormConditionViews(field.GetShowWhen()),
Validation: validation, ExclusiveGroupField: field.GetExclusiveGroupField(),
Validation: validation, ExclusiveGroupField: field.GetExclusiveGroupField(), Ordered: field.GetOrdered(),
})
}
sections := make([]AdminFormSectionView, 0, len(form.GetSections()))
Expand All @@ -134,6 +140,7 @@ func AdminFormViewFromProto(form *pluginv1.AdminFormDescriptor) *AdminFormView {
Key: section.GetKey(), Title: section.GetTitle(), Description: section.GetDescription(),
Collapsible: section.GetCollapsible(), CollapsedDefault: section.GetCollapsedDefault(),
FieldKeys: append([]string(nil), section.GetFieldKeys()...), ShowWhen: adminFormConditionViews(section.GetShowWhen()),
AddGroup: section.GetAddGroup(), AddLabel: section.GetAddLabel(),
})
}
return &AdminFormView{Fields: fields, SubmitLabel: form.GetSubmitLabel(), Sections: sections}
Expand Down
6 changes: 6 additions & 0 deletions web/src/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3935,6 +3935,10 @@ export interface PluginAdminFormSection {
collapsed_default: boolean;
field_keys: string[];
show_when?: PluginAdminFormCondition[];
/** Sections with the same add_group are the slots of one list the admin grows. */
add_group?: string;
/** The text of the button that reveals the next slot. */
add_label?: string;
}

export interface PluginAdminFormField {
Expand All @@ -3953,6 +3957,8 @@ export interface PluginAdminFormField {
show_when?: PluginAdminFormCondition[];
validation?: PluginAdminFormValidation;
exclusive_group_field?: string;
/** The order of a multi-select's values matters; the form lets the admin arrange them. */
ordered?: boolean;
/**
* Names a host-known value this field can be populated from in one click.
* Used by autoscan source config so a path field can be filled from Silo's
Expand Down
6 changes: 6 additions & 0 deletions web/src/api/v2/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19932,6 +19932,8 @@ export interface components {
label: string;
multiline: boolean;
options: components["schemas"]["AdminFormOption"][];
/** @description The order of a multi-select's values matters. The form shows the chosen values as a list that can be put in order. */
ordered?: boolean;
placeholder?: string;
required: boolean;
/** Format: int32 */
Expand All @@ -19941,6 +19943,10 @@ export interface components {
validation?: components["schemas"]["AdminPluginFormValidation"];
};
AdminPluginFormSection: {
/** @description Sections with the same add_group are the slots of one list. The form shows the slots in use and a button that reveals the next. */
add_group?: string;
/** @description The text of the button that reveals the next slot. */
add_label?: string;
collapsed_default: boolean;
collapsible: boolean;
description?: string;
Expand Down
143 changes: 143 additions & 0 deletions web/src/components/admin/plugins/OrderedMultiSelect.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
import { DndContext } from "@dnd-kit/core";
import { SortableContext, useSortable, verticalListSortingStrategy } from "@dnd-kit/sortable";
import { CSS } from "@dnd-kit/utilities";
import { GripVertical, Plus, X } from "lucide-react";

import { Button } from "@/components/ui/button";
import { useSortableList } from "@/hooks/useSortableList";
import { useT } from "@/i18n";

import type { SchemaOption } from "./schemaFormUtils";

function identity(value: string): string {
return value;
}

function SortableValue({
value,
label,
position,
disabled,
onRemove,
}: {
value: string;
label: string;
position: number;
disabled: boolean;
onRemove: () => void;
}) {
const t = useT();
const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({
id: value,
disabled,
});
const style: React.CSSProperties = {
transform: CSS.Transform.toString(transform),
transition,
opacity: isDragging ? 0.4 : 1,
};
return (
<li
ref={setNodeRef}
style={style}
className="bg-card flex items-center gap-2 rounded-md border px-2 py-1.5 text-sm"
>
<button
type="button"
aria-label={t("web.admin.libraries.list.dragToReorder")}
title={t("web.admin.libraries.list.dragToReorder")}
disabled={disabled}
className="hover:bg-surface-hover cursor-grab touch-none rounded-md p-0.5 transition-colors disabled:cursor-default"
{...attributes}
{...listeners}
>
<GripVertical aria-hidden="true" className="text-muted-foreground size-4" />
</button>
<span className="text-muted-foreground w-4 text-end text-xs tabular-nums">{position}</span>
<span className="min-w-0 flex-1 truncate">{label}</span>
<Button
type="button"
size="icon-xs"
variant="ghost"
disabled={disabled}
aria-label={t("web.admin.settings.requests.shared.delete")}
title={t("web.admin.settings.requests.shared.delete")}
onClick={onRemove}
>
<X aria-hidden="true" />
</Button>
</li>
);
}

/**
* A multi-select whose order matters. The chosen values are a list that can
* be put in order by dragging, or with the keyboard on a row's handle; the
* options not chosen yet are buttons that add to the end of it.
*/
export function OrderedMultiSelect({
options,
selected,
onChange,
disabled = false,
describedBy,
}: {
options: SchemaOption[];
selected: string[];
onChange: (next: string[]) => void;
disabled?: boolean;
describedBy?: string;
}) {
const { sensors, collisionDetection, handleDragEnd } = useSortableList(
selected,
identity,
onChange,
);
// A chosen value the options no longer list keeps its place, shown as it is stored.
const labels = new Map(options.map((option) => [option.value, option.label]));
const unchosen = options.filter((option) => !selected.includes(option.value));

return (
<div className="grid gap-2" aria-describedby={describedBy}>
{selected.length > 0 ? (
<DndContext
sensors={sensors}
collisionDetection={collisionDetection}
onDragEnd={handleDragEnd}
>
<SortableContext items={selected} strategy={verticalListSortingStrategy}>
<ol className="grid gap-1.5">
{selected.map((value, index) => (
<SortableValue
key={value}
value={value}
label={labels.get(value) ?? value}
position={index + 1}
disabled={disabled}
onRemove={() => onChange(selected.filter((other) => other !== value))}
/>
))}
</ol>
</SortableContext>
</DndContext>
) : null}
{unchosen.length > 0 ? (
<div className="flex flex-wrap gap-2">
{unchosen.map((option) => (
<Button
key={option.value}
type="button"
size="xs"
variant="outline"
disabled={disabled}
onClick={() => onChange([...selected, option.value])}
>
<Plus aria-hidden="true" />
{option.label}
</Button>
))}
</div>
) : null}
</div>
);
}
Loading
Loading