-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLineSelect.js
More file actions
102 lines (90 loc) · 2.83 KB
/
LineSelect.js
File metadata and controls
102 lines (90 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import React from 'react';
import PropTypes from 'prop-types';
import { observer } from 'mobx-react';
import styled from 'styled-components';
import { ListItem, TextField } from 'material-ui';
const SectionHeading = styled.h3`
margin-bottom: 0.5rem;
`;
const ListItemTitle = styled.h4`
display: inline;
width: fit-content;
`;
const SelectedLinesTitle = styled.h3`
font-size: 1.2rem;
`;
const ListContainer = styled.div`
flex-grow: 1;
max-height: 500px;
overflow-y: scroll;
`;
const mapLineItems = (lines, onClick) => {
if (lines.length > 0 && lines[0] !== null) {
return lines.map((line, index) => (
<ListItem onClick={() => onClick(line)} key={index}>
<ListItemTitle>{line.lineIdParsed}</ListItemTitle> <p>{line.nameFi}</p>
</ListItem>
));
}
return '';
};
const LineSelect = props => (
<div>
<SectionHeading>Linja-aikataulu</SectionHeading>
<TextField
id="line-select"
hintText="Hae linjaa..."
onChange={event =>
event.target.value ? props.setLineQuery(event.target.value) : props.setLineQuery('')
}
value={props.lineQuery}
style={{ width: '100%' }}
/>
<ListContainer>{mapLineItems(props.lines, props.addLine)}</ListContainer>
<div>
<SelectedLinesTitle>Generoitavat linja-aikataulut</SelectedLinesTitle>
{mapLineItems(props.selectedLines, props.removeLine)}
</div>
</div>
);
const SingleLineSelect = props => (
<div>
<SectionHeading>Linjahaku</SectionHeading>
<TextField
id="line-select"
hintText="Hae linjaa..."
onChange={event =>
event.target.value ? props.setLineQuery(event.target.value) : props.setLineQuery('')
}
value={props.lineQuery}
style={{ width: '100%' }}
/>
<ListContainer>{mapLineItems(props.lines, props.setSelectedRoutePlateLine)}</ListContainer>
<div>
<SelectedLinesTitle>Valittu linja</SelectedLinesTitle>
{mapLineItems([props.selectedRoutePlateLine], props.clearSelectedRoutePlateLine)}
</div>
</div>
);
LineSelect.propTypes = {
setLineQuery: PropTypes.func.isRequired,
lineQuery: PropTypes.string.isRequired,
lines: PropTypes.object.isRequired,
addLine: PropTypes.func.isRequired,
removeLine: PropTypes.func.isRequired,
selectedLines: PropTypes.object.isRequired,
};
SingleLineSelect.propTypes = {
setLineQuery: PropTypes.func.isRequired,
lineQuery: PropTypes.string.isRequired,
lines: PropTypes.object.isRequired,
selectedRoutePlateLine: PropTypes.object,
setSelectedRoutePlateLine: PropTypes.func.isRequired,
clearSelectedRoutePlateLine: PropTypes.func.isRequired,
};
SingleLineSelect.defaultProps = {
selectedRoutePlateLine: null,
};
export const ObservedLineSelect = observer(LineSelect);
export const ObservedSingleLineSelect = observer(SingleLineSelect);
export default { ObservedLineSelect, ObservedSingleLineSelect };