-
Notifications
You must be signed in to change notification settings - Fork 928
feat: create and modify organization groups #13887
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
Changes from 10 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
6f5952e
🫣
aslilac 504f561
Merge branch 'main' into org-groups
aslilac 46cb3c7
fix a bunch of stuff
aslilac 571bb5e
🧹
aslilac 9cdee44
u
aslilac 3399d21
iykyk
aslilac b252a50
do the thing here too
aslilac 5ef6485
:^)
aslilac 0c2ddac
better
aslilac 91732b6
oops
aslilac 40faf01
Merge branch 'main' into org-groups
aslilac 560fd4f
query refetching is cool
aslilac c636009
feedback
aslilac bdf5965
🧹
aslilac File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
site/src/pages/ManagementSettingsPage/GroupsPage/CreateGroupPage.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import type { FC } from "react"; | ||
import { Helmet } from "react-helmet-async"; | ||
import { useMutation, useQueryClient } from "react-query"; | ||
import { useNavigate, useParams } from "react-router-dom"; | ||
import { createGroup } from "api/queries/groups"; | ||
import { pageTitle } from "utils/page"; | ||
import CreateGroupPageView from "./CreateGroupPageView"; | ||
|
||
export const CreateGroupPage: FC = () => { | ||
const queryClient = useQueryClient(); | ||
const navigate = useNavigate(); | ||
const { organization } = useParams() as { organization: string }; | ||
const createGroupMutation = useMutation( | ||
createGroup(queryClient, organization), | ||
); | ||
|
||
return ( | ||
<> | ||
<Helmet> | ||
<title>{pageTitle("Create Group")}</title> | ||
</Helmet> | ||
<CreateGroupPageView | ||
onSubmit={async (data) => { | ||
const newGroup = await createGroupMutation.mutateAsync(data); | ||
navigate(`/organizations/${organization}/groups/${newGroup.name}`); | ||
}} | ||
error={createGroupMutation.error} | ||
isLoading={createGroupMutation.isLoading} | ||
/> | ||
</> | ||
); | ||
}; | ||
export default CreateGroupPage; |
23 changes: 23 additions & 0 deletions
23
site/src/pages/ManagementSettingsPage/GroupsPage/CreateGroupPageView.stories.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
import { mockApiError } from "testHelpers/entities"; | ||
import { CreateGroupPageView } from "./CreateGroupPageView"; | ||
|
||
const meta: Meta<typeof CreateGroupPageView> = { | ||
title: "pages/OrganizationGroupsPage/CreateGroupPageView", | ||
component: CreateGroupPageView, | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof CreateGroupPageView>; | ||
|
||
export const Example: Story = {}; | ||
|
||
export const WithError: Story = { | ||
args: { | ||
error: mockApiError({ | ||
message: "A group named new-group already exists.", | ||
validations: [{ field: "name", detail: "Group names must be unique" }], | ||
}), | ||
initialTouched: { name: true }, | ||
}, | ||
}; |
94 changes: 94 additions & 0 deletions
94
site/src/pages/ManagementSettingsPage/GroupsPage/CreateGroupPageView.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import TextField from "@mui/material/TextField"; | ||
import { type FormikTouched, useFormik } from "formik"; | ||
import type { FC } from "react"; | ||
import { useNavigate } from "react-router-dom"; | ||
import * as Yup from "yup"; | ||
import { isApiValidationError } from "api/errors"; | ||
import type { CreateGroupRequest } from "api/typesGenerated"; | ||
import { ErrorAlert } from "components/Alert/ErrorAlert"; | ||
import { | ||
FormFields, | ||
FormFooter, | ||
FormSection, | ||
HorizontalForm, | ||
} from "components/Form/Form"; | ||
import { IconField } from "components/IconField/IconField"; | ||
import { PageHeader, PageHeaderTitle } from "components/PageHeader/PageHeader"; | ||
import { getFormHelpers, onChangeTrimmed } from "utils/formUtils"; | ||
|
||
const validationSchema = Yup.object({ | ||
name: Yup.string().required().label("Name"), | ||
}); | ||
|
||
export type CreateGroupPageViewProps = { | ||
onSubmit: (data: CreateGroupRequest) => void; | ||
error?: unknown; | ||
isLoading: boolean; | ||
// Helpful to show field errors on Storybook | ||
initialTouched?: FormikTouched<CreateGroupRequest>; | ||
aslilac marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; | ||
|
||
export const CreateGroupPageView: FC<CreateGroupPageViewProps> = ({ | ||
onSubmit, | ||
error, | ||
isLoading, | ||
initialTouched, | ||
}) => { | ||
const navigate = useNavigate(); | ||
const form = useFormik<CreateGroupRequest>({ | ||
initialValues: { | ||
name: "", | ||
display_name: "", | ||
avatar_url: "", | ||
quota_allowance: 0, | ||
}, | ||
validationSchema, | ||
onSubmit, | ||
initialTouched, | ||
}); | ||
const getFieldHelpers = getFormHelpers<CreateGroupRequest>(form, error); | ||
const onCancel = () => navigate(-1); | ||
|
||
return ( | ||
<> | ||
<PageHeader css={{ paddingTop: 8 }}> | ||
<PageHeaderTitle>Create a group</PageHeaderTitle> | ||
</PageHeader> | ||
<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} /> | ||
)} | ||
|
||
<TextField | ||
{...getFieldHelpers("name")} | ||
autoFocus | ||
fullWidth | ||
label="Name" | ||
/> | ||
<TextField | ||
{...getFieldHelpers("display_name", { | ||
helperText: "Optional: keep empty to default to the name.", | ||
})} | ||
fullWidth | ||
label="Display Name" | ||
/> | ||
<IconField | ||
{...getFieldHelpers("avatar_url")} | ||
onChange={onChangeTrimmed(form)} | ||
fullWidth | ||
label="Avatar URL" | ||
onPickEmoji={(value) => form.setFieldValue("avatar_url", value)} | ||
/> | ||
</FormFields> | ||
</FormSection> | ||
<FormFooter onCancel={onCancel} isLoading={isLoading} /> | ||
</HorizontalForm> | ||
</> | ||
); | ||
}; | ||
export default CreateGroupPageView; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.