Skip to content
Draft
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
3 changes: 3 additions & 0 deletions frontend/messages/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,9 @@
"addAgentDescription": "FΓΌge einen neuen Agenten hinzu, um Docker-Hosts und Server zu verwalten.",
"editAgentDescription": "Aktualisiere die Agentenkonfiguration.",
"agentNamePlaceholder": "z. B. \"prod-server-01\"",
"icon": "Icon",
"selectIcon": "Icon auswΓ€hlen",
"noIconsFound": "Keine Icons gefunden",
"agentUpdated": "Agent aktualisiert",
"agentConnected": "Agent verbunden",
"failedSaveAgent": "Agent konnte nicht gespeichert werden",
Expand Down
3 changes: 3 additions & 0 deletions frontend/messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,9 @@
"addAgentDescription": "Add a new agent to manage Docker hosts and servers.",
"editAgentDescription": "Update the agent configuration.",
"agentNamePlaceholder": "e.g. \"prod-server-01\"",
"icon": "Icon",
"selectIcon": "Select an icon",
"noIconsFound": "No icons found",
"agentUpdated": "Agent updated",
"agentConnected": "Agent connected",
"failedSaveAgent": "Failed to save agent",
Expand Down
21 changes: 21 additions & 0 deletions frontend/src/components/dialogs/upsert-agent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,19 @@ import { Input } from "../ui/input";
import { createAgent, updateAgent, type Agent } from "@/lib/agents";
import CopyValueDialog from "./copy-value-dialog";
import { m } from "@/lib/paraglide/messages";
import LucideIconPicker, { type LucideIconName } from "@/components/lucide-icon-picker";

Comment thread
alex289 marked this conversation as resolved.
const agentSchema = z.object({
name: z
.string()
.trim()
.min(1, m.validationAgentNameRequired())
.max(128, m.validationAgentNameMaxLength()),
icon: z.string(),
});

const defaultAgentIcon: LucideIconName = "server";

export default function UpsertAgentDialog({
agent,
asDropdownItem = false,
Expand All @@ -45,6 +49,7 @@ export default function UpsertAgentDialog({
const form = useForm({
defaultValues: {
name: agent?.name ?? "",
icon: defaultAgentIcon as string,
},
Comment on lines 49 to 53
validators: {
onSubmit: agentSchema,
Expand All @@ -68,6 +73,7 @@ export default function UpsertAgentDialog({
toast.success(m.agentConnected());
}
setOpen(false);
form.reset();
} catch (err) {
toast.error(err instanceof Error ? err.message : m.failedSaveAgent());
} finally {
Expand Down Expand Up @@ -134,6 +140,21 @@ export default function UpsertAgentDialog({
}}
/>

<form.Field
name="icon"
children={(field) => (
<Field>
<Label>{m.icon()}</Label>
<LucideIconPicker
value={field.state.value as LucideIconName}
onValueChange={field.handleChange}
placeholder={m.selectIcon()}
emptyMessage={m.noIconsFound()}
/>
Comment thread
alex289 marked this conversation as resolved.
</Field>
)}
/>

<div className="flex gap-2 pt-2">
<Button type="submit" disabled={isSubmitting}>
{isSubmitting ? m.savingDots() : isEditing ? m.update() : m.addAgent()}
Expand Down
137 changes: 137 additions & 0 deletions frontend/src/components/lucide-icon-picker.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
import { DynamicIcon, iconNames, type IconName } from "lucide-react/dynamic";
import { useMemo, useState } from "react";
import {
Combobox,
ComboboxContent,
ComboboxEmpty,
ComboboxInput,
ComboboxItem,
ComboboxList,
} from "@/components/ui/combobox";
import { cn } from "@/lib/utils";

type LucideIconPickerProps = {
value: IconName;
onValueChange: (value: IconName) => void;
placeholder: string;
emptyMessage: string;
className?: string;
};

const visibleIconLimit = 84;
const preferredIcons = [
"server",
"container",
"box",
"boxes",
"hard-drive",
"database",
"cloud",
"network",
"router",
"workflow",
"git-branch",
"git-pull-request",
"package",
"rocket",
"terminal",
"monitor",
"cpu",
"settings",
"shield",
"key-round",
"lock",
"activity",
"gauge",
"webhook",
] satisfies IconName[];

function formatIconName(name: IconName) {
return name
.split("-")
.map((part) => part.charAt(0).toUpperCase() + part.slice(1))
.join(" ");
}

const iconOptions = iconNames.map((name) => {
const label = formatIconName(name);

return {
name,
label,
searchText: `${name} ${label}`.toLocaleLowerCase(),
};
});

const preferredIconSet = new Set<IconName>(preferredIcons);
const iconLabelByName = new Map(iconOptions.map((option) => [option.name, option.label]));

function getIconLabel(name: IconName) {
return iconLabelByName.get(name) ?? name;
}

function getVisibleIcons(query: string, value: IconName) {
const normalizedQuery = query.trim().toLocaleLowerCase();
const matchingIcons = normalizedQuery
? iconOptions
.filter((option) => option.searchText.includes(normalizedQuery))
.map((option) => option.name)
: [
...preferredIcons,
...iconOptions
.filter((option) => !preferredIconSet.has(option.name))
.map((option) => option.name),
];

return Array.from(new Set([value, ...matchingIcons])).slice(0, visibleIconLimit);
}

export default function LucideIconPicker({
value,
onValueChange,
placeholder,
emptyMessage,
className,
}: LucideIconPickerProps) {
const [query, setQuery] = useState("");
const visibleIcons = useMemo(() => getVisibleIcons(query, value), [query, value]);

return (
<Combobox
items={visibleIcons}
filter={null}
itemToStringLabel={getIconLabel}
value={value}
onInputValueChange={setQuery}
onValueChange={(nextValue) => {
if (nextValue) {
onValueChange(nextValue);
setQuery("");
}
}}
>
<ComboboxInput
className={cn("w-full", className)}
placeholder={placeholder}
aria-label={placeholder}
>
<div className="pointer-events-none order-first flex h-full items-center pl-2 text-muted-foreground">
<DynamicIcon name={value} className="size-4" />
</div>
</ComboboxInput>
<ComboboxContent className="min-w-72 pointer-events-auto">
<ComboboxEmpty>{emptyMessage}</ComboboxEmpty>
<ComboboxList className="grid max-h-72 grid-cols-2 gap-1 sm:grid-cols-3">
{(name) => (
<ComboboxItem key={name} value={name} className="h-9 min-w-0 pr-2">
<DynamicIcon name={name} className="size-4" />
<span className="truncate">{getIconLabel(name)}</span>
</ComboboxItem>
)}
</ComboboxList>
</ComboboxContent>
</Combobox>
);
}

export type { IconName as LucideIconName };