mirror of
https://github.com/t8y2/dbx.git
synced 2026-10-19 16:16:45 +00:00
feat(editor): naturally sort schema options
This commit is contained in:
@@ -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() {
|
||||
|
||||
@@ -8,7 +8,7 @@ test("schema options respect Oracle visible database filters", () => {
|
||||
db_type: "oracle",
|
||||
visible_databases: ["CAM", "00010"],
|
||||
}),
|
||||
["CAM", "00010"],
|
||||
["00010", "CAM"],
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user