-
Notifications
You must be signed in to change notification settings - Fork 0
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
Edit Dialog for Images #1151
base: develop
Are you sure you want to change the base?
Edit Dialog for Images #1151
Changes from 7 commits
7d9603f
5415b1c
157ed0f
2b0ae3f
9fccbfa
601f256
591651d
1b82001
35dc23a
6fb08c4
6bcdfd4
0cda636
4c39b95
4e6ae2f
3f4e8db
5db78e1
786d1b5
36bf77c
6f49f96
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -87,6 +87,10 @@ describe('Edit file dialog', () => { | |||||
|
||||||
it('Edits an image correctly', async () => { | ||||||
createView(); | ||||||
|
||||||
//Checks if file extension is displayed. If it's editable, actual value will not match expected. | ||||||
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.
Suggested change
|
||||||
expect(screen.getByText('.png')).toBeInTheDocument(); | ||||||
|
||||||
modifyFileValues({ | ||||||
file_name: 'test_file_name.jpeg', | ||||||
title: 'Test Title', | ||||||
|
@@ -98,15 +102,15 @@ describe('Edit file dialog', () => { | |||||
await user.click(saveButton); | ||||||
|
||||||
expect(axiosPatchSpy).toHaveBeenCalledWith('/images/1', { | ||||||
file_name: 'test_file_name.jpeg', | ||||||
file_name: 'test_file_name.jpeg.png', | ||||||
title: 'Test Title', | ||||||
description: 'Test Description', | ||||||
}); | ||||||
|
||||||
expect(onClose).toHaveBeenCalled(); | ||||||
}); | ||||||
|
||||||
it('No values changed shows correct error message', async () => { | ||||||
it('shows correct error message when no values are changed', async () => { | ||||||
createView(); | ||||||
|
||||||
const saveButton = screen.getByRole('button', { name: 'Save' }); | ||||||
|
@@ -120,7 +124,7 @@ describe('Edit file dialog', () => { | |||||
).toBeInTheDocument(); | ||||||
}); | ||||||
|
||||||
it('Required fields show error if they are whitespace or current value just removed', async () => { | ||||||
it('shows error message if required fields are whitespace or their current value was removed', async () => { | ||||||
createView(); | ||||||
modifyFileValues({ | ||||||
file_name: '', | ||||||
|
@@ -133,7 +137,7 @@ describe('Edit file dialog', () => { | |||||
expect(onClose).not.toHaveBeenCalled(); | ||||||
}); | ||||||
|
||||||
it('CatchAllError request works correctly and displays refresh page message', async () => { | ||||||
it('displays refresh page message and a CatchAllError request works correctly', async () => { | ||||||
createView(); | ||||||
modifyFileValues({ | ||||||
file_name: 'Error 500', | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
DialogTitle, | ||
FormHelperText, | ||
Grid, | ||
InputAdornment, | ||
TextField, | ||
} from '@mui/material'; | ||
import { useForm } from 'react-hook-form'; | ||
|
@@ -44,14 +45,25 @@ | |
|
||
const { mutateAsync: patchFile, isPending: isEditPending } = usePatchFile(); | ||
|
||
const point = selectedFile?.file_name?.lastIndexOf('.') ?? 0; | ||
const extension = selectedFile?.file_name?.slice(point) ?? ''; | ||
const initialName = selectedFile?.file_name?.slice(0, point) ?? ''; | ||
|
||
console.log(extension); | ||
|
||
const selectedFileCopy: ObjectFilePatch = React.useMemo( | ||
() => (selectedFile ? { ...selectedFile, file_name: initialName } : {}), | ||
[selectedFile, initialName] | ||
); | ||
|
||
const initialFile: ObjectFilePatch = React.useMemo( | ||
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. Can you make the same changes that you have do to the uppy post here please. So don't allow the user to change the extenstion. and display the extension next the textField please. |
||
() => | ||
selectedFile ?? { | ||
selectedFileCopy ?? { | ||
file_name: '', | ||
title: '', | ||
description: '', | ||
}, | ||
[selectedFile] | ||
[selectedFileCopy] | ||
); | ||
|
||
const { | ||
|
@@ -89,16 +101,18 @@ | |
const handleEditFile = React.useCallback( | ||
(fileData: ObjectFilePatch) => { | ||
if (selectedFile) { | ||
const isFileNameUpdated = fileData.file_name !== selectedFile.file_name; | ||
const isFileNameUpdated = | ||
fileData.file_name !== selectedFileCopy.file_name; | ||
|
||
const isDescriptionUpdated = | ||
fileData.description !== selectedFile.description; | ||
fileData.description !== selectedFileCopy.description; | ||
|
||
const isTitleUpdated = fileData.title !== selectedFile.title; | ||
const isTitleUpdated = fileData.title !== selectedFileCopy.title; | ||
|
||
let fileToEdit: ObjectFilePatch = {}; | ||
const fileToEdit: ObjectFilePatch = {}; | ||
|
||
if (isFileNameUpdated) fileToEdit.file_name = fileData.file_name; | ||
if (isFileNameUpdated) | ||
fileToEdit.file_name = fileData.file_name + extension; | ||
if (isDescriptionUpdated) fileToEdit.description = fileData.description; | ||
if (isTitleUpdated) fileToEdit.title = fileData.title; | ||
|
||
|
@@ -119,11 +133,18 @@ | |
} | ||
} | ||
}, | ||
[selectedFile, patchFile, handleClose, setError] | ||
[ | ||
selectedFile, | ||
selectedFileCopy, | ||
extension, | ||
patchFile, | ||
handleClose, | ||
setError, | ||
] | ||
); | ||
|
||
return ( | ||
<Dialog open={open} maxWidth="lg" fullWidth> | ||
<Dialog open={open} maxWidth="sm" fullWidth> | ||
<DialogTitle>{`Edit ${fileType}`}</DialogTitle> | ||
<DialogContent> | ||
<Grid container direction="column" spacing={1} component="form"> | ||
|
@@ -135,6 +156,11 @@ | |
{...register('file_name')} | ||
error={!!errors.file_name} | ||
helperText={errors.file_name?.message} | ||
InputProps={{ | ||
endAdornment: ( | ||
<InputAdornment position="end">{extension}</InputAdornment> | ||
), | ||
}} | ||
fullWidth | ||
/> | ||
</Grid> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
apologies i know i changed it to this the first time :)