Entry Draft Refactor (#178)
This commit is contained in:
parent
4ddc46ba25
commit
047f84405a
@ -1,7 +1,9 @@
|
|||||||
|
import { List } from 'immutable';
|
||||||
import { actions as notifActions } from 'redux-notifications';
|
import { actions as notifActions } from 'redux-notifications';
|
||||||
import { currentBackend } from '../backends/backend';
|
import { currentBackend } from '../backends/backend';
|
||||||
import { getIntegrationProvider } from '../integrations';
|
import { getIntegrationProvider } from '../integrations';
|
||||||
import { getMedia, selectIntegration } from '../reducers';
|
import { getMedia, selectIntegration } from '../reducers';
|
||||||
|
import { createEntry } from '../valueObjects/Entry';
|
||||||
|
|
||||||
const { notifSend } = notifActions;
|
const { notifSend } = notifActions;
|
||||||
|
|
||||||
@ -205,10 +207,12 @@ export function loadEntries(collection, page = 0) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function createEmptyDraft(collection) {
|
export function createEmptyDraft(collection) {
|
||||||
return (dispatch, getState) => {
|
return (dispatch) => {
|
||||||
const state = getState();
|
const dataFields = {};
|
||||||
const backend = currentBackend(state.config);
|
collection.get('fields', List()).forEach((field) => {
|
||||||
const newEntry = backend.newEntry(collection);
|
dataFields[field.get('name')] = field.get('default', null);
|
||||||
|
});
|
||||||
|
const newEntry = createEntry(collection.get('name'), '', '', { data: dataFields });
|
||||||
dispatch(emmptyDraftCreated(newEntry));
|
dispatch(emmptyDraftCreated(newEntry));
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -108,10 +108,6 @@ class Backend {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
newEntry(collection) {
|
|
||||||
return createEntry(collection.get('name'));
|
|
||||||
}
|
|
||||||
|
|
||||||
entryWithFormat(collectionOrEntity) {
|
entryWithFormat(collectionOrEntity) {
|
||||||
return (entry) => {
|
return (entry) => {
|
||||||
const format = resolveFormat(collectionOrEntity, entry);
|
const format = resolveFormat(collectionOrEntity, entry);
|
||||||
|
@ -13,8 +13,7 @@ export default class ControlPane extends Component {
|
|||||||
const { entry, getMedia, onChange, onAddMedia, onRemoveMedia } = this.props;
|
const { entry, getMedia, onChange, onAddMedia, onRemoveMedia } = this.props;
|
||||||
const widget = resolveWidget(field.get('widget'));
|
const widget = resolveWidget(field.get('widget'));
|
||||||
const fieldName = field.get('name');
|
const fieldName = field.get('name');
|
||||||
const fieldDefaultValue = field.get('default');
|
const value = entry.getIn(['data', fieldName]);
|
||||||
const value = entry.getIn(['data', fieldName], fieldDefaultValue);
|
|
||||||
if (entry.size === 0 || entry.get('partial') === true) return null;
|
if (entry.size === 0 || entry.get('partial') === true) return null;
|
||||||
return (
|
return (
|
||||||
<div className={styles.control}>
|
<div className={styles.control}>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user