Commit 7cd46aa9 authored by Live Jortveit Sagebakken's avatar Live Jortveit Sagebakken
Browse files

(#3) Last changes to filter function for issues

parent 0087ea45
......@@ -18,25 +18,40 @@ class Issue extends React.Component<any, any> {
})
.then((result) => result.json())
.then((issue) => this.setState({ issues: issue }));
console.log(this.state);
}
render() {
// Tenker å legge inn if-setning her (hvis det går) slik at alle issues blir vist når "alle" er valgt, og hvis ikke, så filtreres de med filter-funksjonen under her.
return (
const status = this.props.value;
if(status === "Alle"){
return (
<div>
{this.state.issues
.filter((issue: {labels: string}) =>
issue.labels[0].toLowerCase() === this.props.value.toLowerCase()) // Ikke bra måte å hente label med indeks, måtte bare teste, skal fikse senere!
.map((fIssue: {title: string, id:number}, index: React.Key) =>(
.map((issue: {title: string, id:number}, index: React.Key) =>(
<div key={index} className="panel panel-default">
<div className="panel-heading">{fIssue.title}</div>
<div className="panel-body">{fIssue.id}</div>
</div>
<div className="panel-heading">{issue.title}</div>
<div className="panel-body">{issue.id}</div>
</div>
))
})
}
</div>
);
}
else {
return (
<div>
{this.state.issues
.filter((issue: {labels: string}) =>
issue.labels.includes(this.props.value))
.map((fIssue: {title: string, id:number}, index: React.Key) =>(
<div key={index} className="panel panel-default">
<div className="panel-heading">{fIssue.title}</div>
<div className="panel-body">{fIssue.id}</div>
</div>
))
}
</div>
);
}
}
}
......
......@@ -5,20 +5,19 @@ class IssueView extends React.Component<any, any> {
constructor(props: any) {
super(props);
this.state = {value: 'alle'};
this.state = {value: 'Alle'};
this.handleChange = this.handleChange.bind(this);
}
handleChange(event: any) {
this.setState({value: event.target.value});
alert("Filter on: " + event.target.value);
}
render() {
return (
<>
<h3>Issues</h3>
<label>Filtrer:
<label>Filtrer issues:
<select value = {this.state.value} onChange = {this.handleChange}>
<option value="Alle">Alle</option>
<option value="To do">To do</option>
......@@ -28,7 +27,7 @@ class IssueView extends React.Component<any, any> {
</label>
<div id="issueBox">
{/* Må ha dette hvis Issue skal inni en IssueBox i App: {this.props.children} */}
<Issue value={this.state.value}></Issue>
<Issue value={this.state.value} />
</div>
</>
);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment