-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathRoadmapViewItem.js
More file actions
133 lines (122 loc) · 5.01 KB
/
Copy pathRoadmapViewItem.js
File metadata and controls
133 lines (122 loc) · 5.01 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
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
import {library} from '@fortawesome/fontawesome-svg-core';
import {faGithub} from '@fortawesome/free-brands-svg-icons';
import {faCodeMerge} from '@fortawesome/pro-regular-svg-icons';
import {br, div, filler, span} from '@xh/hoist/cmp/layout';
import {hbox, vbox} from '@xh/hoist/cmp/layout/index';
import {relativeTimestamp} from '@xh/hoist/cmp/relativetimestamp';
import {hoistCmp, XH} from '@xh/hoist/core/index';
import {button} from '@xh/hoist/desktop/cmp/button';
import {capitalizeWords} from '@xh/hoist/format';
import {Icon} from '@xh/hoist/icon/index';
import {menuItem, popover} from '@xh/hoist/kit/blueprint';
import {truncate} from 'lodash';
import {menuButton} from '@xh/hoist/desktop/cmp/contextmenu';
library.add(faGithub, faCodeMerge);
export const roadmapViewItem = hoistCmp.factory({
model: null,
render({record}) {
const {category, name, description, releaseVersion, status, gitLinks, lastUpdated} = record.data;
return vbox({
className: 'tb-roadmap-item',
items: [
hbox(
div({
className: 'tb-roadmap-item__title',
items: [
getCategoryIcon(category),
name.length > 55 ?
popover({
popoverClassName: 'tb-roadmap__popover',
minimal: true,
target: truncate(name, {length: 55, omission: ' ...'}),
content: name
}) : name
]
}),
filler(),
getGitIcon(gitLinks),
popover({
popoverClassName: 'tb-roadmap__popover',
minimal: true,
interactionKind: 'hover',
position: 'top',
target: div({
className: 'tb-roadmap-item__statusIcon',
item: getStatusIcon(status)
}),
content: capitalizeWords(status)
})
),
span({
className: 'tb-roadmap-item__description',
items: [
truncate(description, {length: 290, separator: ' ', omission: ' '}),
description.length > 290 ? popover({
popoverClassName: 'tb-roadmap__popover tb-roadmap__popover--description',
minimal: true,
interactionKind: 'hover',
position: 'left-top',
target: span(' ...'),
content: div({
items: breakUpDescription(description)
})
}) : ''
]
}),
hbox({
className: 'tb-roadmap-item__footer',
items: [
releaseVersion,
filler(),
relativeTimestamp({timestamp: lastUpdated, options: {prefix: 'Last updated'}})
]
})
]
});
}
});
function getStatusIcon(status) {
const prefix = 'fal', size = '2x';
switch (status) {
case 'DEVELOPMENT': return Icon.gear({className: 'xh-orange', prefix, size});
case 'RELEASED': return Icon.checkCircle({className: 'xh-green', prefix, size});
case 'PLANNED': return Icon.clock({className: 'xh-blue-light', prefix, size});
case 'MERGED': return Icon.icon({iconName: 'code-merge', className: 'xh-green', size});
default: return Icon.questionCircle({prefix, size});
}
}
function getCategoryIcon(category) {
let iconName = XH.getConf('roadmapCategories')[category];
iconName = iconName && Icon[iconName] ? iconName : 'experiment';
return Icon[iconName]({className: 'xh-blue', prefix: 'fal'});
}
function getGitIcon(gitLinks) {
if (!gitLinks) return null;
const gitLinksList = gitLinks.split('\n'),
gitIcon = Icon.icon({iconName: 'github', prefix: 'fab', size: '2x'});
if (gitLinksList.length === 1) {
return button({icon: gitIcon, onClick: () => window.open(gitLinksList[0])});
} else {
return menuButton({
icon: gitIcon,
menuItems: getGitMenuItems(gitLinks)
});
}
}
function getGitMenuItems(gitLinks) {
if (!gitLinks) return;
return gitLinks.split('\n').map(link => {
return menuItem({
text: link,
icon: Icon.icon({iconName: 'github', prefix: 'fab'}),
onClick: () => window.open(link)
});
});
}
function breakUpDescription(description) {
return description.split('\n')
.reduce((ret, newLine) => {
ret.push(span(newLine), br());
return ret;
}, []);
}