-
Notifications
You must be signed in to change notification settings - Fork 2
/
prop-types.js
73 lines (61 loc) · 1.83 KB
/
prop-types.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
var React = require('react');
var population = require('./model/population');
var TimeSpan = require('./model/timespan');
var PropTypes = React.PropTypes;
// A collection of commonly used (component) prop types
var populationPropType = PropTypes.oneOfType([
PropTypes.instanceOf(population.Group),
PropTypes.instanceOf(population.Cluster),
PropTypes.instanceOf(population.User)
]);
var seriesPropType = PropTypes.shape({
population: populationPropType,
metric: PropTypes.string,
source: PropTypes.string,
ranking: PropTypes.object,
data: PropTypes.arrayOf(
PropTypes.arrayOf(PropTypes.number)
),
});
var timespanPropType = PropTypes.oneOfType([
PropTypes.oneOf(TimeSpan.commonNames()),
(props, propName, componentName) => (
(PropTypes.arrayOf(PropTypes.number)(props, propName, componentName)) ||
((props[propName].length == 2)? null : (
new Error(propName + ' should be an array of length 2')))
),
]);
var reportPropType = PropTypes.shape({
title: PropTypes.string.isRequired,
level: PropTypes.string.isRequired,
reportName: PropTypes.string.isRequired,
startsAt: PropTypes.string.isRequired,
duration: PropTypes.array.isRequired,
});
// The shape of the global configuration object (passed via props or context)
var configPropType = PropTypes.shape({
utility: PropTypes.shape({
clusters: PropTypes.arrayOf(PropTypes.shape({
groups: PropTypes.array,
key: PropTypes.string,
name: PropTypes.string,
})),
key: PropTypes.string,
name: PropTypes.string,
}),
reports: PropTypes.shape({
levels: PropTypes.object,
byType: PropTypes.object
}),
overview: PropTypes.shape({
reports: PropTypes.object,
sections: PropTypes.object,
}),
});
module.exports = {
timespanPropType,
populationPropType,
seriesPropType,
reportPropType,
configPropType,
};