-
Notifications
You must be signed in to change notification settings - Fork 163
/
Copy pathfooter.js
313 lines (275 loc) · 8.19 KB
/
footer.js
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
import React, { Suspense, lazy } from "react";
import { connect } from "react-redux";
import styled from 'styled-components';
import Collapsible from "react-collapsible";
import { withTranslation } from "react-i18next";
import {FaAngleUp, FaAngleDown} from "react-icons/fa";
import { dataFont } from "../../globalStyles";
import Flex from "./flex";
import { applyFilter } from "../../actions/tree";
import { isValueValid } from "../../util/globals";
import hardCodedFooters from "./footer-descriptions";
import { SimpleFilter } from "../info/filterBadge";
const MarkdownDisplay = lazy(() => import("../markdownDisplay"));
const FooterStyles = styled.div`
margin-left: 30px;
padding-bottom: 0px;
font-family: ${dataFont};
font-size: 15px;
font-weight: 300;
color: rgb(136, 136, 136);
line-height: 1.4;
p {
font-weight: 300;
}
ol {
font-weight: 300;
}
ul {
font-weight: 300;
}
h1 {
font-weight: 700;
font-size: 2.50em;
margin: 0.2em 0;
}
h2 {
font-weight: 600;
font-size: 2.15em;
margin: 0.2em 0;
}
h3 {
font-weight: 500;
font-size: 1.70em;
margin: 0.2em 0;
}
h4 {
font-weight: 500;
font-size: 1.25em;
margin: 0.1em 0;
}
h5 {
font-weight: 500;
font-size: 1.0em;
margin: 0.1em 0;
}
h6 {
font-weight: 500;
font-size: 0.85em;
margin: 0.1em 0;
}
// Style for code block
pre {
padding: 16px;
overflow: auto;
font-size: 85%;
line-height: 1.45;
background-color: #f6f8fa;
border-radius: 3px;
}
// Code within code block
pre code {
padding: 0;
margin: 0;
overflow: visible;
font-size: 100%;
line-height: inherit;
word-wrap: normal;
background-color: initial;
border: 0;
}
// Inline code
p code {
padding: .2em .4em;
margin: 0;
font-size: 85%;
background-color: rgba(27,31,35,.05);
border-radius: 3px;
}
.line {
margin-top: 15px;
margin-bottom: 15px;
border-bottom: 1px solid #CCC;
}
.acknowledgments {
margin-top: 10px;
}
.filterList {
margin-top: 10px;
line-height: 1.0;
}
.imageContainer {
display: flex;
justify-content: center;
align-items: center;
flex-wrap: wrap;
}
img {
margin-left: 30px;
margin-right: 30px;
margin-top: 2px;
margin-bottom: 2px;
}
table {
font-weight: 300;
margin-bottom: 1rem;
th,
td {
text-align: left;
padding: 0.45rem;
vertical-align: top;
border-top: 1px solid #dee2e6;
}
thead th {
vertical-align: bottom;
border-bottom: 2px solid #dee2e6;
}
tbody + tbody {
border-top: 2px solid #dee2e6;
}
}
`;
export const getAcknowledgments = (metadata, dispatch) => {
/**
* If the metadata contains a description key, then it will take precedence the hard-coded
* acknowledgements. Expects the text in the description to be in Markdown format.
* Jover. December 2019.
*/
if (metadata.description) {
return (
<Suspense fallback={<div />}>
<MarkdownDisplay
className="acknowledgments"
mdstring={metadata.description}
placeholder="This dataset contained acknowledgements to be displayed here, however it wasn't correctly formatted." />
</Suspense>
);
}
const preambleContent = "This work is made possible by the open sharing of genetic data by research groups from all over the world. We gratefully acknowledge their contributions.";
const genericPreamble = (<div>{preambleContent}</div>);
if (window.location.hostname === 'nextstrain.org') {
return hardCodedFooters(dispatch, genericPreamble);
}
return (<div>{genericPreamble}</div>);
};
const dispatchFilter = (dispatch, activeFilters, key, value) => {
const activeValuesOfFilter = (activeFilters[key] || []).map((f) => f.value);
const mode = activeValuesOfFilter.indexOf(value) === -1 ? "add" : "remove";
dispatch(applyFilter(mode, key, [value]));
};
const removeFiltersButton = (dispatch, filterNames, outerClassName, label) => (
<SimpleFilter
active
extraStyles={{float: "right", margin: "0px 4px"}}
onClick={() => {filterNames.forEach((n) => dispatch(applyFilter("set", n, [])));}}
>
{label}
</SimpleFilter>
);
const TitleContainer = styled.div`
display: flex;
justify-content: space-between;
margin: 0px;
padding: 0px;
`;
const IconContainer = styled.span`
font-size: 22px;
font-weight: 500;
`;
const CollapseTitle = ({name, isExpanded=false}) => (
<TitleContainer>
{name}
<IconContainer>{isExpanded ? <FaAngleUp /> : <FaAngleDown />}</IconContainer>
</TitleContainer>
);
@connect((state) => {
return {
tree: state.tree,
totalStateCounts: state.tree.totalStateCounts,
metadata: state.metadata,
colorOptions: state.metadata.colorOptions,
browserDimensions: state.browserDimensions.browserDimensions,
activeFilters: state.controls.filters,
filtersInFooter: state.controls.filtersInFooter
};
})
class Footer extends React.Component {
shouldComponentUpdate(nextProps) {
if (this.props.tree.version !== nextProps.tree.version ||
this.props.browserDimensions !== nextProps.browserDimensions) {
return true;
} else if (Object.keys(this.props.activeFilters) !== Object.keys(nextProps.activeFilters)) {
return true;
} else if (Object.keys(this.props.activeFilters).length > 0) {
for (const name of this.props.activeFilters) {
if (this.props.activeFilters[name] !== nextProps.activeFilters[name]) {
return true;
}
}
}
return false;
}
displayFilter(filterName) {
const { t } = this.props;
const totalStateCount = this.props.totalStateCounts[filterName];
if (!totalStateCount) return null;
const filterTitle = this.props.metadata.colorings[filterName] ? this.props.metadata.colorings[filterName].title : filterName;
const activeFilterItems = (this.props.activeFilters[filterName] || []).filter((x) => x.active).map((x) => x.value);
const title = (<div>
{t("Filter by {{filterTitle}}", {filterTitle: filterTitle}) + ` (n=${totalStateCount.size})`}
{this.props.activeFilters?.[filterName]?.length ? removeFiltersButton(this.props.dispatch, [filterName], "inlineRight", t("Clear {{filterName}} filter", { filterName: filterName})) : null}
</div>);
return (
<div>
<Collapsible
triggerWhenOpen={<CollapseTitle name={title} isExpanded />}
trigger={<CollapseTitle name={title} />}
triggerStyle={{cursor: "pointer", textDecoration: "none"}}
transitionTime={100}
>
<div className='filterList'>
<Flex wrap="wrap" justifyContent="flex-start" alignItems="center">
{
Array.from(totalStateCount.keys())
.filter((itemName) => isValueValid(itemName)) // remove invalid values present across the tree
.sort() // filters are sorted alphabetically
.map((itemName) => (
<SimpleFilter
key={itemName}
active={activeFilterItems.indexOf(itemName) !== -1}
onClick={() => dispatchFilter(this.props.dispatch, this.props.activeFilters, filterName, itemName)}
>
<span>
{`${itemName} (${totalStateCount.get(itemName)})`}
</span>
</SimpleFilter>
))
}
</Flex>
</div>
</Collapsible>
</div>
);
}
render() {
if (!this.props.metadata || !this.props.tree.nodes) return null;
const width = this.props.width - 30; // need to subtract margin when calculating div width
return (
<FooterStyles>
<div style={{width: width}}>
<div className='line'/>
{getAcknowledgments(this.props.metadata, this.props.dispatch)}
<div className='line'/>
{this.props.filtersInFooter.map((name) => (
<div key={name}>
{this.displayFilter(name)}
<div className='line'/>
</div>
))}
</div>
</FooterStyles>
);
}
}
const WithTranslation = withTranslation()(Footer);
export default WithTranslation;