mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-11-30 17:42:32 +01:00
Let Enter submit Add client without duplicate requests (#3863)
Use the existing account-scoped native form submit path for keyboard and pointer creation. Keep one pending request per account, disable the named form while pending, and restore its unchanged name and explicit retry controls when a request fails. Update the cloud-paid contract, normal portal regressions, generated embedded bundle and parent-bound native-browser receipt. Comparable desktop and phone captures retain the existing client roster and onboarding information. --- Fleet candidate `20261104T021650Z-web-product` from the `web-product` lane. Reviewed tip `1e7863571d252b7b4e45e923cf7907cf5921d241` on `main`. [How Pulse handles triage](https://github.com/rcourtman/Pulse/blob/main/docs/AI_TRANSPARENCY.md)
This commit is contained in:
@@ -15,6 +15,24 @@
|
||||
|
||||
## Purpose
|
||||
|
||||
### Client creation uses one native form submission
|
||||
|
||||
The existing MSP Add client form submits through its account-scoped submit
|
||||
handler, so Enter in the name field and activating Add client use the same
|
||||
request. Empty input uses native required-field validation; whitespace-only
|
||||
names still return focus without a write. Cancel remains a non-submit button,
|
||||
and unrelated workspace handoff forms retain their ordinary submission.
|
||||
|
||||
Each account admits one pending create request. Its name and action controls
|
||||
are disabled and the form reports busy until the request settles. A failed
|
||||
request preserves the name, clears busy state and restores explicit retry;
|
||||
there is no automatic create retry. Existing account permissions, API payload,
|
||||
workspace identity, licence checks and the created-client onboarding view are
|
||||
unchanged. Normal portal controller, runtime, view and shell tests cover these
|
||||
boundaries. Comparable desktop/phone captures and native-bundle browser checks
|
||||
cover Enter, pointer activation, pending duplicates, failure and deliberate retry;
|
||||
they do not establish live licensing, TLS or installed client recovery.
|
||||
|
||||
### Control-plane account responses are not HTTP-cacheable by default
|
||||
|
||||
`CPSecurityHeaders`, which wraps the registered control-plane routes in the
|
||||
|
||||
52
frontend-modern/browser-verification/00286a132c918a52.json
Normal file
52
frontend-modern/browser-verification/00286a132c918a52.json
Normal file
@@ -0,0 +1,52 @@
|
||||
{
|
||||
"version": 1,
|
||||
"base_sha": "90d1b0b059328fdbdd3af0a15457a78dfb52f70d",
|
||||
"verified_at": "2026-11-04T02:28:35.733119Z",
|
||||
"result": "passed",
|
||||
"changed_paths": [
|
||||
"internal/cloudcp/portal/dist/build_manifest.json",
|
||||
"internal/cloudcp/portal/dist/portal_app.js",
|
||||
"internal/cloudcp/portal/frontend/src/account_controller.ts",
|
||||
"internal/cloudcp/portal/frontend/src/account_runtime.ts",
|
||||
"internal/cloudcp/portal/frontend/src/account_view.ts",
|
||||
"internal/cloudcp/portal/frontend/src/shell_view.ts"
|
||||
],
|
||||
"content_sha256": {
|
||||
"internal/cloudcp/portal/frontend/src/account_controller.ts": "df24a72c8597254c648727a7638fce0384619c0c9e4d52a7a3173d61e8c97518",
|
||||
"internal/cloudcp/portal/frontend/src/account_runtime.ts": "4c1842a3d5b6adaaadf84f8c3f4521a2af526baa33eb104f0ebfc0e1ac2d7a4b",
|
||||
"internal/cloudcp/portal/frontend/src/account_view.ts": "078f0c755458ae1ca217df3d2d553b740e79b060b507b570bf1785594fe45863",
|
||||
"internal/cloudcp/portal/frontend/src/shell_view.ts": "e294badf253f548c7bd7bf064899d91d6b3d9efb22c12469c99126c919036f04",
|
||||
"internal/cloudcp/portal/dist/portal_app.js": "9938de1205e37e4277497ce47c42856d16c71345fb77788edc9d49fc3c858714",
|
||||
"internal/cloudcp/portal/dist/build_manifest.json": "3880cef49389eafdd65c92583888c30d696f290514aab8c90c667e0b28c6ba68"
|
||||
},
|
||||
"routes": [
|
||||
"/portal (native embedded template, bundle and CSS; synthetic provider bootstrap and account APIs)"
|
||||
],
|
||||
"viewports": [
|
||||
{
|
||||
"width": 1440,
|
||||
"height": 1000
|
||||
},
|
||||
{
|
||||
"width": 390,
|
||||
"height": 844
|
||||
}
|
||||
],
|
||||
"states": [
|
||||
"Comparable light-theme before/after native portal: filled name, after Enter, pending, failed request, created-client onboarding. All twenty retained captures were opened with the native image tool.",
|
||||
"The unchanged parent sends no request on Enter; the final bundle sends one. Form controls are disabled and aria-busy is true while pending; an additional submit event starts no duplicate request. Failure clears the spinner and busy state, retains the name and restores explicit retry.",
|
||||
"No status, per-client distinction or existing control is removed, aggregated or moved behind disclosure. Created-client identity, counts, setup instructions and selected row remain visible.",
|
||||
"Playwright 1.56.1 matches tests/integration lock; Chromium 141.0.7390.37. Before 19 checks, final 31 checks. Real frontend request/response flow with safe fixtures; not an installed control-plane, TLS, licence or original client recovery claim."
|
||||
],
|
||||
"interactions": [
|
||||
"Enter in the existing Client name field, pointer submit, controlled HTTP 503, deliberate Enter retry and successful bootstrap refresh/select of the created client.",
|
||||
"Duplicate submit while the first create is pending; pointer still creates once; Cancel makes no additional request; read-only account has no create control.",
|
||||
"No horizontal overflow at desktop or 390px; no page exception. Same fixture, en-GB locale, UTC, viewport and light theme for comparable captures. Filled and Enter pairs use identical keyboard interaction; pending/failure/created parent controls use pointer because parent Enter does nothing."
|
||||
],
|
||||
"evidence": [
|
||||
"BROWSER-BEFORE.json",
|
||||
"BROWSER-AFTER.json",
|
||||
"CAPTURES.md",
|
||||
"RECEIPTS.md"
|
||||
]
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"source_hash": "b7a70a05954be41554248af9cff592b702f874d2c5a03256ae3a84d100e7bded",
|
||||
"source_hash": "1c3413c286253b16c71d15d35377f78d12a05623a0dd306d48d140a104e1fbce",
|
||||
"build_inputs": [
|
||||
"package.json",
|
||||
"tsconfig.json",
|
||||
|
||||
25
internal/cloudcp/portal/dist/portal_app.js
vendored
25
internal/cloudcp/portal/dist/portal_app.js
vendored
File diff suppressed because one or more lines are too long
@@ -35,7 +35,7 @@ describe('account controller', function() {
|
||||
'<button id="job" data-action="set-access-job" data-account-id="acct_1" data-access-job="invite">Invite job</button>' +
|
||||
'<button id="job-close" data-action="clear-access-job" data-account-id="acct_1">Close access job</button>' +
|
||||
'<button id="invite" data-action="invite-member" data-account-id="acct_1">Invite</button>' +
|
||||
'<button id="create" data-action="create-workspace" data-account-id="acct_1">Create</button>' +
|
||||
'<form id="create-form" data-account-form="create-workspace" data-account-id="acct_1"><button type="submit" id="create">Create</button></form>' +
|
||||
'<button id="select" data-action="select-workspace" data-account-id="acct_1" data-workspace-id="ws_1">Manage</button>' +
|
||||
'<button id="close" data-action="clear-workspace-selection" data-account-id="acct_1">Done</button>' +
|
||||
'<button id="manage" data-action="workspace-action" data-account-id="acct_1" data-workspace-id="ws_1" data-workspace-action="suspend" data-workspace-name="Alpha">Suspend</button>' +
|
||||
@@ -62,8 +62,28 @@ describe('account controller', function() {
|
||||
document.getElementById('invite')?.dispatchEvent(new MouseEvent('click', { bubbles: true }));
|
||||
expect(runtime.inviteMember).toHaveBeenCalledWith('acct_1');
|
||||
|
||||
document.getElementById('create')?.dispatchEvent(new MouseEvent('click', { bubbles: true }));
|
||||
(document.getElementById('create') as HTMLButtonElement).click();
|
||||
expect(runtime.createWorkspace).toHaveBeenCalledWith('acct_1');
|
||||
expect(runtime.createWorkspace).toHaveBeenCalledTimes(1);
|
||||
|
||||
// The submit event, not a key handler or button-only click, owns creation.
|
||||
var submit = new Event('submit', { bubbles: true, cancelable: true });
|
||||
document.getElementById('create-form')?.dispatchEvent(submit);
|
||||
expect(submit.defaultPrevented).toBe(true);
|
||||
expect(runtime.createWorkspace).toHaveBeenCalledTimes(2);
|
||||
|
||||
var handoff = document.createElement('form');
|
||||
document.body.appendChild(handoff);
|
||||
var handoffSubmit = new Event('submit', { bubbles: true, cancelable: true });
|
||||
handoff.dispatchEvent(handoffSubmit);
|
||||
expect(handoffSubmit.defaultPrevented).toBe(false);
|
||||
expect(runtime.createWorkspace).toHaveBeenCalledTimes(2);
|
||||
|
||||
document.getElementById('create-form')?.setAttribute('data-account-id', '');
|
||||
var missingAccount = new Event('submit', { bubbles: true, cancelable: true });
|
||||
document.getElementById('create-form')?.dispatchEvent(missingAccount);
|
||||
expect(missingAccount.defaultPrevented).toBe(true);
|
||||
expect(runtime.createWorkspace).toHaveBeenCalledTimes(2);
|
||||
|
||||
document.getElementById('select')?.dispatchEvent(new MouseEvent('click', { bubbles: true }));
|
||||
expect(runtime.selectWorkspace).toHaveBeenCalledWith('acct_1', 'ws_1');
|
||||
|
||||
@@ -7,6 +7,16 @@ export interface AccountControllerDeps {
|
||||
}
|
||||
|
||||
export function installAccountController(deps: AccountControllerDeps): void {
|
||||
document.addEventListener('submit', function(event) {
|
||||
var form = event.target;
|
||||
if (!(form instanceof HTMLFormElement) || form.getAttribute('data-account-form') !== 'create-workspace') return;
|
||||
event.preventDefault();
|
||||
var accountID = form.getAttribute('data-account-id') || '';
|
||||
if (!accountID) return;
|
||||
deps.setShellSection('workspaces');
|
||||
void deps.runtime.createWorkspace(accountID);
|
||||
});
|
||||
|
||||
document.addEventListener('click', function(event) {
|
||||
var target = asHTMLElement(event.target);
|
||||
if (!target) return;
|
||||
@@ -44,11 +54,6 @@ export function installAccountController(deps: AccountControllerDeps): void {
|
||||
event.preventDefault();
|
||||
void deps.runtime.inviteMember(accountID);
|
||||
return;
|
||||
case 'create-workspace':
|
||||
event.preventDefault();
|
||||
deps.setShellSection('workspaces');
|
||||
void deps.runtime.createWorkspace(accountID);
|
||||
return;
|
||||
case 'select-workspace':
|
||||
event.preventDefault();
|
||||
deps.setShellSection('workspaces');
|
||||
|
||||
@@ -126,6 +126,46 @@ describe('account runtime', function() {
|
||||
expect((document.getElementById('ws-spinner-acct_1') as HTMLElement).hidden).toBe(true);
|
||||
});
|
||||
|
||||
it('admits one create request and restores the named form for explicit retry after failure', async function() {
|
||||
deps.store.setBootstrap({ authenticated: true, email: 'owner@example.com', accounts: [{
|
||||
id: 'acct_1', name: 'Example MSP', kind: 'msp', kind_label: 'MSP', role: 'owner',
|
||||
can_manage: true, has_billing: false, members: [], workspaces: [],
|
||||
}] });
|
||||
var rejectRequests: Array<(error: Error) => void> = [];
|
||||
vi.stubGlobal('fetch', vi.fn().mockImplementation(function() {
|
||||
return new Promise(function(_resolve, reject) { rejectRequests.push(reject); });
|
||||
}));
|
||||
document.body.innerHTML = '<form id="add-ws-form-acct_1"><input id="ws-name-acct_1" value="Acme Clinic"><button type="submit">Add client</button><button type="button">Cancel</button><div id="ws-spinner-acct_1" hidden></div></form>';
|
||||
var first = runtime.createWorkspace('acct_1');
|
||||
await flushAsync();
|
||||
var duplicate = runtime.createWorkspace('acct_1');
|
||||
await flushAsync();
|
||||
var requestCount = vi.mocked(fetch).mock.calls.length;
|
||||
var pendingDisabled = (document.getElementById('ws-name-acct_1') as HTMLInputElement).disabled;
|
||||
rejectRequests.forEach(function(reject) { reject(new Error('Temporary failure')); });
|
||||
await Promise.all([first, duplicate]);
|
||||
expect(requestCount).toBe(1);
|
||||
expect(pendingDisabled).toBe(true);
|
||||
expect(deps.store.getAccountState().byAccountID.acct_1.createWorkspace.pending).toBe(false);
|
||||
expect((document.getElementById('ws-spinner-acct_1') as HTMLElement).hidden).toBe(true);
|
||||
expect((document.getElementById('ws-name-acct_1') as HTMLInputElement).disabled).toBe(false);
|
||||
expect((document.getElementById('ws-name-acct_1') as HTMLInputElement).value).toBe('Acme Clinic');
|
||||
expect(deps.showToast).toHaveBeenCalledWith('Failed to create workspace.', true);
|
||||
expect(fetch).toHaveBeenCalledTimes(1);
|
||||
vi.mocked(fetch).mockRejectedValueOnce(new Error('Deliberate retry failure'));
|
||||
await runtime.createWorkspace('acct_1');
|
||||
expect(fetch).toHaveBeenCalledTimes(2);
|
||||
expect(deps.store.getAccountState().byAccountID.acct_1.createWorkspace.pending).toBe(false);
|
||||
});
|
||||
|
||||
it('does not submit a whitespace-only client name', async function() {
|
||||
vi.stubGlobal('fetch', vi.fn());
|
||||
document.body.innerHTML = '<input id="ws-name-acct_1" value=" ">';
|
||||
await runtime.createWorkspace('acct_1');
|
||||
expect(fetch).not.toHaveBeenCalled();
|
||||
expect(document.activeElement?.id).toBe('ws-name-acct_1');
|
||||
});
|
||||
|
||||
it('selects a workspace and routes explicit workspace actions through the management panel', async function() {
|
||||
vi.stubGlobal('fetch', vi.fn().mockResolvedValue(jsonResponse({})));
|
||||
var confirmSpy = vi.spyOn(window, 'confirm').mockReturnValue(true);
|
||||
|
||||
@@ -193,6 +193,7 @@ export function installAccountRuntime(deps: AccountRuntimeDeps): AccountRuntime
|
||||
}
|
||||
|
||||
var createWorkspace = async function(accountID: string): Promise<void> {
|
||||
if (deps.store.getAccountState().byAccountID[accountID]?.createWorkspace.pending) return;
|
||||
var nameEl = getElement<HTMLInputElement>('ws-name-' + accountID);
|
||||
if (!nameEl) return;
|
||||
var name = nameEl.value.trim();
|
||||
@@ -210,7 +211,7 @@ export function installAccountRuntime(deps: AccountRuntimeDeps): AccountRuntime
|
||||
deps.store.updateAccountState(function(accountState) {
|
||||
var entry = ensurePortalAccountUIEntry(accountState, accountID);
|
||||
resetMutationState(entry.createWorkspace);
|
||||
}, { notify: false });
|
||||
});
|
||||
return;
|
||||
}
|
||||
var createdWorkspaceID = created && typeof created.id === 'string' ? created.id : '';
|
||||
@@ -237,7 +238,7 @@ export function installAccountRuntime(deps: AccountRuntimeDeps): AccountRuntime
|
||||
deps.store.updateAccountState(function(accountState) {
|
||||
var entry = ensurePortalAccountUIEntry(accountState, accountID);
|
||||
failMutationState(entry.createWorkspace, message);
|
||||
}, { notify: false });
|
||||
});
|
||||
deps.showToast(message, true);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -103,8 +103,8 @@ describe('account view', function() {
|
||||
|
||||
it('renders add-workspace visibility from account UI state', function() {
|
||||
document.body.innerHTML =
|
||||
'<div id="add-ws-form-acct_1" class="add-workspace-form"></div>' +
|
||||
'<div id="ws-spinner-acct_1" hidden></div>';
|
||||
'<form id="add-ws-form-acct_1" class="add-workspace-form"><input value="Acme Clinic"><button type="submit">Add client</button><button type="button">Cancel</button>' +
|
||||
'<div id="ws-spinner-acct_1" hidden></div></form>';
|
||||
|
||||
renderAddWorkspaceSection('acct_1', createEntry({ addWorkspaceOpen: true }));
|
||||
expect(document.getElementById('add-ws-form-acct_1')?.classList.contains('visible')).toBe(true);
|
||||
@@ -115,6 +115,15 @@ describe('account view', function() {
|
||||
createWorkspace: { pending: true, error: '' },
|
||||
}));
|
||||
expect((document.getElementById('ws-spinner-acct_1') as HTMLElement).hidden).toBe(false);
|
||||
expect(document.querySelector('#add-ws-form-acct_1')?.getAttribute('aria-busy')).toBe('true');
|
||||
expect((document.querySelector('#add-ws-form-acct_1 input') as HTMLInputElement).disabled).toBe(true);
|
||||
expect(Array.from(document.querySelectorAll<HTMLButtonElement>('#add-ws-form-acct_1 button')).every(function(button) { return button.disabled; })).toBe(true);
|
||||
|
||||
renderAddWorkspaceSection('acct_1', createEntry({ addWorkspaceOpen: true, createWorkspace: { pending: false, error: 'Try again' } }));
|
||||
expect((document.querySelector('#add-ws-form-acct_1 input') as HTMLInputElement).disabled).toBe(false);
|
||||
expect((document.querySelector('#add-ws-form-acct_1 input') as HTMLInputElement).value).toBe('Acme Clinic');
|
||||
expect(Array.from(document.querySelectorAll<HTMLButtonElement>('#add-ws-form-acct_1 button')).every(function(button) { return !button.disabled; })).toBe(true);
|
||||
expect(document.querySelector('#add-ws-form-acct_1')?.getAttribute('aria-busy')).toBe('false');
|
||||
|
||||
renderAddWorkspaceSection('acct_1', createEntry({ addWorkspaceOpen: false }));
|
||||
expect(document.getElementById('add-ws-form-acct_1')?.classList.contains('visible')).toBe(false);
|
||||
|
||||
@@ -465,6 +465,10 @@ export function renderAddWorkspaceSection(accountID: string, entry: PortalAccoun
|
||||
var spinner = getElement<HTMLElement>('ws-spinner-' + accountID);
|
||||
if (!form) return;
|
||||
form.classList.toggle('visible', entry.addWorkspaceOpen);
|
||||
form.setAttribute('aria-busy', String(entry.createWorkspace.pending));
|
||||
form.querySelectorAll<HTMLInputElement | HTMLButtonElement>('input, button').forEach(function(control) {
|
||||
control.disabled = entry.createWorkspace.pending;
|
||||
});
|
||||
if (spinner) {
|
||||
spinner.hidden = !entry.createWorkspace.pending;
|
||||
}
|
||||
|
||||
@@ -64,6 +64,27 @@ function createContext(overrides: Partial<ShellViewContext> = {}): ShellViewCont
|
||||
}
|
||||
|
||||
describe('shell view', function() {
|
||||
it('renders native client creation forms without intercepting workspace handoffs', function() {
|
||||
var account = {
|
||||
id: 'acct_1', name: 'Example MSP', kind: 'msp', kind_label: 'MSP',
|
||||
role: 'owner', can_manage: true, has_billing: false, members: [], workspaces: [],
|
||||
};
|
||||
var root = document.createElement('div');
|
||||
root.innerHTML = renderAuthenticatedPortalHTML(createContext({ bootstrap: createBootstrap({ accounts: [account] }) }));
|
||||
var form = root.querySelector('#add-ws-form-acct_1') as HTMLFormElement;
|
||||
expect(form).toBeInstanceOf(HTMLFormElement);
|
||||
expect(form.getAttribute('data-account-form')).toBe('create-workspace');
|
||||
expect(form.getAttribute('data-account-id')).toBe('acct_1');
|
||||
expect(form.querySelector('input')?.required).toBe(true);
|
||||
expect(form.querySelector('button.btn-primary')?.getAttribute('type')).toBe('submit');
|
||||
expect(form.querySelector('button.btn-secondary')?.getAttribute('type')).toBe('button');
|
||||
expect(form.querySelector('[data-action="create-workspace"]')).toBeNull();
|
||||
expect(form.querySelector('form')).toBeNull();
|
||||
|
||||
root.innerHTML = renderAuthenticatedPortalHTML(createContext({ bootstrap: createBootstrap({ accounts: [{ ...account, role: 'read_only', can_manage: false }] }) }));
|
||||
expect(root.querySelector('[data-account-form="create-workspace"]')).toBeNull();
|
||||
});
|
||||
|
||||
it('renders authenticated header with account email and sign-out button', function() {
|
||||
var html = renderHeaderHTML(createContext());
|
||||
|
||||
|
||||
@@ -1106,7 +1106,9 @@ function renderAccountWorkspaceSection(account: PortalAccountSummary, accountAPI
|
||||
|
||||
if (account.kind === 'msp') {
|
||||
addWorkspaceForm =
|
||||
'<div class="add-workspace-form" id="add-ws-form-' +
|
||||
'<form class="add-workspace-form" data-account-form="create-workspace" data-account-id="' +
|
||||
escapeAttr(account.id) +
|
||||
'" id="add-ws-form-' +
|
||||
escapeAttr(account.id) +
|
||||
'">' +
|
||||
'<label for="ws-name-' +
|
||||
@@ -1114,11 +1116,9 @@ function renderAccountWorkspaceSection(account: PortalAccountSummary, accountAPI
|
||||
'">' + escapeHTML(clientLanguage ? 'Client name' : 'Workspace name (for example, a client name)') + '</label>' +
|
||||
'<input type="text" id="ws-name-' +
|
||||
escapeAttr(account.id) +
|
||||
'" placeholder="Acme Corp" maxlength="80" autocomplete="off">' +
|
||||
'" placeholder="Acme Corp" maxlength="80" autocomplete="off" required>' +
|
||||
'<div class="form-actions">' +
|
||||
'<button type="button" class="btn-primary" data-action="create-workspace" data-account-id="' +
|
||||
escapeAttr(account.id) +
|
||||
'">' + escapeHTML(addEntityLabel) + '</button>' +
|
||||
'<button type="submit" class="btn-primary">' + escapeHTML(addEntityLabel) + '</button>' +
|
||||
'<button type="button" class="btn-secondary" data-action="toggle-add-workspace" data-account-id="' +
|
||||
escapeAttr(account.id) +
|
||||
'">Cancel</button>' +
|
||||
@@ -1126,7 +1126,7 @@ function renderAccountWorkspaceSection(account: PortalAccountSummary, accountAPI
|
||||
escapeAttr(account.id) +
|
||||
'" hidden></div>' +
|
||||
'</div>' +
|
||||
'</div>';
|
||||
'</form>';
|
||||
}
|
||||
workspaceManagement =
|
||||
'<section class="workspace-management-panel workspace-management-panel-idle" id="workspace-management-' +
|
||||
|
||||
Reference in New Issue
Block a user