Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: Improve database block menu grouping https://github.com/siyuan-note/siyuan/issues/19321

Daniel27fcc0cc8124
diff --git a/app/src/config/entryVisibility/catalog.test.ts b/app/src/config/entryVisibility/catalog.test.ts
index 7068f2a661..fbc2729a46 100644
--- a/app/src/config/entryVisibility/catalog.test.ts
+++ b/app/src/config/entryVisibility/catalog.test.ts
@@ -1154,3 +1154,17 @@ test("entry catalog resolves navigation columns for deeply nested entries", () =
"gutter.single.turnInto.includeSublists.recursiveParagraph"), []);
assert.deepEqual(getEntryCatalogPathChain("gutter.single", "gutter.single.missing"), []);
});
+test("database block menu groups actions after its stable separator", () => {
+ const children = getEntryCatalogChildren("gutter.single");
+ const index = children.findIndex(item => item.key === "database");
+ assert.equal(children[index - 1].key, "separator_exportCSV");
+ assert.equal(children[index - 1].type, "separator");
+ assert.equal(children[index].simple, true);
+ assert.deepEqual(getEntryCatalogChildren("gutter.single.database").map(item => item.key),
+ ["exportCSV", "showDatabaseInFolder"]);
+ assert.equal(getEntryCatalogNode("gutter.single.exportCSV"), undefined);
+ assert.equal(getEntryCatalogNode("gutter.single.showDatabaseInFolder"), undefined);
+ const source = readFileSync(resolve(process.cwd(), "src/protyle/gutter/index.ts"), "utf8");
+ const section = source.slice(source.indexOf("const submenu: IMenu[] = [];", source.indexOf('type === "NodeAttributeView"')));
+ assert.ok(section.indexOf('id: "exportCSV"') < section.indexOf('id: "showDatabaseInFolder"'));
+});
diff --git a/app/src/config/entryVisibility/catalog.ts b/app/src/config/entryVisibility/catalog.ts
index 00ba75ff54..2ed8516a40 100644
--- a/app/src/config/entryVisibility/catalog.ts
+++ b/app/src/config/entryVisibility/catalog.ts
@@ -393,8 +393,10 @@ const gutterSingle = () => [
separator("separator_table"),
gutterTable(),
separator("separator_exportCSV"),
- node("exportCSV", () => `${window.siyuan.languages.export} CSV`),
- node("showDatabaseInFolder", lang("showInFolder")),
+ node("database", lang("database"), true, [
+ node("exportCSV", () => `${window.siyuan.languages.export} CSV`),
+ node("showDatabaseInFolder", lang("showInFolder")),
+ ]),
separator("separator_VideoOrAudio"),
node("assetVideo", location(lang("video"), lang("assets")), true, [
node("asset", lang("assets")),
diff --git a/app/src/config/entryVisibility/profile.test.ts b/app/src/config/entryVisibility/profile.test.ts
index ffb36bbf0c..9d0f541957 100644
--- a/app/src/config/entryVisibility/profile.test.ts
+++ b/app/src/config/entryVisibility/profile.test.ts
@@ -9,6 +9,23 @@ import {
normalizeEntryVisibilityImportProfile,
} from "./profile";
+test("database submenu migration preserves visibility, order and plugin slots", () => {
+ const profile = normalizeEntryVisibilityImportProfile({
+ name: "Custom",
+ entries: {"gutter.single.exportCSV": false, "gutter.single.showDatabaseInFolder": true},
+ orders: {"gutter.single": ["pluginBefore", "separator_exportCSV", "showDatabaseInFolder", "pluginMiddle", "exportCSV", "pluginAfter"]},
+ }, 4, {});
+ assert.deepEqual(profile.entries, {
+ "gutter.single.database.exportCSV": false,
+ "gutter.single.database.showDatabaseInFolder": true,
+ });
+ assert.deepEqual(profile.orders, {
+ "gutter.single": ["pluginBefore", "separator_exportCSV", "database", "pluginMiddle", "pluginAfter"],
+ "gutter.single.database": ["showDatabaseInFolder", "exportCSV"],
+ });
+ assert.deepEqual(normalizeEntryVisibilityImportProfile(profile, 5, {}), profile);
+});
+
test("font toolbar entries are visible in Full, hidden in Simple and preserve explicit profile choices", () => {
for (const key of ["font-family", "font-size"]) {
const path = `${TOOLBAR_ENTRY_ROOT_PATH}.${key}`;
diff --git a/app/src/config/entryVisibility/profile.ts b/app/src/config/entryVisibility/profile.ts
index db90adb450..b032511390 100644
--- a/app/src/config/entryVisibility/profile.ts
+++ b/app/src/config/entryVisibility/profile.ts
@@ -55,5 +55,30 @@ export const normalizeEntryVisibilityImportProfile = (
delete entries["document.more.editMode.preview"];
delete orders["document.more.editMode"];
}
+ if (version < 5) {
+ const parent = "gutter.single";
+ const children = ["exportCSV", "showDatabaseInFolder"];
+ children.forEach((key) => {
+ if (typeof entries[`${parent}.${key}`] === "boolean") {
+ entries[`${parent}.database.${key}`] = entries[`${parent}.${key}`];
+ delete entries[`${parent}.${key}`];
+ }
+ });
+ const order = orders[parent];
+ if (order?.some(key => children.includes(key))) {
+ orders[`${parent}.database`] = order.filter(key => children.includes(key));
+ let inserted = false;
+ orders[parent] = order.flatMap((key) => {
+ if (!children.includes(key)) {
+ return key === "database" ? [] : [key];
+ }
+ if (inserted) {
+ return [];
+ }
+ inserted = true;
+ return ["database"];
+ });
+ }
+ }
return {name: profile.name, entries, orders};
};
diff --git a/app/src/config/entryVisibility/runtime.ts b/app/src/config/entryVisibility/runtime.ts
index 0ff25d42fa..eda665410e 100644
--- a/app/src/config/entryVisibility/runtime.ts
+++ b/app/src/config/entryVisibility/runtime.ts
@@ -37,7 +37,7 @@ import {
mergeDockEntryOrderSnapshot,
} from "./dockOrder";
-export const ENTRY_VISIBILITY_VERSION = 4;
+export const ENTRY_VISIBILITY_VERSION = 5;
export const ENTRY_PROFILE_SIMPLE = "simple";
export const ENTRY_PROFILE_FULL = "full";
export type TEntryVisibilityTemplate = typeof ENTRY_PROFILE_SIMPLE | typeof ENTRY_PROFILE_FULL;
diff --git a/app/src/protyle/gutter/index.ts b/app/src/protyle/gutter/index.ts
index 5ad189f357..b8efee26f7 100644
--- a/app/src/protyle/gutter/index.ts
+++ b/app/src/protyle/gutter/index.ts
@@ -2445,9 +2445,9 @@ export class Gutter {
}).element);
}
} else if (type === "NodeAttributeView") {
+ const submenu: IMenu[] = [];
if (getHostCapabilities().importExport) {
- window.siyuan.menus.menu.append(new MenuItem({id: "separator_exportCSV", type: "separator"}).element);
- window.siyuan.menus.menu.append(new MenuItem({
+ submenu.push({
id: "exportCSV",
icon: "iconDatabase",
label: window.siyuan.languages.export + " CSV",
@@ -2459,11 +2459,11 @@ export class Gutter {
saveExportFile(response.data.zip);
});
}
- }).element);
+ });
}
/// #if !BROWSER
if (getHostCapabilities().localFileSystem) {
- window.siyuan.menus.menu.append(new MenuItem({
+ submenu.push({
id: "showDatabaseInFolder",
icon: "iconFolder",
label: window.siyuan.languages.showInFolder,
@@ -2476,9 +2476,19 @@ export class Gutter {
: path.join(window.siyuan.config.system.dataDir, "storage", "av");
useShell("showItemInFolder", path.join(avDir, avId) + ".json");
}
- }).element);
+ });
}
/// #endif
+ if (submenu.length > 0) {
+ window.siyuan.menus.menu.append(new MenuItem({id: "separator_exportCSV", type: "separator"}).element);
+ window.siyuan.menus.menu.append(new MenuItem({
+ id: "database",
+ type: "submenu",
+ icon: "iconDatabase",
+ label: window.siyuan.languages.database,
+ submenu,
+ }).element);
+ }
} else if ((type === "NodeVideo" || type === "NodeAudio") && !protyle.disabled) {
window.siyuan.menus.menu.append(new MenuItem({id: "separator_VideoOrAudio", type: "separator"}).element);
window.siyuan.menus.menu.append(new MenuItem({
diff --git a/kernel/conf/appearance.go b/kernel/conf/appearance.go
index 4d07efaeed..b5f399a874 100644
--- a/kernel/conf/appearance.go
+++ b/kernel/conf/appearance.go
@@ -68,7 +68,7 @@ func (appearance *Appearance) NormalizeGlobalFontFamilies() {
}
const (
- EntryVisibilityVersion = 4
+ EntryVisibilityVersion = 5
EntryVisibilityProfileSimple = "simple"
EntryVisibilityProfileFull = "full"
)
@@ -129,6 +129,30 @@ func NormalizeEntryVisibility(entryVisibility *EntryVisibility, fallback string)
delete(profile.Entries, "document.more.editMode.preview")
delete(profile.Orders, "document.more.editMode")
}
+ if version < 5 {
+ const parent = "gutter.single"
+ for _, key := range []string{"exportCSV", "showDatabaseInFolder"} {
+ if visible, ok := profile.Entries[parent+"."+key]; ok {
+ profile.Entries[parent+".database."+key] = visible
+ delete(profile.Entries, parent+"."+key)
+ }
+ }
+ var children, order []string
+ for _, key := range profile.Orders[parent] {
+ if key == "exportCSV" || key == "showDatabaseInFolder" {
+ if len(children) == 0 {
+ order = append(order, "database")
+ }
+ children = append(children, key)
+ } else if key != "database" {
+ order = append(order, key)
+ }
+ }
+ if len(children) > 0 {
+ profile.Orders[parent] = order
+ profile.Orders[parent+".database"] = children
+ }
+ }
profileIDs[profile.ID] = true
profiles = append(profiles, profile)
}
diff --git a/kernel/conf/appearance_test.go b/kernel/conf/appearance_test.go
index c82944c646..df9cd40d53 100644
--- a/kernel/conf/appearance_test.go
+++ b/kernel/conf/appearance_test.go
@@ -172,3 +172,31 @@ func TestNormalizeEntryVisibilityMigratesEditMode(t *testing.T) {
t.Fatalf("legacy mode order should be removed: %+v", profile.Orders)
}
}
+func TestDatabaseMenuMigration(t *testing.T) {
+ config := &EntryVisibility{Version: 4, Active: "custom", Profiles: []*EntryVisibilityProfile{{
+ ID: "custom", Name: "Custom",
+ Entries: map[string]bool{"gutter.single.exportCSV": false, "gutter.single.showDatabaseInFolder": true},
+ Orders: map[string][]string{"gutter.single": {"pluginBefore", "separator_exportCSV", "showDatabaseInFolder", "pluginMiddle", "exportCSV", "pluginAfter"}},
+ }}}
+ NormalizeEntryVisibility(config, EntryVisibilityProfileFull)
+ profile := config.Profiles[0]
+ if visible, ok := profile.Entries["gutter.single.database.exportCSV"]; !ok || visible {
+ t.Fatal("export visibility was not preserved")
+ }
+ if !profile.Entries["gutter.single.database.showDatabaseInFolder"] {
+ t.Fatal("folder visibility was not preserved")
+ }
+ if _, ok := profile.Entries["gutter.single.exportCSV"]; ok {
+ t.Fatal("legacy visibility remains")
+ }
+ want := []string{"pluginBefore", "separator_exportCSV", "database", "pluginMiddle", "pluginAfter"}
+ for i, key := range want {
+ if len(profile.Orders["gutter.single"]) != len(want) || profile.Orders["gutter.single"][i] != key {
+ t.Fatal("parent order was not preserved")
+ }
+ }
+ children := profile.Orders["gutter.single.database"]
+ if len(children) != 2 || children[0] != "showDatabaseInFolder" || children[1] != "exportCSV" {
+ t.Fatal("child order was not preserved")
+ }
+}