mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-06-14 10:29:52 +08:00
🐛 fix(sidebar): 修复视图定位误报未找到
This commit is contained in:
@@ -1434,4 +1434,13 @@ describe('Sidebar locate toolbar', () => {
|
||||
expect(source).toContain('void loadTables(dbNode);');
|
||||
expect(source).toContain("window.removeEventListener('gonavi:sidebar-table-pin-changed'");
|
||||
});
|
||||
|
||||
it('waits long enough for slow object-tree loads before reporting locate misses', () => {
|
||||
const source = readFileSync(new URL('./Sidebar.tsx', import.meta.url), 'utf8');
|
||||
|
||||
expect(source).toContain('const SIDEBAR_LOCATE_LOAD_WAIT_INTERVAL_MS = 50;');
|
||||
expect(source).toContain('const SIDEBAR_LOCATE_LOAD_WAIT_ATTEMPTS = 160;');
|
||||
expect(source).toContain('attempt < SIDEBAR_LOCATE_LOAD_WAIT_ATTEMPTS');
|
||||
expect(source).toContain('window.setTimeout(resolve, SIDEBAR_LOCATE_LOAD_WAIT_INTERVAL_MS)');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -186,6 +186,8 @@ type SidebarContextMenuState = {
|
||||
const SIDEBAR_CONTEXT_MENU_SAFE_GAP = 8;
|
||||
const SIDEBAR_CONTEXT_MENU_FALLBACK_WIDTH = 264;
|
||||
const SIDEBAR_CONTEXT_MENU_FALLBACK_HEIGHT = 420;
|
||||
const SIDEBAR_LOCATE_LOAD_WAIT_INTERVAL_MS = 50;
|
||||
const SIDEBAR_LOCATE_LOAD_WAIT_ATTEMPTS = 160;
|
||||
type ExternalSQLFileModalMode = 'create' | 'rename' | 'create-directory' | 'rename-directory';
|
||||
|
||||
const isExternalSQLDirectoryModalMode = (mode: ExternalSQLFileModalMode): boolean =>
|
||||
@@ -2439,8 +2441,8 @@ const Sidebar: React.FC<{
|
||||
const locateObjectInSidebarRef = useRef<(detail: unknown) => Promise<void>>(async () => {});
|
||||
|
||||
const waitForSidebarLoadKey = async (loadKey: string) => {
|
||||
for (let attempt = 0; attempt < 30 && loadingNodesRef.current.has(loadKey); attempt += 1) {
|
||||
await new Promise(resolve => window.setTimeout(resolve, 50));
|
||||
for (let attempt = 0; attempt < SIDEBAR_LOCATE_LOAD_WAIT_ATTEMPTS && loadingNodesRef.current.has(loadKey); attempt += 1) {
|
||||
await new Promise(resolve => window.setTimeout(resolve, SIDEBAR_LOCATE_LOAD_WAIT_INTERVAL_MS));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -557,6 +557,52 @@ describe('sidebarLocate', () => {
|
||||
]);
|
||||
});
|
||||
|
||||
it('falls back from a schema-qualified view request to a bare table-like node in the same database', () => {
|
||||
const target = resolveSidebarLocateTarget({
|
||||
tabId: 'stale-view-tab-id',
|
||||
connectionId: 'conn-1',
|
||||
dbName: 'SYSDBA',
|
||||
tableName: 'SYSDBA.V_ACCOUNT',
|
||||
schemaName: 'SYSDBA',
|
||||
objectGroup: 'views',
|
||||
}, { groupBySchema: false });
|
||||
|
||||
const tree = [
|
||||
{
|
||||
key: 'conn-1',
|
||||
children: [
|
||||
{
|
||||
key: 'conn-1-SYSDBA',
|
||||
dataRef: { id: 'conn-1', dbName: 'SYSDBA' },
|
||||
children: [
|
||||
{
|
||||
key: 'conn-1-SYSDBA-tables',
|
||||
children: [
|
||||
{
|
||||
key: 'conn-1-SYSDBA-V_ACCOUNT',
|
||||
type: 'table',
|
||||
dataRef: {
|
||||
id: 'conn-1',
|
||||
dbName: 'SYSDBA',
|
||||
tableName: 'V_ACCOUNT',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
expect(findSidebarNodePathForLocate(tree, target)).toEqual([
|
||||
'conn-1',
|
||||
'conn-1-SYSDBA',
|
||||
'conn-1-SYSDBA-tables',
|
||||
'conn-1-SYSDBA-V_ACCOUNT',
|
||||
]);
|
||||
});
|
||||
|
||||
it('falls back to a unique schema-qualified table-like node for an unqualified view request', () => {
|
||||
const target = resolveSidebarLocateTarget({
|
||||
tabId: 'stale-view-tab-id',
|
||||
|
||||
@@ -268,6 +268,15 @@ const matchesLocateObjectName = (
|
||||
|
||||
if (normalize(normalizedNodeName) === normalize(target.tableName)) return true;
|
||||
|
||||
if (
|
||||
resolvedTargetSchema
|
||||
&& !resolvedNodeSchema
|
||||
&& normalize(resolvedTargetSchema) === normalize(target.dbName)
|
||||
&& normalize(nodeObject) === normalize(targetObject)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!resolvedTargetSchema) {
|
||||
if (options.allowUnqualifiedSchemaMatch) {
|
||||
return normalize(nodeObject) === normalize(targetObject);
|
||||
|
||||
Reference in New Issue
Block a user