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.

Let labels name the resource and server pickers

Juan Denis73a93a7b3602
diff --git a/frontend/scripts/LABEL_ASSOCIATION_CEILING b/frontend/scripts/LABEL_ASSOCIATION_CEILING
index 9e5feb52..87523dd7 100644
--- a/frontend/scripts/LABEL_ASSOCIATION_CEILING
+++ b/frontend/scripts/LABEL_ASSOCIATION_CEILING
@@ -1 +1 @@
-46
+41
diff --git a/frontend/scripts/list-rows-browser.mjs b/frontend/scripts/list-rows-browser.mjs
index c234f94a..7eceb87e 100644
--- a/frontend/scripts/list-rows-browser.mjs
+++ b/frontend/scripts/list-rows-browser.mjs
@@ -12,6 +12,7 @@ import { chromium } from 'playwright';
// the state their delete handlers read, so a delete after opening a vault
// or a variable group used first-render values (a null vault, group null).
// - Keyboard: a clickable row opens with Enter like it does with a click.
+// - A label can name a server picker: the picker puts its id on its trigger.
const root = fileURLToPath(new URL('../', import.meta.url));
const fixture = `
import React from 'react';
@@ -19,6 +20,7 @@ import {createRoot} from 'react-dom/client';
import {MemoryRouter} from 'react-router-dom';
import Vaults from '/src/pages/Vaults.jsx';
import SharedVariableGroups from '/src/components/shared/SharedVariableGroups.jsx';
+import ServerPicker from '/src/components/ServerPicker.jsx';
const log=(...a)=>(window.calls=window.calls||[]).push(a);
const vault={id:11,name:'alpha-vault',description:'',secret_count:1,workspace_id:null};
window.testApi={
@@ -32,7 +34,8 @@ window.testApi={
deleteGroupVariable:(gid,vid)=>{log('deleteGroupVariable',gid,vid);return Promise.resolve({});},
};
const which=new URLSearchParams(location.search).get('page');
-createRoot(document.getElementById('root')).render(<MemoryRouter>{which==='vaults'?<Vaults/>:<SharedVariableGroups scopeType="workspace" scopeId={1}/>}</MemoryRouter>);
+const picker=<div><label htmlFor="pick-target">Applies to</label><ServerPicker id="pick-target" label="Server" onChange={()=>{}}/></div>;
+createRoot(document.getElementById('root')).render(<MemoryRouter>{which==='vaults'?<Vaults/>:which==='picker'?picker:<SharedVariableGroups scopeType="workspace" scopeId={1}/>}</MemoryRouter>);
`;
const server = await createServer({
root, configFile: false, logLevel: 'error', resolve: { alias: { '@': path.join(root, 'src') } },
@@ -47,6 +50,7 @@ const server = await createServer({
load(id) {
const normalized = id.replaceAll('\\', '/');
if (id === '\0test-i18n') return `const t=(key,f)=>typeof f==='string'?f:(f&&(f.defaultValue_other||f.defaultValue))||key;export const useTranslation=()=>({t,i18n:{language:'en'}});export const Trans=({children})=>children;export const initReactI18next={type:'3rdParty',init(){}};`;
+ if (normalized.endsWith('/src/contexts/useAuth.js')) return `import {createContext} from 'react';export const AuthContext=createContext(null);const auth={user:{id:1,role:'admin'},isAdmin:true,isAuthenticated:true,hasPermission:()=>true};export const useAuth=()=>auth;`;
if (normalized.endsWith('/src/contexts/useWorkspace.js')) return `const ws={activeWorkspaceId:null,workspaces:[],setActiveWorkspace(){}};export const useWorkspace=()=>ws;`;
if (normalized.endsWith('/src/contexts/useToast.js')) return `const toast={error(m){(window.toasts=window.toasts||[]).push(m)},success(){},info(){},warning(){}};export const useToast=()=>toast;`;
if (normalized.endsWith('/src/hooks/useConfirm.js')) return `const confirm=async()=>true;export function useConfirm(){return {confirm,confirmState:{isOpen:false},handleConfirm(){},handleCancel(){}};}`;
@@ -105,6 +109,16 @@ try {
assert.deepEqual(await keys.evaluate(() => window.calls), [['getVault', 11]]);
assert.deepEqual(keyErrors, []);
console.log('PASS Enter on a focused row opens it');
+
+ const pick = await browser.newPage();
+ const pickErrors = [];
+ pick.on('pageerror', error => pickErrors.push(error.message));
+ await pick.goto(`${base}?page=picker`);
+ // Clicking the label activates the picker it names, as with any field.
+ await pick.locator('label[for="pick-target"]').click();
+ await pick.waitForFunction(() => document.getElementById('pick-target')?.getAttribute('aria-expanded') === 'true', null, { timeout: 5000 });
+ assert.deepEqual(pickErrors, []);
+ console.log('PASS clicking a label opens the server picker it names');
} finally {
await browser?.close();
await server.close();
diff --git a/frontend/src/components/ResourcePicker.jsx b/frontend/src/components/ResourcePicker.jsx
index 65a88176..20fd915c 100644
--- a/frontend/src/components/ResourcePicker.jsx
+++ b/frontend/src/components/ResourcePicker.jsx
@@ -31,6 +31,7 @@ export default function ResourcePicker({
searchPlaceholder,
emptyMessage,
className = '',
+ id,
}) {
const { t } = useTranslation();
const [open, setOpen] = useState(false);
@@ -107,6 +108,7 @@ export default function ResourcePicker({
}}>
<PopoverTrigger asChild>
<Button
+ id={id}
type="button"
variant="outline"
className={triggerClassName}
diff --git a/frontend/src/components/ServerPicker.jsx b/frontend/src/components/ServerPicker.jsx
index 03d4524d..549cacf8 100644
--- a/frontend/src/components/ServerPicker.jsx
+++ b/frontend/src/components/ServerPicker.jsx
@@ -58,6 +58,7 @@ export default function ServerPicker({
label,
disabled = false,
className,
+ id,
}) {
const { t } = useTranslation();
const [servers, setServers] = useState([]);
@@ -149,6 +150,7 @@ export default function ServerPicker({
return (
<ResourcePicker
+ id={id}
value={selected}
onChange={(resource) => {
if (resource.type === 'server-target') {
diff --git a/frontend/src/components/monitoring/FleetThresholdsPanel.jsx b/frontend/src/components/monitoring/FleetThresholdsPanel.jsx
index cee53eb7..55ac65be 100644
--- a/frontend/src/components/monitoring/FleetThresholdsPanel.jsx
+++ b/frontend/src/components/monitoring/FleetThresholdsPanel.jsx
@@ -1,4 +1,4 @@
-import { useState, useEffect } from 'react';
+import { useState, useEffect, useId } from 'react';
import { Plus, XCircle } from 'lucide-react';
import api from '../../services/api';
import { useToast } from '../../contexts/useToast.js';
@@ -29,6 +29,7 @@ const DEFAULT_THRESHOLD = {
// tab: same idea, wider scope. Two lists rather than one because they are two
// backends — the host's four values are a single config, these are rows.
export default function FleetThresholdsPanel({ refreshKey = 0 }) {
+ const fieldId = useId();
const { t } = useTranslation();
const toast = useToast();
const [thresholds, setThresholds] = useState([]);
@@ -145,8 +146,9 @@ export default function FleetThresholdsPanel({ refreshKey = 0 }) {
{adding && (
<div className="mon-threshold-form">
<div className="form-group">
- <Label>{t('app.fleetThresholdsPanel.appliesTo', 'Applies to')}</Label>
+ <Label htmlFor={`${fieldId}-applies-to`}>{t('app.fleetThresholdsPanel.appliesTo', 'Applies to')}</Label>
<ServerPicker
+ id={`${fieldId}-applies-to`}
value={draft.server_id || FLEET_DEFAULT}
onChange={(id) => setDraft((p) => ({ ...p, server_id: id === FLEET_DEFAULT ? undefined : id }))}
includeLocal={false}
diff --git a/frontend/src/pages/RemoteAccess.jsx b/frontend/src/pages/RemoteAccess.jsx
index 641cf642..0d36f119 100644
--- a/frontend/src/pages/RemoteAccess.jsx
+++ b/frontend/src/pages/RemoteAccess.jsx
@@ -376,9 +376,10 @@ const RemoteAccess = ({ serverId }) => {
{!wizardTunnel && (
<>
<div className="ra-service-field">
- <Label>{t('app.remoteAccess.privateHostWhereTheServiceRuns', 'Private host (where the service runs)')}</Label>
+ <Label htmlFor={`${fieldId}-private-host`}>{t('app.remoteAccess.privateHostWhereTheServiceRuns', 'Private host (where the service runs)')}</Label>
{serverId ? (
<Input
+ id={`${fieldId}-private-host`}
value={currentServer?.name || serverId}
disabled
/>
@@ -386,6 +387,7 @@ const RemoteAccess = ({ serverId }) => {
// Tunnel endpoints are agent servers; the panel host
// has no server row, so "Local" is not offered.
<ServerPicker
+ id={`${fieldId}-private-host`}
value={form.privateServerId}
onChange={(id) => setField('privateServerId', id)}
capability="wireguard"
@@ -395,8 +397,9 @@ const RemoteAccess = ({ serverId }) => {
)}
</div>
<div className="ra-service-field">
- <Label>{t('app.remoteAccess.edgeServerPublicIpFrontsThe', 'Edge server (public IP, fronts the tunnel)')}</Label>
+ <Label htmlFor={`${fieldId}-edge-server`}>{t('app.remoteAccess.edgeServerPublicIpFrontsThe', 'Edge server (public IP, fronts the tunnel)')}</Label>
<ServerPicker
+ id={`${fieldId}-edge-server`}
value={form.edgeServerId}
onChange={(id) => setField('edgeServerId', id)}
capability="wireguard"
diff --git a/frontend/src/pages/new-service/ReviewStep.jsx b/frontend/src/pages/new-service/ReviewStep.jsx
index 5287cf1a..4eaef564 100644
--- a/frontend/src/pages/new-service/ReviewStep.jsx
+++ b/frontend/src/pages/new-service/ReviewStep.jsx
@@ -289,10 +289,11 @@ const ReviewStep = ({ form }) => {
<div className="new-service-page__fields-grid">
<div className="new-service-page__field">
- <Label>
+ <Label htmlFor={`${fieldId}-project`}>
{t('common.labels.project', 'Project')} <span className="new-service-page__optional">(optional)</span>
</Label>
<ResourcePicker
+ id={`${fieldId}-project`}
value={selectedProjectResource}
onChange={handleProjectChange}
types={['project']}
@@ -307,8 +308,9 @@ const ReviewStep = ({ form }) => {
</div>
{selectedProjectId && (
<div className="new-service-page__field">
- <Label>{t('app.reviewStep.environment', 'Environment')}</Label>
+ <Label htmlFor={`${fieldId}-environment`}>{t('app.reviewStep.environment', 'Environment')}</Label>
<ResourcePicker
+ id={`${fieldId}-environment`}
value={selectedEnvironmentResource}
onChange={(resource) => setSelectedEnvironmentId(resource.id)}
types={['environment']}