moving lexdata to redux store - wip

master
Malar Kannan 2017-07-13 19:06:47 +05:30
parent 2aa2cf1c83
commit c32fea2881
7 changed files with 29 additions and 9 deletions

View File

@ -8,7 +8,7 @@ import { walleStore } from './WallEStore';
import { Header, Icon, Segment } from 'semantic-ui-react'; import { Header, Icon, Segment } from 'semantic-ui-react';
function mapStateToProps(state: any) { function mapStateToProps(state: any) {
return {...state}; return state;
} }
function mapDispachToProps(dispatch: any) { function mapDispachToProps(dispatch: any) {

View File

@ -16,14 +16,14 @@ export class LexEditor extends React.Component<any, any> {
.filter((q: any) => _.get<any>(q, searchLens, '') === searchText) .filter((q: any) => _.get<any>(q, searchLens, '') === searchText)
.take(10) .take(10)
.value(); .value();
let { fieldMetaMap: fieldMetaMap, save: save } = this.props;
return ( return (
<div> <div>
<LexSearch <LexSearch
{...this.props} {...this.props}
{...{ fieldMetaMap: this.props.fieldMetaMap }}
/> />
<LexMatches <LexMatches
{...{ fieldMetaMap: this.props.fieldMetaMap }} {...{ fieldMetaMap, save }}
matchedEntries={matchedEntries} matchedEntries={matchedEntries}
selectionMeta={this.props.selectFields} selectionMeta={this.props.selectFields}
searchText={searchText} searchText={searchText}
@ -82,7 +82,7 @@ function LexMatches(params: any) {
let uniqueKey = mObj.guid[0] + '#' + mObj.$.id; let uniqueKey = mObj.guid[0] + '#' + mObj.$.id;
return ( return (
<LexEdit <LexEdit
{...{ fieldMetaMap: props.fieldMetaMap }} {...props}
key={uniqueKey} key={uniqueKey}
lexItem={mObj} lexItem={mObj}
selectionMeta={props.selectionMeta} selectionMeta={props.selectionMeta}
@ -93,7 +93,7 @@ function LexMatches(params: any) {
_.set(addProps, props.searchLens, props.searchText); _.set(addProps, props.searchLens, props.searchText);
let addEntry = ( let addEntry = (
<LexEdit <LexEdit
{...{ fieldMetaMap: props.fieldMetaMap }} {...props}
key={props.searchText} key={props.searchText}
lexItem={addProps} lexItem={addProps}
selectionMeta={props.selectionMeta} selectionMeta={props.selectionMeta}

View File

@ -103,11 +103,11 @@ export class LexEdit extends React.Component<any, any> {
let lens = this.props.fieldMetaMap[type].lens; let lens = this.props.fieldMetaMap[type].lens;
let { lexItem: lexItem } = this.state; let { lexItem: lexItem } = this.state;
_.set(lexItem, lens, value); _.set(lexItem, lens, value);
console.log('setting event :', lexItem);
this.setState(lexItem); this.setState(lexItem);
} }
private handleOnSave(event: any) { private handleOnSave(event: any) {
this.props.save(this.state.lexItem);
console.log('saving object :', this.state.lexItem); console.log('saving object :', this.state.lexItem);
} }
} }

View File

@ -59,8 +59,9 @@ export class LexSetup extends React.Component<any, any> {
})); }));
return [lang, langOpts]; return [lang, langOpts];
})); }));
this.props.addXmlData(lexData);
this.setState({ this.setState({
lexData, allEntries, selectFields, fieldMetaMap allEntries, selectFields, fieldMetaMap
}); });
}); });
}) })

View File

@ -2,7 +2,8 @@ import { createStore } from 'redux';
import rootReducer from './reducers'; import rootReducer from './reducers';
const defaultState = { const defaultState = {
searchState: { searchValue: 'just', searchType: 'label' } searchState: { searchValue: 'just', searchType: 'label' },
xmlData: []
}; };
const devToolsKey = '__REDUX_DEVTOOLS_EXTENSION__'; const devToolsKey = '__REDUX_DEVTOOLS_EXTENSION__';

View File

@ -13,6 +13,13 @@ export function searchForValue(searchValue: any) {
}; };
} }
export function addXmlData(xmlData: any) {
return {
type: 'ACTION_XML_DATA',
xmlData
};
}
export function save(lexItem: any) { export function save(lexItem: any) {
return { return {
type: 'ACTION_SAVE_LEXITEM', type: 'ACTION_SAVE_LEXITEM',

View File

@ -24,7 +24,18 @@ function save(state: any = {}, action: any) {
return 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 searchReducer = combineReducers({ searchValue, searchType });
const rootReducer = combineReducers({ searchState: searchReducer, save }); const rootReducer = combineReducers({
searchState: searchReducer,
save,
xmlData: addXmlData
});
export default rootReducer; export default rootReducer;