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

Commit

Permalink
wip(search-engine): edit rules
Browse files Browse the repository at this point in the history
Signed-off-by: Gianfranco Manganiello <[email protected]>
  • Loading branch information
Gianfranco97 committed Oct 15, 2018
1 parent a64b88d commit fe1507c
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/containers/SearchEngine/components/QueryBuilder/Group.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class Group extends PureComponent {
return (
<Rule
key={`criteria-${index.toString()}`}
id={index}
id={[index]}
type="criteria"
changeRule={this.props.changeRule}
fieldList={this.props.fieldList}
Expand All @@ -77,7 +77,7 @@ class Group extends PureComponent {
return (
<Rule
key={`metacriteria-${index.toString()}`}
id={index}
id={[index]}
type="metacriteria"
changeRule={this.props.changeRule}
{...rule}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ Rule.defaultProps = {
}

Rule.propTypes = {
id: PropTypes.number.isRequired,
id: PropTypes.array.isRequired,
itemtype: PropTypes.string,
field: PropTypes.string,
fieldList: PropTypes.array,
Expand Down
21 changes: 16 additions & 5 deletions src/containers/SearchEngine/components/QueryBuilder/SubGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,21 +64,32 @@ class SubGroup extends PureComponent {

render() {
const render = []
const { index } = this.props
const rules = SubGroup.getRules(this.props.rule)

rules.forEach((rule) => {
rules.forEach((rule, index) => {
if (!rule.criteria && !rule.metacriteria) {
if (!rule.itemtype) {
render.push(this.selectRule('criteria', rule, index))
render.push(
this.selectRule(
'criteria',
rule,
[...this.props.index, 'criteria', index],
),
)
} else {
render.push(this.selectRule('metacriteria', rule, index))
render.push(
this.selectRule(
'metacriteria',
rule,
[...this.props.index, 'metacriteria', index],
),
)
}
} else {
render.push(
<SubGroup
key={`group-${index.toString()}`}
index={[index]}
index={[...this.props.index, index]}
rule={rule}
changeRule={this.props.changeRule}
fieldList={this.props.fieldList}
Expand Down
57 changes: 44 additions & 13 deletions src/containers/SearchEngine/components/QueryBuilder/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,18 @@ class QueryBuilder extends PureComponent {
searchtype: 'contains',
value: '',
},
{
link: 'AND',
field: fieldList[0].value,
searchtype: 'contains',
value: 'test',
},
{
link: 'AND',
field: fieldList[0].value,
searchtype: 'contains',
value: '',
},
],
},
],
Expand Down Expand Up @@ -135,19 +147,38 @@ class QueryBuilder extends PureComponent {
*/
changeRule = (type, id, newValue) => {
const CurrentRules = this.state[type]
const newRules = [...CurrentRules]

if (newValue) {
newRules[id] = { ...newRules[id], ...newValue }

this.setState({
[type]: newRules,
})
} else {
this.setState({
[type]: newRules.slice(0, id).concat(newRules.slice(id + 1)),
})
}
let newRules = [...CurrentRules]

console.log(id)

let rule = [...CurrentRules]
id.forEach((index) => {
rule = rule[index]
})

let y
id.forEach((index) => {
if (y) {
newRules = { ...newRules[index] }
}
y = index
})

console.log(rule)
console.log(newRules)


// if (newValue) {
// newRules[id] = { ...newRules[id], ...newValue }

// this.setState({
// [type]: newRules,
// })
// } else {
// this.setState({
// [type]: newRules.slice(0, id).concat(newRules.slice(id + 1)),
// })
// }
}

/**
Expand Down

0 comments on commit fe1507c

Please sign in to comment.