gui: a new partner puts a still dot on Providers in the sidebar
yetone: 有新的合作伙伴的时候,侧边栏这个地方是否也应该有一个精致优雅的点来提醒 用户一下呀?…就是不要太打扰用户。 markNewPartners now lights Providers in the nav (window mode) together with the add button's dot: the same has-dot Plugins uses for an update (6px at the sidebar row's end, 5px at a tab's corner, accent, no animation), titled with the new partners' names. It goes out with the add button's dot, when the add sheet has shown the partners. prefetchProviders calls it once the background read lands, so an app opened on another page shows it too. Run at81a58d2f3+ this change (rebased, the pushed tree): - partners.test.cjs, chromium + webkit: 38 of 38 (new: nav dot at 1280 sidebar and 900 tabs, en + zh, opened on ?view=agents, gone after the sheet and after a reload; the add-button tests also check the nav). With app.js reverted: the 8 dot tests per engine red (18 fail). - plugin-updates, provider-add-gemini, partners alone: 80 of 80. - The 66 GUI files naming has-dot / has-new / addProvider / side-nav plus i18n-keys, concurrency 4 at load ~48: 877 of 894. Reds: builtins and sidebar (masking tab, the same on an origin/main81a58d2f3copy, #3498); plugin-updates de 1024 (#3633) and provider-add-gemini webkit 420px (#3634), both green alone and on the main copy. - Screenshots of the sidebar, light and dark, at 1280: the dot sits at the Providers row's end like Plugins'. Not run: the whole 893-file GUI suite (another session's GUI suite was on the machine); the real Wails app.
This commit is contained in:
@@ -5819,7 +5819,7 @@ let providersEarly = null;
|
||||
function prefetchProviders() {
|
||||
if (providers || providersEarly) return;
|
||||
const e = providersEarly = { read: api("providers") };
|
||||
e.read.then((s) => { e.got = s; }, () => { if (providersEarly === e) providersEarly = null; });
|
||||
e.read.then((s) => { e.got = s; markNewPartners(); }, () => { if (providersEarly === e) providersEarly = null; });
|
||||
}
|
||||
|
||||
// The page's first reading, while it is on its way, is the one every ask
|
||||
@@ -7632,14 +7632,20 @@ function countPartner(what, ids) {
|
||||
|
||||
// a partner listed since the add sheet last showed the partners puts a
|
||||
// small dot on the add button, its name in the button's title, until the
|
||||
// sheet shows it (yetone: 有了新的合作伙伴的时候…提醒吸引用户点击查看)
|
||||
// sheet shows it (yetone: 有了新的合作伙伴的时候…提醒吸引用户点击查看),
|
||||
// and a still one on Providers in the sidebar, as Plugins has for an
|
||||
// update, so it is seen from any page (yetone: 侧边栏…不要太打扰用户)
|
||||
function markNewPartners() {
|
||||
const b = $("#addProvider");
|
||||
if (!b) return;
|
||||
const fresh = adding ? [] : (providers?.presets || []).filter((p) => p.kind === "partner" && p.new && !p.added && partnerShown(p));
|
||||
b.classList.toggle("has-new", fresh.length > 0);
|
||||
if (fresh.length) b.title = t("New in Partners: {names}", { names: fresh.map((p) => p.name).join(", ") });
|
||||
else b.removeAttribute("title");
|
||||
const list = providers || providersEarly?.got;
|
||||
const fresh = adding ? [] : (list?.presets || []).filter((p) => p.kind === "partner" && p.new && !p.added && partnerShown(p));
|
||||
const title = fresh.length ? t("New in Partners: {names}", { names: fresh.map((p) => p.name).join(", ") }) : "";
|
||||
const nav = mode === "window" && document.querySelector('#nav button[data-view="providers"]');
|
||||
for (const [b, cls] of [[$("#addProvider"), "has-new"], [nav, "has-dot"]]) {
|
||||
if (!b) continue;
|
||||
b.classList.toggle(cls, fresh.length > 0);
|
||||
if (title) b.title = title;
|
||||
else b.removeAttribute("title");
|
||||
}
|
||||
}
|
||||
|
||||
// partners new when the sheet showed them, each dotted until opened, this
|
||||
|
||||
@@ -170,11 +170,17 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
const dot = await add.evaluate((b) => { const s = getComputedStyle(b, "::after"); const r = b.getBoundingClientRect(); return { w: s.width, h: s.height, bg: s.backgroundColor, over: b.scrollWidth > b.clientWidth + 1, right: r.right <= innerWidth }; });
|
||||
assert.deepEqual([dot.w, dot.h, dot.over, dot.right], ["6px", "6px", false, true]);
|
||||
assert.notEqual(dot.bg, "rgba(0, 0, 0, 0)");
|
||||
// Providers in the sidebar has the same news, a still dot
|
||||
const nav = page.locator('#nav button[data-view="providers"]');
|
||||
assert.equal(await nav.evaluate((b) => b.classList.contains("has-dot")), true);
|
||||
assert.equal(await nav.getAttribute("title"), title);
|
||||
|
||||
// the sheet shows them: no dot, then or after the page comes back
|
||||
await add.click();
|
||||
await page.locator("#addSheet .tile").first().waitFor();
|
||||
assert.equal(await add.evaluate((b) => b.classList.contains("has-new")), false);
|
||||
assert.equal(await nav.evaluate((b) => b.classList.contains("has-dot")), false);
|
||||
assert.equal(await nav.getAttribute("title"), null);
|
||||
// each new partner's tile has its own dot, inside the tile, and one
|
||||
// listed only in another language isn't there to have one
|
||||
const tileDots = () => page.locator("#addSheet .tile").evaluateAll((ts) => ts.filter((x) => x.querySelector(".new-dot")).map((x) => {
|
||||
@@ -223,6 +229,45 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
await page.context().close();
|
||||
});
|
||||
}
|
||||
// the app opened on another page reads the list in the background and
|
||||
// dots Providers in the sidebar from it: small, still, inside the row,
|
||||
// in the accent; the page opened keeps it until the sheet shows them
|
||||
// 1280 has the sidebar, 900 the header's tabs
|
||||
for (const lang of ["en", "zh"]) for (const width of [1280, 900]) await t.test(`new partner dot in the nav ${lang} ${width}`, async () => {
|
||||
const page = await (await browser.newContext({ viewport: { width, height: 800 } })).newPage();
|
||||
const errors = [];
|
||||
page.on("pageerror", (e) => errors.push(e.message));
|
||||
const counted = [];
|
||||
await page.route("**/*", server(lang, partners.map((p) => ({ ...p, new: true })), counted));
|
||||
await page.goto("http://magpie.test/?view=agents");
|
||||
const nav = page.locator('#nav button[data-view="providers"]');
|
||||
await nav.waitFor();
|
||||
await page.waitForFunction(() => document.querySelector('#nav button[data-view="providers"]').classList.contains("has-dot"));
|
||||
assert.equal(await nav.getAttribute("title"), lang === "en" ? "New in Partners: Acme AI" : "合作伙伴有新成员:Acme AI, China Only");
|
||||
const dot = await nav.evaluate((b) => {
|
||||
const s = getComputedStyle(b, "::after"), r = b.getBoundingClientRect();
|
||||
return { side: document.body.classList.contains("side-nav"), w: s.width, h: s.height, bg: s.backgroundColor, anim: s.animationName, inside: parseFloat(s.right) + parseFloat(s.width) <= r.width };
|
||||
});
|
||||
const px = width === 1280 ? "6px" : "5px";
|
||||
assert.deepEqual([dot.side, dot.w, dot.h, dot.anim, dot.inside], [width === 1280, px, px, "none", true]);
|
||||
assert.notEqual(dot.bg, "rgba(0, 0, 0, 0)");
|
||||
await nav.click();
|
||||
const add = page.locator("#addProvider");
|
||||
await add.waitFor();
|
||||
assert.equal(await nav.evaluate((b) => b.classList.contains("has-dot")), true);
|
||||
await add.click();
|
||||
await page.locator("#addSheet .tile").first().waitFor();
|
||||
assert.equal(await nav.evaluate((b) => b.classList.contains("has-dot")), false);
|
||||
await page.keyboard.press("Escape");
|
||||
await page.locator("#addSheet").waitFor({ state: "hidden" });
|
||||
// read again, the list says they were shown
|
||||
await page.reload();
|
||||
await nav.waitFor();
|
||||
await page.waitForTimeout(300);
|
||||
assert.equal(await nav.evaluate((b) => b.classList.contains("has-dot")), false);
|
||||
assert.deepEqual(errors, []);
|
||||
await page.context().close();
|
||||
});
|
||||
await t.test("no partners, no heading", async () => {
|
||||
const page = await (await browser.newContext({ viewport: { width: 900, height: 800 } })).newPage();
|
||||
await page.route("**/*", server("en", []));
|
||||
|
||||
Reference in New Issue
Block a user