Skip to content
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

Fix file info of new uploaded file not being persisted after edit #8244

Merged
merged 3 commits into from
Oct 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const InputModalStepper = ({
isWarningDeleteOpen,
multiple,
selectedFiles,
submitEditNewFile,
submitEditExistingFile,
toggleModalWarning,
} = useModalContext();
Expand Down Expand Up @@ -175,6 +176,7 @@ const InputModalStepper = ({

const handleSubmitEditNewFile = e => {
e.preventDefault();
submitEditNewFile();
goNext();
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,12 @@ const InputModalStepperProvider = ({
});
};

const submitEditNewFile = () => {
dispatch({
type: 'ON_SUBMIT_EDIT_NEW_FILE',
});
};

const submitEditExistingFile = () => {
dispatch({
type: 'ON_SUBMIT_EDIT_EXISTING_FILE',
Expand Down Expand Up @@ -498,6 +504,7 @@ const InputModalStepperProvider = ({
onInputMediaChange,
removeFilter,
setParam,
submitEditNewFile,
submitEditExistingFile,
toggleModalWarning,
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@ const reducer = (state, action) =>
draftState.selectedFiles = draftState.selectedFiles.filter(file => file && file.id);
break;
}
case 'ON_SUBMIT_EDIT_NEW_FILE': {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add the related test for this case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test added.

const originalIndex = state.fileToEdit.originalIndex;
draftState.filesToUpload[originalIndex] = draftState.fileToEdit;
draftState.fileToEdit = null;
break;
}
case 'ON_SUBMIT_EDIT_EXISTING_FILE': {
draftState.fileToEdit.isUploading = true;
break;
Expand Down Expand Up @@ -211,7 +217,9 @@ const reducer = (state, action) =>
}
case 'SET_FILE_TO_EDIT': {
draftState.fileToEdit = formatFileForEditing(
[...state.files, ...state.selectedFiles].find(file => file.id.toString() === action.fileId.toString())
[...state.files, ...state.selectedFiles].find(
file => file.id.toString() === action.fileId.toString()
)
);
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2250,4 +2250,69 @@ describe('UPLOAD | containers | ModalStepper | reducer', () => {
expect(reducer(state, action)).toEqual(expected);
});
});

describe('ON_SUBMIT_EDIT_NEW_FILE', () => {
it('should update file info after edit', () => {
const action = {
type: 'ON_SUBMIT_EDIT_NEW_FILE',
};
const state = {
currentStep: 'edit-new',
fileToEdit: {
abortController: new AbortController(),
file: { name: 'test1', ok: true },
fileInfo: {
alternativeText: 'test1 alternativeText',
caption: 'test1 caption',
name: 'test1 name',
},
originalName: 'test1',
hasError: false,
errorMessage: null,
isUploading: false,
originalIndex: 0,
tempId: null,
},
filesToUpload: [
{
abortController: new AbortController(),
file: { name: 'test1', ok: true },
fileInfo: {
alternativeText: '',
caption: '',
name: 'test1',
},
originalName: 'test1',
hasError: false,
errorMessage: null,
isUploading: false,
originalIndex: 0,
tempId: null,
},
],
};
const expected = {
currentStep: 'edit-new',
fileToEdit: null,
filesToUpload: [
{
abortController: new AbortController(),
file: { name: 'test1', ok: true },
fileInfo: {
alternativeText: 'test1 alternativeText',
caption: 'test1 caption',
name: 'test1 name',
},
originalName: 'test1',
hasError: false,
errorMessage: null,
isUploading: false,
originalIndex: 0,
tempId: null,
},
],
};
expect(reducer(state, action)).toEqual(expected);
});
});
});