From 8cebb8faa8a41834fcec0e2f95e2aa6353693879 Mon Sep 17 00:00:00 2001 From: Clementlgz Date: Thu, 19 May 2022 14:31:07 +0200 Subject: [PATCH] FEATURE: (un)select items from a corpus. Co-authored-by: dwdw666 <807740079@qq.com> Co-authored-by: corentinprp51 Co-authored-by: dylanbonelli --- src/Selection.js | 43 ++++++++++++++++++ src/components/portfolioPage/Badge.jsx | 2 +- src/components/portfolioPage/Corpora.jsx | 52 ++++++++++++++++++++-- src/components/portfolioPage/Portfolio.jsx | 4 +- src/components/portfolioPage/SearchBar.jsx | 6 ++- src/components/portfolioPage/Status.jsx | 12 ++--- src/model.js | 5 ++- 7 files changed, 110 insertions(+), 14 deletions(-) diff --git a/src/Selection.js b/src/Selection.js index efb2a4be..9a7ae530 100644 --- a/src/Selection.js +++ b/src/Selection.js @@ -154,6 +154,49 @@ export default class Selection { clause.type = (clause.type === 'intersection') ? 'union' : 'intersection'; } + addCorpus = (corpusId) => { + const existing = this.selectionJSON.data.some(e => + e.selection.find(corpus => corpus === corpusId) + || e.exclusion.find(corpus => corpus === corpusId) + ); + if (!existing) { + this.selectionJSON.data = []; + this.selectionJSON.data.push({type: 'intersection', selection: [], exclusion: [corpusId]}); + } + } + + toggleCorpus = (corpusId) => { + const existingClause = this.selectionJSON.data.find(s => { + const allTopics = [...s.selection, ...s.exclusion]; + if (allTopics.length === 0) { + return false; + } + return true; + }); + if (existingClause) { + this.testSwitchPlace(existingClause, corpusId, false, true); + if ([...existingClause.selection, ...existingClause.exclusion].length === 0) + this.selectionJSON.data.splice(this.selectionJSON.data.indexOf(existingClause), 1); + } else { + this.addCorpus(corpusId); + } + } + + testSwitchPlace = (clause, criterion, toDelete, threeState) => { + let index; + if ((index = clause.selection.indexOf(criterion)) > -1) { + clause.selection.splice(index, 1); + if (!toDelete) + clause.exclusion.push(criterion); + } else if ((index = clause.exclusion.indexOf(criterion)) > -1) { + clause.exclusion.splice(index, 1); + if (!toDelete && !threeState) + clause.selection.push(criterion); + } else { + clause.exclusion.push(criterion); + } + }; + getClauses = () => this.selectionJSON.data; getMainClause = () => this.selectionJSON; diff --git a/src/components/portfolioPage/Badge.jsx b/src/components/portfolioPage/Badge.jsx index 177b2ee3..5eb51766 100644 --- a/src/components/portfolioPage/Badge.jsx +++ b/src/components/portfolioPage/Badge.jsx @@ -14,7 +14,7 @@ class Badge extends Component { {this.props.name}