fix: duplicate and new entry action (#3003)

* fix: duplicate and new entry action

* test(e2e): flush clock when duplicating entry to handle debounced fields

Co-authored-by: Erez Rokah <erezrokah@users.noreply.github.com>
This commit is contained in:
Bartholomew
2019-12-25 10:47:02 +01:00
committed by Erez Rokah
parent e4ba4d9d74
commit 9e7aa0c500
4 changed files with 37 additions and 21 deletions

View File

@ -529,7 +529,7 @@ export function publishUnpublishedEntry(collection: string, slug: string) {
);
dispatch(unpublishedEntryPublished(collection, slug, transactionID));
dispatch(loadEntry(collections.get(collection), slug));
return dispatch(loadEntry(collections.get(collection), slug));
})
.catch((error: Error) => {
dispatch(

View File

@ -24,6 +24,7 @@ import {
import { ThunkDispatch } from 'redux-thunk';
import { AnyAction, Dispatch } from 'redux';
import { waitForMediaLibraryToLoad } from './mediaLibrary';
import { waitUntil } from './waitUntil';
const { notifSend } = notifActions;
@ -215,7 +216,7 @@ export function createDraftFromEntry(entry: EntryMap, metadata?: Map<string, unk
};
}
export function createDraftDuplicateFromEntry(entry: EntryMap) {
export function draftDuplicateEntry(entry: EntryMap) {
return {
type: DRAFT_CREATE_DUPLICATE_FROM_ENTRY,
payload: createEntry(entry.get('collection'), '', '', { data: entry.get('data') }),
@ -277,6 +278,17 @@ export function persistLocalBackup(entry: EntryMap, collection: Collection) {
};
}
export function createDraftDuplicateFromEntry(entry: EntryMap) {
return (dispatch: ThunkDispatch<State, {}, AnyAction>) => {
dispatch(
waitUntil({
predicate: ({ type }) => type === DRAFT_CREATE_EMPTY,
run: () => dispatch(draftDuplicateEntry(entry)),
}),
);
};
}
export function retrieveLocalBackup(collection: Collection, slug: string) {
return async (dispatch: ThunkDispatch<State, {}, AnyAction>, getState: () => State) => {
const state = getState();

View File

@ -318,10 +318,10 @@ export class Editor extends React.Component {
return navigateToCollection(collection.get('name'));
};
handleDuplicateEntry = async () => {
handleDuplicateEntry = () => {
const { createDraftDuplicateFromEntry, collection, entryDraft } = this.props;
await navigateToNewEntry(collection.get('name'));
navigateToNewEntry(collection.get('name'));
createDraftDuplicateFromEntry(entryDraft.get('entry'));
};