-
Notifications
You must be signed in to change notification settings - Fork 2k
feat: new service_account page with crud and listing #10535
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
Draft
SagarRajput-7
wants to merge
6
commits into
main
Choose a base branch
from
service-account
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0bac997
feat: new service_account page with crud and listing
SagarRajput-7 1cdd2ec
feat: multiple style and functionality fixes
SagarRajput-7 0ef4106
feat: multiple style and functionality fixes
SagarRajput-7 e7c7afe
feat: feedback fix
SagarRajput-7 f6cdcbe
feat: added pagination and sorter
SagarRajput-7 8bbc71a
feat: feedback fix
SagarRajput-7 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
142 changes: 142 additions & 0 deletions
142
frontend/src/components/CreateServiceAccountModal/CreateServiceAccountModal.styles.scss
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,142 @@ | ||
| .create-sa-modal { | ||
| max-width: 530px; | ||
| background: var(--popover); | ||
| border: 1px solid var(--secondary); | ||
| border-radius: 4px; | ||
| box-shadow: 0 4px 9px 0 rgba(0, 0, 0, 0.04); | ||
|
|
||
| [data-slot='dialog-header'] { | ||
| padding: var(--padding-4); | ||
| border-bottom: 1px solid var(--secondary); | ||
| flex-shrink: 0; | ||
| background: transparent; | ||
| margin: 0; | ||
| } | ||
|
|
||
| [data-slot='dialog-title'] { | ||
| font-family: Inter, sans-serif; | ||
| font-size: var(--label-base-400-font-size); | ||
| font-weight: var(--label-base-400-font-weight); | ||
| line-height: var(--label-base-400-line-height); | ||
| letter-spacing: -0.065px; | ||
| color: var(--bg-base-white); | ||
| margin: 0; | ||
| } | ||
|
|
||
| [data-slot='dialog-description'] { | ||
| padding: 0; | ||
|
|
||
| .create-sa-modal__content { | ||
| padding: var(--padding-4); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| .create-sa-form { | ||
| display: flex; | ||
| flex-direction: column; | ||
| gap: var(--spacing-2); | ||
|
|
||
| .ant-form-item { | ||
| margin-bottom: var(--spacing-4); | ||
| } | ||
|
|
||
| .ant-form-item-label > label { | ||
| font-size: var(--paragraph-base-400-font-size); | ||
| font-weight: var(--paragraph-base-400-font-weight); | ||
| color: var(--foreground); | ||
| letter-spacing: -0.07px; | ||
| } | ||
|
|
||
| &__input { | ||
| height: 32px; | ||
| color: var(--l1-foreground); | ||
| background-color: var(--l2-background); | ||
| border-color: var(--border); | ||
| font-size: var(--paragraph-base-400-font-size); | ||
| border-radius: 2px; | ||
| width: 100%; | ||
|
|
||
| &::placeholder { | ||
| color: var(--l3-foreground); | ||
| } | ||
|
|
||
| &:focus { | ||
| border-color: var(--primary); | ||
| box-shadow: none; | ||
| } | ||
| } | ||
|
|
||
| &__select { | ||
| width: 100%; | ||
|
|
||
| .ant-select-selector { | ||
| min-height: 32px; | ||
| border-radius: 2px; | ||
| background-color: var(--l2-background) !important; | ||
| border: 1px solid var(--border) !important; | ||
| padding: 0 var(--padding-2) !important; | ||
|
|
||
| .ant-select-selection-placeholder { | ||
| color: var(--l3-foreground); | ||
| opacity: 0.4; | ||
| font-size: var(--paragraph-base-400-font-size); | ||
| letter-spacing: -0.07px; | ||
| line-height: 32px; | ||
| } | ||
|
|
||
| .ant-select-selection-item { | ||
| font-size: var(--paragraph-base-400-font-size); | ||
| letter-spacing: -0.07px; | ||
| color: var(--bg-base-white); | ||
| } | ||
| } | ||
|
|
||
| .ant-select-arrow { | ||
| color: var(--foreground); | ||
| } | ||
|
|
||
| &.ant-select-focused .ant-select-selector, | ||
| &:not(.ant-select-disabled):hover .ant-select-selector { | ||
| border-color: var(--primary); | ||
| } | ||
| } | ||
|
|
||
| &__helper { | ||
| font-size: var(--paragraph-small-400-font-size); | ||
| color: var(--l3-foreground); | ||
| margin: calc(var(--spacing-2) * -1) 0 var(--spacing-4) 0; | ||
| line-height: var(--paragraph-small-400-line-height); | ||
| } | ||
| } | ||
|
|
||
| .create-sa-modal__footer { | ||
| display: flex; | ||
| flex-direction: row; | ||
| align-items: center; | ||
| justify-content: flex-end; | ||
| padding: 0 var(--padding-4); | ||
| height: 56px; | ||
| min-height: 56px; | ||
| border-top: 1px solid var(--secondary); | ||
| gap: var(--spacing-4); | ||
| flex-shrink: 0; | ||
| } | ||
|
|
||
| .lightMode { | ||
| .create-sa-modal { | ||
| [data-slot='dialog-title'] { | ||
| color: var(--bg-base-black); | ||
| } | ||
| } | ||
|
|
||
| .create-sa-form { | ||
| &__select { | ||
| .ant-select-selector { | ||
| .ant-select-selection-item { | ||
| color: var(--bg-base-black); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
185 changes: 185 additions & 0 deletions
185
frontend/src/components/CreateServiceAccountModal/CreateServiceAccountModal.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,185 @@ | ||
| import { useCallback, useEffect, useState } from 'react'; | ||
| import { Button } from '@signozhq/button'; | ||
| import { DialogFooter, DialogWrapper } from '@signozhq/dialog'; | ||
| import { X } from '@signozhq/icons'; | ||
| import { toast } from '@signozhq/sonner'; | ||
| import { Form, Input } from 'antd'; | ||
| import { convertToApiError } from 'api/ErrorResponseHandlerForGeneratedAPIs'; | ||
| import { useCreateServiceAccount } from 'api/generated/services/serviceaccount'; | ||
| import type { RenderErrorResponseDTO } from 'api/generated/services/sigNoz.schemas'; | ||
| import { AxiosError } from 'axios'; | ||
| import RolesSelect, { useRoles } from 'components/RolesSelect'; | ||
|
|
||
| import './CreateServiceAccountModal.styles.scss'; | ||
|
|
||
| interface CreateServiceAccountModalProps { | ||
| open: boolean; | ||
| onClose: () => void; | ||
| onSuccess: () => void; | ||
| } | ||
|
|
||
| interface FormValues { | ||
| name: string; | ||
| email: string; | ||
| roles: string[]; | ||
| } | ||
|
|
||
| function CreateServiceAccountModal({ | ||
| open, | ||
| onClose, | ||
| onSuccess, | ||
| }: CreateServiceAccountModalProps): JSX.Element { | ||
| const [form] = Form.useForm<FormValues>(); | ||
| const [isSubmitting, setIsSubmitting] = useState(false); | ||
| const [submittable, setSubmittable] = useState(false); | ||
|
|
||
| const values = Form.useWatch([], form); | ||
|
|
||
| useEffect(() => { | ||
| form | ||
| .validateFields({ validateOnly: true }) | ||
| .then(() => setSubmittable(true)) | ||
| .catch(() => setSubmittable(false)); | ||
| }, [values, form]); | ||
|
|
||
| const { mutateAsync: createServiceAccount } = useCreateServiceAccount(); | ||
| const { | ||
| roles, | ||
| isLoading: rolesLoading, | ||
| isError: rolesError, | ||
| error: rolesErrorObj, | ||
| refetch: refetchRoles, | ||
| } = useRoles(); | ||
|
|
||
| const handleClose = useCallback((): void => { | ||
| form.resetFields(); | ||
| onClose(); | ||
| }, [form, onClose]); | ||
|
|
||
| const handleSubmit = useCallback(async (): Promise<void> => { | ||
| try { | ||
| const values = await form.validateFields(); | ||
| setIsSubmitting(true); | ||
| await createServiceAccount({ | ||
| data: { | ||
| name: values.name.trim(), | ||
| email: values.email.trim(), | ||
| roles: values.roles, | ||
| }, | ||
| }); | ||
| toast.success('Service account created successfully', { richColors: true }); | ||
| form.resetFields(); | ||
| onSuccess(); | ||
| onClose(); | ||
| } catch (err: unknown) { | ||
| if (err && typeof err === 'object' && 'errorFields' in err) { | ||
| return; | ||
| } | ||
| const errMessage = | ||
| convertToApiError( | ||
| err as AxiosError<RenderErrorResponseDTO, unknown> | null, | ||
| )?.getErrorMessage() || 'An error occurred'; | ||
| toast.error(`Failed to create service account: ${errMessage}`, { | ||
| richColors: true, | ||
| }); | ||
| } finally { | ||
| setIsSubmitting(false); | ||
| } | ||
| }, [form, createServiceAccount, onSuccess, onClose]); | ||
|
|
||
| return ( | ||
| <DialogWrapper | ||
| title="New Service Account" | ||
| open={open} | ||
| onOpenChange={(isOpen): void => { | ||
| if (!isOpen) { | ||
| handleClose(); | ||
| } | ||
| }} | ||
| showCloseButton | ||
| width="narrow" | ||
| className="create-sa-modal" | ||
| disableOutsideClick={false} | ||
| > | ||
| <div className="create-sa-modal__content"> | ||
| <Form form={form} layout="vertical" className="create-sa-form"> | ||
| <Form.Item | ||
| name="name" | ||
| label="Name" | ||
| rules={[{ required: true, message: 'Name is required' }]} | ||
| className="create-sa-form__item" | ||
| > | ||
| <Input placeholder="Enter a name" className="create-sa-form__input" /> | ||
| </Form.Item> | ||
|
|
||
| <Form.Item | ||
| name="email" | ||
| label="Email Address" | ||
| rules={[ | ||
| { required: true, message: 'Email Address is required' }, | ||
| { type: 'email', message: 'Please enter a valid email address' }, | ||
| ]} | ||
| className="create-sa-form__item" | ||
| > | ||
| <Input | ||
| type="email" | ||
| placeholder="email@example.com" | ||
| className="create-sa-form__input" | ||
| /> | ||
| </Form.Item> | ||
| <p className="create-sa-form__helper"> | ||
| Used only for notifications about this service account. It is not used for | ||
| authentication. | ||
| </p> | ||
|
|
||
| <Form.Item | ||
| name="roles" | ||
| label="Roles" | ||
| rules={[{ required: true, message: 'At least one role is required' }]} | ||
| className="create-sa-form__item" | ||
| > | ||
| <RolesSelect | ||
| mode="multiple" | ||
| roles={roles} | ||
| loading={rolesLoading} | ||
| isError={rolesError} | ||
| error={rolesErrorObj} | ||
| onRefetch={refetchRoles} | ||
| placeholder="Select roles" | ||
| className="create-sa-form__select" | ||
| getPopupContainer={(triggerNode): HTMLElement => | ||
| (triggerNode?.closest('.create-sa-modal') as HTMLElement) || | ||
| document.body | ||
| } | ||
| /> | ||
| </Form.Item> | ||
| </Form> | ||
| </div> | ||
|
|
||
| <DialogFooter className="create-sa-modal__footer"> | ||
| <Button | ||
| type="button" | ||
| variant="solid" | ||
| color="secondary" | ||
| size="sm" | ||
| onClick={handleClose} | ||
| > | ||
| <X size={12} /> | ||
| Cancel | ||
| </Button> | ||
|
|
||
| <Button | ||
| variant="solid" | ||
| color="primary" | ||
| size="sm" | ||
| onClick={handleSubmit} | ||
| disabled={isSubmitting || !submittable} | ||
| > | ||
| {isSubmitting ? 'Creating...' : 'Create Service Account'} | ||
| </Button> | ||
| </DialogFooter> | ||
| </DialogWrapper> | ||
| ); | ||
| } | ||
|
|
||
| export default CreateServiceAccountModal; |
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.