mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
handleFileUploadComplete updates wrong draft (#23983)
This commit is contained in:
parent
49919d2be5
commit
3f641588fa
@ -850,7 +850,9 @@ describe('components/advanced_create_post', () => {
|
|||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
instance.draftsForChannel[currentChannelProp.id] = uploadsInProgressDraft;
|
const channelId = 'another_channel_id';
|
||||||
|
|
||||||
|
instance.draftsForChannel[channelId] = uploadsInProgressDraft;
|
||||||
|
|
||||||
wrapper.setProps({draft: uploadsInProgressDraft});
|
wrapper.setProps({draft: uploadsInProgressDraft});
|
||||||
const fileInfos = [TestHelper.getFileInfoMock({id: 'a'})];
|
const fileInfos = [TestHelper.getFileInfoMock({id: 'a'})];
|
||||||
@ -862,10 +864,9 @@ describe('components/advanced_create_post', () => {
|
|||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
instance.handleFileUploadComplete(fileInfos, clientIds, currentChannelProp.id);
|
instance.handleFileUploadComplete(fileInfos, clientIds, channelId);
|
||||||
|
|
||||||
jest.advanceTimersByTime(Constants.SAVE_DRAFT_TIMEOUT);
|
expect(setDraft).toHaveBeenCalledWith(StoragePrefixes.DRAFT + channelId, expectedDraft, channelId);
|
||||||
expect(setDraft).toHaveBeenCalledWith(StoragePrefixes.DRAFT + currentChannelProp.id, expectedDraft, currentChannelProp.id);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('check for handleUploadError callback', () => {
|
it('check for handleUploadError callback', () => {
|
||||||
@ -945,7 +946,7 @@ describe('components/advanced_create_post', () => {
|
|||||||
|
|
||||||
jest.advanceTimersByTime(Constants.SAVE_DRAFT_TIMEOUT);
|
jest.advanceTimersByTime(Constants.SAVE_DRAFT_TIMEOUT);
|
||||||
expect(setDraft).toHaveBeenCalledTimes(1);
|
expect(setDraft).toHaveBeenCalledTimes(1);
|
||||||
expect(setDraft).toHaveBeenCalledWith(StoragePrefixes.DRAFT + currentChannelProp.id, draftProp, currentChannelProp.id, false);
|
expect(setDraft).toHaveBeenCalledWith(StoragePrefixes.DRAFT + currentChannelProp.id, draftProp, currentChannelProp.id);
|
||||||
expect(instance.handleFileUploadChange).toHaveBeenCalledTimes(1);
|
expect(instance.handleFileUploadChange).toHaveBeenCalledTimes(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -565,8 +565,7 @@ class AdvancedCreatePost extends React.PureComponent<Props, State> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.isDraftSubmitting = false;
|
this.isDraftSubmitting = false;
|
||||||
this.props.actions.setDraft(StoragePrefixes.DRAFT + channelId, null, channelId);
|
this.removeDraft(channelId);
|
||||||
this.draftsForChannel[channelId] = null;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
handleNotifyAllConfirmation = () => {
|
handleNotifyAllConfirmation = () => {
|
||||||
@ -796,7 +795,6 @@ class AdvancedCreatePost extends React.PureComponent<Props, State> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
sendReaction(isReaction: RegExpExecArray) {
|
sendReaction(isReaction: RegExpExecArray) {
|
||||||
const channelId = this.props.currentChannel.id;
|
|
||||||
const action = isReaction[1];
|
const action = isReaction[1];
|
||||||
const emojiName = isReaction[2];
|
const emojiName = isReaction[2];
|
||||||
const postId = this.props.latestReplyablePostId;
|
const postId = this.props.latestReplyablePostId;
|
||||||
@ -805,8 +803,7 @@ class AdvancedCreatePost extends React.PureComponent<Props, State> {
|
|||||||
this.props.actions.submitReaction(postId, action, emojiName);
|
this.props.actions.submitReaction(postId, action, emojiName);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.props.actions.setDraft(StoragePrefixes.DRAFT + channelId, null, channelId);
|
this.removeDraft();
|
||||||
this.draftsForChannel[channelId] = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
focusTextbox = (keepFocus = false) => {
|
focusTextbox = (keepFocus = false) => {
|
||||||
@ -891,9 +888,7 @@ class AdvancedCreatePost extends React.PureComponent<Props, State> {
|
|||||||
this.handleDraftChange(draft);
|
this.handleDraftChange(draft);
|
||||||
};
|
};
|
||||||
|
|
||||||
handleDraftChange = (draft: PostDraft, instant = false) => {
|
handleDraftChange = (draft: PostDraft, channelId = this.props.currentChannel.id, instant = false) => {
|
||||||
const channelId = this.props.currentChannel.id;
|
|
||||||
|
|
||||||
if (this.saveDraftFrame) {
|
if (this.saveDraftFrame) {
|
||||||
clearTimeout(this.saveDraftFrame);
|
clearTimeout(this.saveDraftFrame);
|
||||||
}
|
}
|
||||||
@ -909,6 +904,11 @@ class AdvancedCreatePost extends React.PureComponent<Props, State> {
|
|||||||
this.draftsForChannel[channelId] = draft;
|
this.draftsForChannel[channelId] = draft;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
removeDraft = (channelId = this.props.currentChannel.id) => {
|
||||||
|
this.props.actions.setDraft(StoragePrefixes.DRAFT + channelId, null, channelId);
|
||||||
|
this.draftsForChannel[channelId] = null;
|
||||||
|
};
|
||||||
|
|
||||||
handleFileUploadChange = () => {
|
handleFileUploadChange = () => {
|
||||||
this.focusTextbox();
|
this.focusTextbox();
|
||||||
};
|
};
|
||||||
@ -921,8 +921,7 @@ class AdvancedCreatePost extends React.PureComponent<Props, State> {
|
|||||||
uploadsInProgress,
|
uploadsInProgress,
|
||||||
};
|
};
|
||||||
|
|
||||||
this.props.actions.setDraft(StoragePrefixes.DRAFT + channelId, draft, channelId);
|
this.handleDraftChange(draft, channelId, true);
|
||||||
this.draftsForChannel[channelId] = draft;
|
|
||||||
|
|
||||||
// this is a bit redundant with the code that sets focus when the file input is clicked,
|
// this is a bit redundant with the code that sets focus when the file input is clicked,
|
||||||
// but this also resets the focus after a drag and drop
|
// but this also resets the focus after a drag and drop
|
||||||
@ -955,7 +954,7 @@ class AdvancedCreatePost extends React.PureComponent<Props, State> {
|
|||||||
draft.fileInfos = sortFileInfos(draft.fileInfos.concat(fileInfos), this.props.locale);
|
draft.fileInfos = sortFileInfos(draft.fileInfos.concat(fileInfos), this.props.locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.handleDraftChange(draft, true);
|
this.handleDraftChange(draft, channelId, true);
|
||||||
};
|
};
|
||||||
|
|
||||||
handleUploadError = (uploadError: string | ServerError | null, clientId?: string, channelId?: string) => {
|
handleUploadError = (uploadError: string | ServerError | null, clientId?: string, channelId?: string) => {
|
||||||
@ -971,8 +970,7 @@ class AdvancedCreatePost extends React.PureComponent<Props, State> {
|
|||||||
...draft,
|
...draft,
|
||||||
uploadsInProgress,
|
uploadsInProgress,
|
||||||
};
|
};
|
||||||
this.props.actions.setDraft(StoragePrefixes.DRAFT + channelId, modifiedDraft, channelId);
|
this.handleDraftChange(modifiedDraft, channelId, true);
|
||||||
this.draftsForChannel[channelId] = modifiedDraft;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -989,7 +987,6 @@ class AdvancedCreatePost extends React.PureComponent<Props, State> {
|
|||||||
removePreview = (id: string) => {
|
removePreview = (id: string) => {
|
||||||
let modifiedDraft = {} as PostDraft;
|
let modifiedDraft = {} as PostDraft;
|
||||||
const draft = {...this.props.draft};
|
const draft = {...this.props.draft};
|
||||||
const channelId = this.props.currentChannel.id;
|
|
||||||
|
|
||||||
// Clear previous errors
|
// Clear previous errors
|
||||||
this.setState({serverError: null});
|
this.setState({serverError: null});
|
||||||
@ -1020,9 +1017,7 @@ class AdvancedCreatePost extends React.PureComponent<Props, State> {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
this.props.actions.setDraft(StoragePrefixes.DRAFT + channelId, modifiedDraft, channelId, false);
|
this.handleDraftChange(modifiedDraft, this.props.currentChannel.id, true);
|
||||||
this.draftsForChannel[channelId] = modifiedDraft;
|
|
||||||
|
|
||||||
this.handleFileUploadChange();
|
this.handleFileUploadChange();
|
||||||
|
|
||||||
if (this.saveDraftFrame) {
|
if (this.saveDraftFrame) {
|
||||||
@ -1284,7 +1279,7 @@ class AdvancedCreatePost extends React.PureComponent<Props, State> {
|
|||||||
updatedDraft.metadata = {};
|
updatedDraft.metadata = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
this.handleDraftChange(updatedDraft, true);
|
this.handleDraftChange(updatedDraft, this.props.currentChannel.id, true);
|
||||||
this.focusTextbox();
|
this.focusTextbox();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user