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
30 changes: 30 additions & 0 deletions apps/desktop/src/lib/trpc/routers/settings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,36 @@ export const createSettingsRouter = () => {
return { success: true };
}),

setDefaultPreset: publicProcedure
.input(z.object({ id: z.string().nullable() }))
.mutation(({ input }) => {
const row = getSettings();
const presets = row.terminalPresets ?? [];

// Clear existing default and set new one (if id is provided)
const updatedPresets = presets.map((p) => ({
...p,
isDefault: input.id === p.id ? true : undefined,
}));

localDb
.insert(settings)
.values({ id: 1, terminalPresets: updatedPresets })
.onConflictDoUpdate({
target: settings.id,
set: { terminalPresets: updatedPresets },
})
.run();

return { success: true };
}),

getDefaultPreset: publicProcedure.query(() => {
const row = getSettings();
const presets = row.terminalPresets ?? [];
return presets.find((p) => p.isDefault) ?? null;
}),

getSelectedRingtoneId: publicProcedure.query(() => {
const row = getSettings();
const storedId = row.selectedRingtoneId;
Expand Down
20 changes: 20 additions & 0 deletions apps/desktop/src/renderer/react-query/presets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,21 @@ function useDeleteTerminalPreset(
});
}

function useSetDefaultPreset(
options?: Parameters<typeof trpc.settings.setDefaultPreset.useMutation>[0],
) {
const utils = trpc.useUtils();

return trpc.settings.setDefaultPreset.useMutation({
...options,
onSuccess: async (...args) => {
await utils.settings.getTerminalPresets.invalidate();
await utils.settings.getDefaultPreset.invalidate();
await options?.onSuccess?.(...args);
},
});
}

