-
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 4 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
108 changes: 108 additions & 0 deletions
108
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,108 @@ | ||
| import { type PropsWithChildren, type ReactNode } from 'react' | ||
| import { Controller, useForm } from 'react-hook-form' | ||
| import { Button, Icon, InputTextSmall, RadioGroup, useModal } from '@qovery/shared/ui' | ||
| import { twMerge } from '@qovery/shared/util-js' | ||
| import { type ActionItem, type DatabaseDeployModalData } from './use-database-deploy-modal/use-database-deploy-modal' | ||
|
|
||
| export interface DatabaseDeployModalProps extends PropsWithChildren { | ||
| title: string | ||
| description?: ReactNode | ||
| actions: ActionItem[] | ||
| name?: string | ||
| entities?: ReactNode[] | ||
| submitButtonText?: string | ||
| } | ||
|
|
||
| export function DatabaseDeployModal({ | ||
| title, | ||
| description, | ||
| actions, | ||
| children, | ||
| entities, | ||
| 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 ( | ||
| <div className="p-6"> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you use component |
||
| <h2 className="h4 mb-1 max-w-sm text-neutral-400 dark:text-neutral-50">{title}</h2> | ||
| <div className="mb-4"> | ||
| {description && <div className="text-sm text-neutral-350 dark:text-neutral-50">{description}</div>} | ||
| {entities && <div className="mt-1 flex gap-1.5">{entities.map((entity) => entity)}</div>} | ||
| </div> | ||
|
|
||
| <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> | ||
| <span className="inline-block text-sm text-neutral-350">{action.description}</span> | ||
|
rmnbrd marked this conversation as resolved.
Outdated
|
||
| </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={!submitButtonText && selectedAction?.color ? selectedAction?.color : 'brand'} | ||
| disabled={!isValid} | ||
| > | ||
| {submitButtonText ?? selectedAction?.title} | ||
| </Button> | ||
|
rmnbrd marked this conversation as resolved.
Outdated
|
||
| </div> | ||
| </form> | ||
| </div> | ||
| ) | ||
| } | ||
|
|
||
| export default DatabaseDeployModal | ||
59 changes: 59 additions & 0 deletions
59
...ure/src/lib/database-deploy-modal/use-database-deploy-modal/use-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,59 @@ | ||
| import { type IconName } from '@fortawesome/fontawesome-common-types' | ||
| import { type EnvironmentModeEnum } from 'qovery-typescript-axios' | ||
| import { type ReactNode, useEffect, useState } from 'react' | ||
| import { useModal } from '@qovery/shared/ui' | ||
| import { DatabaseDeployModal } from '../database-deploy-modal' | ||
|
|
||
| export type DatabaseDeployModalData = { | ||
| action: string | ||
| name: string | ||
| } | ||
|
|
||
| export 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 | ||
| color?: 'brand' | 'red' | 'yellow' | 'green' | 'neutral' | ||
| } | ||
|
|
||
| export interface UseDatabaseDeployModalProps { | ||
| title: string | ||
| actions: ActionItem[] | ||
| entities?: ReactNode[] | ||
| description?: ReactNode | ||
| name?: string | ||
| submitButtonText?: string | ||
| mode?: keyof typeof EnvironmentModeEnum | string | undefined | ||
| warning?: ReactNode | ||
| } | ||
|
|
||
| export function useDatabaseDeployModal() { | ||
|
rmnbrd marked this conversation as resolved.
Outdated
|
||
| const [databaseDeployModal, openDatabaseDeployModal] = useState<UseDatabaseDeployModalProps>() | ||
| const { openModal } = useModal() | ||
|
|
||
| useEffect(() => { | ||
| if (databaseDeployModal) { | ||
| openModal({ | ||
| content: ( | ||
| <DatabaseDeployModal | ||
| title={databaseDeployModal.title} | ||
| actions={databaseDeployModal.actions} | ||
| entities={databaseDeployModal.entities} | ||
| description={databaseDeployModal.description} | ||
| name={databaseDeployModal.name} | ||
| submitButtonText={databaseDeployModal.submitButtonText} | ||
| /> | ||
| ), | ||
| options: { | ||
| width: 740, | ||
| }, | ||
| }) | ||
| } | ||
| }, [databaseDeployModal, openModal]) | ||
|
|
||
| return { openDatabaseDeployModal } | ||
| } | ||
|
|
||
| export default useDatabaseDeployModal | ||
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.
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.