From 2035f9f476bbbe53a29020183e6fdfc6cf468922 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=85=E8=86=80?= Date: Sat, 17 Oct 2026 13:06:45 +0800 Subject: [PATCH] feat(console): prioritize group titles over actions Place New Route after Reorder in the group bar. Measure available space and remove the reorder label first, then the creation label, before truncating the group title; remeasure on resize, locale and font changes. --- app/components/ConsolePage.vue | 186 ++++++++++++++++++++++++++++----- 1 file changed, 160 insertions(+), 26 deletions(-) diff --git a/app/components/ConsolePage.vue b/app/components/ConsolePage.vue index b132339..a905fb5 100644 --- a/app/components/ConsolePage.vue +++ b/app/components/ConsolePage.vue @@ -63,11 +63,6 @@ {{ t("metrics.refresh") }} - {{ t("app.newRoute") }} @@ -104,9 +99,13 @@ /> + + +

{{ t("routes.reorderHint") }}

+ + -

{{ t("routes.reorderHint") }}

{{ groupRoutesError }}

@@ -214,7 +247,7 @@ t("status.loading") }} {{ t("app.newGroup") }} r.id !== groupRoutes.value[i]?.id), ); +const canCreateRoute = computed( + () => + !needLogin.value && + !!selectedGroup.value && + canEditRoutes(selectedGroup.value.id) && + !reordering.value, +); const canReorder = computed( () => !!selectedGroup.value && canEditRoutes(selectedGroup.value.id) && groupRoutes.value.length > 1, ); +/** + * Labels of the group bar's buttons, given up so the group name stays whole: + * first Reorder turns into an icon, then New route; only with both on icons + * may a long name be cut short. + */ +const barLabels = ref<"all" | "new" | "none">("all"); +const groupBarEl = ref(null); +const groupNameEl = ref(null); +const barSizerEl = ref(null); + +function fitBarLabels(): void { + const bar = groupBarEl.value; + const name = groupNameEl.value; + const sizer = barSizerEl.value; + if (!bar || !name || !sizer) return; + // Fractional widths throughout: a rounded pixel decides whether a name fits. + const px = (value: string): number => parseFloat(value) || 0; + const gap = (el: Element | null): number => (el ? px(getComputedStyle(el).columnGap) : 0); + const width = (el: Element | Range | null | undefined): number => + el?.getBoundingClientRect().width ?? 0; + const barStyle = getComputedStyle(bar); + const room = + width(bar) - + px(barStyle.paddingLeft) - + px(barStyle.paddingRight) - + px(barStyle.borderLeftWidth) - + px(barStyle.borderRightWidth) - + 1; + // The whole name (its text, not the ellipsis box) plus the count after it. + const text = document.createRange(); + text.selectNodeContents(name); + const count = name.nextElementSibling; + const heading = width(text) + (count ? gap(name.parentElement) + width(count) : 0); + const full = (key: string): number => width(sizer.querySelector(`[data-size="${key}"]`)); + // An icon-only button is a 2rem square (see `.labels-*` below). + const icon = 2 * px(getComputedStyle(document.documentElement).fontSize); + const reorder = full("reorder"); + const create = full("new"); + const actionsGap = gap(bar.querySelector(".console-context-actions")); + const fits = (widths: number[]): boolean => { + const shown = widths.filter((w) => w > 0); + const actions = shown.reduce((sum, w) => sum + w, 0) + (shown.length - 1) * actionsGap; + return heading + px(barStyle.columnGap) + actions <= room; + }; + if (fits([reorder, create])) barLabels.value = "all"; + else if (fits([reorder && icon, create])) barLabels.value = "new"; + else barLabels.value = "none"; +} + +let barObserver: ResizeObserver | undefined; +watch(groupBarEl, (bar) => { + barObserver?.disconnect(); + if (!bar || typeof ResizeObserver === "undefined") return; + barObserver = new ResizeObserver(() => fitBarLabels()); + barObserver.observe(bar); +}); +watch( + () => [ + selectedGroup.value?.name, + groupRoutes.value.length, + locale.value, + canReorder.value, + canCreateRoute.value, + reordering.value, + ], + () => nextTick(fitBarLabels), +); +onMounted(() => document.fonts?.ready.then(fitBarLabels)); +onBeforeUnmount(() => barObserver?.disconnect()); + +const canCreateGroup = computed( + () => !needLogin.value && !routeGroupId.value && view.value === "groups" && isSuper.value, +); + const logFilterGroup = ref(""); const auditFilterGroup = ref(""); const metricsFilterGroup = ref(""); @@ -1178,6 +1292,33 @@ async function onDeleteGroup(group: Group): Promise { .console-group-bar .console-context-actions { flex: none; } +/* Labels given up for the name (see fitBarLabels): an icon-only button + turns into a 2rem square. */ +.labels-new .console-reorder-label, +.labels-none .console-reorder-label, +.labels-none .console-new-route-label { + display: none; +} +.labels-new .console-reorder-btn, +.labels-none .console-reorder-btn, +.labels-none .console-new-route-btn { + width: 2rem; + padding-inline: 0; +} +/* Measures the buttons with their labels without showing or overflowing. */ +.console-bar-sizer { + position: absolute; + top: 0; + left: 0; + display: flex; + width: 100%; + overflow: hidden; + visibility: hidden; + pointer-events: none; +} +.console-bar-sizer > * { + flex: none; +} .console-context-bar .console-reorder-hint { flex-basis: 100%; font-size: 0.78rem; @@ -1233,13 +1374,6 @@ async function onDeleteGroup(group: Group): Promise { } } @media (max-width: 620px) { - .console-reorder-label { - display: none; - } - .console-reorder-btn { - width: 2rem; - padding-inline: 0; - } /* Title left with theme/language pinned top-right; page actions below, right-aligned. */ .console-topbar { display: grid;