Merge pull request 'Quick Command remembers the mode and workers' (#79) from quick-remember into main
CI / UI screenshots (before/after) (push) Skipped
CI / Lint (eslint) (push) Successful in 22s
CI / Security (npm audit) (push) Successful in 17s
CI / Test (jest) (push) Successful in 23s
CI / Scan (secrets, workflows, shell) (push) Successful in 2m14s
CI / Integration (api) (push) Successful in 3m43s
CI / UI (playwright) (push) Successful in 2m9s
CI / Deploy (push) Successful in 19s
CI / Deploy worker (push) Successful in 8s
CI / Notify (push) Successful in 3s
CI / UI screenshots (before/after) (push) Skipped
CI / Lint (eslint) (push) Successful in 22s
CI / Security (npm audit) (push) Successful in 17s
CI / Test (jest) (push) Successful in 23s
CI / Scan (secrets, workflows, shell) (push) Successful in 2m14s
CI / Integration (api) (push) Successful in 3m43s
CI / UI (playwright) (push) Successful in 2m9s
CI / Deploy (push) Successful in 19s
CI / Deploy worker (push) Successful in 8s
CI / Notify (push) Successful in 3s
This commit was merged in pull request #79.
This commit is contained in:
commit
e92fa42b4e
2 files changed
+54
-3
No files matched your search
@@ -48,6 +48,16 @@
|
||||
/* -------------------------------------------------------------------
|
||||
Worker select / checkbox list
|
||||
------------------------------------------------------------------- */
|
||||
/* Last mode and worker choice, kept across reloads (#31). */
|
||||
const PREFS_KEY = 'pulse_qc_prefs';
|
||||
function loadPrefs() {
|
||||
const p = Pulse.util.storage.get(PREFS_KEY, null);
|
||||
return p && typeof p === 'object' ? p : {};
|
||||
}
|
||||
function savePrefs(patch) {
|
||||
Pulse.util.storage.set(PREFS_KEY, Object.assign(loadPrefs(), patch));
|
||||
}
|
||||
|
||||
function currentMode() {
|
||||
const checked = document.querySelector('input[name="qc-exec-mode"]:checked');
|
||||
return checked ? checked.value : 'single';
|
||||
@@ -99,10 +109,18 @@
|
||||
return Array.from(document.querySelectorAll('input[name="qc-worker-cb"]:checked')).map(cb => cb.value);
|
||||
}
|
||||
|
||||
let _restored = false;
|
||||
async function loadWorkers() {
|
||||
const select = document.getElementById('qc-worker');
|
||||
const preserveSingle = select ? select.value : '';
|
||||
const preserveMulti = new Set(selectedWorkerCheckboxIds());
|
||||
let preserveSingle = select ? select.value : '';
|
||||
let preserveMulti = new Set(selectedWorkerCheckboxIds());
|
||||
if (!_restored) {
|
||||
// First load: start from the saved choice rather than the first worker.
|
||||
_restored = true;
|
||||
const prefs = loadPrefs();
|
||||
preserveSingle = prefs.worker || preserveSingle;
|
||||
if (Array.isArray(prefs.workers)) preserveMulti = new Set(prefs.workers);
|
||||
}
|
||||
try {
|
||||
_workers = await Pulse.api.get('/api/workers') || [];
|
||||
} catch (e) {
|
||||
@@ -230,6 +248,7 @@
|
||||
}
|
||||
const worker = _workers.find(w => w.id === workerId);
|
||||
const workerName = worker ? worker.name : 'Unknown';
|
||||
savePrefs({ mode: 'single', worker: workerId });
|
||||
renderExecuting(1);
|
||||
try {
|
||||
const data = await Pulse.api.post('/api/workers/' + encodeURIComponent(workerId) + '/command', { command });
|
||||
@@ -248,6 +267,7 @@
|
||||
Pulse.toast.error('Please select at least one worker');
|
||||
return;
|
||||
}
|
||||
savePrefs({ mode: 'multi', workers: workerIds });
|
||||
renderExecuting(workerIds.length);
|
||||
// Send to every selected worker at once (#26); results keep the selection order.
|
||||
const results = await Promise.all(workerIds.map(async (workerId) => {
|
||||
@@ -310,7 +330,7 @@
|
||||
|
||||
function init() {
|
||||
Pulse.actions.registerAll({
|
||||
'qc:mode': applyMode,
|
||||
'qc:mode': () => { applyMode(); savePrefs({ mode: currentMode() }); },
|
||||
'qc:templates-open': () => { renderTemplates(); if (window.lt && lt.modal) lt.modal.open('qc-templates-modal'); },
|
||||
'qc:template-use': (el) => {
|
||||
const idx = Number(el.getAttribute('data-index'));
|
||||
@@ -348,6 +368,9 @@
|
||||
lt.keys.on('ctrl+enter', () => { execute(); });
|
||||
}
|
||||
|
||||
const saved = loadPrefs().mode;
|
||||
const savedRadio = saved && document.querySelector('input[name="qc-exec-mode"][value="' + (saved === 'multi' ? 'multi' : 'single') + '"]');
|
||||
if (savedRadio) savedRadio.checked = true;
|
||||
applyMode();
|
||||
return loadWorkers().then(() => { consumeRerun(); });
|
||||
}
|
||||
|
||||
@@ -80,3 +80,31 @@ test('searching Executions finds a run by its command (#16)', async ({ page, req
|
||||
await expect(rows).toHaveCount(1);
|
||||
await expect(rows.first()).toHaveAttribute('data-execution-id', id);
|
||||
});
|
||||
|
||||
test('Quick Command remembers the mode and workers after a reload (#31)', async ({ page }) => {
|
||||
await page.goto('/quick');
|
||||
await page.locator('#qc-mode-multi').check();
|
||||
const boxes = page.locator('#qc-worker-list label');
|
||||
await boxes.filter({ hasText: 'node-02' }).locator('input').check();
|
||||
await boxes.filter({ hasText: 'node-03' }).locator('input').check();
|
||||
await page.locator('#qc-command').fill('true');
|
||||
await page.locator('#qc-execute-btn').click();
|
||||
await expect(page.locator('#qc-result')).toContainText(/2/);
|
||||
|
||||
await page.reload();
|
||||
await expect(page.locator('#qc-mode-multi')).toBeChecked();
|
||||
await expect(boxes.filter({ hasText: 'node-02' }).locator('input')).toBeChecked();
|
||||
await expect(boxes.filter({ hasText: 'node-03' }).locator('input')).toBeChecked();
|
||||
await expect(boxes.filter({ hasText: 'node-01' }).locator('input')).not.toBeChecked();
|
||||
|
||||
// Single mode remembers its worker too.
|
||||
await page.locator('#qc-mode-single').check();
|
||||
const node3 = await page.locator('#qc-worker option', { hasText: 'node-03' }).getAttribute('value');
|
||||
await page.locator('#qc-worker').selectOption(node3);
|
||||
await page.locator('#qc-command').fill('true'); // the reload emptied it
|
||||
await page.locator('#qc-execute-btn').click();
|
||||
await expect(page.locator('#qc-result')).toContainText('Command sent successfully');
|
||||
await page.reload();
|
||||
await expect(page.locator('#qc-mode-single')).toBeChecked();
|
||||
await expect(page.locator('#qc-worker option:checked')).toContainText('node-03');
|
||||
});
|
||||
Reference in new issue
Block a user