panel: profiles open from Profiles at the Agents tab's foot, on its left, instead of a tab of their own (Image #65: tray window 中方案不应该有一个单独的 tab,在 Agents tab 左下角有个方案即可) — the tray panel's tabs are Agents and Routing; the footer's left corner, on the Agents tab only, has Profiles (方案) with how many there are, and a click opens them upward over the list as a popover (the .pop look and fade, reduced motion kept): the chips, + Save current and its name field as before, the popover scrolling within itself when there are many, sized between the tabs and the footer. A click outside, Escape (the name field's Escape closes the field alone first), another tab or a profile applied closes it; the list under it is never moved. A remembered Profiles tab opens Agents. fit() no longer measures the profiles. Tested: panel-profiles.test.cjs reworked (no Profiles tab; the popover above the button at the foot's left and under the tabs, the count shown; scrolling to + Save current inside it, the field whole and nothing moving; Escape, outside click, Routing tab and applying a profile close it; Profiles only on Agents) and old-webkit.test.cjs opening it before Save, in Chromium and WebKit, en and zh. Screenshots looked at in light and dark, en and zh. go build -tags nogui (and GOOS=linux, GOOS=windows), go test -tags nogui ./... and the GUI suite pass (click-scroll, panel-profiles, panel-routing and routing-kind failed under --test-concurrency=4 and pass alone). Not tried in the real Wails window.
This commit is contained in:
@@ -720,10 +720,9 @@ body.panel .view { padding-top: 2px; }
|
||||
.ptabs button.on { color: var(--fg); font-weight: 550; }
|
||||
.ptabs button[hidden] { display: none; }
|
||||
.ptabs em { font-style: normal; font-weight: 400; color: var(--faint); font-variant-numeric: tabular-nums; }
|
||||
body.panel[data-ptab="usage"] :is(#agents, .profiles, #panelRouting),
|
||||
body.panel[data-ptab="routing"] :is(#agents, .profiles, #panelQuota),
|
||||
body.panel[data-ptab="profiles"] :is(#agents, #panelQuota, #panelRouting),
|
||||
body.panel[data-ptab="agents"] :is(.profiles, #panelQuota, #panelRouting) { display: none; }
|
||||
body.panel[data-ptab="usage"] :is(#agents, #panelRouting),
|
||||
body.panel[data-ptab="routing"] :is(#agents, #panelQuota),
|
||||
body.panel[data-ptab="agents"] :is(#panelQuota, #panelRouting) { display: none; }
|
||||
|
||||
/* ---- the panel's agents: one quiet line each, opened in place ------------ */
|
||||
/* icon · name · model · effort · chevron, the last three in columns of their
|
||||
@@ -800,10 +799,25 @@ body.panel .agent-fold-cap { padding-left: 12px; }
|
||||
/* "Show 9 more", the list's last line, where the names start */
|
||||
body.panel .agent-more { justify-content: flex-start; gap: 6px; padding: 9px 14px; }
|
||||
|
||||
/* ---- the panel's profiles tab ---------------------------------------------- */
|
||||
/* ---- the panel's profiles: Profiles at the Agents tab's foot, left, opens
|
||||
them over the list, upward from it ------------------------------------------ */
|
||||
.prof-btn { display: inline-flex; align-items: center; gap: 4px; margin-left: -7px; }
|
||||
.prof-btn em { font-style: normal; color: var(--faint); font-variant-numeric: tabular-nums; }
|
||||
.prof-btn[aria-expanded="true"] { color: var(--fg); background: var(--pill-hover); }
|
||||
body.panel:not([data-ptab="agents"]) .prof-btn { display: none; }
|
||||
body.panel .foot .status { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
body.panel .profiles { display: none; }
|
||||
/* the chips a line of their own; a name field opened goes beside the button */
|
||||
body.panel .profiles { flex-wrap: wrap; align-items: center; gap: 8px; padding: 2px 0; }
|
||||
body.panel .profiles > .label { display: none; }
|
||||
body.panel .profiles.open {
|
||||
display: flex; position: fixed; z-index: 30; left: 8px; width: min(360px, calc(100vw - 16px)); min-height: 0;
|
||||
flex-wrap: wrap; align-items: center; align-content: flex-start; gap: 8px; padding: 10px; overflow-y: auto; overscroll-behavior: contain;
|
||||
background: var(--pop-bg); -webkit-backdrop-filter: blur(24px); backdrop-filter: blur(24px);
|
||||
border: 1px solid var(--line); border-radius: 11px; box-shadow: var(--shadow);
|
||||
transform-origin: 24px bottom; --pop-dy: 6px;
|
||||
animation: pop-fade .18s ease-out, pop-in .42s cubic-bezier(.16, 1, .3, 1);
|
||||
}
|
||||
@media (prefers-reduced-motion: reduce) { body.panel .profiles.open { animation: pop-fade .12s ease-out; } }
|
||||
body.panel .profiles > .label { display: block; flex: 1 1 100%; padding: 0 2px; }
|
||||
body.panel .profiles .chips { flex: 1 1 100%; flex-wrap: wrap; }
|
||||
body.panel .profiles .chips .hint { white-space: normal; line-height: 1.4; padding: 0 4px; color: var(--muted); }
|
||||
body.panel .profiles.naming .chips .hint { display: none; }
|
||||
|
||||
@@ -440,6 +440,7 @@ function renderProfiles() {
|
||||
$(".profiles > .chip-input")?.remove(); // a name field open goes with the list it was for
|
||||
$(".profiles").classList.remove("naming");
|
||||
$("#save").textContent = t("+ Save current");
|
||||
$("#profN").textContent = state.profiles.length || "";
|
||||
if (!state.profiles.length) chips.append(el("span", "hint", t("none yet · save the setup to switch back in one click")));
|
||||
for (const p of state.profiles) {
|
||||
const c = el("button", "chip");
|
||||
@@ -953,7 +954,7 @@ function fit(extra = 0, glide) {
|
||||
const body = document.body, tab = body.dataset.ptab;
|
||||
delete body.dataset.ptab;
|
||||
// extra is only ever the agents' (a row opening, the scroll unrolling)
|
||||
const tallest = Math.max($("#agents").offsetHeight + extra, $(".profiles").offsetHeight, $("#panelQuota").offsetHeight, $("#panelRouting").offsetHeight);
|
||||
const tallest = Math.max($("#agents").offsetHeight + extra, $("#panelQuota").offsetHeight, $("#panelRouting").offsetHeight);
|
||||
if (tab) body.dataset.ptab = tab;
|
||||
const h = $(".top").offsetHeight + $("#ptabs").offsetHeight + tallest + $(".foot").offsetHeight + 4;
|
||||
if (h === fit.last) return;
|
||||
@@ -1604,6 +1605,7 @@ async function profileAction(action, name, update) {
|
||||
state = data;
|
||||
renderAgents();
|
||||
if (action === "use") {
|
||||
closeProfiles(); // the agents, as they are now, in sight
|
||||
let msg = t(data.changed === 1 ? "{name} applied · {n} setting changed" : "{name} applied · {n} settings changed", { name, n: data.changed });
|
||||
const lib = data.library;
|
||||
if (lib?.missing?.length) msg += " · " + t("skipped, no longer in the Library: {names}", { names: lib.missing.map((m) => m.replace(/^\w+:/, "")).join(", ") });
|
||||
@@ -5221,16 +5223,49 @@ function planSpan(q) {
|
||||
return s;
|
||||
}
|
||||
|
||||
// The tray panel is four tabs over the one page: the agents, the allowances
|
||||
// of every subscription and key (the "usage" tab, as it was named before),
|
||||
// the gateway's latest requests (routing.js draws those) and the saved
|
||||
// profiles. The tab is remembered.
|
||||
// The tray panel is three tabs over the one page: the agents, the allowances
|
||||
// of every subscription and key (the "usage" tab, as it was named before)
|
||||
// and the gateway's latest requests (routing.js draws those). The saved
|
||||
// profiles open from Profiles at the Agents tab's foot, over the list (a tab
|
||||
// of their own was one too many). The tab is remembered.
|
||||
const profBtn = $("#profBtn"), profBox = $(".profiles");
|
||||
function placeProfiles() {
|
||||
if (!profBox.classList.contains("open")) return;
|
||||
const r = profBtn.getBoundingClientRect(), top = $("#ptabs").getBoundingClientRect().bottom;
|
||||
profBox.style.bottom = Math.round(innerHeight - r.top + 6) + "px";
|
||||
profBox.style.maxHeight = Math.max(120, Math.round(r.top - 6 - top - 4)) + "px";
|
||||
}
|
||||
function openProfiles() {
|
||||
profBox.classList.add("open");
|
||||
profBtn.setAttribute("aria-expanded", "true");
|
||||
placeProfiles();
|
||||
}
|
||||
function closeProfiles() {
|
||||
if (!profBox.classList.contains("open")) return;
|
||||
profBox.classList.remove("open");
|
||||
profBtn.setAttribute("aria-expanded", "false");
|
||||
const f = $(".profiles > .chip-input");
|
||||
if (f) closeSave(f);
|
||||
}
|
||||
if (mode === "panel") {
|
||||
profBtn.hidden = false;
|
||||
document.body.append(profBox); // over the page, not in the list's scroll
|
||||
profBtn.onclick = () => profBox.classList.contains("open") ? closeProfiles() : openProfiles();
|
||||
document.addEventListener("mousedown", (e) => {
|
||||
if (profBox.classList.contains("open") && !profBox.contains(e.target) && !profBtn.contains(e.target)) closeProfiles();
|
||||
}, true);
|
||||
// the name field's Escape is its own (it stops there)
|
||||
document.addEventListener("keydown", (e) => { if (e.key === "Escape" && profBox.classList.contains("open")) { closeProfiles(); profBtn.focus({ preventScroll: true }); } });
|
||||
addEventListener("resize", placeProfiles);
|
||||
}
|
||||
let panelTab = "agents";
|
||||
try { panelTab = localStorage.getItem("magpie.panelTab") || "agents"; } catch {}
|
||||
function setPanelTab(tab) {
|
||||
const tabs = $("#ptabs");
|
||||
// no usage to show, no tab for it
|
||||
if (tabs.querySelector(`[data-ptab="${tab}"]`)?.hidden) tab = "agents";
|
||||
// no usage to show, no tab for it (nor for profiles: they open from the foot)
|
||||
const b = tabs.querySelector(`[data-ptab="${tab}"]`);
|
||||
if (!b || b.hidden) tab = "agents";
|
||||
closeProfiles();
|
||||
panelTab = tab;
|
||||
try { localStorage.setItem("magpie.panelTab", tab); } catch {}
|
||||
document.body.dataset.ptab = tab;
|
||||
|
||||
@@ -47,7 +47,6 @@
|
||||
<button type="button" data-ptab="agents"><span data-t>Agents</span><em id="ptabN"></em></button>
|
||||
<button type="button" data-ptab="usage"><span data-t>Allowances</span></button>
|
||||
<button type="button" data-ptab="routing"><span data-t>Routing</span></button>
|
||||
<button type="button" data-ptab="profiles"><span data-t>Profiles</span></button>
|
||||
</nav>
|
||||
|
||||
<main class="view" id="view-agents">
|
||||
@@ -243,6 +242,7 @@
|
||||
</main>
|
||||
|
||||
<footer class="foot">
|
||||
<button type="button" class="text prof-btn" id="profBtn" hidden aria-haspopup="dialog" aria-expanded="false"><span data-t>Profiles</span><em id="profN"></em></button>
|
||||
<span id="pqAge" class="pq-age" hidden></span>
|
||||
<span id="status" class="status"></span>
|
||||
<span class="grow"></span>
|
||||
|
||||
@@ -212,11 +212,12 @@ test("with Safari 15.0's built-ins, the panel and the window draw every page", a
|
||||
assert.equal(await page.evaluate(() => [1, 2, 3].at(-1)), 3);
|
||||
if (mode === "panel") {
|
||||
assert(await page.locator("#ptabs").isVisible(), "the panel's tabs are the page's own, drawn by app.js");
|
||||
for (const tab of ["usage", "routing", "agents", "profiles"]) {
|
||||
for (const tab of ["usage", "routing", "agents"]) {
|
||||
const b = page.locator(`#ptabs [data-ptab="${tab}"]`);
|
||||
if (await b.isVisible()) await b.click();
|
||||
await page.waitForTimeout(150);
|
||||
}
|
||||
await page.locator("#profBtn").click();
|
||||
await page.locator("#save").click();
|
||||
assert(await page.locator(".profiles.naming > .chip-input").isVisible(), "Save current opens the name field");
|
||||
} else {
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
// Run with Node's test runner and Playwright on the module path; see README.md.
|
||||
// Saving the current setup as a profile in the tray panel's Profiles tab:
|
||||
// The tray panel's profiles open from Profiles at the Agents tab's foot, on
|
||||
// its left, over the list and upward from it (the user: tray window 中方案不
|
||||
// 应该有一个单独的 tab,在 Agents tab 左下角有个方案即可): no Profiles tab; the
|
||||
// button shows how many there are, only on the Agents tab; a click outside,
|
||||
// Escape, another tab or a profile applied closes them.
|
||||
// Saving the current setup as a profile there:
|
||||
// "+ Save current", with the list scrolled to its end, opens a name field
|
||||
// beside it without moving the list (the field at the list's head drew it
|
||||
// up under the tabs, the field's top cut off) and with one ring, not the
|
||||
@@ -49,6 +54,7 @@ function server(lang, saved, { count = 30, delay = 0, refuse = "" } = {}) {
|
||||
profiles = profiles.filter((p) => p.name !== name);
|
||||
return route.fulfill({ json: state() });
|
||||
}
|
||||
if (url.pathname === "/api/profile/use") return route.fulfill({ json: { ...state(), changed: 1 } });
|
||||
if (url.pathname === "/api/usage/quotas") return route.fulfill({ json: [] });
|
||||
if (url.pathname === "/api/groups") return route.fulfill({ json: { groups: [] } });
|
||||
if (url.pathname === "/api/providers") return route.fulfill({ json: { providers: [], gateway: { running: true } } });
|
||||
@@ -80,12 +86,14 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
page.on("pageerror", (e) => errors.push(e.message));
|
||||
await page.route("**/*", server(lang, saved, opts));
|
||||
await page.goto("http://magpie.test/?mode=panel");
|
||||
await page.locator("#profiles .chip, #profiles .hint").first().waitFor({ state: "attached" }); // shown with the tab
|
||||
await page.locator('[data-ptab="profiles"]').click();
|
||||
await page.waitForTimeout(300);
|
||||
await page.locator("#profiles .chip, #profiles .hint").first().waitFor({ state: "attached" });
|
||||
assert.equal(await page.locator('[data-ptab="profiles"]').count(), 0, "no Profiles tab");
|
||||
await page.locator("#profBtn").click();
|
||||
await page.locator(".profiles.open").waitFor();
|
||||
await page.waitForTimeout(450);
|
||||
return page;
|
||||
};
|
||||
const view = (page) => page.locator("#view-agents").evaluate((v) => v.scrollTop);
|
||||
const view = (page) => page.locator(".profiles").evaluate((v) => v.scrollTop);
|
||||
|
||||
for (const [lang, add, save] of [["en", "+ Save current", "Save"], ["zh", "+ 保存当前", "保存"]]) {
|
||||
await t.test(lang, async () => {
|
||||
@@ -94,9 +102,19 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
const button = page.locator("#save");
|
||||
assert.equal((await button.textContent()).trim(), add);
|
||||
|
||||
// over the list, upward from the button at its foot's left, the list
|
||||
// left where it was
|
||||
const pos = await page.evaluate(() => {
|
||||
const p = document.querySelector(".profiles").getBoundingClientRect(), b = document.querySelector("#profBtn").getBoundingClientRect();
|
||||
const f = document.querySelector(".foot").getBoundingClientRect(), tabs = document.querySelector("#ptabs").getBoundingClientRect();
|
||||
return { above: p.bottom <= b.top, near: b.top - p.bottom < 12, left: Math.abs(p.left - b.left) < 16 && b.left - f.left < 20, under: p.top >= tabs.bottom, count: document.querySelector("#profBtn").textContent, agents: getComputedStyle(document.querySelector("#agents")).display };
|
||||
});
|
||||
assert(pos.above && pos.near && pos.left && pos.under, JSON.stringify(pos));
|
||||
assert.match(pos.count, new RegExp(`${lang === "zh" ? "方案" : "Profiles"}\\s*30`));
|
||||
assert.notEqual(pos.agents, "none", "the agents stay under them");
|
||||
// the reader scrolls to the button; the field opens beside it, whole,
|
||||
// with one ring, and nothing moves
|
||||
const box = await page.locator("#view-agents").boundingBox();
|
||||
const box = await page.locator(".profiles").boundingBox();
|
||||
await page.mouse.move(box.x + box.width / 2, box.y + 60);
|
||||
for (let i = 0; i < 20; i++) { await page.mouse.wheel(0, 40); await page.waitForTimeout(20); }
|
||||
await page.waitForTimeout(400);
|
||||
@@ -108,7 +126,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
await page.waitForTimeout(300);
|
||||
assert.equal(await view(page), before, "opening the field must not scroll the list");
|
||||
const cut = await page.evaluate(() => {
|
||||
const v = document.querySelector("#view-agents").getBoundingClientRect(), f = document.querySelector(".profiles > .chip-input");
|
||||
const v = document.querySelector(".profiles").getBoundingClientRect(), f = document.querySelector(".profiles > .chip-input");
|
||||
const inView = (e) => { const r = e.getBoundingClientRect(); return r.top >= v.top + 1 && r.bottom <= v.bottom; };
|
||||
return { field: inView(f), button: inView(document.querySelector("#save")), outline: getComputedStyle(f).outlineStyle, focused: document.activeElement === f };
|
||||
});
|
||||
@@ -145,6 +163,27 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
await field.press("Escape");
|
||||
assert.equal(await field.count(), 0);
|
||||
assert.equal((await button.textContent()).trim(), add);
|
||||
assert(await page.locator(".profiles.open").isVisible(), "Escape in the field closes the field alone");
|
||||
|
||||
// Escape closes them, the button opens them again, a click outside
|
||||
// closes them, and so does another tab (where the button isn't)
|
||||
await page.keyboard.press("Escape");
|
||||
assert.equal(await page.locator(".profiles.open").count(), 0);
|
||||
await page.locator("#profBtn").click();
|
||||
await page.locator(".profiles.open").waitFor();
|
||||
await page.mouse.click(420, 150);
|
||||
assert.equal(await page.locator(".profiles.open").count(), 0);
|
||||
await page.locator("#profBtn").click();
|
||||
await page.locator('[data-ptab="routing"]').click();
|
||||
assert.equal(await page.locator(".profiles.open").count(), 0);
|
||||
assert(!(await page.locator("#profBtn").isVisible()), "Profiles is the Agents tab's");
|
||||
await page.locator('[data-ptab="agents"]').click();
|
||||
assert(await page.locator("#profBtn").isVisible());
|
||||
|
||||
// a profile applied closes them, the agents in sight
|
||||
await page.locator("#profBtn").click();
|
||||
await page.locator('#profiles .chip:has-text("profile-1")').first().click();
|
||||
await page.waitForFunction(() => !document.querySelector(".profiles.open"));
|
||||
});
|
||||
|
||||
await t.test(lang + ": a slow magpie, from none", async () => {
|
||||
@@ -153,7 +192,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
const button = page.locator("#save"), field = page.locator(".profiles > .chip-input");
|
||||
const chip = (name) => page.locator("#profiles .chip", { hasText: name });
|
||||
const where = () => page.evaluate(() => {
|
||||
const v = document.querySelector("#view-agents"), tabs = document.querySelector("#ptabs").getBoundingClientRect();
|
||||
const v = document.querySelector(".profiles"), tabs = document.querySelector("#ptabs").getBoundingClientRect();
|
||||
const c = document.querySelector("#profiles .chip");
|
||||
return { scroll: v.scrollTop, below: !c || c.getBoundingClientRect().top >= tabs.bottom, status: document.querySelector("#status").textContent };
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user