|
1 | | - |
2 | | -import React from 'react'; |
3 | | -import Badge from 'react-bootstrap/lib/Badge'; |
4 | | -import ListGroupItem from 'react-bootstrap/lib/ListGroupItem'; |
| 1 | +import React from "react"; |
| 2 | +import Badge from "react-bootstrap/lib/Badge"; |
| 3 | +import ListGroupItem from "react-bootstrap/lib/ListGroupItem"; |
5 | 4 |
|
6 | 5 | export default class Candidate extends React.Component { |
| 6 | + get url() { |
| 7 | + let view = null; |
| 8 | + let manifest = this.props.manifest; |
| 9 | + if ( |
| 10 | + "view" in manifest && |
| 11 | + "url" in this.props.manifest.view && |
| 12 | + "id" in this.props.candidate |
| 13 | + ) { |
| 14 | + view = this.props.manifest.view.url.replace( |
| 15 | + "{{id}}", |
| 16 | + this.props.candidate.id |
| 17 | + ); |
| 18 | + } |
| 19 | + return view; |
| 20 | + } |
| 21 | + |
| 22 | + renderDescription() { |
| 23 | + const { candidate } = this.props; |
| 24 | + const description = candidate?.description; |
| 25 | + |
| 26 | + if (!description) return null; |
| 27 | + |
| 28 | + return ( |
| 29 | + <div> |
| 30 | + <div className="candidateField">Description</div> |
| 31 | + <div className="candidateValue">{description}</div> |
| 32 | + </div> |
| 33 | + ); |
| 34 | + } |
| 35 | + |
| 36 | + renderTypes() { |
| 37 | + const types = this.props.candidate?.type; |
| 38 | + if (!types) return null; |
| 39 | + |
| 40 | + return ( |
| 41 | + <div> |
| 42 | + <div className="candidateField">Types</div> |
| 43 | + <div className="candidateValue"> |
| 44 | + {types.map((type, idx) => [ |
| 45 | + idx > 0 && ", ", |
| 46 | + `${type.name} (${type.id})`, |
| 47 | + ])} |
| 48 | + </div> |
| 49 | + </div> |
| 50 | + ); |
| 51 | + } |
| 52 | + |
| 53 | + renderFeatures() { |
| 54 | + const features = this.props.candidate?.features; |
| 55 | + if (!features) return null; |
| 56 | + |
| 57 | + return ( |
| 58 | + <div> |
| 59 | + {features.map((feature, idx) => ( |
| 60 | + <div key={idx}> |
| 61 | + <div className="candidateField">Feature {feature.id}</div> |
| 62 | + <div className="candidateValue">{feature.value}</div> |
| 63 | + </div> |
| 64 | + ))} |
| 65 | + </div> |
| 66 | + ); |
| 67 | + } |
| 68 | + |
| 69 | + render() { |
| 70 | + const { candidate } = this.props; |
7 | 71 |
|
8 | | - get url() { |
9 | | - let view = null; |
10 | | - let manifest = this.props.manifest; |
11 | | - if ('view' in manifest && 'url' in this.props.manifest.view && 'id' in this.props.candidate) { |
12 | | - view = this.props.manifest.view.url.replace('{{id}}', this.props.candidate.id); |
13 | | - } |
14 | | - return view; |
15 | | - } |
16 | | - |
17 | | - renderDescription() { |
18 | | - let description = this.props.candidate.description; |
19 | | - if (description !== undefined) { |
20 | | - return (<div><div className="candidateField">Description</div><div className="candidateValue">{description}</div></div>); |
21 | | - } |
22 | | - } |
23 | | - |
24 | | - renderTypes() { |
25 | | - let types = this.props.candidate.type; |
26 | | - if (types !== undefined) { |
27 | | - return (<div><div className="candidateField">Types</div><div className="candidateValue"> |
28 | | - {types.map((type, idx) => [ |
29 | | - idx > 0 && ", ", |
30 | | - type.name + ' (' + type.id + ')' |
31 | | - ])} |
32 | | - </div></div>); |
33 | | - } |
34 | | - } |
35 | | - |
36 | | - renderFeatures() { |
37 | | - let features = this.props.candidate.features; |
38 | | - if (features !== undefined) { |
39 | | - return (<div> |
40 | | - {features.map((feature, idx) => |
41 | | - (<div key={idx}><div className="candidateField">Feature {feature.id}</div><div className="candidateValue">{feature.value}</div></div>) |
42 | | - )} |
43 | | - </div>); |
44 | | - } |
45 | | - } |
46 | | - |
47 | | - render() { |
48 | | - let candidate = this.props.candidate; |
49 | | - return (<ListGroupItem key={candidate.id} header={candidate.name} active={candidate.match}> |
50 | | - <Badge style={{float: 'right'}}>{this.props.candidate.score}</Badge> |
51 | | - <div> |
52 | | - <div><div className="candidateField">ID</div><div className="candidateValue"> |
53 | | - <a href={this.url}>{candidate.id}</a></div></div> |
54 | | - {this.renderDescription()} |
55 | | - {this.renderTypes()} |
56 | | - {this.renderFeatures()} |
57 | | - </div> |
58 | | - </ListGroupItem>); |
59 | | - } |
| 72 | + return ( |
| 73 | + <ListGroupItem |
| 74 | + key={candidate.id} |
| 75 | + header={candidate.name} |
| 76 | + active={candidate.match} |
| 77 | + > |
| 78 | + <Badge style={{ float: "right" }}>{candidate.score}</Badge> |
| 79 | + <div> |
| 80 | + <div className="candidateField">ID</div> |
| 81 | + <div className="candidateValue"> |
| 82 | + <a href={this.url}>{candidate.id}</a> |
| 83 | + </div> |
| 84 | + {this.renderDescription()} |
| 85 | + {this.renderTypes()} |
| 86 | + {this.renderFeatures()} |
| 87 | + </div> |
| 88 | + </ListGroupItem> |
| 89 | + ); |
| 90 | + } |
60 | 91 | } |
0 commit comments