Skip to content
This repository was archived by the owner on Sep 23, 2021. It is now read-only.

Commit 472af6f

Browse files
committed
refactor(search-engine): improve the organization of the groups
Signed-off-by: Gianfranco Manganiello <gmanganiello@teclib.com>
1 parent c1b2261 commit 472af6f

3 files changed

Lines changed: 55 additions & 28 deletions

File tree

src/containers/SearchEngine/components/QueryBuilder/Group.js

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class Group extends PureComponent {
5252
rule={rule}
5353
changeRule={this.props.changeRule}
5454
fieldList={this.props.fieldList}
55+
addGroup={this.props.addGroup}
5556
/>,
5657
)
5758
}
@@ -87,40 +88,33 @@ class Group extends PureComponent {
8788

8889
render() {
8990
return (
90-
<>
91-
<div className="search-engine__group">
92-
{this.getRules(this.props.criteria)}
93-
<button
94-
className="btn btn--primary"
95-
type="button"
96-
onClick={() => console.log('test')}
97-
>
98-
+
99-
{' '}
100-
{I18n.t('search_engine.group')}
101-
</button>
102-
</div>
103-
104-
<div className="search-engine__group">
105-
{this.getRules(this.props.metacriteria)}
106-
</div>
107-
</>
91+
<div className="search-engine__group">
92+
{this.getRules(this.props.rules)}
93+
<button
94+
className="btn btn--secondary"
95+
type="button"
96+
onClick={() => this.props.addGroup()}
97+
>
98+
+
99+
{' '}
100+
{I18n.t('search_engine.group')}
101+
</button>
102+
</div>
108103
)
109104
}
110105
}
111106

112107
Group.defaultProps = {
113-
criteria: [],
114-
metacriteria: [],
108+
rules: [],
115109
index: [],
116110
}
117111

118112
Group.propTypes = {
119113
index: PropTypes.array,
120-
criteria: PropTypes.array,
121-
metacriteria: PropTypes.array,
114+
rules: PropTypes.array,
122115
changeRule: PropTypes.func.isRequired,
123116
fieldList: PropTypes.array.isRequired,
117+
addGroup: PropTypes.func.isRequired,
124118
}
125119

126120
export default Group

src/containers/SearchEngine/components/QueryBuilder/SubGroup.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import React, {
3030
PureComponent,
3131
} from 'react'
3232
import PropTypes from 'prop-types'
33+
import I18n from 'shared/i18n'
3334
import Rule from './Rule'
3435

3536
class SubGroup extends PureComponent {
@@ -101,6 +102,15 @@ class SubGroup extends PureComponent {
101102
return (
102103
<div className="search-engine__group">
103104
{ render }
105+
<button
106+
className="btn btn--secondary"
107+
type="button"
108+
onClick={() => this.props.addGroup()}
109+
>
110+
+
111+
{' '}
112+
{I18n.t('search_engine.group')}
113+
</button>
104114
</div>
105115
)
106116
}
@@ -115,6 +125,7 @@ SubGroup.propTypes = {
115125
rule: PropTypes.object.isRequired,
116126
changeRule: PropTypes.func.isRequired,
117127
fieldList: PropTypes.array.isRequired,
128+
addGroup: PropTypes.func.isRequired,
118129
}
119130

120131
export default SubGroup

src/containers/SearchEngine/components/QueryBuilder/index.js

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,10 @@ class QueryBuilder extends PureComponent {
207207
})
208208
}
209209

210+
addGroup = () => {
211+
console.log('test')
212+
}
213+
210214
/**
211215
* Render component
212216
* @function render
@@ -235,12 +239,30 @@ class QueryBuilder extends PureComponent {
235239
</button>
236240
</div>
237241

238-
<Group
239-
criteria={this.state.criteria}
240-
metacriteria={this.state.metacriteria}
241-
changeRule={this.changeRule}
242-
fieldList={this.state.fieldList}
243-
/>
242+
243+
{
244+
this.state.criteria.length > 0
245+
&& (
246+
<Group
247+
rules={this.state.criteria}
248+
changeRule={this.changeRule}
249+
fieldList={this.state.fieldList}
250+
addGroup={this.addGroup}
251+
/>
252+
)
253+
}
254+
255+
{
256+
this.state.metacriteria.length > 0
257+
&& (
258+
<Group
259+
rules={this.state.metacriteria}
260+
changeRule={this.changeRule}
261+
fieldList={this.state.fieldList}
262+
addGroup={this.addGroup}
263+
/>
264+
)
265+
}
244266
</div>
245267
)
246268
}

0 commit comments

Comments
 (0)