feat(editor): naturally sort schema options

This commit is contained in:
t8y2
2026-07-10 13:16:07 +08:00
parent cc72b7a4e7
commit a9428e3c73
3 changed files with 26 additions and 2 deletions
@@ -0,0 +1,22 @@
import { describe, expect, it } from "vitest";
import { schemaOptionsForConnection } from "@/composables/useSchemaOptions";
describe("schemaOptionsForConnection", () => {
it("sorts schema names with numeric suffixes naturally", () => {
const schemaNames = ["WMWMSE16", "WMWMSE17", "WMWMSE18", "WMWMSE19", "WMWMSE2", "WMWMSE20", "WMWMSE1", "WMWMSE10"];
expect(schemaOptionsForConnection(schemaNames, undefined)).toEqual(["WMWMSE1", "WMWMSE2", "WMWMSE10", "WMWMSE16", "WMWMSE17", "WMWMSE18", "WMWMSE19", "WMWMSE20"]);
expect(schemaNames).toEqual(["WMWMSE16", "WMWMSE17", "WMWMSE18", "WMWMSE19", "WMWMSE2", "WMWMSE20", "WMWMSE1", "WMWMSE10"]);
});
it("sorts after applying the visible schema filter", () => {
const connection = {
db_type: "oracle" as const,
visible_schemas: {
ORCL: ["WMWMSE10", "WMWMSE2"],
},
};
expect(schemaOptionsForConnection(["WMWMSE10", "SYSTEM", "WMWMSE2", "WMWMSE1"], connection, "ORCL")).toEqual(["WMWMSE2", "WMWMSE10"]);
});
});
@@ -1,6 +1,7 @@
import { ref } from "vue";
import { useConnectionStore } from "@/stores/connectionStore";
import { isSchemaAware as isSchemaAwareType, isSingleDatabase, usesTreeSchemaMode } from "@/lib/database/databaseCapabilities";
import { sortSidebarNames } from "@/lib/database/databaseTree";
import { filterSchemaNamesForConnection } from "@/lib/database/visibleDatabases";
import type { ConnectionConfig } from "@/types/database";
import * as api from "@/lib/backend/api";
@@ -10,7 +11,8 @@ export function hasSchemaOptionsCacheEntry(options: Record<string, string[]>, ke
}
export function schemaOptionsForConnection(schemaNames: string[], connection: Pick<ConnectionConfig, "db_type" | "driver_profile" | "visible_databases" | "visible_schemas"> | undefined, database = ""): string[] {
return filterSchemaNamesForConnection(schemaNames, connection, database);
// Keep numeric schema suffixes in human order (SCHEMA2 before SCHEMA10), matching the database tree.
return sortSidebarNames(filterSchemaNamesForConnection(schemaNames, connection, database));
}
export function useSchemaOptions() {
+1 -1
View File
@@ -8,7 +8,7 @@ test("schema options respect Oracle visible database filters", () => {
db_type: "oracle",
visible_databases: ["CAM", "00010"],
}),
["CAM", "00010"],
["00010", "CAM"],
);
});