feat: konsola — edytor skilla, wersje z różnicą linii, publikacja, archiwizacja i eksport (E3, 6.2)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
e37b915896
commit
e7f2b8d5f1
+1
-1
@@ -29,7 +29,7 @@
|
||||
|
||||
## Etap 6: konsola (E3)
|
||||
- [x] 6.1 W `frontend/app.js` dodaj pozycję „Skille i agenci / Skills and agents” w głównym menu obok „Połączone aplikacje” oraz widok listy z zakładkami Moje / Firmy (skille i agenci osobno), z PL/EN, przez `esc()`, API z `document.baseURI`. Gotowe gdy: `node --check frontend/app.js` i bramka zielone, a pozycja menu prowadzi do widoku listy.
|
||||
- [ ] 6.2 Dodaj edytor skilla (nazwa, opis, treść, pliki jako base64; przy `.docx/.xlsx/.pdf` napis „plik do pobrania, model go jeszcze nie czyta”), listę wersji z różnicą linii względem poprzedniej (prosty diff w JS bez biblioteki), archiwizację, publikację i link eksportu — zapisy przez `mutate()`. Gotowe gdy: bramka zielona, każdy zapis idzie przez `mutate()`.
|
||||
- [x] 6.2 Dodaj edytor skilla (nazwa, opis, treść, pliki jako base64; przy `.docx/.xlsx/.pdf` napis „plik do pobrania, model go jeszcze nie czyta”), listę wersji z różnicą linii względem poprzedniej (prosty diff w JS bez biblioteki), archiwizację, publikację i link eksportu — zapisy przez `mutate()`. Gotowe gdy: bramka zielona, każdy zapis idzie przez `mutate()`.
|
||||
- [ ] 6.3 Dodaj import (wybór pliku → `fetch` z surowym ciałem `application/zip` i `?filename=`; ekran wyniku pokazuje odrzucenie z powodem wg `code` w PL/EN albo listę rzeczy zapisanych tylko jako informacja, oraz pytanie „dodać jako nową wersję?” przy tej samej sumie) i edytor agenta (instrukcja, wybór przypiętych wersji skilli, podpowiedź modelu, publikacja, eksport). Gotowe gdy: bramka zielona.
|
||||
- [ ] 6.4 Dodaj w Administracji ekran „Prośby o publikację” (różnica wersji przed zatwierdzeniem, zatwierdź/odrzuć) widoczny tylko dla administratora oraz dwa nowe ustawienia w istniejącym ekranie ustawień. Gotowe gdy: bramka zielona.
|
||||
- [ ] 6.5 Napisz `backend/tests/test_skills_console.py` wzorem `test_providers_console.py`: widoki są w routerze konsoli, woła wyłącznie trasy istniejące w routerach backendu, wartości dynamiczne przez `esc()`, ekran próśb tylko dla administratora, brak `href`/`src` z wiodącym `/`. Gotowe gdy: bramka zielona i nowe testy przechodzą.
|
||||
|
||||
@@ -32,3 +32,5 @@
|
||||
- 5.2: 9 nowych testów w `test_skills_integration.py` — agent firmowy z osobistym skillem = 422 `agent_pin_refused` (przy publikacji i przy nowej wersji już firmowego), T2 eksportu skilla i agenta (agent osobisty z firmowym skillem: autor 403 pod `administrator`, administrator 404 na cudzym osobistym), import→eksport→import u innej osoby = ta sama suma, u siebie = `duplicate`, złośliwy ZIP (`pack_bad_path`, `pack_file_type`, `pack_not_zip`) = Problem Details bez zapisu, UPDATE/DELETE na `skill_version` jako rola runtime = permission denied. Odpalone na postgres:17 w Dockerze — całość zielona (poza wiszącym lokalnie `test_deploy_init_add.py`).
|
||||
- 6.1: `app.js` — pozycja NAV `#/skills` (ikona Tabler `book` w ICN) obok „Połączone aplikacje”, trasa `#/skills` (Moje = `mine`) i `#/skills/firm` (Firmy = `scope=firm`, więc własny firmowy jest w obu), `viewSkills` + `skillTabs` + `skillChips` (osobisty/firmowy, „Czeka na zgodę” gdy firmowy bez `current_version_id`, zarchiwizowany, zaimportowany); napisy w I18N.
|
||||
- Dla 6.2/6.3: wiersze listy nie są jeszcze linkami — edytor podepnie trasy `#/skills/skill/<id>` i `#/skills/agent/<id>` (router: `seg[1] === 'firm'` to jedyny zajęty segment). Apostrofy w I18N pisz w cudzysłowie podwójnym (wzorzec repo); heredoc w bash zjada `\'`.
|
||||
- 6.2: `app.js` — trasa `#/skills/skill/<id>` (`viewSkill`: aktualna wersja, pliki z napisem przy .docx/.xlsx/.pdf, lista wersji z `diffHtml` = LCS po liniach z obciętą wspólną głową/ogonem, 2 linie kontekstu), „Nowy skill” na liście + linki w wierszach skilli, `openSkillEditor`/`saveSkill` (pliki base64; wybrane ZASTĘPUJĄ obecne, brak wyboru = przeniesienie, checkbox = `files: {}`), publikacja/archiwizacja przez `mutate()`, eksport jako `<a download>` na `API + /skills/<id>/export`. `mutate` przyjmuje teraz `done` jako funkcję wyniku (publikacja: „wysłano do zatwierdzenia” vs „opublikowano”).
|
||||
- Zauważone: konsola nie zna T2 eksportu firmowego skilla — link pokazuje się każdemu, odmowa = 403 jako pobrany JSON. Wersje czytane osobnym GET na każdą (ponytail). Dla 6.3: `state._skill`/`_skillLatest` trzyma edytor skilla; wiersze agentów jeszcze bez linków.
|
||||
|
||||
@@ -175,6 +175,10 @@ pre.diff {
|
||||
margin: 6px 0 0; padding: 8px; border-radius: var(--radius-sm); background: var(--surface-2);
|
||||
font: 11.5px/1.4 var(--mono); white-space: pre-wrap; word-break: break-word; max-width: 46ch;
|
||||
}
|
||||
/* A skill's body and the line diff between its versions: as wide as the card, + and − tinted. */
|
||||
pre.diff.lines { max-width: none; }
|
||||
pre.diff .add { color: var(--ok); background: var(--ok-bg); }
|
||||
pre.diff .del { color: var(--err); background: var(--err-bg); }
|
||||
/* The one field that ever holds a secret: a freshly minted app token, shown once and never again.
|
||||
Monospace so it can be proof-read character by character, because where the clipboard API is
|
||||
unavailable — plain HTTP is not a secure context — copying it by hand is the fallback. */
|
||||
|
||||
+190
-6
@@ -459,6 +459,34 @@ const I18N = {
|
||||
'Nie masz jeszcze żadnego agenta.': "You don't have any agents yet.",
|
||||
'Firma nie ma jeszcze żadnego skilla.': 'The firm has no skills yet.',
|
||||
'Firma nie ma jeszcze żadnego agenta.': 'The firm has no agents yet.',
|
||||
'Nowy skill': 'New skill',
|
||||
'Nowa wersja': 'New version',
|
||||
'Opublikuj w firmie': 'Publish to the firm',
|
||||
'Eksportuj': 'Export',
|
||||
'Archiwizuj': 'Archive',
|
||||
'Aktualna': 'Current',
|
||||
'Utworzona': 'Created',
|
||||
'Różnice względem': 'Changes since',
|
||||
'Pierwsza wersja': 'First version',
|
||||
'Bez zmian w treści.': 'No change in the content.',
|
||||
'Wersja': 'Version',
|
||||
'Wersje': 'Versions',
|
||||
'Pliki': 'Files',
|
||||
'Treść': 'Content',
|
||||
'np. umowa-najmu': 'e.g. lease-agreement',
|
||||
'Małe litery, cyfry i myślniki. Nie da się go później zmienić.': "Lower-case letters, digits and hyphens. It can't be changed later.",
|
||||
'Opis mówi modelowi, kiedy sięgnąć po ten skill.': 'The description tells the model when to reach for this skill.',
|
||||
'Wybrane pliki zastąpią obecne. Bez wyboru obecne pliki przechodzą do nowej wersji.': 'The files you pick replace the current ones. Pick none and the current files carry over to the new version.',
|
||||
'Pliki pomocnicze, łącznie do 10 MB.': 'Supporting files, up to 10 MB in total.',
|
||||
'Usuń obecne pliki': 'Remove the current files',
|
||||
'plik do pobrania, model go jeszcze nie czyta': "a file to download, the model doesn't read it yet",
|
||||
'Plik do pobrania, model go jeszcze nie czyta:': "Files to download, the model doesn't read them yet:",
|
||||
'Ta wersja czeka na zgodę administratora.': 'This version is waiting for an administrator to approve it.',
|
||||
'Zapisano nową wersję.': 'New version saved.',
|
||||
'Skill utworzony.': 'Skill created.',
|
||||
'Wysłano do zatwierdzenia przez administratora.': 'Sent to an administrator for approval.',
|
||||
'Opublikowano w firmie.': 'Published to the firm.',
|
||||
'Zarchiwizowano.': 'Archived.',
|
||||
'Aplikacje i skrypty, które logują się twoim kontem bez hasła.': 'Apps and scripts that sign in as you, without a password.',
|
||||
'Twoje tokeny': 'Your tokens',
|
||||
'Nowy token': 'New token',
|
||||
@@ -1013,6 +1041,7 @@ async function router() {
|
||||
else if (seg[0] === 'marketplace') await viewMarketplace(C, q);
|
||||
else if (seg[0] === 'requests') await viewMyRequests(C);
|
||||
else if (seg[0] === 'tokens') await viewTokens(C);
|
||||
else if (seg[0] === 'skills' && seg[1] === 'skill' && seg[2]) await viewSkill(C, seg[2]);
|
||||
else if (seg[0] === 'skills') await viewSkills(C, seg[1] === 'firm' ? 'firm' : 'mine');
|
||||
else if (seg[0] === 'admin' && isAdmin()) await adminRoute(C, seg.slice(1), q);
|
||||
else { setCrumb([]); C.innerHTML = '<div class="empty">Nie znaleziono strony.</div>'; }
|
||||
@@ -1525,22 +1554,177 @@ async function viewSkills(C, tab) {
|
||||
const [skills, agents] = await Promise.all([api('GET', '/skills'), api('GET', '/agents')]);
|
||||
const pick = (xs) => xs.filter((x) => (tab === 'firm' ? x.scope === 'firm' : x.mine));
|
||||
setCrumb([{ label: 'Skille i agenci', href: '#/skills' }, { label: tab === 'firm' ? 'Firmy' : 'Moje' }]);
|
||||
const table = (xs, sub, empty) => (xs.length
|
||||
const table = (xs, sub, empty, href) => (xs.length
|
||||
? `<div class="tablewrap"><table class="rt"><thead><tr><th>Nazwa</th><th>Zasięg</th></tr></thead><tbody>${
|
||||
xs.map((x) => `<tr><td><div>${dat(x.name)}${sub(x)}</div></td><td${lbl('Zasięg')}>${skillChips(x)}</td></tr>`).join('')
|
||||
xs.map((x) => `<tr><td><div>${href ? `<a href="${esc(href(x))}">${dat(x.name)}</a>` : dat(x.name)}${sub(x)}</div></td><td${lbl('Zasięg')}>${skillChips(x)}</td></tr>`).join('')
|
||||
}</tbody></table></div>`
|
||||
: `<div class="empty">${esc(empty)}</div>`);
|
||||
const mine = tab !== 'firm';
|
||||
const s = pick(skills);
|
||||
const a = pick(agents);
|
||||
C.innerHTML = pageHead('Skille i agenci', 'Instrukcje i asystenci, z których korzystasz ty i twoja firma.') + skillTabs(tab)
|
||||
C.innerHTML = pageHead('Skille i agenci', 'Instrukcje i asystenci, z których korzystasz ty i twoja firma.',
|
||||
`<button class="btn primary" onclick="openSkillEditor()">${svg(ICN.plus)}<span>Nowy skill</span></button>`)
|
||||
+ skillTabs(tab)
|
||||
+ `<div class="card"><h3>Skille<span class="n">${s.length}</span></h3>${
|
||||
table(s, (x) => `<div class="mono tiny faint wrap">${dat(x.slug)}</div>`,
|
||||
mine ? 'Nie masz jeszcze żadnego skilla.' : 'Firma nie ma jeszcze żadnego skilla.')}</div>`
|
||||
mine ? 'Nie masz jeszcze żadnego skilla.' : 'Firma nie ma jeszcze żadnego skilla.',
|
||||
(x) => '#/skills/skill/' + enc(x.id))}</div>`
|
||||
+ `<div class="card"><h3>Agenci<span class="n">${a.length}</span></h3>${
|
||||
table(a, () => '', mine ? 'Nie masz jeszcze żadnego agenta.' : 'Firma nie ma jeszcze żadnego agenta.')}</div>`;
|
||||
}
|
||||
|
||||
/* Line diff by longest common subsequence, after trimming the common head and tail so the table only
|
||||
covers what changed. ponytail: O(n·m) table — fine for one skill (≤ 30 000 characters); Myers'
|
||||
algorithm if bodies ever reach many thousands of changed lines. */
|
||||
function lineDiff(a, b) {
|
||||
const x = a.split('\n');
|
||||
const y = b.split('\n');
|
||||
let h = 0;
|
||||
while (h < x.length && h < y.length && x[h] === y[h]) h++;
|
||||
let t = 0;
|
||||
while (t < x.length - h && t < y.length - h && x[x.length - 1 - t] === y[y.length - 1 - t]) t++;
|
||||
const xs = x.slice(h, x.length - t);
|
||||
const ys = y.slice(h, y.length - t);
|
||||
const n = xs.length;
|
||||
const m = ys.length;
|
||||
const L = Array.from({ length: n + 1 }, () => new Uint32Array(m + 1));
|
||||
for (let i = n - 1; i >= 0; i--) {
|
||||
for (let j = m - 1; j >= 0; j--) L[i][j] = xs[i] === ys[j] ? L[i + 1][j + 1] + 1 : Math.max(L[i + 1][j], L[i][j + 1]);
|
||||
}
|
||||
const out = x.slice(0, h).map((l) => [' ', l]);
|
||||
let i = 0;
|
||||
let j = 0;
|
||||
while (i < n && j < m) {
|
||||
if (xs[i] === ys[j]) { out.push([' ', xs[i]]); i++; j++; }
|
||||
else if (L[i + 1][j] >= L[i][j + 1]) out.push(['-', xs[i++]]);
|
||||
else out.push(['+', ys[j++]]);
|
||||
}
|
||||
while (i < n) out.push(['-', xs[i++]]);
|
||||
while (j < m) out.push(['+', ys[j++]]);
|
||||
return out.concat(x.slice(x.length - t).map((l) => [' ', l]));
|
||||
}
|
||||
|
||||
/* Changed lines with two lines of context each side; the rest folds into "…". */
|
||||
function diffHtml(a, b) {
|
||||
const d = lineDiff(a, b);
|
||||
const near = (i) => d.slice(Math.max(0, i - 2), i + 3).some((r) => r[0] !== ' ');
|
||||
let out = '';
|
||||
let gap = false;
|
||||
d.forEach((r, i) => {
|
||||
if (!near(i)) { gap = true; return; }
|
||||
if (gap && out) out += '<span class="faint">…</span>\n';
|
||||
gap = false;
|
||||
out += `<span class="${r[0] === '+' ? 'add' : r[0] === '-' ? 'del' : ''}">${esc(r[0] + ' ' + r[1])}</span>\n`;
|
||||
});
|
||||
return out ? `<pre class="diff lines" data-no-i18n>${out}</pre>` : '<div class="faint tiny">Bez zmian w treści.</div>';
|
||||
}
|
||||
|
||||
/* What a version is, as lines to compare: the description, the body, then each file by its checksum —
|
||||
a replaced .docx shows up as one changed line, not as bytes. */
|
||||
const versionText = (v) => [v.description, '', v.body, ...(v.files.length ? ['', '---'] : []),
|
||||
...v.files.map((f) => `${f.path} ${f.sha256.slice(0, 12)}`)].join('\n');
|
||||
|
||||
// Word, Excel and PDF are kept for download only in this release; nothing reads their text yet.
|
||||
const unreadFile = (path) => /\.(docx|xlsx|pdf)$/i.test(path);
|
||||
const fileNote = (path) => (unreadFile(path) ? ' <span class="faint tiny">plik do pobrania, model go jeszcze nie czyta</span>' : '');
|
||||
|
||||
async function viewSkill(C, id) {
|
||||
const s = await api('GET', '/skills/' + enc(id));
|
||||
// ponytail: one request per readable version; a versions-with-bodies endpoint if skills reach dozens.
|
||||
const vs = await Promise.all(s.versions.map((v) => api('GET', `/skills/${enc(id)}/versions/${v.n}`)));
|
||||
state._skill = s;
|
||||
state._skillLatest = vs[0] || null;
|
||||
setCrumb([{ label: 'Skille i agenci', href: '#/skills' }, { label: s.name, data: true }]);
|
||||
const shown = s.current || vs[0];
|
||||
const active = s.status !== 'archived';
|
||||
const latest = vs[0];
|
||||
const publishable = s.editable && active && latest && !(s.scope === 'firm' && latest.id === s.current_version_id);
|
||||
const acts = (s.editable && active ? `<button class="btn" onclick="openSkillEditor('${esc(s.id)}')">${svg(ICN.plus)}<span>Nowa wersja</span></button>` : '')
|
||||
+ (publishable ? `<button class="btn" onclick="publishSkill('${esc(s.id)}')"><span>Opublikuj w firmie</span></button>` : '')
|
||||
+ (vs.length ? `<a class="btn" href="${esc(API + '/skills/' + enc(s.id) + '/export')}" download><span>Eksportuj</span></a>` : '')
|
||||
+ (s.editable && active ? `<button class="btn danger" onclick="confirmTwice(this, () => archiveSkill('${esc(s.id)}'))"><span>Archiwizuj</span></button>` : '');
|
||||
const rows = vs.map((v, k) => `<tr>
|
||||
<td class="nowrap">v${esc(String(v.n))}${v.id === s.current_version_id ? ' <span class="chip ok">Aktualna</span>' : ''}</td>
|
||||
<td class="faint tiny nowrap"${lbl('Utworzona')}>${esc(fmtDateTime(v.created_at))}</td>
|
||||
<td class="wrap"${lbl('Zmiany')}>${vs[k + 1]
|
||||
? `<details><summary class="faint"><span>Różnice względem</span> v${esc(String(vs[k + 1].n))}</summary>${diffHtml(versionText(vs[k + 1]), versionText(v))}</details>`
|
||||
: '<span class="faint tiny">Pierwsza wersja</span>'}</td>
|
||||
</tr>`).join('');
|
||||
C.innerHTML = pageHead(s.name, s.slug, acts)
|
||||
+ `<div class="row" style="margin-bottom:12px">${skillChips(s)}</div>`
|
||||
+ (shown ? `<div class="card"><h3><span>Wersja</span> v${esc(String(shown.n))}</h3>
|
||||
<div class="prose" data-no-i18n>${esc(shown.description)}</div>
|
||||
<pre class="diff lines" data-no-i18n>${esc(shown.body)}</pre>
|
||||
${shown.files.length ? `<h4 class="minor">Pliki</h4><ul>${shown.files.map((f) => `<li>${dat(f.path)}${fileNote(f.path)}</li>`).join('')}</ul>` : ''}
|
||||
</div>` : '<div class="empty">Ta wersja czeka na zgodę administratora.</div>')
|
||||
+ (vs.length ? `<div class="card"><h3>Wersje<span class="n">${vs.length}</span></h3>
|
||||
<div class="tablewrap"><table class="rt"><thead><tr><th>Wersja</th><th>Utworzona</th><th>Zmiany</th></tr></thead>
|
||||
<tbody>${rows}</tbody></table></div></div>` : '');
|
||||
}
|
||||
|
||||
/* Files travel as base64 inside the version's JSON (the one route the spec allows). Picked files
|
||||
REPLACE the version's set; picking none carries the current ones over, because the console never
|
||||
holds their bytes to send them back. */
|
||||
async function filesBase64(input) {
|
||||
const out = {};
|
||||
for (const f of input.files) {
|
||||
const bytes = new Uint8Array(await f.arrayBuffer());
|
||||
let bin = '';
|
||||
for (let i = 0; i < bytes.length; i += 0x8000) bin += String.fromCharCode(...bytes.subarray(i, i + 0x8000));
|
||||
out[f.name] = btoa(bin);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
function skillFilesNote() {
|
||||
const unread = [...$('skFiles').files].map((f) => f.name).filter(unreadFile);
|
||||
$('skFilesNote').innerHTML = unread.length
|
||||
? `<span>${esc(_tr('Plik do pobrania, model go jeszcze nie czyta:'))}</span> ${dat(unread.join(', '))}`
|
||||
: '';
|
||||
}
|
||||
|
||||
function openSkillEditor(id) {
|
||||
const s = id ? state._skill : null;
|
||||
const v = id ? state._skillLatest : null;
|
||||
modal(id ? 'Nowa wersja' : 'Nowy skill', s ? s.name : '',
|
||||
(id ? '' : `<label class="field">Identyfikator<input id="skSlug" maxlength="64" placeholder="np. umowa-najmu" /></label>
|
||||
<div class="faint tiny">Małe litery, cyfry i myślniki. Nie da się go później zmienić.</div>`)
|
||||
+ `<label class="field">Nazwa<input id="skName" maxlength="200" value="${esc(s ? s.name : '')}" /></label>
|
||||
<label class="field">Opis<textarea id="skDesc" maxlength="1024" data-no-i18n>${esc(v ? v.description : '')}</textarea></label>
|
||||
<div class="faint tiny">Opis mówi modelowi, kiedy sięgnąć po ten skill.</div>
|
||||
<label class="field">Treść<textarea id="skBody" rows="14" maxlength="30000" data-no-i18n>${esc(v ? v.body : '')}</textarea></label>
|
||||
<label class="field">Pliki<input id="skFiles" type="file" multiple accept=".md,.txt,.docx,.pdf,.xlsx,.csv,.json,.yaml,.yml" onchange="skillFilesNote()" /></label>
|
||||
<div class="faint tiny">${id ? 'Wybrane pliki zastąpią obecne. Bez wyboru obecne pliki przechodzą do nowej wersji.' : 'Pliki pomocnicze, łącznie do 10 MB.'}</div>
|
||||
<div id="skFilesNote" class="faint tiny"></div>
|
||||
${v && v.files.length ? '<label class="check"><input type="checkbox" id="skDrop" /> <span>Usuń obecne pliki</span></label>' : ''}`,
|
||||
`<button class="btn" onclick="closeModal()">Anuluj</button>
|
||||
<button class="btn primary" onclick="saveSkill(${id ? `'${esc(id)}'` : ''})">Zapisz</button>`, { wide: true });
|
||||
}
|
||||
|
||||
function saveSkill(id) {
|
||||
return guard(async () => {
|
||||
const body = { name: $('skName').value.trim(), description: $('skDesc').value.trim(), body: $('skBody').value };
|
||||
if ($('skFiles').files.length) body.files = await filesBase64($('skFiles'));
|
||||
else if ($('skDrop') && $('skDrop').checked) body.files = {};
|
||||
if (id) {
|
||||
await mutate('POST', `/skills/${enc(id)}/versions`, body, { done: 'Zapisano nową wersję.' });
|
||||
} else {
|
||||
body.slug = $('skSlug').value.trim();
|
||||
await mutate('POST', '/skills', body, { done: 'Skill utworzony.', go: (r) => '#/skills/skill/' + enc(r.id) });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function publishSkill(id) {
|
||||
mutate('POST', `/skills/${enc(id)}/publish`, undefined, {
|
||||
done: (r) => (r.status === 'pending' ? 'Wysłano do zatwierdzenia przez administratora.' : 'Opublikowano w firmie.'),
|
||||
});
|
||||
}
|
||||
|
||||
function archiveSkill(id) {
|
||||
mutate('POST', `/skills/${enc(id)}/archive`, undefined, { done: 'Zarchiwizowano.' });
|
||||
}
|
||||
|
||||
function openTokenNew() {
|
||||
const policy = tokenPolicy();
|
||||
const max = policy.max_idle_days || 365;
|
||||
@@ -2524,12 +2708,12 @@ function guard(fn) {
|
||||
/* Every write behind a button: send it, confirm it, then show the outcome. By default any dialog
|
||||
closes and the page re-renders, and the router re-reads what api() marked stale. `go(result)` returns
|
||||
a hash to navigate to instead; `reopen(result)` redraws a dialog that stays open; `done` replaces the
|
||||
confirmation. `body` may be a function, so a form reader that refuses input (orderValue) reports
|
||||
confirmation (or is a function of the result, when the outcome decides the wording). `body` may be a function, so a form reader that refuses input (orderValue) reports
|
||||
through the same error path. */
|
||||
function mutate(method, path, body, { go, reopen, done = 'Zapisano.' } = {}) {
|
||||
return guard(async () => {
|
||||
const result = await api(method, path, typeof body === 'function' ? body() : body);
|
||||
toast(done);
|
||||
toast(typeof done === 'function' ? done(result) : done);
|
||||
// A dialog that stays open means no navigation to re-read the shared state, so read it here.
|
||||
if (reopen) { await Promise.all([reopen(result), refreshShared()]); return; }
|
||||
closeModal();
|
||||
|
||||
Reference in New Issue
Block a user