Add metadata to draft entry fields (#196)

* Add metadata to draft entry fields
* Do not render widget if value is null
* Pass along metadata
* Namespace queries to avoid conflict
* Query relational field on mount (for when editing entries)
* Make sure metadata is Immutable
* Added collection name  as metadata keys
This commit is contained in:
Cássio Souza
2016-12-29 17:18:24 -02:00
committed by GitHub
parent e47a12f6ec
commit ddfdc59941
12 changed files with 112 additions and 44 deletions

View File

@ -2,7 +2,7 @@ import { Map, List, fromJS } from 'immutable';
import * as actions from '../../actions/entries';
import reducer from '../entryDraft';
let initialState = Map({ entry: Map(), mediaFiles: List() });
let initialState = Map({ entry: Map(), mediaFiles: List(), fieldsMetaData: Map() });
const entry = {
collection: 'posts',
@ -29,6 +29,7 @@ describe('entryDraft reducer', () => {
newRecord: false,
},
mediaFiles: [],
fieldsMetaData: Map(),
})
);
});
@ -39,7 +40,7 @@ describe('entryDraft reducer', () => {
expect(
reducer(
initialState,
actions.emmptyDraftCreated(fromJS(entry))
actions.emptyDraftCreated(fromJS(entry))
)
).toEqual(
fromJS({
@ -48,6 +49,7 @@ describe('entryDraft reducer', () => {
newRecord: true,
},
mediaFiles: [],
fieldsMetaData: Map(),
})
);
});

View File

@ -3,7 +3,7 @@ import {
DRAFT_CREATE_FROM_ENTRY,
DRAFT_CREATE_EMPTY,
DRAFT_DISCARD,
DRAFT_CHANGE,
DRAFT_CHANGE_FIELD,
ENTRY_PERSIST_REQUEST,
ENTRY_PERSIST_SUCCESS,
ENTRY_PERSIST_FAILURE,
@ -13,7 +13,7 @@ import {
REMOVE_MEDIA,
} from '../actions/media';
const initialState = Map({ entry: Map(), mediaFiles: List() });
const initialState = Map({ entry: Map(), mediaFiles: List(), fieldsMetaData: Map() });
const entryDraftReducer = (state = Map(), action) => {
switch (action.type) {
@ -23,6 +23,7 @@ const entryDraftReducer = (state = Map(), action) => {
state.set('entry', action.payload);
state.setIn(['entry', 'newRecord'], false);
state.set('mediaFiles', List());
state.set('fieldsMetaData', Map());
});
case DRAFT_CREATE_EMPTY:
// New Entry
@ -30,12 +31,15 @@ const entryDraftReducer = (state = Map(), action) => {
state.set('entry', fromJS(action.payload));
state.setIn(['entry', 'newRecord'], true);
state.set('mediaFiles', List());
state.set('fieldsMetaData', Map());
});
case DRAFT_DISCARD:
return initialState;
case DRAFT_CHANGE:
return state.set('entry', action.payload);
case DRAFT_CHANGE_FIELD:
return state.withMutations((state) => {
state.setIn(['entry', 'data', action.payload.field], action.payload.value);
state.mergeIn(['fieldsMetaData'], fromJS(action.payload.metadata));
});
case ENTRY_PERSIST_REQUEST: {
return state.setIn(['entry', 'isPersisting'], true);
}

View File

@ -44,7 +44,7 @@ const entries = (state = defaultState, action) => {
case QUERY_REQUEST:
if (action.payload.searchTerm !== state.get('term')) {
return state.withMutations((map) => {
map.set('isFetching', true);
map.set('isFetching', action.payload.namespace);
map.set('term', action.payload.searchTerm);
});
}
@ -56,7 +56,7 @@ const entries = (state = defaultState, action) => {
return state.withMutations((map) => {
map.set('isFetching', false);
map.set('term', searchTerm);
map.set('queryHits', response.hits);
map.set('queryHits', Map({ [action.payload.namespace]: response.hits }));
});
default: