Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion packages/decap-cms-core/src/actions/__tests__/entries.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { fromJS, Map } from 'immutable';
import { fromJS, List, Map } from 'immutable';
import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';

Expand Down Expand Up @@ -99,6 +99,41 @@ describe('entries', () => {
});
});

it('should populate draft entry from repeated URL param', () => {
const store = mockStore({ mediaLibrary: fromJS({ files: [] }) });

const collection = fromJS({
fields: [{ name: 'post', multiple: true }],
});

return store
.dispatch(createEmptyDraft(collection, '?post=2026-05-07-test&post=2026-05-08-test'))
.then(() => {
const actions = store.getActions();
expect(actions).toHaveLength(1);

expect(actions[0]).toEqual({
payload: {
author: '',
collection: undefined,
data: { post: List(['2026-05-07-test', '2026-05-08-test']) },
meta: {},
i18n: {},
isModification: null,
label: null,
mediaFiles: [],
partial: false,
path: '',
raw: '',
slug: '',
status: '',
updatedOn: '',
},
type: 'DRAFT_CREATE_EMPTY',
});
});
});

it('should html escape URL params', () => {
const store = mockStore({ mediaLibrary: fromJS({ files: [] }) });

Expand Down
29 changes: 22 additions & 7 deletions packages/decap-cms-core/src/actions/entries.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { fromJS, List, Map } from 'immutable';
import { fromJS, List, Map, Set } from 'immutable';
import isEqual from 'lodash/isEqual';
import { Cursor } from 'decap-cms-lib-util';

import { selectCollectionEntriesCursor } from '../reducers/cursors';
import { selectFields, updateFieldByKey, selectDefaultSortField } from '../reducers/collections';
import {
selectFields,
selectField,
updateFieldByKey,
selectDefaultSortField,
} from '../reducers/collections';
import { selectIntegration, selectPublishedSlugs } from '../reducers';
import { getIntegrationProvider } from '../integrations';
import { currentBackend } from '../backend';
Expand Down Expand Up @@ -38,7 +43,6 @@ import type {
import type { EntryValue } from '../valueObjects/Entry';
import type { Backend } from '../backend';
import type AssetProxy from '../valueObjects/AssetProxy';
import type { Set } from 'immutable';

/*
* Constant Declarations
Expand Down Expand Up @@ -740,10 +744,21 @@ function getMetaFields(fields: EntryFields) {
export function createEmptyDraft(collection: Collection, search: string) {
return async (dispatch: ThunkDispatch<State, {}, AnyAction>, getState: () => State) => {
const params = new URLSearchParams(search);
params.forEach((value, key) => {
collection = updateFieldByKey(collection, key, field =>
field.set('default', processValue(value)),
);
const uniqueKeys = Set([...params.keys()]).toArray();

uniqueKeys.forEach(key => {
const field = selectField(collection, key);
const isMultiple = field?.get('multiple', false);
const values = params.getAll(key);

collection = updateFieldByKey(collection, key, field => {
if (isMultiple) {
const allValues = values.flatMap(v => v.split(',')).map(processValue);
return field.set('default', List(allValues));
} else {
return field.set('default', processValue(values[values.length - 1]));
}
});
});

const fields = collection.get('fields', List());
Expand Down
1 change: 1 addition & 0 deletions packages/decap-cms-core/src/types/redux.ts
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,7 @@ export type EntryField = StaticallyTypedRecord<{
name: string;
default: string | null | boolean | List<unknown>;
media_folder?: string;
multiple?: boolean;
public_folder?: string;
comment?: string;
meta?: boolean;
Expand Down
Loading