fixed tree uncheck

This commit is contained in:
snoop 2017-07-26 19:43:16 +09:00
parent fa016d93f9
commit 508cd6f5bc

View File

@ -35,6 +35,7 @@ export type SensorItemTreeProps = SensorItemTreeStateProps & SensorItemTreeDispa
export interface SensorItemTreeState { export interface SensorItemTreeState {
categoryState: Map<number, boolean>; categoryState: Map<number, boolean>;
categoryCheckState: Map<number, boolean>;
itemState: Map<number, Array<boolean>>; itemState: Map<number, Array<boolean>>;
} }
@ -56,6 +57,7 @@ export class SensorItemTree extends React.Component<SensorItemTreeProps, SensorI
this.state = { this.state = {
categoryState: new Map(), categoryState: new Map(),
categoryCheckState: new Map(),
itemState: new Map(), itemState: new Map(),
}; };
this.sortItemMap(); this.sortItemMap();
@ -86,7 +88,7 @@ export class SensorItemTree extends React.Component<SensorItemTreeProps, SensorI
this.itemMap.forEach((data: TreeItem, key: number) => { this.itemMap.forEach((data: TreeItem, key: number) => {
// this.state.itemState[key] = new Array(data.metaSensorItemList.length).fill(false); // this.state.itemState[key] = new Array(data.metaSensorItemList.length).fill(false);
elems.push( elems.push(
<List.Item key={key + 1} > <List.Item key={key} >
<List.Icon name={this.state.categoryState[key] ? 'chevron up' : 'chevron down'} onClick={() => { <List.Icon name={this.state.categoryState[key] ? 'chevron up' : 'chevron down'} onClick={() => {
let newCategoryState: Map<number, boolean> = _.clone(this.state.categoryState); let newCategoryState: Map<number, boolean> = _.clone(this.state.categoryState);
newCategoryState[key] = !newCategoryState[key]; newCategoryState[key] = !newCategoryState[key];
@ -94,8 +96,10 @@ export class SensorItemTree extends React.Component<SensorItemTreeProps, SensorI
}} /> }} />
<List.Content> <List.Content>
<List.Header> <Checkbox label={data.metaSensorItemType.name} onChange={ <List.Header> <Checkbox label={data.metaSensorItemType.name} checked={this.state.categoryCheckState[key]} onChange={
(event: React.FormEvent<HTMLInputElement>, checkProps: CheckboxProps) => { (event: React.FormEvent<HTMLInputElement>, checkProps: CheckboxProps) => {
this.state.categoryCheckState[key] = checkProps.checked;
let newItemState: Map<number, Array<boolean>> = _.clone(this.state.itemState); let newItemState: Map<number, Array<boolean>> = _.clone(this.state.itemState);
if (newItemState[key] === undefined) { if (newItemState[key] === undefined) {
newItemState[key] = new Array(data.metaSensorItemList.length).fill(false); newItemState[key] = new Array(data.metaSensorItemList.length).fill(false);
@ -150,6 +154,11 @@ export class SensorItemTree extends React.Component<SensorItemTreeProps, SensorI
if (index >= 0) { if (index >= 0) {
this.selectedItemMap[parentKey].splice(index, 1); this.selectedItemMap[parentKey].splice(index, 1);
} }
if (this.selectedItemMap[parentKey].length <= 0) {
let newCheckState: Map<number, boolean> = _.clone(this.state.categoryCheckState);
newCheckState[parentKey] = false;
this.setState({ categoryCheckState: newCheckState });
}
} }
}} /></List.Header> }} /></List.Header>
<List.Description>Sensor Item</List.Description> <List.Description>Sensor Item</List.Description>
@ -175,6 +184,13 @@ export class SensorItemTree extends React.Component<SensorItemTreeProps, SensorI
); );
} }
private checkUnCheckParent(metaSensorItemList: Array<MetaSensorItem>): boolean {
if (metaSensorItemList.length <= 0) {
return true;
}
return false;
}
private GetMetaSensorItemType(id: number): MetaSensorItemType { private GetMetaSensorItemType(id: number): MetaSensorItemType {
for (let i: number = 0; i < SensorTypeJsonData.length; ++i) { for (let i: number = 0; i < SensorTypeJsonData.length; ++i) {