From 3a44072e539c1bc6f99229a98a3be313b11784e1 Mon Sep 17 00:00:00 2001 From: snoop Date: Wed, 26 Jul 2017 15:04:35 +0900 Subject: [PATCH] fixed tree --- .../meta/react/components/SensorItemTree.tsx | 47 ++++++++++++++----- 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/src/ts/@overflow/meta/react/components/SensorItemTree.tsx b/src/ts/@overflow/meta/react/components/SensorItemTree.tsx index 74c593e..16c5257 100644 --- a/src/ts/@overflow/meta/react/components/SensorItemTree.tsx +++ b/src/ts/@overflow/meta/react/components/SensorItemTree.tsx @@ -8,7 +8,7 @@ import { Label, Accordion, Icon, - List, + List, Button, ListItemProps, CheckboxProps, } from 'semantic-ui-react'; @@ -39,23 +39,25 @@ export interface SensorItemTreeState { } interface TreeItem { - metaSensorItemList: MetaSensorItem[]; + metaSensorItemList: Array; metaSensorItemType: MetaSensorItemType; } export class SensorItemTree extends React.Component { private itemMap: Map; + private selectedItemMap: Map>; constructor(props: any, context: any) { super(props, context); this.itemMap = new Map; + this.selectedItemMap = new Map, - this.state = { - categoryState: new Map(), - itemState: new Map(), - }; + this.state = { + categoryState: new Map(), + itemState: new Map(), + }; this.sortItemMap(); // fs.readFile('../../../../../dh.json', this.handlJSONFile); @@ -73,7 +75,7 @@ export class SensorItemTree extends React.Component = new Map(this.state.portState);*/ } let newCategoryState: Map = _.clone(this.state.categoryState); - newCategoryState[key] = !newCategoryState[key]; - this.setState({ categoryState: newCategoryState }); }} /> @@ -99,8 +99,15 @@ export class SensorItemTree extends React.Component , checkProps: CheckboxProps) => { let newItemState: Map> = _.clone(this.state.itemState); - newItemState[key] = _.cloneDeep(this.state.itemState[key]); + if (newItemState[key] === undefined) { + newItemState[key] = new Array(data.metaSensorItemList.length).fill(false); + } newItemState[key].fill(checkProps.checked); + if (checkProps.checked) { + this.selectedItemMap[key] = _.clone(data.metaSensorItemList); + } else { + this.selectedItemMap[key].length = 0; + } this.setState({ itemState: newItemState }); }} /> Category @@ -116,7 +123,7 @@ export class SensorItemTree extends React.Component - + , checkProps: CheckboxProps) => { + if(this.selectedItemMap[parentKey] === undefined) { + this.selectedItemMap[parentKey] = []; + } + if (checkProps.checked) { + this.selectedItemMap[parentKey].push(item); + } else { + let index: number = this.selectedItemMap[parentKey].indexOf(item); + if(index >= 0) { + this.selectedItemMap[parentKey].splice(index, 1); + } + } + }} /> Sensor Item @@ -150,6 +170,9 @@ export class SensorItemTree extends React.Component {this.ViewSensorItemType()} +