Skip to content

Commit 7e66ff0

Browse files
authored
feat: implement "Revert" button for workspace name (#276)
* Label Workspaces dropdown with Active Workspace instead of just Workspace. * Add indicator to the "active" workspace within the Workspace Settings page. * change wording of workspace settings title * add jsonforms * . * types fix * fix failing test * better schema for string * make form label in jsonforms loook like design * add revert feature * make dropdown work * remove useless stuff * . * Revert "." This reverts commit 0b1edec. * . * . * . * fixes * implement James's suggestions * remove some unused stuff
1 parent 7529f73 commit 7e66ff0

19 files changed

+726
-86
lines changed

package-lock.json

+133-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+6
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,26 @@
2121
},
2222
"dependencies": {
2323
"@hey-api/client-fetch": "^0.7.1",
24+
"@jsonforms/core": "^3.5.1",
25+
"@jsonforms/react": "^3.5.1",
26+
"@jsonforms/vanilla-renderers": "^3.5.1",
2427
"@monaco-editor/react": "^4.6.0",
2528
"@radix-ui/react-dialog": "^1.1.4",
2629
"@radix-ui/react-separator": "^1.1.0",
2730
"@radix-ui/react-slot": "^1.1.0",
31+
"@sinclair/typebox": "^0.34.16",
2832
"@stacklok/ui-kit": "^1.0.1-1",
2933
"@tanstack/react-query": "^5.64.1",
3034
"@tanstack/react-query-devtools": "^5.66.0",
35+
"@types/lodash": "^4.17.15",
3136
"@types/prismjs": "^1.26.5",
3237
"@types/react-syntax-highlighter": "^15.5.13",
3338
"@untitled-ui/icons-react": "^0.1.4",
3439
"clsx": "^2.1.1",
3540
"date-fns": "^4.1.0",
3641
"fuse.js": "^7.0.0",
3742
"highlight.js": "^11.11.1",
43+
"lodash": "^4.17.21",
3844
"prismjs": "^1.29.0",
3945
"react": "19.0.0",
4046
"react-dom": "19.0.0",

src/App.test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ describe("App", () => {
9393
);
9494

9595
const workspaceSelectionButton = screen.getByRole("button", {
96-
name: "Workspace default",
96+
name: "Active workspace default",
9797
});
9898
await waitFor(() => expect(workspaceSelectionButton).toBeVisible());
9999

src/features/workspace/components/workspace-heading.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export function WorkspaceHeading({
55
title,
66
children,
77
}: {
8-
title: string;
8+
title: React.ReactNode;
99
children?: React.ReactNode;
1010
}) {
1111
return (
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
1-
import {
2-
Button,
3-
Card,
4-
CardBody,
5-
CardFooter,
6-
Form,
7-
Input,
8-
Label,
9-
TextField,
10-
} from "@stacklok/ui-kit";
11-
import { twMerge } from "tailwind-merge";
121
import { useMutationCreateWorkspace } from "../hooks/use-mutation-create-workspace";
13-
import { FormEvent, useEffect, useState } from "react";
142
import { useNavigate } from "react-router-dom";
3+
import { Static, Type } from "@sinclair/typebox";
4+
import { FormCard } from "@/forms/FormCard";
5+
6+
const schema = Type.Object({
7+
workspaceName: Type.String({
8+
title: "Workspace name",
9+
minLength: 1,
10+
}),
11+
});
1512

1613
export function WorkspaceName({
1714
className,
@@ -23,59 +20,30 @@ export function WorkspaceName({
2320
isArchived: boolean | undefined;
2421
}) {
2522
const navigate = useNavigate();
26-
const { mutateAsync, isPending, error, reset } = useMutationCreateWorkspace();
23+
const { mutateAsync, isPending, error } = useMutationCreateWorkspace();
2724
const errorMsg = error?.detail ? `${error?.detail}` : "";
2825

29-
const [name, setName] = useState(() => workspaceName);
30-
// NOTE: When navigating from one settings page to another, this value is not
31-
// updated, hence the synchronization effect
32-
useEffect(() => {
33-
setName(workspaceName);
34-
reset();
35-
}, [reset, workspaceName]);
26+
const initialData = { workspaceName };
3627

37-
const handleSubmit = (e: FormEvent<HTMLFormElement>) => {
38-
e.preventDefault();
28+
const handleSubmit = (data: Static<typeof schema>) => {
3929
mutateAsync(
40-
{ body: { name: workspaceName, rename_to: name } },
30+
{ body: { name: workspaceName, rename_to: data.workspaceName } },
4131
{
42-
onSuccess: () => navigate(`/workspace/${name}`),
32+
onSuccess: () => navigate(`/workspace/${data.workspaceName}`),
4333
},
4434
);
4535
};
4636

4737
return (
48-
<Form onSubmit={handleSubmit} validationBehavior="aria" key={workspaceName}>
49-
<Card
50-
className={twMerge(className, "shrink-0")}
51-
data-testid="workspace-name"
52-
>
53-
<CardBody>
54-
<TextField
55-
key={workspaceName}
56-
aria-label="Workspace name"
57-
value={name}
58-
name="Workspace name"
59-
validationBehavior="aria"
60-
isRequired
61-
isDisabled={isArchived}
62-
onChange={setName}
63-
>
64-
<Label>Workspace name</Label>
65-
<Input />
66-
{errorMsg && <div className="p-1 text-red-700">{errorMsg}</div>}
67-
</TextField>
68-
</CardBody>
69-
<CardFooter className="justify-end gap-2">
70-
<Button
71-
isDisabled={isArchived || name === ""}
72-
isPending={isPending}
73-
type="submit"
74-
>
75-
Save
76-
</Button>
77-
</CardFooter>
78-
</Card>
79-
</Form>
38+
<FormCard
39+
data-testid="workspace-name"
40+
className={className}
41+
formError={errorMsg}
42+
schema={schema}
43+
isDisabled={isArchived}
44+
isPending={isPending}
45+
initialData={initialData}
46+
onSubmit={handleSubmit}
47+
/>
8048
);
8149
}

src/features/workspace/components/workspaces-selection.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ export function WorkspacesSelection() {
4646
return (
4747
<DialogTrigger isOpen={isOpen} onOpenChange={(test) => setIsOpen(test)}>
4848
<Button variant="tertiary" className="flex cursor-pointer">
49-
Workspace {activeWorkspaceName ?? "default"}
49+
Active workspace{" "}
50+
<span className="font-bold">{activeWorkspaceName ?? "default"}</span>
5051
<ChevronDown />
5152
</Button>
5253

0 commit comments

Comments
 (0)