Skip to content

chore: clean up groups page #16259

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 13 commits into from
Jan 29, 2025
Prev Previous commit
Next Next commit
have mercy on my soul
  • Loading branch information
aslilac committed Jan 24, 2025
commit 7791f86178d01b3c48786dcdb91acbee45390987
7 changes: 3 additions & 4 deletions site/src/modules/management/OrganizationSettingsLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,9 @@ const OrganizationSettingsLayout: FC = () => {
const canViewOrganizationSettingsPage =
permissions.viewDeploymentValues || permissions.editAnyOrganization;

const organization =
organizations && orgName
? organizations.find((org) => org.name === orgName)
: undefined;
const organization = orgName
? organizations.find((org) => org.name === orgName)
: undefined;

return (
<RequirePermission isFeatureVisible={canViewOrganizationSettingsPage}>
Expand Down
13 changes: 10 additions & 3 deletions site/src/pages/GroupsPage/CreateGroupPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ import { createGroup } from "api/queries/groups";
import type { FC } from "react";
import { Helmet } from "react-helmet-async";
import { useMutation, useQueryClient } from "react-query";
import { useNavigate } from "react-router-dom";
import { useNavigate, useParams } from "react-router-dom";
import { pageTitle } from "utils/page";
import CreateGroupPageView from "./CreateGroupPageView";

export const CreateGroupPage: FC = () => {
const queryClient = useQueryClient();
const navigate = useNavigate();
const createGroupMutation = useMutation(createGroup(queryClient, "default"));
const { organization } = useParams() as { organization: string };
const createGroupMutation = useMutation(
createGroup(queryClient, organization ?? "default"),
);

return (
<>
Expand All @@ -19,7 +22,11 @@ export const CreateGroupPage: FC = () => {
<CreateGroupPageView
onSubmit={async (data) => {
const newGroup = await createGroupMutation.mutateAsync(data);
navigate(`/deployment/groups/${newGroup.name}`);
navigate(
organization
? `/organizations/${organization}/groups/${newGroup.name}`
: `/deployment/groups/${newGroup.name}`,
);
}}
error={createGroupMutation.error}
isLoading={createGroupMutation.isLoading}
Expand Down
12 changes: 10 additions & 2 deletions site/src/pages/GroupsPage/CreateGroupPageView.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { mockApiError } from "testHelpers/entities";
import { CreateGroupPageView } from "./CreateGroupPageView";

const meta: Meta<typeof CreateGroupPageView> = {
title: "pages/GroupsPage/CreateGroupPageView",
title: "pages/OrganizationGroupsPage/CreateGroupPageView",
component: CreateGroupPageView,
};

Expand All @@ -19,7 +19,15 @@ export const WithError: Story = {
message: "A group named new-group already exists.",
validations: [{ field: "name", detail: "Group names must be unique" }],
}),
initialTouched: { name: true },
},
play: async ({ canvasElement, step }) => {
const canvas = within(canvasElement);

await step("Enter name", async () => {
const input = canvas.getByLabelText("Name");
await userEvent.type(input, "new-group");
input.blur();
});
},
};

Expand Down
61 changes: 34 additions & 27 deletions site/src/pages/GroupsPage/CreateGroupPageView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ import { isApiValidationError } from "api/errors";
import type { CreateGroupRequest } from "api/typesGenerated";
import { ErrorAlert } from "components/Alert/ErrorAlert";
import { Button } from "components/Button/Button";
import { FormFooter } from "components/Form/Form";
import { FullPageForm } from "components/FullPageForm/FullPageForm";
import {
FormFields,
FormFooter,
FormSection,
HorizontalForm,
} from "components/Form/Form";
import { IconField } from "components/IconField/IconField";
import { Margins } from "components/Margins/Margins";
import { SettingsHeader } from "components/SettingsHeader/SettingsHeader";
import { Spinner } from "components/Spinner/Spinner";
import { Stack } from "components/Stack/Stack";
import { type FormikTouched, useFormik } from "formik";
import { useFormik } from "formik";
import type { FC } from "react";
import { useNavigate } from "react-router-dom";
import {
Expand All @@ -27,15 +30,12 @@ export type CreateGroupPageViewProps = {
onSubmit: (data: CreateGroupRequest) => void;
error?: unknown;
isLoading: boolean;
// Helpful to show field errors on Storybook
initialTouched?: FormikTouched<CreateGroupRequest>;
};

export const CreateGroupPageView: FC<CreateGroupPageViewProps> = ({
onSubmit,
error,
isLoading,
initialTouched,
}) => {
const navigate = useNavigate();
const form = useFormik<CreateGroupRequest>({
Expand All @@ -47,16 +47,23 @@ export const CreateGroupPageView: FC<CreateGroupPageViewProps> = ({
},
validationSchema,
onSubmit,
initialTouched,
});
const getFieldHelpers = getFormHelpers<CreateGroupRequest>(form, error);
const onCancel = () => navigate("/deployment/groups");
const onCancel = () => navigate(-1);

return (
<Margins>
<FullPageForm title="Create group">
<form onSubmit={form.handleSubmit}>
<Stack spacing={2.5}>
<>
<SettingsHeader
title="New Group"
description="Create a group in this organization."
/>

<HorizontalForm onSubmit={form.handleSubmit}>
<FormSection
title="Group settings"
description="Set a name and avatar for this group."
>
<FormFields>
{Boolean(error) && !isApiValidationError(error) && (
<ErrorAlert error={error} />
)}
Expand Down Expand Up @@ -84,21 +91,21 @@ export const CreateGroupPageView: FC<CreateGroupPageViewProps> = ({
label="Avatar URL"
onPickEmoji={(value) => form.setFieldValue("avatar_url", value)}
/>
</Stack>
</FormFields>
</FormSection>

<FormFooter className="mt-8">
<Button onClick={onCancel} variant="outline">
Cancel
</Button>
<FormFooter>
<Button onClick={onCancel} variant="outline">
Cancel
</Button>

<Button type="submit" disabled={isLoading}>
{isLoading && <Spinner />}
Save
</Button>
</FormFooter>
</form>
</FullPageForm>
</Margins>
<Button type="submit" disabled={isLoading}>
<Spinner loading={isLoading} />
Save
</Button>
</FormFooter>
</HorizontalForm>
</>
);
};
export default CreateGroupPageView;
Loading
Loading