-
-
Notifications
You must be signed in to change notification settings - Fork 184
/
Copy pathcomponents.js
187 lines (183 loc) · 4.68 KB
/
components.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
import VueSelect from 'vue-select';
import {octokit} from './octokit';
export const IssueLabel = {
template: `
<span class="gh-label" :class="className">
{{ name }}
</span>`,
data() {
return {
labels: window.labels
}
},
props: {
name: {
type: String,
required: true
}
},
computed: {
/**
* Get the name of the class to apply to the label based on the group to
* which it belongs. Falls back to miscellaneous if the label does not
* belong to a group or a class cannot be identified.
*
* @returns {string} the name of the class to apply to the label
*/
className() {
return window.className[this.name] || 'miscellaneous'
}
}
}
export const IssueCard = {
template: `
<div class="card entry-post vertical margin-top-normal padding-normal">
<h4 class="card-title b-header margin-bottom-small">{{ issue.title }}</h4>
<a :href="issue.html_url" class="button is-text tiny site-link" target="_blank">
<span class="has-color-forest-green">
{{ issue.repository.name }}#{{ issue.number }}
</span>
<i class="icon external-link has-color-forest-green"></i>
</a>
<div class="labels margin-top-small">
<IssueLabel
v-for="(name, index) in issue.labelNames"
:key="index"
:name="name"/>
</div>
</div>`,
components: {
IssueLabel
},
props: {
issue: {
type: Object,
required: true
},
}
}
export const App = {
el: '#vue-app',
template: `
<div class="find-issues">
<div class="columns">
<div class="column is-one-quarter">
<form id="filters">
<label for="skills">
<strong>Skill set</strong><br>
Choose up to three skills that you would like to see issues for.
</label>
<VueSelect
v-model="filters.skills"
id="skills"
name="skills"
placeholder="No preference"
:options="options.skills"
:reduce="skill => skill.toLocaleLowerCase()"
:selectable="() => filters.skills.length < 3"
multiple/>
<br/>
<label for="experience">
<strong>Experience</strong><br>
Is this your first time contributing to CC?
</label>
<VueSelect
v-model="filters.experience"
id="experience"
name="experience"
:options="options.experiences"
label="name"
:reduce="experience => experience.code"
:clearable="false"/>
</form>
</div>
<div class="column">
<template v-if="issues.length">
<issue-card
v-for="issue in filteredIssues"
:key="issue.id"
:issue="issue"/>
</template>
<p
v-else
class="margin-top-normal">
No results.
</p>
</div>
</div>
</div>`,
components: {
VueSelect,
IssueCard
},
data() {
return {
options: {
skills: window.skillSet,
experiences: [
{name: 'Yes, it is', code: 'beginner'},
{name: 'No, it isn\'t', code: 'experienced'}
]
},
filters: {
skills: [],
experience: 'experienced'
},
issues: []
}
},
computed: {
/**
* Get a filtered list of issues matching the chosen skill labels.
*
* @returns {array} the array of filtered issues
*/
filteredIssues() {
return this.issues.filter(issue => {
const joinedLabels = issue.labelNames.join(',')
if (this.filters.skills.length && !this.filters.skills.some(skill => joinedLabels.includes(skill))) {
return false
}
if (this.filters.experience === 'beginner' && !joinedLabels.includes('good first issue')) {
return false
}
return true
})
}
},
methods: {
/**
* Run the search based on the data submitted via the form and load all
* results into the `issues` attribute. Can be reused for a future
* 'Load More' button.
*
* @param {number} page - the page of results to fetch
*/
search(page = 1) {
octokit
.issues
.listForOrg({
org: 'creativecommons',
state: 'open',
filter: 'all',
labels: 'help wanted',
sort: 'created',
direction: 'desc',
per_page: 100,
page
})
.then(response => response.data)
.then(issueLists => {
const issues = issueLists.flat()
issues.forEach(issue => {
issue.labelNames = issue.labels.map(label => label.name)
})
this.issues = issues
})
.catch(err => console.error(err))
}
},
mounted() {
this.search()
}
}