Entry Draft Refactor (#178)

This commit is contained in:
Cássio Souza 2016-11-30 16:52:17 -02:00 committed by GitHub
parent 4ddc46ba25
commit 047f84405a
3 changed files with 9 additions and 10 deletions

View File

@ -1,7 +1,9 @@
import { List } from 'immutable';
import { actions as notifActions } from 'redux-notifications';
import { currentBackend } from '../backends/backend';
import { getIntegrationProvider } from '../integrations';
import { getMedia, selectIntegration } from '../reducers';
import { createEntry } from '../valueObjects/Entry';
const { notifSend } = notifActions;
@ -205,10 +207,12 @@ export function loadEntries(collection, page = 0) {
}
export function createEmptyDraft(collection) {
return (dispatch, getState) => {
const state = getState();
const backend = currentBackend(state.config);
const newEntry = backend.newEntry(collection);
return (dispatch) => {
const dataFields = {};
collection.get('fields', List()).forEach((field) => {
dataFields[field.get('name')] = field.get('default', null);
});
const newEntry = createEntry(collection.get('name'), '', '', { data: dataFields });
dispatch(emmptyDraftCreated(newEntry));
};
}

View File

@ -108,10 +108,6 @@ class Backend {
);
}
newEntry(collection) {
return createEntry(collection.get('name'));
}
entryWithFormat(collectionOrEntity) {
return (entry) => {
const format = resolveFormat(collectionOrEntity, entry);

View File

@ -13,8 +13,7 @@ export default class ControlPane extends Component {
const { entry, getMedia, onChange, onAddMedia, onRemoveMedia } = this.props;
const widget = resolveWidget(field.get('widget'));
const fieldName = field.get('name');
const fieldDefaultValue = field.get('default');
const value = entry.getIn(['data', fieldName], fieldDefaultValue);
const value = entry.getIn(['data', fieldName]);
if (entry.size === 0 || entry.get('partial') === true) return null;
return (
<div className={styles.control}>