Skip to content

Commit 7d80de2

Browse files
matthieudufoncallistasMaximeMZ
committed
FEATURE: Consult attributes whilst doing a search (see #572).
Co-authored-by: Callista Spiteri <spitericallista@gmail.com> Co-authored-by: Maxime Macrez <maxime.macrez@utt.fr>
1 parent 4dc2f4b commit 7d80de2

3 files changed

Lines changed: 91 additions & 5 deletions

File tree

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import React, { Component } from 'react';
2+
import { Items } from '../../model.js';
3+
import Selection from '../../Selection.js';
4+
import { withRouter } from 'react-router-dom';
5+
6+
class AttributeSearch extends Component {
7+
constructor(props) {
8+
super(props);
9+
this.handleChange = this.handleChange.bind(this);
10+
this.state = {
11+
selectedValue: '',
12+
};
13+
}
14+
render() {
15+
let attributeValues = this._getValues();
16+
let options = this._getOptions(attributeValues);
17+
let handleChange = (e) => {
18+
const selection = Selection.fromURI();
19+
if (e.target.value !== '') {
20+
if (this.state.selectedValue !== '') {
21+
selection.removeTopic(this.state.selectedValue);
22+
}
23+
selection.addTopic(e.target.value);
24+
} else {
25+
selection.removeTopic(this.state.selectedValue);
26+
}
27+
console.log(selection.toURI());
28+
this.props.history.push(selection.toURI());
29+
this.setState({selectedValue: e.target.value});
30+
};
31+
return (
32+
<div className={'AttributesList ' + this.props.name}>
33+
{this.props.name}
34+
<select id={this.props.name} onChange={handleChange} className="selectValue">
35+
<option value="">Choisir</option>
36+
{options}
37+
</select>
38+
</div>
39+
);
40+
}
41+
42+
_getValues() {
43+
let attributesValues = new Items(this.props.items)
44+
.getAttributeValues(this.props.name);
45+
attributesValues = new Set(attributesValues);
46+
attributesValues = Array.from(attributesValues);
47+
return attributesValues;
48+
}
49+
50+
_getOptions(attributeValues) {
51+
return attributeValues.map(value => {
52+
let optVal = this.props.name + ' : ' + value;
53+
return <option key={optVal} value={optVal}>{value}</option>;
54+
});
55+
}
56+
57+
handleChange(e) {
58+
e.preventDefault();
59+
console.log(this.props.query.toURI());
60+
}
61+
62+
}
63+
64+
export default withRouter(AttributeSearch);

src/components/portfolioPage/Portfolio.jsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import queryString from 'query-string';
55
import Hypertopic from 'hypertopic';
66
import conf from '../../config.js';
77
import Viewpoint from './Viewpoint.jsx';
8+
import AttributeSearch from './AttributeSearch.jsx';
89
import Corpora from './Corpora.jsx';
910
import Header from '../Header.jsx';
1011
import Status from './Status.jsx';
@@ -20,6 +21,7 @@ class Portfolio extends Component {
2021
super();
2122
this.state = {
2223
viewpoints: [],
24+
attributes: [],
2325
corpora: [],
2426
items: [],
2527
selectedItems: [],
@@ -42,6 +44,7 @@ class Portfolio extends Component {
4244
.map(([key, value]) => key.concat(' : ', value))
4345
.map(x => ({[x]: {name: x}}));
4446
let candidates = this.state.viewpoints.concat(attributes);
47+
let attributesSearch = this._getAttributes();
4548
const urlParams = new URLSearchParams(window.location.search);
4649
const selectionJSON = JSON.parse(urlParams.get('t'));
4750
// Normal items have numbers in their names, but building maps don't,
@@ -70,6 +73,12 @@ class Portfolio extends Component {
7073
<div className="container-fluid">
7174
<div className="App-content row">
7275
<div className="col-md-4 p-4 d-none d-sm-block">
76+
<div className="AttributesSearch">
77+
<h2 className="h4 font-weight-bold text-center"><Trans>Attributs</Trans></h2>
78+
<div className="p-3">
79+
{attributesSearch}
80+
</div>
81+
</div>
7382
<div className="Description">
7483
<h2 className="h4 font-weight-bold text-center"><Trans>Points de vue</Trans></h2>
7584
<div className="p-3">
@@ -252,6 +261,12 @@ class Portfolio extends Component {
252261
);
253262
}
254263

264+
_getAttributes() {
265+
let attributesKeys = new Items(this.state.items)
266+
.getAttributeKeys();
267+
return attributesKeys.map(key => <AttributeSearch key={key} name={key} items={this.state.items} query={this.query} history={this.history} />);
268+
}
269+
255270
_getCorpora() {
256271
let ids = this.state.corpora.map(c => c.id);
257272
return (

src/styles/App.css

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,12 @@ h1 a, h1 a:hover {
4848
min-height: 100vh;
4949
}
5050

51-
.Subject, .Description {
51+
.Subject, .Description, .AttributesSearch {
5252
background: #fff;
53+
margin-bottom: 2rem;
5354
}
5455

55-
.Subject h2, .Description h2 {
56+
.Subject h2, .Description h2, .AttributesSearch h2 {
5657
color: ivory;
5758
margin: 0;
5859
padding: .5rem;
@@ -62,7 +63,7 @@ h1 a, h1 a:hover {
6263
background-color: dimgrey;
6364
}
6465

65-
.Description h2 {
66+
.Description h2, .AttributesSearch h2 {
6667
background-color: #8b0000;
6768
}
6869

@@ -457,6 +458,12 @@ ul.Outliner,
457458
padding: 20px 30px 20px 30px;
458459
}
459460

460-
button {
461-
margin-top: 2%;
461+
.selectValue {
462+
width: 18em;
463+
float: right;
464+
}
465+
466+
.AttributesList {
467+
flex-direction: column;
468+
text-align: left;
462469
}

0 commit comments

Comments
 (0)