This repository was archived by the owner on Sep 23, 2021. It is now read-only.
File tree Expand file tree Collapse file tree
src/containers/SearchEngine/components/QueryBuilder Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -65,7 +65,7 @@ class Group extends PureComponent {
6565 return (
6666 < Rule
6767 key = { `criteria-${ index . toString ( ) } ` }
68- id = { index }
68+ id = { [ index ] }
6969 type = "criteria"
7070 changeRule = { this . props . changeRule }
7171 fieldList = { this . props . fieldList }
@@ -77,7 +77,7 @@ class Group extends PureComponent {
7777 return (
7878 < Rule
7979 key = { `metacriteria-${ index . toString ( ) } ` }
80- id = { index }
80+ id = { [ index ] }
8181 type = "metacriteria"
8282 changeRule = { this . props . changeRule }
8383 { ...rule }
Original file line number Diff line number Diff line change @@ -182,7 +182,7 @@ Rule.defaultProps = {
182182}
183183
184184Rule . propTypes = {
185- id : PropTypes . number . isRequired ,
185+ id : PropTypes . array . isRequired ,
186186 itemtype : PropTypes . string ,
187187 field : PropTypes . string ,
188188 fieldList : PropTypes . array ,
Original file line number Diff line number Diff line change @@ -64,21 +64,32 @@ class SubGroup extends PureComponent {
6464
6565 render ( ) {
6666 const render = [ ]
67- const { index } = this . props
6867 const rules = SubGroup . getRules ( this . props . rule )
6968
70- rules . forEach ( ( rule ) => {
69+ rules . forEach ( ( rule , index ) => {
7170 if ( ! rule . criteria && ! rule . metacriteria ) {
7271 if ( ! rule . itemtype ) {
73- render . push ( this . selectRule ( 'criteria' , rule , index ) )
72+ render . push (
73+ this . selectRule (
74+ 'criteria' ,
75+ rule ,
76+ [ ...this . props . index , 'criteria' , index ] ,
77+ ) ,
78+ )
7479 } else {
75- render . push ( this . selectRule ( 'metacriteria' , rule , index ) )
80+ render . push (
81+ this . selectRule (
82+ 'metacriteria' ,
83+ rule ,
84+ [ ...this . props . index , 'metacriteria' , index ] ,
85+ ) ,
86+ )
7687 }
7788 } else {
7889 render . push (
7990 < SubGroup
8091 key = { `group-${ index . toString ( ) } ` }
81- index = { [ index ] }
92+ index = { [ ... this . props . index , index ] }
8293 rule = { rule }
8394 changeRule = { this . props . changeRule }
8495 fieldList = { this . props . fieldList }
Original file line number Diff line number Diff line change @@ -99,6 +99,18 @@ class QueryBuilder extends PureComponent {
9999 searchtype : 'contains' ,
100100 value : '' ,
101101 } ,
102+ {
103+ link : 'AND' ,
104+ field : fieldList [ 0 ] . value ,
105+ searchtype : 'contains' ,
106+ value : 'test' ,
107+ } ,
108+ {
109+ link : 'AND' ,
110+ field : fieldList [ 0 ] . value ,
111+ searchtype : 'contains' ,
112+ value : '' ,
113+ } ,
102114 ] ,
103115 } ,
104116 ] ,
@@ -135,19 +147,38 @@ class QueryBuilder extends PureComponent {
135147 */
136148 changeRule = ( type , id , newValue ) => {
137149 const CurrentRules = this . state [ type ]
138- const newRules = [ ...CurrentRules ]
139-
140- if ( newValue ) {
141- newRules [ id ] = { ...newRules [ id ] , ...newValue }
142-
143- this . setState ( {
144- [ type ] : newRules ,
145- } )
146- } else {
147- this . setState ( {
148- [ type ] : newRules . slice ( 0 , id ) . concat ( newRules . slice ( id + 1 ) ) ,
149- } )
150- }
150+ let newRules = [ ...CurrentRules ]
151+
152+ console . log ( id )
153+
154+ let rule = [ ...CurrentRules ]
155+ id . forEach ( ( index ) => {
156+ rule = rule [ index ]
157+ } )
158+
159+ let y
160+ id . forEach ( ( index ) => {
161+ if ( y ) {
162+ newRules = { ...newRules [ index ] }
163+ }
164+ y = index
165+ } )
166+
167+ console . log ( rule )
168+ console . log ( newRules )
169+
170+
171+ // if (newValue) {
172+ // newRules[id] = { ...newRules[id], ...newValue }
173+
174+ // this.setState({
175+ // [type]: newRules,
176+ // })
177+ // } else {
178+ // this.setState({
179+ // [type]: newRules.slice(0, id).concat(newRules.slice(id + 1)),
180+ // })
181+ // }
151182 }
152183
153184 /**
You can’t perform that action at this time.
0 commit comments