Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
import { Component, For, Show } from 'solid-js';
import { InlineNotice } from '@/components/shared/InlineNotice';
import { Dialog } from '@/components/shared/Dialog';
import { FormSelect } from '@/components/shared/FormSelect';
import type { Permission, Role } from '@/types/rbac';
import { RBAC_PERMISSION_ACTIONS, RBAC_PERMISSION_RESOURCES } from '@/utils/rbacPermissions';
import Plus from 'lucide-solid/icons/plus';
import Trash2 from 'lucide-solid/icons/trash-2';
import X from 'lucide-solid/icons/x';
interface RolesEditorDialogProps {
actionError?: string | null;
editingRole: Role | null;
formDescription: string;
formId: string;
formName: string;
formPermissions: Permission[];
isOpen: boolean;
saving: boolean;
onAddPermission: () => void;
onClose: () => void;
onFormDescriptionInput: (value: string) => void;
onFormIdInput: (value: string) => void;
onFormNameInput: (value: string) => void;
onRemovePermission: (index: number) => void;
onSave: () => void;
onUpdatePermission: (index: number, field: keyof Permission, value: string) => void;
}
export const RolesEditorDialog: Component<RolesEditorDialogProps> = (props) => (
<Show when={props.isOpen}>
<Dialog
isOpen={true}
onClose={props.onClose}
panelClass="max-w-2xl"
closeOnBackdrop={false}
ariaLabel={props.editingRole ? 'Edit role' : 'New role'}
>
<div class="flex min-h-0 w-full flex-col">
<div class="flex shrink-0 items-start justify-between gap-3 px-4 sm:px-6 py-4 border-b border-border">
<h3 class="text-lg font-semibold text-base-content">
{props.editingRole ? 'Edit Role' : 'New Role'}
</h3>
<button
type="button"
onClick={props.onClose}
disabled={props.saving}
aria-label="Close role editor"
title="Close"
class="p-1.5 rounded-md text-slate-500 hover:text-base-content hover:bg-surface-hover"
>
<X class="w-5 h-5" />
</button>
</div>
<div class="min-h-0 overflow-y-auto">
<fieldset disabled={props.saving} class="px-4 sm:px-6 py-4 space-y-4">
<div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
<div class="space-y-1">
<label for="role-editor-id" class="block text-sm font-medium text-base-content">
Role ID
</label>
<input
id="role-editor-id"
type="text"
value={props.formId}
onInput={(event) => props.onFormIdInput(event.currentTarget.value)}
placeholder="e.g., custom-auditor"
disabled={!!props.editingRole}
class="w-full rounded-md border border-border bg-surface px-3 py-2 text-sm shadow-xs focus:border-blue-500 focus:outline-hidden focus:ring-2 focus:ring-blue-200 dark:focus:border-blue-400 dark:focus:ring-blue-900/25 disabled:opacity-50"
/>
</div>
<div class="space-y-1">
<label for="role-editor-name" class="block text-sm font-medium text-base-content">
Role Name
</label>
<input
id="role-editor-name"
type="text"
value={props.formName}
onInput={(event) => props.onFormNameInput(event.currentTarget.value)}
placeholder="e.g., Custom Auditor"
class="w-full rounded-md border border-border bg-surface px-3 py-2 text-sm shadow-xs focus:border-blue-500 focus:outline-hidden focus:ring-2 focus:ring-blue-200 dark:focus:border-blue-400 dark:focus:ring-blue-900/25"
/>
</div>
</div>
<div class="space-y-1">
<label
for="role-editor-description"
class="block text-sm font-medium text-base-content"
>
Description
</label>
<input
id="role-editor-description"
type="text"
value={props.formDescription}
onInput={(event) => props.onFormDescriptionInput(event.currentTarget.value)}
placeholder="Brief description of this role's purpose"
class="w-full rounded-md border border-border bg-surface px-3 py-2 text-sm text-base-content shadow-xs focus:border-blue-500 focus:outline-hidden focus:ring-2 focus:ring-blue-200 dark:focus:border-blue-400 dark:focus:ring-blue-900/25"
/>
</div>
<div class="space-y-3 pt-2">
<div class="flex flex-col items-start gap-2 sm:flex-row sm:items-center sm:justify-between">
<span class="block text-sm font-medium text-base-content">Permissions</span>
<button
type="button"
onClick={props.onAddPermission}
class="text-xs font-medium text-blue-600 hover:text-blue-700 dark:text-blue-300 flex items-center gap-1"
>
<Plus class="w-3 h-3" /> Add Permission
</button>
</div>
<div class="space-y-2">
<For each={props.formPermissions}>
{(permission, index) => (
<div class="flex flex-col sm:flex-row sm:items-center gap-2">
<FormSelect
label={`Permission ${index() + 1} action`}
labelClass="sr-only"
fieldBaseClass="contents"
value={permission.action}
onChange={(event) =>
props.onUpdatePermission(index(), 'action', event.currentTarget.value)
}
selectBaseClass="w-full sm:flex-1 rounded-md border border-border bg-surface px-2 py-1.5 text-sm text-base-content"
>
<Show
when={
!RBAC_PERMISSION_ACTIONS.some((action) => action === permission.action)
}
>
<option value={permission.action}>{permission.action}</option>
</Show>
<For each={RBAC_PERMISSION_ACTIONS}>
{(action) => <option value={action}>{action}</option>}
</For>
</FormSelect>
<span class="hidden sm:inline text-slate-400 text-sm">:</span>
<FormSelect
label={`Permission ${index() + 1} resource`}
labelClass="sr-only"
fieldBaseClass="contents"
value={permission.resource}
onChange={(event) =>
props.onUpdatePermission(index(), 'resource', event.currentTarget.value)
}
selectBaseClass="w-full sm:flex-1 rounded-md border bg-surface px-2 py-1.5 text-sm text-base-content"
>
<Show
when={
!RBAC_PERMISSION_RESOURCES.some(
(resource) => resource === permission.resource,
)
}
>
<option value={permission.resource}>{permission.resource}</option>
</Show>
<For each={RBAC_PERMISSION_RESOURCES}>
{(resource) => <option value={resource}>{resource}</option>}
</For>
</FormSelect>
<button
type="button"
onClick={() => props.onRemovePermission(index())}
disabled={props.formPermissions.length <= 1}
aria-label="Remove permission"
title="Remove permission"
class="self-end sm:self-auto p-1.5 text-slate-400 hover:text-red-500 disabled:opacity-30"
>
<Trash2 class="w-4 h-4" />
</button>
</div>
)}
</For>
</div>
</div>
</fieldset>
<Show when={props.actionError}>
<InlineNotice tone="danger" role="alert" aria-live="polite">
{props.actionError}
</InlineNotice>
</Show>
</div>
<div class="grid shrink-0 grid-cols-1 sm:flex sm:items-center sm:justify-end gap-3 px-4 sm:px-6 py-4 border-t border-border">
<button
type="button"
onClick={props.onClose}
disabled={props.saving}
class="w-full sm:w-auto rounded-md px-4 py-2 text-sm font-medium text-base-content hover:bg-surface-hover"
>
Cancel
</button>
<button
type="button"
onClick={props.onSave}
disabled={props.saving || !props.formName.trim()}
class="inline-flex w-full sm:w-auto items-center justify-center gap-2 rounded-md bg-blue-600 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-blue-700 disabled:cursor-not-allowed disabled:opacity-60"
>
{props.saving ? 'Saving...' : props.editingRole ? 'Update Role' : 'Create Role'}
</button>
</div>
</div>
</Dialog>
</Show>
);