fix(saved-sql): 修复 SQL 库连接关联丢失与历史文件不可见
* fix: 持久化并显示 SQL 库连接关联 * fix: 补充 SQL 库关联状态翻译 * chore: 修复数据标签页策略格式 --------- Co-authored-by: zipg <4047349+zipg@users.noreply.github.com>
This commit is contained in:
1 parent
580b70e1d4
commit
445b6473f4
18 files changed
+336
-115
No files matched your search
+14
-8
@@ -30,7 +30,6 @@ vi.mock("@/lib/sqlFile/sqlFileFolders", async () => {
|
||||
function emptySavedSqlStore() {
|
||||
return {
|
||||
allFiles: [] as any[],
|
||||
orphanedFileIds: vi.fn().mockReturnValue(new Set<string>()),
|
||||
getFile: vi.fn().mockReturnValue(undefined),
|
||||
};
|
||||
}
|
||||
@@ -661,7 +660,6 @@ describe("useQuickOpen", () => {
|
||||
const fileMap = new Map(files.map((f) => [f.id, f]));
|
||||
return {
|
||||
allFiles: files,
|
||||
orphanedFileIds: vi.fn().mockReturnValue(new Set<string>()),
|
||||
getFile: vi.fn().mockImplementation((id: string) => fileMap.get(id)),
|
||||
};
|
||||
}
|
||||
@@ -713,7 +711,7 @@ describe("useQuickOpen", () => {
|
||||
expect(sqlItems[0].sqlFileId).toBe("f1");
|
||||
});
|
||||
|
||||
it("excludes orphaned SQL library files", () => {
|
||||
it("includes SQL library files whose connection was deleted", () => {
|
||||
const mockConnStore = {
|
||||
connections: [{ id: "conn1", name: "Active", type: "mssql" }],
|
||||
treeNodes: [],
|
||||
@@ -724,16 +722,24 @@ describe("useQuickOpen", () => {
|
||||
{ id: "f1", name: "active_query.sql", connectionId: "conn1", updatedAt: "2024-01-01T00:00:00.000Z" },
|
||||
{ id: "f2", name: "orphaned_query.sql", connectionId: "deleted_conn", updatedAt: "2024-01-02T00:00:00.000Z" },
|
||||
];
|
||||
const store = savedSqlStoreWithFiles(files);
|
||||
store.orphanedFileIds = vi.fn().mockReturnValue(new Set(["f2"]));
|
||||
vi.mocked(useSavedSqlStore).mockReturnValue(store as any);
|
||||
vi.mocked(useSavedSqlStore).mockReturnValue(savedSqlStoreWithFiles(files) as any);
|
||||
|
||||
const { filteredItems, setQuery } = useQuickOpen();
|
||||
setQuery("query");
|
||||
|
||||
const sqlItems = filteredItems.value.filter((item) => item.type === "sql_library_file");
|
||||
expect(sqlItems).toHaveLength(1);
|
||||
expect(sqlItems[0].label).toBe("active_query.sql");
|
||||
expect(sqlItems).toHaveLength(2);
|
||||
expect(sqlItems.find((item) => item.label === "orphaned_query.sql")?.description).toBe("Connection deleted");
|
||||
});
|
||||
|
||||
it("labels SQL library files without a connection as unassociated", () => {
|
||||
vi.mocked(useConnectionStore).mockReturnValue({ connections: [], treeNodes: [] } as any);
|
||||
vi.mocked(useSavedSqlStore).mockReturnValue(savedSqlStoreWithFiles([{ id: "f1", name: "draft.sql", connectionId: "", updatedAt: "2024-01-01T00:00:00.000Z" }]) as any);
|
||||
|
||||
const { filteredItems, setQuery } = useQuickOpen();
|
||||
setQuery("draft");
|
||||
|
||||
expect(filteredItems.value.find((item) => item.type === "sql_library_file")?.description).toBe("Unassociated");
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import { useSavedSqlStore } from "@/stores/savedSqlStore";
|
||||
import * as api from "@/lib/backend/api";
|
||||
import type { SqlFileEntry } from "@/lib/backend/api";
|
||||
import { getSqlFileFolderPaths, sqlFileFoldersVersion } from "@/lib/sqlFile/sqlFileFolders";
|
||||
import i18n from "@/i18n";
|
||||
|
||||
const REMOTE_SEARCH_DEBOUNCE_MS = 180;
|
||||
const REMOTE_SEARCH_MIN_QUERY_LENGTH = 2;
|
||||
@@ -118,25 +119,22 @@ export function useQuickOpen() {
|
||||
let sqlFilesLoadGeneration = 0;
|
||||
|
||||
function getConnectionLabel(connectionId: string): string {
|
||||
if (!connectionId) return i18n.global.t("sqlLibrary.unassociated");
|
||||
const conn = connectionStore.connections.find((c) => c.id === connectionId);
|
||||
return conn?.name || connectionId;
|
||||
return conn?.name || i18n.global.t("sqlLibrary.deletedConnection");
|
||||
}
|
||||
|
||||
const sqlLibraryAllItems = computed<QuickOpenItem[]>(() => {
|
||||
const activeConnectionIds = new Set(connectionStore.connections.map((c) => c.id));
|
||||
const orphanedIds = savedSqlStore.orphanedFileIds(activeConnectionIds);
|
||||
return savedSqlStore.allFiles
|
||||
.filter((file) => !orphanedIds.has(file.id))
|
||||
.map((file) => ({
|
||||
id: `sqllib-${file.id}`,
|
||||
type: "sql_library_file" as const,
|
||||
label: file.name,
|
||||
description: getConnectionLabel(file.connectionId),
|
||||
connectionId: file.connectionId,
|
||||
connectionName: getConnectionLabel(file.connectionId),
|
||||
sqlFileId: file.id,
|
||||
searchText: `${file.name} ${getConnectionLabel(file.connectionId)}`,
|
||||
}));
|
||||
return savedSqlStore.allFiles.map((file) => ({
|
||||
id: `sqllib-${file.id}`,
|
||||
type: "sql_library_file" as const,
|
||||
label: file.name,
|
||||
description: getConnectionLabel(file.connectionId),
|
||||
connectionId: file.connectionId,
|
||||
connectionName: getConnectionLabel(file.connectionId),
|
||||
sqlFileId: file.id,
|
||||
searchText: `${file.name} ${getConnectionLabel(file.connectionId)}`,
|
||||
}));
|
||||
});
|
||||
|
||||
const sqlLibraryRecentItems = computed<QuickOpenItem[]>(() => {
|
||||
|
||||
Reference in new issue
Block a user