Skip to content

feat: implement "Revert" button for workspace name #276

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Feb 11, 2025
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
138 changes: 133 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,26 @@
},
"dependencies": {
"@hey-api/client-fetch": "^0.7.1",
"@jsonforms/core": "^3.5.1",
"@jsonforms/react": "^3.5.1",
"@jsonforms/vanilla-renderers": "^3.5.1",
"@monaco-editor/react": "^4.6.0",
"@radix-ui/react-dialog": "^1.1.4",
"@radix-ui/react-separator": "^1.1.0",
"@radix-ui/react-slot": "^1.1.0",
"@sinclair/typebox": "^0.34.16",
"@stacklok/ui-kit": "^1.0.1-1",
"@tanstack/react-query": "^5.64.1",
"@tanstack/react-query-devtools": "^5.66.0",
"@types/lodash": "^4.17.15",
"@types/prismjs": "^1.26.5",
"@types/react-syntax-highlighter": "^15.5.13",
"@untitled-ui/icons-react": "^0.1.4",
"clsx": "^2.1.1",
"date-fns": "^4.1.0",
"fuse.js": "^7.0.0",
"highlight.js": "^11.11.1",
"lodash": "^4.17.21",
"prismjs": "^1.29.0",
"react": "19.0.0",
"react-dom": "19.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ describe("App", () => {
);

const workspaceSelectionButton = screen.getByRole("button", {
name: "Workspace default",
name: "Active workspace default",
});
await waitFor(() => expect(workspaceSelectionButton).toBeVisible());

Expand Down
2 changes: 1 addition & 1 deletion src/features/workspace/components/workspace-heading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export function WorkspaceHeading({
title,
children,
}: {
title: string;
title: React.ReactNode;
children?: React.ReactNode;
}) {
return (
Expand Down
80 changes: 24 additions & 56 deletions src/features/workspace/components/workspace-name.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import {
Button,
Card,
CardBody,
CardFooter,
Form,
Input,
Label,
TextField,
} from "@stacklok/ui-kit";
import { twMerge } from "tailwind-merge";
import { useMutationCreateWorkspace } from "../hooks/use-mutation-create-workspace";
import { FormEvent, useEffect, useState } from "react";
import { useNavigate } from "react-router-dom";
import { Static, Type } from "@sinclair/typebox";
import { FormCard } from "@/forms/FormCard";

const schema = Type.Object({
workspaceName: Type.String({
title: "Workspace name",
minLength: 1,
}),
});

export function WorkspaceName({
className,
Expand All @@ -23,59 +20,30 @@ export function WorkspaceName({
isArchived: boolean | undefined;
}) {
const navigate = useNavigate();
const { mutateAsync, isPending, error, reset } = useMutationCreateWorkspace();
const { mutateAsync, isPending, error } = useMutationCreateWorkspace();
const errorMsg = error?.detail ? `${error?.detail}` : "";

const [name, setName] = useState(() => workspaceName);
// NOTE: When navigating from one settings page to another, this value is not
// updated, hence the synchronization effect
useEffect(() => {
setName(workspaceName);
reset();
}, [reset, workspaceName]);
const initialData = { workspaceName };

const handleSubmit = (e: FormEvent<HTMLFormElement>) => {
e.preventDefault();
const handleSubmit = (data: Static<typeof schema>) => {
mutateAsync(
{ body: { name: workspaceName, rename_to: name } },
{ body: { name: workspaceName, rename_to: data.workspaceName } },
{
onSuccess: () => navigate(`/workspace/${name}`),
onSuccess: () => navigate(`/workspace/${data.workspaceName}`),
},
);
};

return (
<Form onSubmit={handleSubmit} validationBehavior="aria" key={workspaceName}>
<Card
className={twMerge(className, "shrink-0")}
data-testid="workspace-name"
>
<CardBody>
<TextField
key={workspaceName}
aria-label="Workspace name"
value={name}
name="Workspace name"
validationBehavior="aria"
isRequired
isDisabled={isArchived}
onChange={setName}
>
<Label>Workspace name</Label>
<Input />
{errorMsg && <div className="p-1 text-red-700">{errorMsg}</div>}
</TextField>
</CardBody>
<CardFooter className="justify-end gap-2">
<Button
isDisabled={isArchived || name === ""}
isPending={isPending}
type="submit"
>
Save
</Button>
</CardFooter>
</Card>
</Form>
<FormCard
data-testid="workspace-name"
className={className}
formError={errorMsg}
schema={schema}
isDisabled={isArchived}
isPending={isPending}
initialData={initialData}
onSubmit={handleSubmit}
/>
);
}
3 changes: 2 additions & 1 deletion src/features/workspace/components/workspaces-selection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ export function WorkspacesSelection() {
return (
<DialogTrigger isOpen={isOpen} onOpenChange={(test) => setIsOpen(test)}>
<Button variant="tertiary" className="flex cursor-pointer">
Workspace {activeWorkspaceName ?? "default"}
Active workspace{" "}
<span className="font-bold">{activeWorkspaceName ?? "default"}</span>
<ChevronDown />
</Button>

Expand Down
Loading
Loading