From b7bb5da8579500872eb8652e0dd8b7e680051f2e Mon Sep 17 00:00:00 2001 From: Malar Kannan Date: Thu, 27 Jul 2017 18:47:32 +0530 Subject: [PATCH] implemented list/proplist as separate uis. wip reducer for xmldata save lexitem --- src/LexEdit.tsx | 4 ++-- src/LexSetup.tsx | 2 ++ src/LexSingleInput.tsx | 2 +- src/actionCreators.tsx | 3 ++- src/reducers.tsx | 30 ++++++++++++++++-------------- 5 files changed, 23 insertions(+), 18 deletions(-) diff --git a/src/LexEdit.tsx b/src/LexEdit.tsx index 31f2462..c6e0169 100644 --- a/src/LexEdit.tsx +++ b/src/LexEdit.tsx @@ -1,6 +1,6 @@ import * as React from 'react'; import * as _ from 'lodash'; -import { componentForType} from './LexSingleInput'; +import { componentForType } from './LexSingleInput'; import { Card, Button @@ -113,6 +113,6 @@ export class LexEdit extends React.Component { } private handleOnSave(event: any) { - this.props.save(this.state.lexItem); + this.props.save(this.state.lexItem, this.props.fieldMetaMap); } } diff --git a/src/LexSetup.tsx b/src/LexSetup.tsx index 2d3360c..6f4ed6d 100644 --- a/src/LexSetup.tsx +++ b/src/LexSetup.tsx @@ -234,6 +234,8 @@ export class LexSetup extends React.Component { .then((response) => response.text()) .then((xmlString) => { XML.parseString(xmlString, (err, xmlData) => { + let props = this.props; + _.noop(props); this.props.addXmlData(xmlData); this.setState({ xmlLoaded: true }); }); diff --git a/src/LexSingleInput.tsx b/src/LexSingleInput.tsx index f72742f..b0b6118 100644 --- a/src/LexSingleInput.tsx +++ b/src/LexSingleInput.tsx @@ -140,7 +140,7 @@ export function componentForType(type: string, params: any) { return listInput(params); } default: { - console.log('type discarded :', type); + // console.log('type discarded :', type); // console.log('values discarded :', fieldMeta.get(li)); return null; } diff --git a/src/actionCreators.tsx b/src/actionCreators.tsx index b75c9ec..353741d 100644 --- a/src/actionCreators.tsx +++ b/src/actionCreators.tsx @@ -20,9 +20,10 @@ export function addXmlData(xmlData: any) { }; } -export function save(lexItem: any) { +export function save(lexItem: any, lexSelector: any) { return { type: 'ACTION_SAVE_LEXITEM', lexItem, + lexSelector }; } diff --git a/src/reducers.tsx b/src/reducers.tsx index 60e7d24..7e47950 100644 --- a/src/reducers.tsx +++ b/src/reducers.tsx @@ -1,4 +1,5 @@ import { combineReducers } from 'redux'; +import * as _ from 'lodash'; function searchValue(state: any = {}, action: any) { if (action.type === 'ACTION_SEARCH_VALUE_CHANGE') { @@ -14,28 +15,29 @@ function searchType(state: any = {}, action: any) { return state; } -function save(state: any = {}, action: any) { +function updateXMLState(state: any = {}, action: any) { + if (action.type === 'ACTION_XML_DATA') { + return action.xmlData; + } if (action.type === 'ACTION_SAVE_LEXITEM') { + // debugger; + // let guid = action.lexSelector.guid.get(action.lexItem); + // let lang = action.lexSelector.lang.get(action.lexItem); + // // action.lexItem; + // _.findIndex(_.get(state,'document.lexicon[0].item'),(o)=>{ + // return _.isEqual(_.get(o,'$.guid'),guid) && _.isEqual(_.get(o,'entry[0].lang'),lang) + // }); + _.noop(); return { - ...state, - lexItem: action.lexItem, + ...state }; } return state; } -function addXmlData(state: any = {}, action: any) { - if (action.type === 'ACTION_XML_DATA') { - return action.xmlData; - } - return state; -} - -const searchReducer = combineReducers({ searchValue, searchType }); const rootReducer = combineReducers({ - searchState: searchReducer, - save, - xmlData: addXmlData + searchState: combineReducers({ searchValue, searchType }), + xmlData: updateXMLState }); export default rootReducer;