-
Notifications
You must be signed in to change notification settings - Fork 3.3k
feat(description): add deployment version descriptions #3048
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 all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d4af644
feat(description): added version description for deployments table
waleedlatif1 43f7f3b
feat(description): refactor to tanstack query and remove useEffect
waleedlatif1 242710f
add wand to generate diff
waleedlatif1 8aaaefc
ack comments
waleedlatif1 1a1f3e8
removed redundant logic, kept single source of truth for diff
waleedlatif1 aada851
updated docs
waleedlatif1 7852998
use consolidated sse parsing util, add loops & parallels check
waleedlatif1 8fe763f
DRY
waleedlatif1 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
170 changes: 170 additions & 0 deletions
170
...eploy/components/deploy-modal/components/general/components/version-description-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,170 @@ | ||
| 'use client' | ||
|
|
||
| import { useCallback, useRef, useState } from 'react' | ||
| import { | ||
| Button, | ||
| Modal, | ||
| ModalBody, | ||
| ModalContent, | ||
| ModalFooter, | ||
| ModalHeader, | ||
| Textarea, | ||
| } from '@/components/emcn' | ||
| import { | ||
| useGenerateVersionDescription, | ||
| useUpdateDeploymentVersion, | ||
| } from '@/hooks/queries/deployments' | ||
|
|
||
| interface VersionDescriptionModalProps { | ||
| open: boolean | ||
| onOpenChange: (open: boolean) => void | ||
| workflowId: string | ||
| version: number | ||
| versionName: string | ||
| currentDescription: string | null | undefined | ||
| } | ||
|
|
||
| export function VersionDescriptionModal({ | ||
| open, | ||
| onOpenChange, | ||
| workflowId, | ||
| version, | ||
| versionName, | ||
| currentDescription, | ||
| }: VersionDescriptionModalProps) { | ||
| const initialDescriptionRef = useRef(currentDescription || '') | ||
| const [description, setDescription] = useState(initialDescriptionRef.current) | ||
| const [showUnsavedChangesAlert, setShowUnsavedChangesAlert] = useState(false) | ||
|
|
||
| const updateMutation = useUpdateDeploymentVersion() | ||
| const generateMutation = useGenerateVersionDescription() | ||
|
|
||
| const hasChanges = description.trim() !== initialDescriptionRef.current.trim() | ||
| const isGenerating = generateMutation.isPending | ||
|
|
||
| const handleCloseAttempt = useCallback(() => { | ||
| if (updateMutation.isPending || isGenerating) { | ||
| return | ||
| } | ||
| if (hasChanges) { | ||
| setShowUnsavedChangesAlert(true) | ||
| } else { | ||
| onOpenChange(false) | ||
| } | ||
| }, [hasChanges, updateMutation.isPending, isGenerating, onOpenChange]) | ||
|
|
||
| const handleDiscardChanges = useCallback(() => { | ||
| setShowUnsavedChangesAlert(false) | ||
| setDescription(initialDescriptionRef.current) | ||
| onOpenChange(false) | ||
| }, [onOpenChange]) | ||
|
|
||
| const handleGenerateDescription = useCallback(() => { | ||
| generateMutation.mutate({ | ||
| workflowId, | ||
| version, | ||
| onStreamChunk: (accumulated) => { | ||
| setDescription(accumulated) | ||
| }, | ||
| }) | ||
| }, [workflowId, version, generateMutation]) | ||
|
|
||
| const handleSave = useCallback(() => { | ||
| if (!workflowId) return | ||
|
|
||
| updateMutation.mutate( | ||
| { | ||
| workflowId, | ||
| version, | ||
| description: description.trim() || null, | ||
| }, | ||
| { | ||
| onSuccess: () => { | ||
| onOpenChange(false) | ||
| }, | ||
| } | ||
| ) | ||
| }, [workflowId, version, description, updateMutation, onOpenChange]) | ||
|
|
||
| return ( | ||
| <> | ||
| <Modal open={open} onOpenChange={(openState) => !openState && handleCloseAttempt()}> | ||
| <ModalContent className='max-w-[480px]'> | ||
| <ModalHeader> | ||
| <span>Version Description</span> | ||
| </ModalHeader> | ||
| <ModalBody className='space-y-[10px]'> | ||
| <div className='flex items-center justify-between'> | ||
| <p className='text-[12px] text-[var(--text-secondary)]'> | ||
| {currentDescription ? 'Edit the' : 'Add a'} description for{' '} | ||
| <span className='font-medium text-[var(--text-primary)]'>{versionName}</span> | ||
| </p> | ||
| <Button | ||
| variant='active' | ||
| className='-my-1 h-5 px-2 py-0 text-[11px]' | ||
| onClick={handleGenerateDescription} | ||
| disabled={isGenerating || updateMutation.isPending} | ||
| > | ||
| {isGenerating ? 'Generating...' : 'Generate'} | ||
| </Button> | ||
| </div> | ||
| <Textarea | ||
| placeholder='Describe the changes in this deployment version...' | ||
| className='min-h-[120px] resize-none' | ||
| value={description} | ||
| onChange={(e) => setDescription(e.target.value)} | ||
| maxLength={500} | ||
| disabled={isGenerating} | ||
| /> | ||
| <div className='flex items-center justify-between'> | ||
| {(updateMutation.error || generateMutation.error) && ( | ||
| <p className='text-[12px] text-[var(--text-error)]'> | ||
| {updateMutation.error?.message || generateMutation.error?.message} | ||
| </p> | ||
| )} | ||
| {!updateMutation.error && !generateMutation.error && <div />} | ||
| <p className='text-[11px] text-[var(--text-tertiary)]'>{description.length}/500</p> | ||
| </div> | ||
| </ModalBody> | ||
| <ModalFooter> | ||
| <Button | ||
| variant='default' | ||
| onClick={handleCloseAttempt} | ||
| disabled={updateMutation.isPending || isGenerating} | ||
| > | ||
| Cancel | ||
| </Button> | ||
| <Button | ||
| variant='tertiary' | ||
| onClick={handleSave} | ||
| disabled={updateMutation.isPending || isGenerating || !hasChanges} | ||
| > | ||
| {updateMutation.isPending ? 'Saving...' : 'Save'} | ||
| </Button> | ||
| </ModalFooter> | ||
| </ModalContent> | ||
| </Modal> | ||
|
|
||
| <Modal open={showUnsavedChangesAlert} onOpenChange={setShowUnsavedChangesAlert}> | ||
| <ModalContent className='max-w-[400px]'> | ||
| <ModalHeader> | ||
| <span>Unsaved Changes</span> | ||
| </ModalHeader> | ||
| <ModalBody> | ||
| <p className='text-[14px] text-[var(--text-secondary)]'> | ||
| You have unsaved changes. Are you sure you want to discard them? | ||
| </p> | ||
| </ModalBody> | ||
| <ModalFooter> | ||
| <Button variant='default' onClick={() => setShowUnsavedChangesAlert(false)}> | ||
| Keep Editing | ||
| </Button> | ||
| <Button variant='destructive' onClick={handleDiscardChanges}> | ||
| Discard Changes | ||
| </Button> | ||
| </ModalFooter> | ||
| </ModalContent> | ||
| </Modal> | ||
| </> | ||
| ) | ||
| } | ||
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.