/**
* Combined hook for accessing terminal presets with all CRUD operations
* Provides easy access to presets data and mutations from anywhere in the app
Expand All @@ -56,15 +71,20 @@ export function usePresets() {
const { data: presets = [], isLoading } =
trpc.settings.getTerminalPresets.useQuery();

const { data: defaultPreset } = trpc.settings.getDefaultPreset.useQuery();

const createPreset = useCreateTerminalPreset();
const updatePreset = useUpdateTerminalPreset();
const deletePreset = useDeleteTerminalPreset();
const setDefaultPreset = useSetDefaultPreset();

return {
presets,
defaultPreset,
isLoading,
createPreset,
updatePreset,
deletePreset,
setDefaultPreset,
};
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Button } from "@superset/ui/button";
import { Input } from "@superset/ui/input";
import { Tooltip, TooltipContent, TooltipTrigger } from "@superset/ui/tooltip";
import { HiOutlineStar, HiStar } from "react-icons/hi2";
import { LuTrash } from "react-icons/lu";
import { CommandsEditor } from "../CommandsEditor";
import {
Expand Down Expand Up @@ -62,6 +64,7 @@ interface PresetRowProps {
onCommandsChange: (rowIndex: number, commands: string[]) => void;
onCommandsBlur: (rowIndex: number) => void;
onDelete: (rowIndex: number) => void;
onSetDefault: (presetId: string | null) => void;
}

export function PresetRow({
Expand All @@ -73,7 +76,13 @@ export function PresetRow({
onCommandsChange,
onCommandsBlur,
onDelete,
onSetDefault,
}: PresetRowProps) {
const handleToggleDefault = () => {
// If already default, clear it; otherwise set this preset as default
onSetDefault(preset.isDefault ? null : preset.id);
};

return (
<div
className={`flex items-start gap-4 py-3 px-4 ${
Expand All @@ -93,7 +102,31 @@ export function PresetRow({
/>
</div>
))}
<div className="w-12 flex justify-center shrink-0 pt-1">
<div className="w-20 flex justify-center gap-1 shrink-0 pt-1">
<Tooltip>
<TooltipTrigger asChild>
<Button
variant="ghost"
size="sm"
onClick={handleToggleDefault}
className={`h-8 w-8 p-0 ${preset.isDefault ? "text-yellow-500 hover:text-yellow-600" : "text-muted-foreground hover:text-foreground"}`}
aria-label={
preset.isDefault ? "Remove default" : "Set as default"
}
>
{preset.isDefault ? (
<HiStar className="h-4 w-4" />
) : (
<HiOutlineStar className="h-4 w-4" />
)}
</Button>
</TooltipTrigger>
<TooltipContent side="top">
{preset.isDefault
? "Remove as default"
: "Set as default for new terminals"}
</TooltipContent>
</Tooltip>
<Button
variant="ghost"
size="sm"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export function PresetsSettings() {
createPreset,
updatePreset,
deletePreset,
setDefaultPreset,
} = usePresets();
const [localPresets, setLocalPresets] =
useState<TerminalPreset[]>(serverPresets);
Expand Down Expand Up @@ -161,6 +162,10 @@ export function PresetsSettings() {
deletePreset.mutate({ id: preset.id });
};

const handleSetDefault = (presetId: string | null) => {
setDefaultPreset.mutate({ id: presetId });
};

if (isLoading) {
return (
<div className="p-6 w-full max-w-6xl">
Expand Down Expand Up @@ -241,7 +246,7 @@ export function PresetsSettings() {
{column.label}
</div>
))}
<div className="w-12 text-xs font-medium text-muted-foreground uppercase tracking-wider text-center shrink-0">
<div className="w-20 text-xs font-medium text-muted-foreground uppercase tracking-wider text-center shrink-0">
Actions
</div>
</div>
Expand All @@ -259,6 +264,7 @@ export function PresetsSettings() {
onCommandsChange={handleCommandsChange}
onCommandsBlur={handleCommandsBlur}
onDelete={handleDeleteRow}
onSetDefault={handleSetDefault}
/>
))
) : (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
HiMiniCog6Tooth,
HiMiniCommandLine,
HiMiniPlus,
HiStar,
} from "react-icons/hi2";
import {
getPresetIcon,
Expand All @@ -24,6 +25,7 @@ import { trpc } from "renderer/lib/trpc";
import { usePresets } from "renderer/react-query/presets";
import { useOpenSettings } from "renderer/stores";
import { useTabsStore } from "renderer/stores/tabs/store";
import { useTabsWithPresets } from "renderer/stores/tabs/useTabsWithPresets";
import { type ActivePaneStatus, pickHigherStatus } from "shared/tabs-types";
import { GroupItem } from "./GroupItem";

Expand All @@ -34,7 +36,7 @@ export function GroupStrip() {
const allTabs = useTabsStore((s) => s.tabs);
const panes = useTabsStore((s) => s.panes);
const activeTabIds = useTabsStore((s) => s.activeTabIds);
const addTab = useTabsStore((s) => s.addTab);
const { addTab } = useTabsWithPresets();
const renameTab = useTabsStore((s) => s.renameTab);
const removeTab = useTabsStore((s) => s.removeTab);
const setActiveTab = useTabsStore((s) => s.setActiveTab);
Expand Down Expand Up @@ -89,9 +91,8 @@ export function GroupStrip() {
}, [panes]);

const handleAddGroup = () => {
if (activeWorkspaceId) {
addTab(activeWorkspaceId);
}
if (!activeWorkspaceId) return;
addTab(activeWorkspaceId);
};

const handleSelectPreset = (preset: TerminalPreset) => {
Expand Down Expand Up @@ -208,6 +209,9 @@ export function GroupStrip() {
<HiMiniCommandLine className="size-4" />
)}
<span className="truncate">{preset.name || "default"}</span>
{preset.isDefault && (
<HiStar className="size-3 text-yellow-500 ml-auto flex-shrink-0" />
)}
</DropdownMenuItem>
);
})}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { dragDropManager } from "renderer/lib/dnd";
import { trpc } from "renderer/lib/trpc";
import { useTabsStore } from "renderer/stores/tabs/store";
import type { Pane, Tab } from "renderer/stores/tabs/types";
import { useTabsWithPresets } from "renderer/stores/tabs/useTabsWithPresets";
import {
cleanLayout,
extractPaneIdsFromLayout,
Expand All @@ -28,9 +29,8 @@ export function TabView({ tab, panes }: TabViewProps) {
const updateTabLayout = useTabsStore((s) => s.updateTabLayout);
const removePane = useTabsStore((s) => s.removePane);
const removeTab = useTabsStore((s) => s.removeTab);
const splitPaneAuto = useTabsStore((s) => s.splitPaneAuto);
const splitPaneHorizontal = useTabsStore((s) => s.splitPaneHorizontal);
const splitPaneVertical = useTabsStore((s) => s.splitPaneVertical);
const { splitPaneAuto, splitPaneHorizontal, splitPaneVertical } =
useTabsWithPresets();
const setFocusedPane = useTabsStore((s) => s.setFocusedPane);
const focusedPaneIds = useTabsStore((s) => s.focusedPaneIds);
const movePaneToTab = useTabsStore((s) => s.movePaneToTab);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useMemo } from "react";
import { trpc } from "renderer/lib/trpc";
import { useAppHotkey } from "renderer/stores/hotkeys";
import { useTabsStore } from "renderer/stores/tabs/store";
import { useTabsWithPresets } from "renderer/stores/tabs/useTabsWithPresets";
import { getNextPaneId, getPreviousPaneId } from "renderer/stores/tabs/utils";
import {
useHasWorkspaceFailed,
Expand Down Expand Up @@ -33,7 +34,7 @@ export function WorkspaceView() {
const allTabs = useTabsStore((s) => s.tabs);
const activeTabIds = useTabsStore((s) => s.activeTabIds);
const focusedPaneIds = useTabsStore((s) => s.focusedPaneIds);
const addTab = useTabsStore((s) => s.addTab);
const { addTab } = useTabsWithPresets();
const setActiveTab = useTabsStore((s) => s.setActiveTab);
const removePane = useTabsStore((s) => s.removePane);
const setFocusedPane = useTabsStore((s) => s.setFocusedPane);
Expand Down
6 changes: 3 additions & 3 deletions apps/desktop/src/renderer/screens/main/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { getPaneDimensions } from "renderer/stores/tabs/pane-refs";
import { useTabsStore } from "renderer/stores/tabs/store";
import type { Tab } from "renderer/stores/tabs/types";
import { useAgentHookListener } from "renderer/stores/tabs/useAgentHookListener";
import { useTabsWithPresets } from "renderer/stores/tabs/useTabsWithPresets";
import { findPanePath, getFirstPaneId } from "renderer/stores/tabs/utils";
import { useWorkspaceInitStore } from "renderer/stores/workspace-init";
import { useWorkspaceSidebarStore } from "renderer/stores/workspace-sidebar-state";
Expand Down Expand Up @@ -94,9 +95,8 @@ export function MainScreen() {
enabled: isSignedIn,
});
const [isRetrying, setIsRetrying] = useState(false);
const splitPaneAuto = useTabsStore((s) => s.splitPaneAuto);
const splitPaneVertical = useTabsStore((s) => s.splitPaneVertical);
const splitPaneHorizontal = useTabsStore((s) => s.splitPaneHorizontal);
const { splitPaneAuto, splitPaneVertical, splitPaneHorizontal } =
useTabsWithPresets();
const setFocusedPane = useTabsStore((s) => s.setFocusedPane);
const activeTabIds = useTabsStore((s) => s.activeTabIds);
const focusedPaneIds = useTabsStore((s) => s.focusedPaneIds);
Expand Down
1 change: 1 addition & 0 deletions apps/desktop/src/renderer/stores/tabs/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from "./store";
export * from "./types";
export * from "./useAgentHookListener";
export * from "./useTabsWithPresets";
export * from "./utils";
14 changes: 7 additions & 7 deletions apps/desktop/src/renderer/stores/tabs/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ export const useTabsStore = create<TabsStore>()(
},

// Split operations
splitPaneVertical: (tabId, sourcePaneId, path) => {
splitPaneVertical: (tabId, sourcePaneId, path, options) => {
const state = get();
const tab = state.tabs.find((t) => t.id === tabId);
if (!tab) return;
Expand All @@ -626,7 +626,7 @@ export const useTabsStore = create<TabsStore>()(
if (!sourcePane || sourcePane.tabId !== tabId) return;

// Always create a new terminal when splitting
const newPane = createPane(tabId);
const newPane = createPane(tabId, "terminal", options);

let newLayout: MosaicNode<string>;
if (path && path.length > 0) {
Expand Down Expand Up @@ -666,7 +666,7 @@ export const useTabsStore = create<TabsStore>()(
});
},

splitPaneHorizontal: (tabId, sourcePaneId, path) => {
splitPaneHorizontal: (tabId, sourcePaneId, path, options) => {
const state = get();
const tab = state.tabs.find((t) => t.id === tabId);
if (!tab) return;
Expand All @@ -675,7 +675,7 @@ export const useTabsStore = create<TabsStore>()(
if (!sourcePane || sourcePane.tabId !== tabId) return;

// Always create a new terminal when splitting
const newPane = createPane(tabId);
const newPane = createPane(tabId, "terminal", options);

let newLayout: MosaicNode<string>;
if (path && path.length > 0) {
Expand Down Expand Up @@ -715,11 +715,11 @@ export const useTabsStore = create<TabsStore>()(
});
},

splitPaneAuto: (tabId, sourcePaneId, dimensions, path) => {
splitPaneAuto: (tabId, sourcePaneId, dimensions, path, options) => {
if (dimensions.width >= dimensions.height) {
get().splitPaneVertical(tabId, sourcePaneId, path);
get().splitPaneVertical(tabId, sourcePaneId, path, options);
} else {
get().splitPaneHorizontal(tabId, sourcePaneId, path);
get().splitPaneHorizontal(tabId, sourcePaneId, path, options);
}
},

Expand Down
3 changes: 3 additions & 0 deletions apps/desktop/src/renderer/stores/tabs/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,20 @@ export interface TabsStore extends TabsState {
tabId: string,
sourcePaneId: string,
path?: MosaicBranch[],
options?: AddTabOptions,
) => void;
splitPaneHorizontal: (
tabId: string,
sourcePaneId: string,
path?: MosaicBranch[],
options?: AddTabOptions,
) => void;
splitPaneAuto: (
tabId: string,
sourcePaneId: string,
dimensions: { width: number; height: number },
path?: MosaicBranch[],
options?: AddTabOptions,
) => void;

// Move operations
Expand Down
Loading