Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { useWorkspace } from "renderer/routes/_authenticated/_dashboard/v2-workspace/providers/WorkspaceProvider";
import { StatusIndicator } from "renderer/screens/main/components/StatusIndicator";
import {
useV2SourcesNotificationStatus,
type V2NotificationSourceInput,
} from "renderer/stores/v2-notifications";

interface V2NotificationStatusIndicatorProps {
workspaceId: string;
sources: Iterable<V2NotificationSourceInput>;
className?: string;
}

export function V2NotificationStatusIndicator({
workspaceId,
sources,
className,
}: V2NotificationStatusIndicatorProps) {
const status = useV2SourcesNotificationStatus(workspaceId, sources);
const { workspace } = useWorkspace();
const status = useV2SourcesNotificationStatus(workspace.id, sources);
if (!status) return null;
return <StatusIndicator status={status} className={className} />;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { WorkspaceStore } from "@superset/panes";
import { useEffect } from "react";
import { useWorkspace } from "renderer/routes/_authenticated/_dashboard/v2-workspace/providers/WorkspaceProvider";
import {
getV2NotificationSourcesForPane,
useV2NotificationStore,
Expand All @@ -10,27 +11,29 @@ import type { StoreApi } from "zustand/vanilla";
import type { PaneViewerData } from "../../types";

export function useClearActivePaneAttention({
workspaceId,
store,
}: {
workspaceId: string;
store: StoreApi<WorkspaceStore<PaneViewerData>>;
}): void {
const { workspace } = useWorkspace();
const activePane = useStore(store, (state) => {
const tab = state.tabs.find(
(candidate) => candidate.id === state.activeTabId,
);
return tab?.activePaneId ? tab.panes[tab.activePaneId] : undefined;
});
const activePaneStatus = useV2PaneNotificationStatus(workspaceId, activePane);
const activePaneStatus = useV2PaneNotificationStatus(
workspace.id,
activePane,
);
const clearSourceAttention = useV2NotificationStore(
(state) => state.clearSourceAttention,
);

useEffect(() => {
if (activePaneStatus !== "review") return;
for (const source of getV2NotificationSourcesForPane(activePane)) {
clearSourceAttention(source, workspaceId);
clearSourceAttention(source, workspace.id);
}
}, [activePane, activePaneStatus, clearSourceAttention, workspaceId]);
}, [activePane, activePaneStatus, clearSourceAttention, workspace.id]);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@ import type { WorkspaceProps } from "@superset/panes";
import { alert } from "@superset/ui/atoms/Alert";
import { useCallback } from "react";
import { getBaseName } from "renderer/lib/pathBasename";
import { useWorkspace } from "renderer/routes/_authenticated/_dashboard/v2-workspace/providers/WorkspaceProvider";
import { getDocument } from "../../state/fileDocumentStore";
import type { FilePaneData, PaneViewerData } from "../../types";

type OnBeforeCloseTab = NonNullable<
WorkspaceProps<PaneViewerData>["onBeforeCloseTab"]
>;

export function useDirtyTabCloseGuard({
workspaceId,
}: {
workspaceId: string;
}): OnBeforeCloseTab {
export function useDirtyTabCloseGuard(): OnBeforeCloseTab {
const { workspace } = useWorkspace();
const workspaceId = workspace.id;
return useCallback<OnBeforeCloseTab>(
(tab) => {
const dirtyPanes = Object.values(tab.panes).filter((pane) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ export function ChatPaneTitle({ context, workspaceId }: ChatPaneTitleProps) {
onDeleteSession={handleDeleteSession}
/>
<V2NotificationStatusIndicator
workspaceId={workspaceId}
sources={getV2NotificationSourcesForPane(context.pane)}
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { useHotkeyDisplay } from "renderer/hotkeys";
import { getBaseName } from "renderer/lib/pathBasename";
import { consumeTerminalBackgroundIntent } from "renderer/lib/terminal/terminal-background-intents";
import { terminalRuntimeRegistry } from "renderer/lib/terminal/terminal-runtime-registry";
import { useWorkspace } from "renderer/routes/_authenticated/_dashboard/v2-workspace/providers/WorkspaceProvider";
import { FileIcon } from "renderer/screens/main/components/WorkspaceView/RightSidebar/FilesView/utils";
import {
clearV2TerminalRunStatus,
Expand Down Expand Up @@ -107,10 +108,12 @@ interface UsePaneRegistryOptions {
onRevealPath: (path: string) => void;
}

export function usePaneRegistry(
workspaceId: string,
{ onOpenFile, onRevealPath }: UsePaneRegistryOptions,
): PaneRegistry<PaneViewerData> {
export function usePaneRegistry({
onOpenFile,
onRevealPath,
}: UsePaneRegistryOptions): PaneRegistry<PaneViewerData> {
const { workspace } = useWorkspace();
const workspaceId = workspace.id;
const clearShortcut = useHotkeyDisplay("CLEAR_TERMINAL").text;
const scrollToBottomShortcut = useHotkeyDisplay("SCROLL_TO_BOTTOM").text;
const workspaceTrpcUtils = workspaceTrpc.useUtils();
Expand Down Expand Up @@ -254,7 +257,6 @@ export function usePaneRegistry(
<div className="flex min-w-0 flex-1 items-center gap-1.5">
<TerminalSessionDropdown context={ctx} workspaceId={workspaceId} />
<V2NotificationStatusIndicator
workspaceId={workspaceId}
sources={getV2NotificationSourcesForPane(ctx.pane)}
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { CreatePaneInput, WorkspaceStore } from "@superset/panes";
import { toast } from "@superset/ui/sonner";
import { useLiveQuery } from "@tanstack/react-db";
import { useCallback, useMemo } from "react";
import { useWorkspace } from "renderer/routes/_authenticated/_dashboard/v2-workspace/providers/WorkspaceProvider";
import { useCollections } from "renderer/routes/_authenticated/providers/CollectionsProvider";
import type { V2TerminalPresetRow } from "renderer/routes/_authenticated/providers/CollectionsProvider/dashboardSidebarLocal";
import { getPresetLaunchPlan } from "renderer/stores/tabs/preset-launch";
Expand All @@ -27,14 +28,11 @@ function resolveTarget(executionMode: V2TerminalPresetRow["executionMode"]) {

interface UseV2PresetExecutionArgs {
store: StoreApi<WorkspaceStore<PaneViewerData>>;
workspaceId: string;
projectId: string;
}

export function useV2PresetExecution({
store,
projectId,
}: UseV2PresetExecutionArgs) {
export function useV2PresetExecution({ store }: UseV2PresetExecutionArgs) {
const { workspace } = useWorkspace();
const projectId = workspace.projectId;
const collections = useCollections();

const { data: allPresets = [] } = useLiveQuery(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createWorkspaceStore, type WorkspaceState } from "@superset/panes";
import { eq } from "@tanstack/db";
import { useLiveQuery } from "@tanstack/react-db";
import { useEffect, useMemo, useRef, useState } from "react";
import { useDashboardSidebarState } from "renderer/routes/_authenticated/hooks/useDashboardSidebarState";
import { useWorkspace } from "renderer/routes/_authenticated/_dashboard/v2-workspace/providers/WorkspaceProvider";
import { useCollections } from "renderer/routes/_authenticated/providers/CollectionsProvider";
import type { PaneViewerData } from "../../types";

Expand All @@ -16,17 +16,10 @@ function getSnapshot(state: WorkspaceState<PaneViewerData>): string {
return JSON.stringify(state);
}

interface UseV2WorkspacePaneLayoutParams {
projectId: string;
workspaceId: string;
}

export function useV2WorkspacePaneLayout({
projectId,
workspaceId,
}: UseV2WorkspacePaneLayoutParams) {
export function useV2WorkspacePaneLayout() {
const { workspace } = useWorkspace();
const workspaceId = workspace.id;
const collections = useCollections();
const { ensureWorkspaceInSidebar } = useDashboardSidebarState();
const [store] = useState(() =>
createWorkspaceStore<PaneViewerData>({
initialState: EMPTY_STATE,
Expand All @@ -52,10 +45,6 @@ export function useV2WorkspacePaneLayout({
[localWorkspaceState],
);

useEffect(() => {
ensureWorkspaceInSidebar(workspaceId, projectId);
}, [ensureWorkspaceInSidebar, projectId, workspaceId]);

useEffect(() => {
const nextSnapshot = getSnapshot(persistedPaneLayout);
if (nextSnapshot === lastSyncedSnapshotRef.current) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { WorkspaceStore } from "@superset/panes";
import { workspaceTrpc } from "@superset/workspace-client";
import { useCallback, useEffect, useMemo, useState } from "react";
import type { V2UserPreferencesApi } from "renderer/hooks/useV2UserPreferences";
import { useWorkspace } from "renderer/routes/_authenticated/_dashboard/v2-workspace/providers/WorkspaceProvider";
import {
toAbsoluteWorkspacePath,
toRelativeWorkspacePath,
Expand All @@ -20,12 +21,10 @@ interface PendingReveal {
}

export function useWorkspaceFileNavigation({
workspaceId,
store,
setRightSidebarOpen,
setRightSidebarTab,
}: {
workspaceId: string;
store: StoreApi<WorkspaceStore<PaneViewerData>>;
setRightSidebarOpen: V2UserPreferencesApi["setRightSidebarOpen"];
setRightSidebarTab: V2UserPreferencesApi["setRightSidebarTab"];
Expand All @@ -42,12 +41,13 @@ export function useWorkspaceFileNavigation({
recentFiles: RecentFile[];
openFilePaths: Set<string>;
} {
const { workspace } = useWorkspace();
Comment on lines 41 to +44
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Redundant trpc query for data already in context

useWorkspace() now provides a full SelectV2Workspace row (fetched via useLiveQuery in the layout). If SelectV2Workspace includes worktreePath, workspaceTrpc.workspace.get.useQuery is making an extra round-trip to the host service to retrieve a value already available as workspace.worktreePath. Worth checking whether the trpc query is needed for freshness or whether the context value suffices.

Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/desktop/src/renderer/routes/_authenticated/_dashboard/v2-workspace/$workspaceId/hooks/useWorkspaceFileNavigation/useWorkspaceFileNavigation.ts
Line: 41-44

Comment:
**Redundant trpc query for data already in context**

`useWorkspace()` now provides a full `SelectV2Workspace` row (fetched via `useLiveQuery` in the layout). If `SelectV2Workspace` includes `worktreePath`, `workspaceTrpc.workspace.get.useQuery` is making an extra round-trip to the host service to retrieve a value already available as `workspace.worktreePath`. Worth checking whether the trpc query is needed for freshness or whether the context value suffices.

How can I resolve this? If you propose a fix, please make it concise.

const workspaceQuery = workspaceTrpc.workspace.get.useQuery({
id: workspaceId,
id: workspace.id,
});
const worktreePath = workspaceQuery.data?.worktreePath ?? "";

const { recentFiles, recordView } = useRecentlyViewedFiles(workspaceId);
const { recentFiles, recordView } = useRecentlyViewedFiles(workspace.id);

const activeFilePanePath = useStore(store, (state) => {
const tab = state.tabs.find(
Expand Down
Loading
Loading