Skip to content
Merged
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
61 changes: 59 additions & 2 deletions docs/development/staff-inventory-ui.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,63 @@ The building blocks are in `ui/provider/src/components/inventory-record-layout.t
banners, hidden empty fields, list columns, and the Device page's header
strip, picture, table, one count line and tab contents.

## Form controls (implemented)

Every control in the staff and consumer plugins comes from datum-ui:
Select, Input, Button, Table and the `picker` DateTimePicker. Neither plugin
renders a native `<select>`, `<input>`, `<textarea>` or `<button>`, apart from
the exemptions below.

- **Selects.** `FieldSelect` (`ui/provider/src/components/field-select.tsx`)
wraps the datum-ui Select and takes a plain string value, where `''` means
none. A field that can be cleared (the directory filters, Catalog model,
a lane's device, and Facility, Rack, Face and Depth in the location
correction) lists its clearing choice first: "All facilities", "All
models", "All media", "No catalog assignment", "Device or feed",
"Unknown / not recorded" or "Unknown". A required field (Location,
Installation plan, Cable medium, a lane's port, a Rack's Facility and the
capacity registration's Device) shows its prompt until a choice is made,
and the prompt is not a choice. Groups (facilities and racks, racks and
power feeds) keep their headings. A marked option keeps its amber text and
its reason as its tooltip ("· has device", "· cabled"). An unavailable
option, such as an ineligible Device or "Selected catalog unavailable", is
listed but cannot be chosen. The open list may be wider than a narrow
trigger, up to the screen width less 32 px.
- **Keyboard.** Enter, Space or an arrow key opens a Select. Arrow keys move
through the options, typing jumps to a match, Enter chooses and Escape
closes without choosing. A disabled Select does not open.
- **Directory filters.** The facility and model (or medium) filters still
write `location` and `model` to the URL. Choosing the "All" option removes
the parameter.
- **Validation.** Inside a form, each Select keeps a hidden form select, so
required Selects and lane ports (with their `data-problem` rule) take part
in validation. `InventoryForm` reports the problem against the visible
trigger: it is marked invalid, described by the summary line, and focused
when that line is clicked. Choosing a value clears the mark.
- **Observed at.** The location correction picks the observation time with
the datum-ui date-time picker: a calendar, a typed `HH:mm` time, and the
browser time zone shown. It opens set to the time the form was opened,
cannot be cleared, and cannot pick a future date. The picker greys out
later days only, so a later time today shows "Observation time cannot be
later than now." under the field at once, marks the trigger invalid, and
disables Save until the time is earlier. The save still rejects a time
later than now.
- **Tables.** The component and lane editors are datum-ui Tables.
- **Copy.** The TLS key fingerprint's Copy button on the Device page is a
datum-ui Button. Its tooltip and text change to "Copied" for 1.5 s.
- **Exemptions.** Port tiles (`PortTileButton` in `device-faceplate.tsx`)
stay native buttons. They are drawn faceplate tiles, and their look is the
drawing. Rack slot links are links, not form controls.
- **Guard.** `src/test/native-controls.test.ts` in each plugin fails when a
component uses a native `<select>`, `<input>`, `<textarea>`, `<button>` or
`<table>`. The only exemption is the `<button>` inside the `PortTileButton`
function; a native control anywhere else in `device-faceplate.tsx` still
fails, and the guard tests that.
- **Tests.** `ui/provider/src/test/field-select.ts` opens a Select from the
keyboard and picks an option by value (`chooseValue`), lists the options a
reader would see (`selectOptions`) and reads the chosen value
(`selectedValue`).

## Default-only directory and stable controls

Implemented on top of `baa210318fe17927f447a8e9e9e8053a23f6b173` on
Expand Down Expand Up @@ -746,8 +803,8 @@ physically verified", with the reason and evidence on a small second line;
any recorded size. **Correct location** (or **Add reported location**) sits
on the Placement row and stays behind its permission check, with the reason
as its tooltip. Its dialog is two columns: Facility | Rack, Position |
Height, Face | Depth, then Mount, then Observation time | Evidence and the
reason. Choosing a rack sets its facility; changing the facility clears a
Height, Face | Depth, then Mount, then Observed at | Evidence and the
reason. Observed at is a date-time picker (see [Form controls](#form-controls-implemented)). Choosing a rack sets its facility; changing the facility clears a
rack outside it. Hardware & management groups its
facts into titled sections of label/value rows: **Hardware** (the reported
model when a catalog model is assigned, system UUID, MAC addresses without
Expand Down
3 changes: 2 additions & 1 deletion ui/consumer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ list; the layout follows network-services-operator's NLB pages.
behind "+N") appears only when some Machine has an address, and **Location**
only when the Machines are in more than one location. Search matches the
status labels shown and the addresses. Under the table, **Available to
deploy** shows a card for each profile the project can deploy, and a muted,
deploy** shows a card for each profile the project can deploy (each card is
a datum-ui Button that opens the deploy dialog), and a muted,
disabled card for each class that isn't usable yet, with the reason in its
tooltip. A class published from another project (with `spec.source`) is read
from `status.resolvedClass` and stays unusable until Fleet resolves it; the
Expand Down
11 changes: 7 additions & 4 deletions ui/consumer/src/components/deploy-options.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Eyebrow } from './fact';
import { Dot } from './machine-status';
import type { CatalogOffering, CatalogProfile } from '../types';
import { Button } from '@datum-cloud/datum-ui/button';
import { Icon } from '@datum-cloud/datum-ui/icons';
import { Tooltip } from '@datum-cloud/datum-ui/tooltip';
import { ArrowRightIcon, CpuIcon, WarehouseIcon } from 'lucide-react';
Expand Down Expand Up @@ -62,12 +63,14 @@ export function ProfileCard({
}) {
const { className, profile } = option;
return (
<button
type="button"
<Button
type="secondary"
theme="outline"
htmlType="button"
data-testid="fleet-plugin-profile-card"
aria-label={`Deploy ${profile.name} from ${className}`}
onClick={() => onDeploy(option)}
className="border-border bg-card hover:bg-muted flex h-full w-full flex-col gap-3 rounded-lg border p-4 text-left transition-colors">
className="border-border bg-card hover:bg-muted h-full w-full flex-col items-stretch justify-start gap-3 rounded-lg p-4 text-left font-normal whitespace-normal text-foreground">
<span className="flex items-center gap-2">
<Icon icon={CpuIcon} size={16} className="fleet-accent shrink-0" />
<span className="min-w-0 flex-1 truncate font-mono text-xs font-semibold">{profile.name}</span>
Expand All @@ -80,7 +83,7 @@ export function ProfileCard({
<Icon icon={ArrowRightIcon} size={13} />
</span>
</span>
</button>
</Button>
);
}

Expand Down
27 changes: 27 additions & 0 deletions ui/consumer/src/test/native-controls.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Form controls come from datum-ui so every control looks and behaves the
// same. A native <select>, <input>, <textarea>, <button> or <table> in a component
// fails this check unless it is listed below with the reason it is exempt.

import { readdir, readFile } from 'node:fs/promises';
import { join, relative, resolve } from 'node:path';
import { expect, it } from 'vitest';

const SRC = resolve(import.meta.dirname, '..');
const NATIVE = /<(select|input|textarea|button|table)\b/g;
/** File (relative to src) → native elements it may use, and why. */
const ALLOWED: Record<string, { elements: string[]; reason: string }> = {};

async function components(directory: string): Promise<string[]> {
const entries = await readdir(directory, { withFileTypes: true });
const files = await Promise.all(entries.map(entry => entry.isDirectory() ? components(join(directory, entry.name)) : entry.name.endsWith('.tsx') && !entry.name.endsWith('.test.tsx') ? [join(directory, entry.name)] : []));
return files.flat();
}

it('uses datum-ui controls instead of native form elements and tables', async () => {
const found: string[] = [];
for (const file of await components(SRC)) {
const name = relative(SRC, file);
for (const [, element] of (await readFile(file, 'utf8')).matchAll(NATIVE)) if (!ALLOWED[name]?.elements.includes(element)) found.push(`${name}: <${element}>`);
}
expect(found).toEqual([]);
});
11 changes: 8 additions & 3 deletions ui/provider/src/components/create-capacity-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { Device } from '../../../shared/fleet-api';
import { capacityNameFor, ineligibleReason, registerCapacity, registrationDevices, registrationPermission, RegistrationUnknown } from '../lib/capacity-registration';
import { InventoryOperationContext, InventoryOperationReadyContext, InventoryOperationScope, type InventoryOperation } from '../lib/inventory-operation';
import { useInventoryRead } from '../lib/inventory-read';
import { FieldSelect } from './field-select';
import { confirmInventoryDismissal, InventoryDraftGuard, InventoryForm, InventoryFormSurface } from './inventory-form-surface';
import { InventorySessionBoundary } from './inventory-session-boundary';

Expand Down Expand Up @@ -64,10 +65,14 @@ export function CapacityRegistrationForm({ onRegistered }: { onRegistered?: () =
}}>Register capacity</Button>}>
<InventoryForm onSubmit={event => void submit(event)} message={message}>
<fieldset disabled={pending || unknown || !available}>
<Label>Device<select required value={selected?.metadata.uid ?? ''} onChange={event => {
const device = devices.data?.find(item => item.metadata.uid === event.target.value);
<Label>Device<FieldSelect required value={selected?.metadata.uid ?? ''} onValueChange={value => {
const device = devices.data?.find(item => item.metadata.uid === value);
setSelected(device ? structuredClone(device) : undefined);
}}><option value="">Choose an existing Device</option>{devices.data?.map(device => <option key={device.metadata.uid ?? device.metadata.name} value={device.metadata.uid ?? ''} disabled={!!ineligibleReason(device, devices.data)}>{device.metadata.name}{ineligibleReason(device, devices.data) ? ` — ${ineligibleReason(device, devices.data)}` : ''}</option>)}</select></Label>
}} placeholder="Choose an existing Device" options={devices.data?.map(device => {
const reason = ineligibleReason(device, devices.data);
// A Device without a uid is listed as ineligible; its placeholder value never matches a selection.
return { value: device.metadata.uid ?? `unidentified/${device.metadata.name}`, disabled: !!reason, label: `${device.metadata.name}${reason ? ` — ${reason}` : ''}` };
})} /></Label>
{devices.isPending && <p>Loading Devices…</p>}
{devices.error && <p role="alert">Devices are unavailable or access is denied. Registration is blocked.</p>}
{devices.data?.length === 0 && <p>No Devices are available in default.</p>}
Expand Down
18 changes: 16 additions & 2 deletions ui/provider/src/components/device-discovery.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { render, screen, within } from '@testing-library/react';
import { fireEvent, render, screen, waitFor, within } from '@testing-library/react';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { MemoryRouter } from 'react-router';
import { describe, expect, it } from 'vitest';
import { describe, expect, it, vi } from 'vitest';
import { PhysicalInventory } from './physical-inventory';
import { fixtureInventory, FIXTURE_NAMES } from '../lib/inventory-fixtures';
import { redactInventory } from '../lib/inventory-read-access';
Expand Down Expand Up @@ -71,6 +71,20 @@ describe('Device page: discovery health', () => {
expect(fact('Key expiry').querySelector('[data-tone]')).toBeNull();
});

it('copies the full fingerprint and says so in the button and its tooltip', async () => {
const writeText = vi.fn(async () => undefined);
vi.stubGlobal('navigator', { ...navigator, clipboard: { writeText } });
try {
show(MATCHED);
const copy = within(fact('TLS key')).getByRole('button', { name: 'Copy TLS key fingerprint' });
expect(copy).toHaveAttribute('title', 'Copy TLS key fingerprint');
fireEvent.click(copy);
await waitFor(() => expect(copy).toHaveTextContent(/^Copied$/));
expect(copy).toHaveAttribute('title', 'Copied');
expect(writeText).toHaveBeenCalledWith('3f'.repeat(32));
} finally { vi.unstubAllGlobals(); }
});

it('shows PinNotApproved as not approved, amber, with the reason in the tooltip, and an expiring key amber', () => {
const { container } = show(PENDING);
const approval = fact('Key approval').querySelector('[data-tone="warning"]')!;
Expand Down
5 changes: 3 additions & 2 deletions ui/provider/src/components/device-discovery.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// The Device page's view of BMC discovery: Device.status, next to the spec it
// is compared with. See "Device page" in docs/development/staff-inventory-ui.md.
// Red is a disagreement or failure, amber needs checking, and OK stays plain.
import { Button } from '@datum-cloud/datum-ui/button';
import { useState, type ReactNode } from 'react';
import type { Device } from '../../../shared/fleet-api';
import {
Expand Down Expand Up @@ -40,10 +41,10 @@ export function ConditionChips({ device }: { device: Device }) {

function CopyValue({ value, label }: { value: string; label: string }) {
const [copied, setCopied] = useState(false);
return <button type="button" className="inventory-copy" aria-label={`Copy ${label}`} title={copied ? 'Copied' : `Copy ${label}`}
return <Button type="secondary" theme="outline" size="xs" htmlType="button" className="inventory-copy" aria-label={`Copy ${label}`} title={copied ? 'Copied' : `Copy ${label}`}
onClick={() => { void navigator.clipboard?.writeText(value).then(() => { setCopied(true); setTimeout(() => setCopied(false), 1500); }, () => undefined); }}>
{copied ? 'Copied' : 'Copy'}
</button>;
</Button>;
}

/** Discovery health: conditions, last attempt, TLS key, expiry and approval. */
Expand Down
4 changes: 2 additions & 2 deletions ui/provider/src/components/device-faceplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -475,9 +475,9 @@ export function PortFaceplate({ faces: laid, names, namespace, href, cablesDenie
{face.clusters.some(hidden) && (
<p className="inventory-port-hidden">
{face.clusters.filter(hidden).map(cluster => (
<button key={cluster.group} type="button" className="inventory-link-button" aria-expanded={false} onClick={() => setExpanded(value => new Set(value).add(cluster.group))}>
<Button key={cluster.group} type="secondary" theme="link" size="link" htmlType="button" aria-expanded={false} onClick={() => setExpanded(value => new Set(value).add(cluster.group))}>
Show {cluster.title} · {portsWord(cluster.tiles.length)}, catalog only
</button>
</Button>
))}
</p>
)}
Expand Down
Loading
Loading