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
31 changes: 22 additions & 9 deletions apps/desktop/src/lib/trpc/routers/config/config.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
import { readFile } from "node:fs/promises";
import { join } from "node:path";
import { projects } from "@superset/local-db";
import { eq } from "drizzle-orm";
import { localDb } from "main/lib/local-db";
import { z } from "zod";
import { publicProcedure, router } from "../..";

function configExists(mainRepoPath: string): boolean {
async function hasConfiguredScripts(mainRepoPath: string): Promise<boolean> {
const configPath = join(mainRepoPath, ".superset", "config.json");
return existsSync(configPath);
try {
const content = await readFile(configPath, "utf-8");
const parsed = JSON.parse(content);
const setup = Array.isArray(parsed.setup)
? parsed.setup.filter((s: string) => s.trim().length > 0)
: [];
const teardown = Array.isArray(parsed.teardown)
? parsed.teardown.filter((s: string) => s.trim().length > 0)
: [];
return setup.length > 0 || teardown.length > 0;
} catch {
return false;
}
}

const CONFIG_TEMPLATE = `{
Expand Down Expand Up @@ -39,10 +52,10 @@ function ensureConfigExists(mainRepoPath: string): string {

export const createConfigRouter = () => {
return router({
// Check if we should show the config toast for a project
shouldShowConfigToast: publicProcedure
// Check if we should show the setup card for a project
shouldShowSetupCard: publicProcedure
.input(z.object({ projectId: z.string() }))
.query(({ input }) => {
.query(async ({ input }) => {
const project = localDb
.select()
.from(projects)
Expand All @@ -52,16 +65,16 @@ export const createConfigRouter = () => {
return false;
}

// Don't show if already dismissed or if config exists
// Don't show if already dismissed or if config has scripts
if (project.configToastDismissed) {
return false;
}

return !configExists(project.mainRepoPath);
return !(await hasConfiguredScripts(project.mainRepoPath));
}),

// Mark the config toast as dismissed for a project
dismissConfigToast: publicProcedure
// Mark the setup card as dismissed for a project
dismissSetupCard: publicProcedure
.input(z.object({ projectId: z.string() }))
.mutation(({ input }) => {
localDb
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { toast } from "@superset/ui/sonner";
import { useNavigate } from "@tanstack/react-router";
import { electronTrpc } from "renderer/lib/electron-trpc";
import { navigateToWorkspace } from "renderer/routes/_authenticated/_dashboard/utils/workspace-navigation";
import { useOpenConfigModal } from "renderer/stores/config-modal";
import { useTabsStore } from "renderer/stores/tabs/store";

export function useOpenExternalWorktree(
Expand All @@ -15,9 +13,6 @@ export function useOpenExternalWorktree(
const addTab = useTabsStore((state) => state.addTab);
const setTabAutoTitle = useTabsStore((state) => state.setTabAutoTitle);
const createOrAttach = electronTrpc.terminal.createOrAttach.useMutation();
const openConfigModal = useOpenConfigModal();
const dismissConfigToast =
electronTrpc.config.dismissConfigToast.useMutation();

return electronTrpc.workspaces.openExternalWorktree.useMutation({
...options,
Expand All @@ -41,19 +36,6 @@ export function useOpenExternalWorktree(
initialCommands,
});

if (!initialCommands) {
toast.info("No setup script configured", {
description: "Automate workspace setup with a config.json file",
action: {
label: "Configure",
onClick: () => openConfigModal(data.projectId),
},
onDismiss: () => {
dismissConfigToast.mutate({ projectId: data.projectId });
},
});
}

navigateToWorkspace(data.workspace.id, navigate);

await options?.onSuccess?.(data, ...rest);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import { toast } from "@superset/ui/sonner";
import { useNavigate } from "@tanstack/react-router";
import { electronTrpc } from "renderer/lib/electron-trpc";
import { navigateToWorkspace } from "renderer/routes/_authenticated/_dashboard/utils/workspace-navigation";
import { useOpenConfigModal } from "renderer/stores/config-modal";
import { useTabsStore } from "renderer/stores/tabs/store";

/**
* Mutation hook for opening an existing worktree as a new workspace
* Automatically invalidates all workspace queries on success
* Creates a terminal tab with setup commands if present
* Shows config toast if no setup commands are configured
*/
export function useOpenWorktree(
options?: Parameters<
Expand All @@ -21,9 +18,6 @@ export function useOpenWorktree(
const addTab = useTabsStore((state) => state.addTab);
const setTabAutoTitle = useTabsStore((state) => state.setTabAutoTitle);
const createOrAttach = electronTrpc.terminal.createOrAttach.useMutation();
const openConfigModal = useOpenConfigModal();
const dismissConfigToast =
electronTrpc.config.dismissConfigToast.useMutation();

return electronTrpc.workspaces.openWorktree.useMutation({
...options,
Expand All @@ -47,19 +41,6 @@ export function useOpenWorktree(
initialCommands,
});

if (!initialCommands) {
toast.info("No setup script configured", {
description: "Automate workspace setup with a config.json file",
action: {
label: "Configure",
onClick: () => openConfigModal(data.projectId),
},
onDismiss: () => {
dismissConfigToast.mutate({ projectId: data.projectId });
},
});
}

navigateToWorkspace(data.workspace.id, navigate);

await options?.onSuccess?.(data, ...rest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,11 @@ function DashboardLayout() {
handleSide="right"
clampWidth={false}
>
<WorkspaceSidebar isCollapsed={isWorkspaceSidebarCollapsed()} />
<WorkspaceSidebar
isCollapsed={isWorkspaceSidebarCollapsed()}
activeProjectId={currentWorkspace?.projectId ?? null}
activeProjectName={currentWorkspace?.project?.name ?? null}
/>
</ResizablePanel>
)}
<Outlet />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ export function ProjectSettings({ projectId }: ProjectSettingsProps) {
<ClickablePath path={project.mainRepoPath} />
</div>

<div className="pt-4 border-t">
<ScriptsEditor projectId={project.id} />
</div>

<div className="pt-4 border-t space-y-4">
<div className="space-y-2">
<h3 className="text-base font-semibold text-foreground flex items-center gap-2">
Expand Down Expand Up @@ -188,20 +192,6 @@ export function ProjectSettings({ projectId }: ProjectSettingsProps) {
</code>
</p>
</div>

<div className="pt-4 border-t space-y-4">
<div className="space-y-2">
<h3 className="text-base font-semibold text-foreground flex items-center gap-2">
<HiOutlineCog6Tooth className="h-4 w-4" />
Scripts
</h3>
<p className="text-sm text-muted-foreground">
Configure setup and teardown scripts that run when workspaces are
created or deleted.
</p>
</div>
<ScriptsEditor projectId={project.id} projectName={project.name} />
</div>
</div>
</div>
);
Expand Down
Loading