Порівняти коміти

...
Автор SHA1 Повідомлення Дата
l0ng-ai 3c8e95e658 fix(run): show configuration types in the UI language in Add New Configuration
The type picker and the Templates list showed each type's English label while the form showed the translation. Rows now carry the translated label, which is also what the list sorts and searches by.
2026-11-30 14:54:29 +08:00
3 змінених файлів з 49 додано та 13 видалено

No files matched your search

+34 -12
Переглянути файл
@@ -13,32 +13,48 @@ import {
type PopupAnchor,
} from "@/ui";
import { useRowHeight } from "@/ui/density";
import { useTx } from "@/platform/i18n";
import { useRunConfigTypes, runConfigTypes, type RunConfigTypeContribution } from "@/workbench/contributions";
import styles from "./Run.module.css";
export type TypeRow =
| { kind: "group"; key: string; label: string }
| { kind: "type"; key: string; type: RunConfigTypeContribution; indices: number[] | null; nested: boolean };
| {
kind: "type";
key: string;
type: RunConfigTypeContribution;
/** The type's label in the UI language: what the row shows and the query matches. */
label: string;
indices: number[] | null;
nested: boolean;
};
const ROW = 24;
/** "Add New Configuration" rows: types by label, grouped ones under their group; filtered by `query`. */
export function typeRows(types: readonly RunConfigTypeContribution[], query: string): TypeRow[] {
/**
* "Add New Configuration" rows: types by label, grouped ones under their group; filtered by `query`. Labels and groups
* go through `translate` first, so the list is sorted, shown and searched in the UI language.
*/
export function typeRows(
types: readonly RunConfigTypeContribution[],
query: string,
translate: (text: string) => string = (text) => text,
): TypeRow[] {
const q = query.trim();
const match = (t: RunConfigTypeContribution) =>
q ? (fuzzyMatch(t.label, q) ?? (t.group && fuzzyMatch(t.group, q) ? [] : null)) : null;
q ? (fuzzyMatch(translate(t.label), q) ?? (t.group && fuzzyMatch(translate(t.group), q) ? [] : null)) : null;
const rows: TypeRow[] = [];
const groups = new Map<string, RunConfigTypeContribution[]>();
const entries: Array<{ label: string; group?: string; type?: RunConfigTypeContribution }> = [];
for (const t of types) {
if (!t.group) {
entries.push({ label: t.label, type: t });
entries.push({ label: translate(t.label), type: t });
continue;
}
let g = groups.get(t.group);
if (!g) {
groups.set(t.group, (g = []));
entries.push({ label: t.group, group: t.group });
entries.push({ label: translate(t.group), group: t.group });
}
g.push(t);
}
@@ -46,7 +62,8 @@ export function typeRows(types: readonly RunConfigTypeContribution[], query: str
for (const e of entries) {
if (e.type) {
const indices = match(e.type);
if (!q || indices) rows.push({ kind: "type", key: e.type.id, type: e.type, indices, nested: false });
if (!q || indices)
rows.push({ kind: "type", key: e.type.id, type: e.type, label: e.label, indices, nested: false });
continue;
}
const members = groups
@@ -54,8 +71,9 @@ export function typeRows(types: readonly RunConfigTypeContribution[], query: str
.map((t) => ({ t, indices: match(t) }))
.filter((x) => !q || x.indices);
if (!members.length) continue;
rows.push({ kind: "group", key: `group:${e.group}`, label: e.group! });
for (const { t, indices } of members) rows.push({ kind: "type", key: t.id, type: t, indices, nested: true });
rows.push({ kind: "group", key: `group:${e.group}`, label: e.label });
for (const { t, indices } of members)
rows.push({ kind: "type", key: t.id, type: t, label: translate(t.label), indices, nested: true });
}
return rows;
}
@@ -73,7 +91,8 @@ export function AddConfigPopup({
const types = useRunConfigTypes((s) => s.types);
const rowHeight = useRowHeight(ROW);
const [query, setQuery] = useState("");
const rows = useMemo(() => typeRows(runConfigTypes(types), query), [types, query]);
const tx = useTx();
const rows = useMemo(() => typeRows(runConfigTypes(types), query, tx), [types, query, tx]);
const isSection = (r: TypeRow) => r.kind === "group";
const [active, setActive] = useState(-1);
const clamped = Math.min(active, rows.length - 1);
@@ -149,10 +168,13 @@ export function AddConfigPopup({
}
renderItem={(r) =>
r.kind === "type" ? (
<span className={clsx(styles.chooserRow, r.nested && styles.typeNested)} title={r.type.description}>
<span
className={clsx(styles.chooserRow, r.nested && styles.typeNested)}
title={r.type.description && tx(r.type.description)}
>
<Icon name={r.type.icon} size={16} className={styles.chooserIcon} />
<span className={styles.chooserName}>
{r.indices?.length ? <HighlightedText text={r.type.label} indices={r.indices} /> : r.type.label}
{r.indices?.length ? <HighlightedText text={r.label} indices={r.indices} /> : r.label}
</span>
</span>
) : null
+1 -1
Переглянути файл
@@ -647,7 +647,7 @@ function EditConfigsDialog() {
onClick={() => setSelection({ type: "template", kind: t.id })}
>
<Icon name={t.icon} size={13} className={styles.chooserIcon} />
<span className={styles.chooserName}>{t.label}</span>
<span className={styles.chooserName}>{tx(t.label)}</span>
</button>
);
})}
+14
Переглянути файл
@@ -796,6 +796,20 @@ describe("configuration types", () => {
expect(typeRows(types, "grad").map((r) => r.key)).toEqual(["gradle"]);
expect(typeRows(types, "dock").map((r) => r.key)).toEqual(["group:Docker", "docker-image"]);
});
it("Add New Configuration shows, sorts and searches types in the UI language", () => {
const zh: Record<string, string> = { Compound: "复合", "Docker Image": "Docker 镜像", Docker: "Docker 组" };
const translate = (text: string) => zh[text] ?? text;
const types = [
...runConfigTypes(),
{ ...BUILTIN_TYPES[0]!, id: "docker-image", label: "Docker Image", group: "Docker" },
];
const rows = typeRows(types, "", translate);
expect(rows.find((r) => r.kind === "type" && r.type.id === "compound")).toMatchObject({ label: "复合" });
expect(rows.find((r) => r.kind === "group")).toMatchObject({ label: "Docker 组" });
expect(typeRows(types, "复合", translate).map((r) => r.key)).toEqual(["compound"]);
expect(typeRows(types, "镜像", translate).map((r) => r.key)).toEqual(["group:Docker", "docker-image"]);
});
});
describe("compound configurations", () => {