Skip to content

Commit 987b3ee

Browse files
authored
refactor: harmonize route/ folder structure (#129)
* refactor: move workspaces route under routes/ * refactor: move a bunch of routes to the routes/ folder * refactor: move all remainig routes under routes/
1 parent 750d8f6 commit 987b3ee

11 files changed

+52
-54
lines changed

src/App.tsx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
import { Header } from "./components/Header";
22
import { PromptList } from "./components/PromptList";
3-
import { Dashboard } from "./components/Dashboard";
43
import { Routes, Route, Link } from "react-router-dom";
5-
import { Chat } from "./components/Chat";
64
import { usePromptsData } from "./hooks/usePromptsData";
75
import { Sidebar } from "./components/Sidebar";
86
import { useSse } from "./hooks/useSse";
9-
import { Help } from "./components/Help";
10-
import { Certificates } from "./components/Certificates";
11-
import { CertificateSecurity } from "./components/CertificateSecurity";
127
import {
138
Breadcrumb,
149
BreadcrumbList,
@@ -18,7 +13,12 @@ import {
1813
} from "./components/ui/breadcrumb";
1914
import { useBreadcrumb } from "./hooks/useBreadcrumb";
2015
import { RouteWorkspace } from "./routes/route-workspace";
21-
import { Workspaces } from "./components/Workspaces";
16+
import { RouteWorkspaces } from "./routes/route-workspaces";
17+
import { RouteCertificates } from "./routes/route-certificates";
18+
import { RouteHelp } from "./routes/route-help";
19+
import { RouteChat } from "./routes/route-chat";
20+
import { RouteDashboard } from "./routes/route-dashboard";
21+
import { RouteCertificateSecurity } from "./routes/route-certificate-security";
2222

2323
function App() {
2424
const { data: prompts, isLoading } = usePromptsData();
@@ -55,15 +55,15 @@ function App() {
5555

5656
<div className="flex-1 overflow-y-auto p-6">
5757
<Routes>
58-
<Route path="/" element={<Dashboard />} />
59-
<Route path="/prompt/:id" element={<Chat />} />
60-
<Route path="/help/:section" element={<Help />} />
61-
<Route path="/certificates" element={<Certificates />} />
58+
<Route path="/" element={<RouteDashboard />} />
59+
<Route path="/prompt/:id" element={<RouteChat />} />
60+
<Route path="/help/:section" element={<RouteHelp />} />
61+
<Route path="/certificates" element={<RouteCertificates />} />
6262
<Route path="/workspace/:id" element={<RouteWorkspace />} />
63-
<Route path="/workspaces" element={<Workspaces />} />
63+
<Route path="/workspaces" element={<RouteWorkspaces />} />
6464
<Route
6565
path="/certificates/security"
66-
element={<CertificateSecurity />}
66+
element={<RouteCertificateSecurity />}
6767
/>
6868
</Routes>
6969
</div>

src/components/__tests__/Certificates.test.tsx renamed to src/routes/__tests__/route-certificates.test.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { render } from "@/lib/test-utils";
22
import { screen } from "@testing-library/react";
33
import { describe, expect, it } from "vitest";
4-
import { Certificates } from "../Certificates";
54
import userEvent from "@testing-library/user-event";
5+
import { RouteCertificates } from "../route-certificates";
66

77
describe("Certificates", () => {
88
it("should render download certificate", () => {
9-
render(<Certificates />);
9+
render(<RouteCertificates />);
1010
expect(
1111
screen.getByRole("heading", { name: "CodeGate CA certificate" }),
1212
).toBeVisible();
@@ -28,7 +28,7 @@ describe("Certificates", () => {
2828
});
2929

3030
it("should render macOS certificate installation", async () => {
31-
render(<Certificates />);
31+
render(<RouteCertificates />);
3232

3333
expect(
3434
screen.getByText(
@@ -43,7 +43,7 @@ describe("Certificates", () => {
4343
});
4444

4545
it("should render Windows certificate installation", async () => {
46-
render(<Certificates />);
46+
render(<RouteCertificates />);
4747

4848
await userEvent.click(screen.getByText("Windows"));
4949

@@ -58,7 +58,7 @@ describe("Certificates", () => {
5858
});
5959

6060
it("should render Linux certificate installation", async () => {
61-
render(<Certificates />);
61+
render(<RouteCertificates />);
6262

6363
await userEvent.click(screen.getByText("Linux"));
6464

src/components/__tests__/Chat.test.tsx renamed to src/routes/__tests__/route-chat.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { render } from "@/lib/test-utils";
2-
import { Chat } from "../Chat";
32
import { screen, within } from "@testing-library/react";
43
import { describe, expect, it } from "vitest";
4+
import { RouteChat } from "../route-chat";
55

66
vi.mock("@stacklok/ui-kit", async (importOriginal) => {
77
return {
@@ -50,7 +50,7 @@ vi.mock("@/hooks/usePromptsData", () => ({
5050

5151
describe("Chat", () => {
5252
it("should render secret issue chat", () => {
53-
render(<Chat />, {
53+
render(<RouteChat />, {
5454
routeConfig: {
5555
initialEntries: ["/prompt/chatcmpl-7d87679de7ed41639eb91d8ebbaa6f72"],
5656
},

src/components/__tests__/Dashboard.test.tsx renamed to src/routes/__tests__/route-dashboard.test.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { render } from "@/lib/test-utils";
22
import { screen, waitFor, within } from "@testing-library/react";
33
import { describe, expect, it, vi } from "vitest";
4-
import { Dashboard } from "../Dashboard";
54
import { faker } from "@faker-js/faker";
65
import React from "react";
76
import { server } from "@/mocks/msw/node";
87
import { HttpResponse, http } from "msw";
98
import mockedAlerts from "@/mocks/msw/fixtures/GET_ALERTS.json";
109
import userEvent from "@testing-library/user-event";
10+
import { RouteDashboard } from "../route-dashboard";
1111

1212
vi.mock("recharts", async (importOriginal) => {
1313
const originalModule = (await importOriginal()) as Record<string, unknown>;
@@ -113,7 +113,7 @@ function mockManyAlerts() {
113113

114114
describe("Dashboard", () => {
115115
it("should render charts and table", async () => {
116-
render(<Dashboard />);
116+
render(<RouteDashboard />);
117117
expect(screen.getByText(/security issues detected/i)).toBeVisible();
118118
expect(screen.getByText(/malicious packages by type/i)).toBeVisible();
119119
expect(screen.getByText(/alerts by date/i)).toBeVisible();
@@ -192,7 +192,7 @@ describe("Dashboard", () => {
192192

193193
it("should render malicious pkg", async () => {
194194
mockAlertsWithMaliciousPkg();
195-
render(<Dashboard />);
195+
render(<RouteDashboard />);
196196

197197
expect(
198198
(await screen.findAllByTestId(/mock-responsive-container/i)).length,
@@ -224,7 +224,7 @@ describe("Dashboard", () => {
224224

225225
it("should filter by malicious pkg", async () => {
226226
mockAlertsWithMaliciousPkg();
227-
render(<Dashboard />);
227+
render(<RouteDashboard />);
228228

229229
expect(
230230
(await screen.findAllByTestId(/mock-responsive-container/i)).length,
@@ -269,7 +269,7 @@ describe("Dashboard", () => {
269269

270270
it("should search by secrets alert", async () => {
271271
mockAlertsWithMaliciousPkg();
272-
render(<Dashboard />);
272+
render(<RouteDashboard />);
273273

274274
expect(
275275
(await screen.findAllByTestId(/mock-responsive-container/i)).length,
@@ -300,7 +300,7 @@ describe("Dashboard", () => {
300300
});
301301

302302
it("should sort alerts by date desc", async () => {
303-
render(<Dashboard />);
303+
render(<RouteDashboard />);
304304
expect(
305305
(await screen.findAllByTestId(/mock-responsive-container/i)).length,
306306
).toEqual(1);
@@ -319,7 +319,7 @@ describe("Dashboard", () => {
319319
it("only displays a limited number of items in the table", async () => {
320320
mockManyAlerts();
321321

322-
render(<Dashboard />);
322+
render(<RouteDashboard />);
323323

324324
await waitFor(() => {
325325
expect(
@@ -331,7 +331,7 @@ describe("Dashboard", () => {
331331
it("allows pagination", async () => {
332332
mockManyAlerts();
333333

334-
render(<Dashboard />);
334+
render(<RouteDashboard />);
335335

336336
await waitFor(
337337
async () => {

src/components/Workspaces.test.tsx renamed to src/routes/__tests__/route-workspaces.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { render } from "@/lib/test-utils";
22
import { screen, waitFor, within } from "@testing-library/react";
33
import { describe, expect, it } from "vitest";
4-
import { Workspaces } from "./Workspaces";
4+
import { RouteWorkspaces } from "../route-workspaces";
55

66
describe("Workspaces page", () => {
77
beforeEach(() => {
8-
render(<Workspaces />);
8+
render(<RouteWorkspaces />);
99
});
1010

1111
it("has a title", () => {

src/components/CertificateSecurity.tsx renamed to src/routes/route-certificate-security.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const OpenSourceIcon = () => (
5757
</svg>
5858
);
5959

60-
export function CertificateSecurity() {
60+
export function RouteCertificateSecurity() {
6161
return (
6262
<div className="flex flex-col h-full">
6363
<div className="max-w-4xl mx-auto mb-4">

src/components/Certificates.tsx renamed to src/routes/route-certificates.tsx

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,7 @@ function InstructionStep({ number, text }: { number: number; text: string }) {
3434
}
3535

3636
const CheckIcon = () => (
37-
<svg
38-
viewBox="0 0 24 24"
39-
className="size-5 text-brand-700 shrink-0 mt-1"
40-
>
37+
<svg viewBox="0 0 24 24" className="size-5 text-brand-700 shrink-0 mt-1">
4138
<path
4239
fill="none"
4340
stroke="currentColor"
@@ -75,7 +72,7 @@ const ArrowIcon = () => (
7572
</svg>
7673
);
7774

78-
export function Certificates() {
75+
export function RouteCertificates() {
7976
const [activeOS, setActiveOS] = useState<OS>("macos");
8077
const [activeAction, setActiveAction] = useState<Action>("install");
8178

@@ -172,24 +169,25 @@ export function Certificates() {
172169
<CheckIcon />
173170
<p className="text-secondary">
174171
<strong>Local-only:</strong> CodeGate runs entirely on your
175-
machine within an isolated container, ensuring all data processing
176-
stays local without any external transmissions.
172+
machine within an isolated container, ensuring all data
173+
processing stays local without any external transmissions.
177174
</p>
178175
</div>
179176
<div className="flex gap-3">
180177
<CheckIcon />
181178
<p className="text-secondary">
182179
<strong>Secure certificate handling:</strong> this custom CA is
183-
locally generated and managed. CodeGate developers have no access
184-
to it.
180+
locally generated and managed. CodeGate developers have no
181+
access to it.
185182
</p>
186183
</div>
187184
<div className="flex gap-3">
188185
<CheckIcon />
189186
<p className="text-secondary">
190-
<strong>No external communications:</strong> CodeGate is designed
191-
with no capability to call home or communicate with external
192-
servers, outside of those requested by the IDE or Agent.
187+
<strong>No external communications:</strong> CodeGate is
188+
designed with no capability to call home or communicate with
189+
external servers, outside of those requested by the IDE or
190+
Agent.
193191
</p>
194192
</div>
195193
</div>

src/components/Chat.tsx renamed to src/routes/route-chat.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1+
import { useParams } from "react-router-dom";
2+
import { usePromptsData } from "@/hooks/usePromptsData";
3+
import { sanitizeQuestionPrompt } from "@/lib/utils";
4+
import { ChatMessageList } from "@/components/ui/chat/chat-message-list";
15
import {
26
ChatBubble,
37
ChatBubbleAvatar,
48
ChatBubbleMessage,
5-
} from "./ui/chat/chat-bubble";
6-
import { ChatMessageList } from "./ui/chat/chat-message-list";
7-
import { useParams } from "react-router-dom";
8-
import { usePromptsData } from "@/hooks/usePromptsData";
9-
import { Markdown } from "./Markdown";
10-
import { sanitizeQuestionPrompt } from "@/lib/utils";
9+
} from "@/components/ui/chat/chat-bubble";
10+
import { Markdown } from "@/components/Markdown";
1111

12-
export function Chat() {
12+
export function RouteChat() {
1313
const { id } = useParams();
1414
const { data: prompts } = usePromptsData();
1515
const chat = prompts?.find((prompt) => prompt.chat_id === id);

src/components/Dashboard.tsx renamed to src/routes/route-dashboard.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import {
1010
useMaliciousPackagesChartData,
1111
} from "@/hooks/useAlertsData";
1212
import { useAlertSearch } from "@/hooks/useAlertSearch";
13-
import { AlertsTable } from "./AlertsTable";
13+
import { AlertsTable } from "@/components/AlertsTable";
1414

15-
export function Dashboard() {
15+
export function RouteDashboard() {
1616
const [searchParams] = useSearchParams();
1717

1818
const { setIsMaliciousFilterActive, setSearch } = useAlertSearch();

src/components/Help.tsx renamed to src/routes/route-help.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { useEffect, useState } from "react";
22
import { useParams } from "react-router-dom";
3-
import { Markdown } from "./Markdown";
43
import Prism from "prismjs";
54
import "prismjs/themes/prism-tomorrow.css";
65
import "prismjs/components/prism-bash";
76
import "prismjs/components/prism-javascript";
87
import "prismjs/components/prism-python";
98
import "prismjs/components/prism-json";
109
import "prismjs/components/prism-yaml";
10+
import { Markdown } from "@/components/Markdown";
1111

12-
export function Help() {
12+
export function RouteHelp() {
1313
const { section } = useParams();
1414
const [content, setContent] = useState<string>("");
1515

src/components/Workspaces.tsx renamed to src/routes/route-workspaces.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
} from "@stacklok/ui-kit";
1212
import { Settings } from "lucide-react";
1313

14-
export function Workspaces() {
14+
export function RouteWorkspaces() {
1515
const result = useWorkspacesData();
1616
const workspaces = result.data?.workspaces ?? [];
1717

0 commit comments

Comments
 (0)