-
Notifications
You must be signed in to change notification settings - Fork 31
feat: add "deploy and apply immediately" action for managed databases #2570
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
Open
rmnbrd
wants to merge
7
commits into
staging
Choose a base branch
from
feat/databases/redeploy-immediately-QOV-1553
base: staging
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.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ec8c3ae
feat: add "deploy and apply immediately" action for managed databases
rmnbrd 796f154
Use 2-choices confirm modal
rmnbrd 3bdde43
feat(deployment): add DatabaseDeployModal and implement 2 entry points
rmnbrd 3d3d4f4
Remove useless condition
rmnbrd 1763295
Post-review fixes
rmnbrd 7627910
Post-review fixes
rmnbrd 19a6c84
Remove useless component's prop
rmnbrd 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
118 changes: 118 additions & 0 deletions
118
libs/domains/services/feature/src/lib/database-deploy-modal/database-deploy-modal.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,118 @@ | ||
| import { type IconName } from '@fortawesome/fontawesome-common-types' | ||
| import * as Dialog from '@radix-ui/react-dialog' | ||
| import { type PropsWithChildren, type ReactNode } from 'react' | ||
| import { Controller, useForm } from 'react-hook-form' | ||
| import { Button, Heading, Icon, RadioGroup, Section, useModal } from '@qovery/shared/ui' | ||
| import { twMerge } from '@qovery/shared/util-js' | ||
|
|
||
| type DatabaseDeployModalData = { | ||
| action: string | ||
| name: string | ||
| } | ||
|
|
||
| interface ActionItem { | ||
| id: string // Also used as the text the user has to type to confirm | ||
| title: string | ||
| callback: (data: DatabaseDeployModalData) => void | ||
| description?: ReactNode | ||
| icon?: IconName | ||
| } | ||
|
|
||
| export interface DatabaseDeployModalProps extends PropsWithChildren { | ||
| title: string | ||
| description?: ReactNode | ||
| actions: ActionItem[] | ||
| name?: string | ||
| submitButtonText?: string | ||
| } | ||
|
|
||
| export function DatabaseDeployModal({ | ||
| title, | ||
| description, | ||
| actions, | ||
| children, | ||
| submitButtonText, | ||
| }: DatabaseDeployModalProps) { | ||
| const { | ||
| handleSubmit, | ||
| control, | ||
| watch, | ||
| formState: { isValid }, | ||
| } = useForm<DatabaseDeployModalData>({ | ||
| mode: 'onChange', | ||
| defaultValues: { | ||
| name: '', | ||
| action: actions[0]?.id, | ||
| }, | ||
| }) | ||
| const { closeModal } = useModal() | ||
|
|
||
| const selectedActionId = watch('action') | ||
| const selectedAction = actions.find((action) => action.id === selectedActionId) | ||
|
|
||
| const onSubmit = handleSubmit((data) => { | ||
| if (data) { | ||
| closeModal() | ||
| selectedAction?.callback?.(data) | ||
| } | ||
| }) | ||
|
|
||
| return ( | ||
| <Section className="p-5"> | ||
| <Dialog.Title asChild> | ||
| <Heading level={1} className="text-neutral mb-2 max-w-sm text-2xl"> | ||
| {title} | ||
| </Heading> | ||
| </Dialog.Title> | ||
| <Dialog.Description className="mb-6 text-sm text-neutral-350 dark:text-neutral-50"> | ||
| {description} | ||
| </Dialog.Description> | ||
|
|
||
| <form onSubmit={onSubmit} className="space-y-6"> | ||
| <div className="flex flex-col gap-5"> | ||
| <div className="flex w-full flex-col gap-4"> | ||
| <Controller | ||
| name="action" | ||
| control={control} | ||
| render={({ field }) => ( | ||
| <RadioGroup.Root onValueChange={field.onChange} value={field.value} className="grid grid-cols-2 gap-4"> | ||
| {actions.map((action) => ( | ||
| <label | ||
| key={action.id} | ||
| className={twMerge( | ||
| 'flex cursor-pointer flex-col gap-2 rounded border border-neutral-250 bg-neutral-100 p-5 text-left text-sm shadow transition-all', | ||
| selectedActionId === action.id && 'border-brand-500 bg-brand-50' | ||
| )} | ||
| > | ||
| <div className="flex items-center gap-3"> | ||
| <RadioGroup.Item value={action.id} /> | ||
| {action.icon && ( | ||
| <Icon iconName={action.icon} iconStyle="regular" className="text-base text-neutral-350" /> | ||
| )} | ||
| <span className="font-medium text-neutral-400">{action.title}</span> | ||
| </div> | ||
| <div className="inline-block text-sm text-neutral-350">{action.description}</div> | ||
| </label> | ||
| ))} | ||
| </RadioGroup.Root> | ||
| )} | ||
| /> | ||
| </div> | ||
| </div> | ||
|
|
||
| {children} | ||
|
|
||
| <div className="flex justify-end gap-3"> | ||
| <Button type="button" color="neutral" variant="plain" size="lg" onClick={() => closeModal()}> | ||
| Cancel | ||
| </Button> | ||
| <Button type="submit" size="lg" color="brand" disabled={!isValid}> | ||
| {submitButtonText ?? selectedAction?.title} | ||
| </Button> | ||
| </div> | ||
| </form> | ||
| </Section> | ||
| ) | ||
| } | ||
|
|
||
| export default DatabaseDeployModal |
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
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.