Skip to content

Commit

Permalink
fix: don't add media files on entry when not a draft
Browse files Browse the repository at this point in the history
  • Loading branch information
erezrokah committed Nov 10, 2019
1 parent 8c70204 commit 62dc650
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,21 @@ describe('mediaLibrary', () => {
createAssetProxy.mockReturnValue(assetProxy);

return store.dispatch(persistMedia(file)).then(() => {
const actions = store.getActions();

expect(actions).toHaveLength(3);
expect(actions[0]).toEqual({ type: 'MEDIA_PERSIST_REQUEST' });
expect(actions[1]).toEqual({
type: 'ADD_ASSET',
payload: { public_path: '/media/name.png' },
});
expect(actions[2]).toEqual({
type: 'MEDIA_PERSIST_SUCCESS',
payload: {
file: { draft: false, id: 'id', displayURL: 'displayURL' },
},
});

expect(backend.persistMedia).toHaveBeenCalledTimes(1);
expect(backend.persistMedia).toHaveBeenCalledWith(
store.getState().config,
Expand Down
18 changes: 10 additions & 8 deletions packages/netlify-cms-core/src/actions/mediaLibrary.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,16 @@ export function persistMedia(file, opts = {}) {
const assetId = asset.id || id;
const displayURL = asset.displayURL || URL.createObjectURL(file);

dispatch(
addDraftEntryMediaFile({
...asset,
id: assetId,
draft,
public_path: assetProxy.public_path,
}),
);
if (draft) {
dispatch(
addDraftEntryMediaFile({
...asset,
id: assetId,
draft,
public_path: assetProxy.public_path,
}),
);
}

return dispatch(
mediaPersisted({
Expand Down

0 comments on commit 62dc650

Please sign in to comment.