fix(subdirectory): reorder navigationUtils so primitives precede helpers

oxlint's `no-use-before-define` rejects function-declaration hoisting:
`redirect()` calls `navigateTo()` declared further down in the file, and
the rule fires on the call site even though the runtime ordering is
sound.

Moves `navigateTo` and `navigateWithState` to the top of the module
(directly after imports) and removes the corresponding "Legacy multi-mode
helpers" section that previously held them at the bottom. The channel-3
section now follows and can reference the primitives in textual order.
Section comment updated to explain the placement.

Also extracts the long template-literal expression in `getShareableUrl`
into a `safePath` local so the line fits under prettier's print width.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Joe Li
2026-05-07 10:56:44 -07:00
parent f8b26caf9d
commit 5c0d2bfc5b

View File

@@ -23,6 +23,42 @@ import {
} from 'react';
import { ensureAppRoot } from './pathUtils';
// =============================================================================
// Underlying primitives
// =============================================================================
// These multi-mode helpers are the long-standing sink-bearing functions that
// the channel-3 helpers further down delegate to. They are kept here at the
// top of the file so the channel-3 helpers can reference them in textual
// order (oxlint's `no-use-before-define` does not honour function-declaration
// hoisting). Migration commits will eventually rewrite call sites to use the
// channel-3 surface and delete these.
// =============================================================================
export function navigateTo(
url: string,
options?: { newWindow?: boolean; assign?: boolean },
): void {
if (options?.newWindow) {
window.open(ensureAppRoot(url), '_blank', 'noopener noreferrer');
} else if (options?.assign) {
window.location.assign(ensureAppRoot(url));
} else {
window.location.href = ensureAppRoot(url);
}
}
export function navigateWithState(
url: string,
state: Record<string, unknown>,
options?: { replace?: boolean },
): void {
if (options?.replace) {
window.history.replaceState(state, '', ensureAppRoot(url));
} else {
window.history.pushState(state, '', ensureAppRoot(url));
}
}
// =============================================================================
// Channel-3 helpers (browser-direct sinks)
// =============================================================================
@@ -119,7 +155,8 @@ export function redirect(path: string): void {
* to round-trip through external systems back to this Superset deployment.
*/
export function getShareableUrl(path: string): string {
return `${window.location.origin}${assertSafeNavigationUrl(ensureAppRoot(path))}`;
const safePath = assertSafeNavigationUrl(ensureAppRoot(path));
return `${window.location.origin}${safePath}`;
}
/**
@@ -138,37 +175,3 @@ export function AppLink(
href: assertSafeNavigationUrl(ensureAppRoot(href)),
});
}
// =============================================================================
// Legacy multi-mode helpers
// =============================================================================
// These predate the focused helpers above. They behave correctly but are
// scheduled for replacement so the channel-3 surface is entirely composed of
// single-purpose functions. Migration commits will rewrite call sites to use
// the focused helpers, then delete these.
// =============================================================================
export function navigateTo(
url: string,
options?: { newWindow?: boolean; assign?: boolean },
): void {
if (options?.newWindow) {
window.open(ensureAppRoot(url), '_blank', 'noopener noreferrer');
} else if (options?.assign) {
window.location.assign(ensureAppRoot(url));
} else {
window.location.href = ensureAppRoot(url);
}
}
export function navigateWithState(
url: string,
state: Record<string, unknown>,
options?: { replace?: boolean },
): void {
if (options?.replace) {
window.history.replaceState(state, '', ensureAppRoot(url));
} else {
window.history.pushState(state, '', ensureAppRoot(url));
}
}