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

...
Автор SHA1 Повідомлення Дата
l0ng-ai 20c64d4f3e fix(database): don't leave the tree loading after a disconnect or rename
Disconnecting a data source (Deactivate, or Auto-disconnect when idle)
forgets what it loaded, but its expanded tree nodes stayed expanded and
showed Loading until collapsed by hand, since only expanding a node loads
its children. A disconnect now also collapses the nodes of what it
forgot: the source with all its databases, or one database. Renaming a
source dropped its metadata the same way; it now saves like any edit,
which reloads what the tree had expanded.

Fixes #4388
2026-11-19 10:50:38 +08:00
l0ng-ai 10aa367df3 feat(vcs): add File › New › Project from Version Control (#4398)
The clone dialog was only reachable from the Git menu and the welcome
screen. File › New now lists it too, as its own action
(vcs.cloneProject) since a menu bar holds each action id once.

Closes #4100
2026-11-19 10:35:19 +08:00
8 змінених файлів з 69 додано та 9 видалено

No files matched your search

+9 -1
Переглянути файл
@@ -223,6 +223,7 @@ pub fn spec(os: Os) -> Vec<Entry> {
vec![
act("file.newProject", "Project…"),
act("workspace.create", "Workspace…"),
act("vcs.cloneProject", "Project from Version Control…"),
SEP,
act("file.new", "File…"),
act("file.newScratchFile", "Scratch File"),
@@ -2014,7 +2015,14 @@ mod tests {
};
assert_eq!(
action_ids(new),
["file.newProject", "workspace.create", "file.new", "file.newScratchFile", "file.newUntitled"],
[
"file.newProject",
"workspace.create",
"vcs.cloneProject",
"file.new",
"file.newScratchFile",
"file.newUntitled"
],
"{os:?}"
);
}
+14
Переглянути файл
@@ -337,6 +337,20 @@ export function targetOf(id: string, database: string | null, current: string |
/** Key of the Database tree node of database `name` of data source `id`. */
export const databaseKey = (id: string, name: string) => `${id}/@${name}`;
/**
* `expanded` without the Database tree nodes that show what target `id` loaded (a data source
* id: the source and all its databases). Once that is forgotten, an expanded node would wait
* for children nothing loads until it is expanded again.
*/
export function collapseTarget(expanded: ReadonlySet<string>, id: string): Set<string> {
const { id: source, database } = splitTarget(id);
const under = (key: string, node: string) => key === node || key.startsWith(`${node}/`);
const shows = database
? (key: string) => under(key, databaseKey(source, database)) || under(key, id)
: (key: string) => under(key, source) || key.startsWith(`${source}:`);
return new Set([...expanded].filter((key) => !shows(key)));
}
const SSL_MODES: Record<string, DbSslMode> = {
disable: "disable",
disabled: "disable",
+30 -2
Переглянути файл
@@ -274,6 +274,31 @@ describe("database metadata request lifetimes", () => {
expect(useDatabase.getState().connected.has("pg:app")).toBe(false);
});
it("collapses the tree nodes of what a disconnect forgets", async () => {
const tree = [
"pg",
"pg/@app",
"pg/public",
"pg/public/tables",
"pg:other/public",
"pg/@other",
"pg2",
"pg2/public",
];
useDatabase.setState({ treeExpanded: new Set(tree) });
await disconnect("pg:other");
expect([...useDatabase.getState().treeExpanded]).toEqual([
"pg",
"pg/@app",
"pg/public",
"pg/public/tables",
"pg2",
"pg2/public",
]);
await disconnect("pg");
expect([...useDatabase.getState().treeExpanded]).toEqual(["pg2", "pg2/public"]);
});
it("disconnects one database without invalidating its sibling", async () => {
const response = deferred();
backend.schemas.mockReturnValueOnce(response.promise);
@@ -334,11 +359,14 @@ describe("database metadata request lifetimes", () => {
});
describe("connection and metadata continuations", () => {
it("reloads every level the tree had expanded after a data source is edited", async () => {
it.each([
["edited", () => saveSource({ ...pg, host: "new-host" }, undefined)],
["renamed", () => renameSource("pg", "Renamed")],
])("reloads every level the tree had expanded after a data source is %s", async (_, change) => {
await loadSchemas("pg");
await loadTables("pg", "public");
await loadDetails("pg", "public", "users");
await saveSource({ ...pg, host: "new-host" }, undefined);
await change();
const st = useDatabase.getState();
expect(st.schemas.pg).toEqual({ status: "ok", value: ["public"] });
expect(st.tables["pg\u0000public"]?.status).toBe("ok");
+4 -6
Переглянути файл
@@ -38,6 +38,7 @@ import { workflowSettings } from "@/platform/workflowSettings";
import { ask, confirm } from "@/workbench/messages";
import {
activeSchema,
collapseTarget,
colorVar,
connectRemedy,
databaseKey,
@@ -437,12 +438,8 @@ export async function duplicateSource(id: string): Promise<void> {
export async function renameSource(id: string, name: string): Promise<void> {
const src = sourceById(id);
if (!src || !name.trim() || name.trim() === src.name) return;
const sources = useDatabase.getState().sources.map((s) => (s.id === src.id ? { ...s, name: name.trim() } : s));
forget(id);
const current = sourceMutation(id);
await call(commands.dbSaveSources(sources));
if (!current()) return;
await loadSources();
// Saved like any edit, so what the tree had loaded under the source is loaded again.
await saveSource({ ...src, name: name.trim() }, undefined);
}
/** Removes the data source after asking (Database tree › Drop on a source). */
@@ -572,6 +569,7 @@ export async function disconnect(id: string): Promise<void> {
if (!targets.includes(id)) targets.push(id);
const current = projectRequest();
forget(id);
useDatabase.setState((s) => ({ treeExpanded: collapseTarget(s.treeExpanded, id) }));
const intent = {};
for (const target of targets) connectionIntents.set(target, intent);
if (!splitTarget(id).database) sourceConnectionIntents.set(id, {});
+9
Переглянути файл
@@ -291,6 +291,15 @@ export function registerVcsActions(): () => void {
keywords: ["clone", "checkout", "git"],
run: (c) => showCloneDialog(typeof c.arg === "string" ? c.arg : ""),
},
{
// File › New › Project from Version Control: the same dialog, under the name the File menu uses.
id: "vcs.cloneProject",
title: "Project from Version Control…",
category: "File",
icon: "git-pull",
keywords: ["clone", "checkout", "git", "new project"],
run: () => showCloneDialog(""),
},
{
id: "vcs.push",
title: "Push…",
+1
Переглянути файл
@@ -201,6 +201,7 @@
"menu.file.newScratchFile": "Scratch File",
"menu.new": "New",
"menu.workspace.create": "Workspace…",
"menu.vcs.cloneProject": "Project from Version Control…",
"menu.workspace.open": "Open Workspace…",
"menu.workspace.manage": "Manage Workspace…",
"menu.file.newUntitled": "Untitled File",
+1
Переглянути файл
@@ -1514,6 +1514,7 @@
"Generate Requests for Controller": "为控制器生成请求",
"Generate…": "生成…",
"Get from Version Control…": "从版本控制获取…",
"Project from Version Control…": "来自版本控制的项目…",
"Gevent compatible": "兼容 Gevent",
"Git Branches": "Git 分支",
"Git Log": "Git 日志",
+1
Переглянути файл
@@ -201,6 +201,7 @@
"menu.file.newScratchFile": "临时文件",
"menu.new": "新建",
"menu.workspace.create": "工作区…",
"menu.vcs.cloneProject": "来自版本控制的项目…",
"menu.workspace.open": "打开工作区…",
"menu.workspace.manage": "管理工作区…",
"menu.file.newUntitled": "无标题文件",