Skip to content

ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.

feat(templates): add capability-aware server picker

Juan Denis86c2ce5530eb
diff --git a/frontend/src/components/ResourcePicker.jsx b/frontend/src/components/ResourcePicker.jsx
index 2c885b0f..2e9f3c3f 100644
--- a/frontend/src/components/ResourcePicker.jsx
+++ b/frontend/src/components/ResourcePicker.jsx
@@ -12,6 +12,7 @@ import { normalizeResourceRef, resourceKey } from '../utils/resourceRefs';
const normalizeList = (options) => options.map(normalizeResourceRef).filter(Boolean);
const allowOption = () => true;
+const preserveOption = (option) => option;
export default function ResourcePicker({
value,
@@ -21,11 +22,14 @@ export default function ResourcePicker({
capabilities,
staticOptions = [],
filterOption = allowOption,
+ decorateOption = preserveOption,
icon: ResourceIcon = Server,
+ showCapabilities = false,
disabled = false,
label,
placeholder,
searchPlaceholder,
+ emptyMessage,
className = '',
}) {
const { t } = useTranslation();
@@ -38,8 +42,14 @@ export default function ResourcePicker({
query,
enabled: open,
});
- const normalizedStatic = useMemo(() => normalizeList(staticOptions), [staticOptions]);
- const normalizedValue = useMemo(() => normalizeResourceRef(value), [value]);
+ const normalizedStatic = useMemo(
+ () => normalizeList(staticOptions).map(decorateOption),
+ [decorateOption, staticOptions],
+ );
+ const normalizedValue = useMemo(() => {
+ const normalized = normalizeResourceRef(value);
+ return normalized ? decorateOption(normalized) : null;
+ }, [decorateOption, value]);
const normalizedQuery = query.trim().toLowerCase();
const visibleStatic = normalizedStatic.filter((option) => (
filterOption(option)
@@ -48,7 +58,7 @@ export default function ResourcePicker({
const visibleGroups = search.groups
.map((group) => ({
...group,
- options: group.options.filter(filterOption),
+ options: group.options.map(decorateOption).filter(filterOption),
}))
.filter((group) => group.options.length);
const hasOptions = visibleStatic.length > 0
@@ -78,6 +88,9 @@ export default function ResourcePicker({
{option.status && (
<span className={`sk-state sk-state--${option.status}`}>{option.status}</span>
)}
+ {showCapabilities && option.capabilities.slice(0, 2).map((capability) => (
+ <span className="sk-tag" key={capability}>{capability}</span>
+ ))}
{selected && <Check className="sk-resource-picker__check" aria-hidden="true" />}
</CommandItem>
);
@@ -131,7 +144,9 @@ export default function ResourcePicker({
</div>
)}
{!search.isLoading && !search.isError && !hasOptions && (
- <CommandEmpty>{t('common.state.noResults', 'No results found')}</CommandEmpty>
+ <CommandEmpty>
+ {emptyMessage || t('common.state.noResults', 'No results found')}
+ </CommandEmpty>
)}
</CommandList>
</Command>
diff --git a/frontend/src/components/templates/ServerPicker.jsx b/frontend/src/components/templates/ServerPicker.jsx
index adbc5bb6..db9ad861 100644
--- a/frontend/src/components/templates/ServerPicker.jsx
+++ b/frontend/src/components/templates/ServerPicker.jsx
@@ -1,77 +1,85 @@
-import { useState, useMemo } from 'react';
-import { Search } from 'lucide-react';
+import { useMemo } from 'react';
+import { Server } from 'lucide-react';
import { useTranslation } from 'react-i18next';
-const GIB = 1024 ** 3;
+import ResourcePicker from '../ResourcePicker';
+import { formatBytes } from '../../utils/formatBytes';
+
+const enabledCapabilities = (server) => Object.entries(server?.capabilities || {})
+ .filter(([, enabled]) => enabled === true)
+ .map(([name]) => name);
-// "8 vCPU · 32 GB" — whichever halves the agent has actually reported.
function capacityLabel(server) {
const parts = [];
if (server.cpu_cores) parts.push(`${server.cpu_cores} vCPU`);
- if (server.total_memory) parts.push(`${Math.round(server.total_memory / GIB)} GB`);
+ if (server.total_memory) parts.push(formatBytes(server.total_memory, { decimals: 0 }));
return parts.join(' · ');
}
-// Radio list of deploy targets showing each one's capacity, so placing a
-// service on a second box is a visible choice rather than a hidden default.
-// Gains a filter box once the fleet outgrows a glanceable list.
-export default function ServerPicker({ servers, value, onChange, filterThreshold = 6 }) {
- const { t } = useTranslation();
- const [query, setQuery] = useState('');
+function serverResource(server) {
+ const capacity = capacityLabel(server);
+ const location = server.is_local ? 'this panel' : (server.group_name || 'remote');
+ const platform = server.os_type ? `${location} · ${server.os_type}` : location;
+ const capabilities = enabledCapabilities(server);
+ if ((server.is_local || server.has_docker) && !capabilities.includes('docker')) {
+ capabilities.push('docker');
+ }
+ return {
+ type: server.is_local ? 'server-target' : 'server',
+ id: String(server.id),
+ label: server.name || String(server.id),
+ sublabel: [platform, capacity].filter(Boolean).join(' · '),
+ path: server.is_local ? '/servers' : `/servers/${server.id}`,
+ scope: { workspaceId: server.workspace_id ?? null },
+ status: server.status || null,
+ capabilities,
+ };
+}
- const list = useMemo(() => {
- const q = query.trim().toLowerCase();
- if (!q) return servers;
- return servers.filter((s) =>
- (s.name || '').toLowerCase().includes(q)
- || (s.group_name || '').toLowerCase().includes(q)
- || (s.os_type || '').toLowerCase().includes(q)
- );
- }, [servers, query]);
+export default function ServerPicker({ servers, value, onChange }) {
+ const { t } = useTranslation();
+ const serverById = useMemo(
+ () => new Map(servers.map((server) => [String(server.id), server])),
+ [servers],
+ );
+ const staticOptions = useMemo(
+ () => servers.filter((server) => server.is_local).map(serverResource),
+ [servers],
+ );
+ const selectedServer = serverById.get(String(value));
+ const selectedResource = selectedServer ? serverResource(selectedServer) : null;
+ const decorateOption = (resource) => {
+ const server = serverById.get(resource.id);
+ if (!server) return resource;
+ const metadata = serverResource(server);
+ return {
+ ...resource,
+ sublabel: metadata.sublabel,
+ capabilities: [...new Set([...resource.capabilities, ...metadata.capabilities])],
+ };
+ };
return (
- <div className="sk-srvpick">
- {servers.length > filterThreshold && (
- <div className="sk-srvpick__find">
- <Search size={14} />
- <input
- type="search"
- placeholder={t('app.serverPicker.findAServer', 'Find a server…')}
- value={query}
- onChange={(e) => setQuery(e.target.value)}
- aria-label={t('app.serverPicker.filterServers', 'Filter servers')}
- />
- </div>
+ <ResourcePicker
+ value={selectedResource}
+ onChange={(resource) => {
+ const server = serverById.get(resource.id);
+ onChange(server?.id ?? resource.id);
+ }}
+ types={['server']}
+ capabilities={['docker']}
+ staticOptions={staticOptions}
+ filterOption={(resource) => (
+ resource.type === 'server-target' || serverById.has(resource.id)
)}
- <div className="sk-srvpick__list" role="radiogroup" aria-label={t('app.serverPicker.deployToServer', 'Deploy to server')}>
- {list.map((server) => {
- const capacity = capacityLabel(server);
- const selected = value === server.id;
- return (
- <button
- type="button"
- role="radio"
- aria-checked={selected}
- key={server.id}
- className={`sk-srvpick__row${selected ? ' is-selected' : ''}`}
- onClick={() => onChange(server.id)}
- >
- <span className="sk-srvpick__radio" />
- <span className="sk-srvpick__meta">
- <span className="sk-srvpick__name">{server.name}</span>
- <span className="sk-srvpick__sub">
- {server.is_local ? 'this panel' : (server.group_name || 'remote')}
- {server.os_type ? ` · ${server.os_type}` : ''}
- </span>
- </span>
- {capacity && <span className="sk-srvpick__tag">{capacity}</span>}
- </button>
- );
- })}
- {list.length === 0 && (
- <div className="sk-srvpick__empty">{t('app.serverPicker.noServersMatch', 'No servers match.')}</div>
- )}
- </div>
- </div>
+ decorateOption={decorateOption}
+ icon={Server}
+ showCapabilities
+ label={t('app.serverPicker.deployToServer', 'Deploy to server')}
+ placeholder={t('app.serverPicker.deployToServer', 'Deploy to server')}
+ searchPlaceholder={t('app.serverPicker.findAServer', 'Find a server…')}
+ emptyMessage={t('app.serverPicker.noServersMatch', 'No servers match.')}
+ className="sk-srvpick__resource-picker"
+ />
);
}
diff --git a/frontend/src/styles/pages/_templates.scss b/frontend/src/styles/pages/_templates.scss
index 8a3fbc7b..0824dfd1 100644
--- a/frontend/src/styles/pages/_templates.scss
+++ b/frontend/src/styles/pages/_templates.scss
@@ -717,105 +717,9 @@
}
-// ---- server picker (shared: template deploy, and any future placement UI) ---
-.sk-srvpick {
- &__find {
- display: flex;
- align-items: center;
- gap: 8px;
- height: 34px;
- margin-bottom: 8px;
- padding: 0 10px;
- background: var(--surface-2);
- border: 1px solid var(--border);
- border-radius: $radius-md;
-
- svg { flex-shrink: 0; color: $text-tertiary; }
-
- input {
- flex: 1;
- min-width: 0;
- background: none;
- border: none;
- outline: none;
- color: $text-primary;
- font-size: $font-size-sm;
- }
- }
-
- &__list {
- max-height: 210px;
- overflow-y: auto;
- background: var(--surface-2);
- border: 1px solid var(--border);
- border-radius: $radius-md;
- }
-
- &__row {
- display: flex;
- align-items: center;
- gap: 12px;
- width: 100%;
- padding: 10px 13px;
- background: none;
- border: none;
- text-align: left;
- cursor: pointer;
- transition: background $transition-fast;
-
- + .sk-srvpick__row { border-top: 1px solid $border-subtle; }
- &:hover { background: var(--surface-3); }
- &.is-selected { background: var(--accent-bg); }
- }
-
- &__radio {
- flex-shrink: 0;
- width: 15px;
- height: 15px;
- border: 2px solid var(--border-strong);
- border-radius: 50%;
- transition: border-color $transition-fast;
- }
-
- &__row.is-selected &__radio {
- border-color: var(--accent-bright);
- background: radial-gradient(circle, var(--accent-bright) 0 4px, transparent 5px);
- }
-
- &__meta { flex: 1; min-width: 0; }
-
- &__name {
- display: block;
- overflow: hidden;
- color: $text-primary;
- font-size: 13px;
- font-weight: 550;
- text-overflow: ellipsis;
- white-space: nowrap;
- }
-
- &__sub {
- display: block;
- margin-top: 1px;
- color: $text-tertiary;
- font-size: 11px;
- }
-
- &__tag {
- flex-shrink: 0;
- padding: 3px 8px;
- background: var(--surface-3);
- border-radius: $radius-sm;
- color: $text-tertiary;
- font-family: var(--mono);
- font-size: 10.5px;
- }
-
- &__empty {
- padding: 14px;
- color: $text-tertiary;
- font-size: 12.5px;
- }
+.sk-srvpick__resource-picker {
+ width: 100%;
+ max-width: none;
}
// Capacity note in the deploy drawer — does this template fit the server the