From ce6f06d9306b65ef8f15dac6abc5ba7834a60dc4 Mon Sep 17 00:00:00 2001 From: Daniel Kantor Date: Mon, 20 Jan 2025 10:33:05 +0100 Subject: [PATCH 1/8] add workspaces route --- src/App.tsx | 3 +++ src/components/Workspaces.tsx | 3 +++ 2 files changed, 6 insertions(+) create mode 100644 src/components/Workspaces.tsx diff --git a/src/App.tsx b/src/App.tsx index f0da106f..b1edf538 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -18,6 +18,7 @@ import { } from "./components/ui/breadcrumb"; import { useBreadcrumb } from "./hooks/useBreadcrumb"; import { RouteWorkspace } from "./routes/route-workspace"; +import { Workspaces } from "./components/Workspaces"; function App() { const { data: prompts, isLoading } = usePromptsData(); @@ -59,6 +60,8 @@ function App() { } /> } /> } /> + } /> + } diff --git a/src/components/Workspaces.tsx b/src/components/Workspaces.tsx new file mode 100644 index 00000000..14b0d6a6 --- /dev/null +++ b/src/components/Workspaces.tsx @@ -0,0 +1,3 @@ +export function Workspaces() { + return
hello world
; +} From fdfcfc5841b2103c96f7e4b41a5dd5b477eca2a1 Mon Sep 17 00:00:00 2001 From: Daniel Kantor Date: Mon, 20 Jan 2025 11:27:17 +0100 Subject: [PATCH 2/8] add header to page --- src/components/Workspaces.test.tsx | 16 ++++++++++++++++ src/components/Workspaces.tsx | 6 +++++- 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 src/components/Workspaces.test.tsx diff --git a/src/components/Workspaces.test.tsx b/src/components/Workspaces.test.tsx new file mode 100644 index 00000000..fe267cc8 --- /dev/null +++ b/src/components/Workspaces.test.tsx @@ -0,0 +1,16 @@ +import { render } from "@/lib/test-utils"; +import { screen } from "@testing-library/react"; +import { describe, expect, it } from "vitest"; +import { Workspaces } from "./Workspaces"; + +describe("Workspaces page", () => { + beforeEach(() => { + render(); + }); + + it("has a title", () => { + expect( + screen.getByRole("heading", { name: /manage workspaces/i }), + ).toBeVisible(); + }); +}); diff --git a/src/components/Workspaces.tsx b/src/components/Workspaces.tsx index 14b0d6a6..89e050a0 100644 --- a/src/components/Workspaces.tsx +++ b/src/components/Workspaces.tsx @@ -1,3 +1,7 @@ export function Workspaces() { - return
hello world
; + return ( +
+

Manage Workspaces

+
+ ); } From 673472c494009e85ce8f746a758763e14f4a4f4c Mon Sep 17 00:00:00 2001 From: Daniel Kantor Date: Mon, 20 Jan 2025 11:34:38 +0100 Subject: [PATCH 3/8] make sure table has correct columns --- src/components/Workspaces.test.tsx | 7 +++++++ src/components/Workspaces.tsx | 13 +++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/components/Workspaces.test.tsx b/src/components/Workspaces.test.tsx index fe267cc8..31f9a285 100644 --- a/src/components/Workspaces.test.tsx +++ b/src/components/Workspaces.test.tsx @@ -13,4 +13,11 @@ describe("Workspaces page", () => { screen.getByRole("heading", { name: /manage workspaces/i }), ).toBeVisible(); }); + + it("has a table with the correct columns", () => { + expect(screen.getByRole("columnheader", { name: /name/i })).toBeVisible(); + expect( + screen.getByRole("columnheader", { name: /configuration/i }), + ).toBeVisible(); + }); }); diff --git a/src/components/Workspaces.tsx b/src/components/Workspaces.tsx index 89e050a0..da50694e 100644 --- a/src/components/Workspaces.tsx +++ b/src/components/Workspaces.tsx @@ -1,7 +1,20 @@ +import { Column, Row, Table, TableBody, TableHeader } from "@stacklok/ui-kit"; + export function Workspaces() { return (

Manage Workspaces

+ + + + + Name + + Configuration + + + +
); } From ea7b3a8a51b239100dee0027a3d9fbb72cd85d3e Mon Sep 17 00:00:00 2001 From: Daniel Kantor Date: Mon, 20 Jan 2025 11:37:40 +0100 Subject: [PATCH 4/8] make sure there are rows for each workspace --- src/components/Workspaces.test.tsx | 4 ++++ src/components/Workspaces.tsx | 20 ++++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/components/Workspaces.test.tsx b/src/components/Workspaces.test.tsx index 31f9a285..733334d3 100644 --- a/src/components/Workspaces.test.tsx +++ b/src/components/Workspaces.test.tsx @@ -20,4 +20,8 @@ describe("Workspaces page", () => { screen.getByRole("columnheader", { name: /configuration/i }), ).toBeVisible(); }); + + it("has a row for each workspace", () => { + expect(screen.getAllByRole("row")).toHaveLength(3); + }); }); diff --git a/src/components/Workspaces.tsx b/src/components/Workspaces.tsx index da50694e..b78643a0 100644 --- a/src/components/Workspaces.tsx +++ b/src/components/Workspaces.tsx @@ -1,4 +1,11 @@ -import { Column, Row, Table, TableBody, TableHeader } from "@stacklok/ui-kit"; +import { + Cell, + Column, + Row, + Table, + TableBody, + TableHeader, +} from "@stacklok/ui-kit"; export function Workspaces() { return ( @@ -13,7 +20,16 @@ export function Workspaces() { Configuration - + + + My workspace + hello + + + My workspace + hello + + ); From 71f9084da1c39e653e047d7633fb1b2df34f325a Mon Sep 17 00:00:00 2001 From: Daniel Kantor Date: Mon, 20 Jan 2025 12:08:40 +0100 Subject: [PATCH 5/8] . --- src/App.tsx | 1 - src/components/Workspaces.tsx | 25 +++++++++++++++++-------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index b1edf538..cbfe765b 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -61,7 +61,6 @@ function App() { } /> } /> } /> - } diff --git a/src/components/Workspaces.tsx b/src/components/Workspaces.tsx index b78643a0..f13ec47e 100644 --- a/src/components/Workspaces.tsx +++ b/src/components/Workspaces.tsx @@ -8,6 +8,17 @@ import { } from "@stacklok/ui-kit"; export function Workspaces() { + const data = [ + { + name: "Workspace 1", + configuration: "hello", + }, + { + name: "Workspace 2", + configuration: "hello", + }, + ]; + return (

Manage Workspaces

@@ -21,14 +32,12 @@ export function Workspaces() { - - My workspace - hello - - - My workspace - hello - + {data.map((workspace) => ( + + {workspace.name} + hello + + ))}
From c53297eb88308da4842a843823251bbd8620e7c8 Mon Sep 17 00:00:00 2001 From: Daniel Kantor Date: Mon, 20 Jan 2025 12:27:05 +0100 Subject: [PATCH 6/8] handle data fetching --- src/components/Workspaces.test.tsx | 15 ++++++++--- src/components/Workspaces.tsx | 15 +++-------- src/mocks/msw/fixtures/GET_WORKSPACES.json | 30 ++++++++++++++-------- 3 files changed, 36 insertions(+), 24 deletions(-) diff --git a/src/components/Workspaces.test.tsx b/src/components/Workspaces.test.tsx index 733334d3..b2e32709 100644 --- a/src/components/Workspaces.test.tsx +++ b/src/components/Workspaces.test.tsx @@ -1,5 +1,5 @@ import { render } from "@/lib/test-utils"; -import { screen } from "@testing-library/react"; +import { screen, waitFor } from "@testing-library/react"; import { describe, expect, it } from "vitest"; import { Workspaces } from "./Workspaces"; @@ -21,7 +21,16 @@ describe("Workspaces page", () => { ).toBeVisible(); }); - it("has a row for each workspace", () => { - expect(screen.getAllByRole("row")).toHaveLength(3); + it("has a row for each workspace", async () => { + await waitFor(() => { + expect(screen.getAllByRole("row").length).toBeGreaterThan(1); + }); + + expect( + screen.getByRole("rowheader", { name: /myworkspace/i }), + ).toBeVisible(); + expect( + screen.getByRole("rowheader", { name: /anotherworkspae/i }), + ).toBeVisible(); }); }); diff --git a/src/components/Workspaces.tsx b/src/components/Workspaces.tsx index f13ec47e..c6828728 100644 --- a/src/components/Workspaces.tsx +++ b/src/components/Workspaces.tsx @@ -1,3 +1,4 @@ +import { useWorkspacesData } from "@/hooks/useWorkspacesData"; import { Cell, Column, @@ -8,16 +9,8 @@ import { } from "@stacklok/ui-kit"; export function Workspaces() { - const data = [ - { - name: "Workspace 1", - configuration: "hello", - }, - { - name: "Workspace 2", - configuration: "hello", - }, - ]; + const result = useWorkspacesData(); + const workspaces = result.data?.workspaces ?? []; return (
@@ -32,7 +25,7 @@ export function Workspaces() { - {data.map((workspace) => ( + {workspaces.map((workspace) => ( {workspace.name} hello diff --git a/src/mocks/msw/fixtures/GET_WORKSPACES.json b/src/mocks/msw/fixtures/GET_WORKSPACES.json index e7669999..571fdb2b 100644 --- a/src/mocks/msw/fixtures/GET_WORKSPACES.json +++ b/src/mocks/msw/fixtures/GET_WORKSPACES.json @@ -1,10 +1,20 @@ -[ - { - "name": "workspace-1", - "is_active": true - }, - { - "name": "workspace-2", - "is_active": false - } -] \ No newline at end of file +{ + "workspaces": [ + { + "name": "default", + "is_active": true + }, + { + "name": "myworkspace", + "is_active": false + }, + { + "name": "anotherworkspae", + "is_active": false + }, + { + "name": "favoriteworkspace", + "is_active": false + } + ] +} From 65f2070325c570b6fc42609049f5aa7b6ddc2211 Mon Sep 17 00:00:00 2001 From: Daniel Kantor Date: Mon, 20 Jan 2025 12:36:20 +0100 Subject: [PATCH 7/8] add settigns button --- src/components/Workspaces.test.tsx | 10 +++++++++- src/components/Workspaces.tsx | 12 +++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/components/Workspaces.test.tsx b/src/components/Workspaces.test.tsx index b2e32709..e6f706b0 100644 --- a/src/components/Workspaces.test.tsx +++ b/src/components/Workspaces.test.tsx @@ -1,5 +1,5 @@ import { render } from "@/lib/test-utils"; -import { screen, waitFor } from "@testing-library/react"; +import { screen, waitFor, within } from "@testing-library/react"; import { describe, expect, it } from "vitest"; import { Workspaces } from "./Workspaces"; @@ -32,5 +32,13 @@ describe("Workspaces page", () => { expect( screen.getByRole("rowheader", { name: /anotherworkspae/i }), ).toBeVisible(); + + const firstRow = screen.getByRole("row", { name: /myworkspace/i }); + const firstButton = within(firstRow).getByRole("link", { + name: /settings/i, + }); + + expect(firstButton).toBeVisible(); + expect(firstButton).toHaveAttribute("href", "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/workspace/myworkspace"); }); }); diff --git a/src/components/Workspaces.tsx b/src/components/Workspaces.tsx index c6828728..da449461 100644 --- a/src/components/Workspaces.tsx +++ b/src/components/Workspaces.tsx @@ -2,11 +2,13 @@ import { useWorkspacesData } from "@/hooks/useWorkspacesData"; import { Cell, Column, + LinkButton, Row, Table, TableBody, TableHeader, } from "@stacklok/ui-kit"; +import { Settings } from "lucide-react"; export function Workspaces() { const result = useWorkspacesData(); @@ -28,7 +30,15 @@ export function Workspaces() { {workspaces.map((workspace) => ( {workspace.name} - hello + + + + Settings + + ))} From 96b408152490c9f8f600b49071b972bf6113b77a Mon Sep 17 00:00:00 2001 From: Daniel Kantor Date: Mon, 20 Jan 2025 12:43:02 +0100 Subject: [PATCH 8/8] visual adjustments --- src/components/Workspaces.tsx | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/components/Workspaces.tsx b/src/components/Workspaces.tsx index da449461..e57787a5 100644 --- a/src/components/Workspaces.tsx +++ b/src/components/Workspaces.tsx @@ -2,6 +2,7 @@ import { useWorkspacesData } from "@/hooks/useWorkspacesData"; import { Cell, Column, + Heading, LinkButton, Row, Table, @@ -16,14 +17,19 @@ export function Workspaces() { return (
-

Manage Workspaces

+ + Manage Workspaces + + - + Name - Configuration + + Configuration +