import VueSelect from 'vue-select';
import {hydrateAppWithData} from "./hydration";
export const IssueLabel = {
template: `
{{ name }}
`,
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 this.$root.categories[this.name] || 'miscellaneous'
}
}
}
export const IssueCard = {
template: `
`,
components: {
IssueLabel
},
props: {
issue: {
type: Object,
required: true
},
},
computed: {
dateCreated() {
const dateCreated = new Date(this.issue.createdAt * 1000)
const [dateComponent,] = dateCreated.toISOString().split("T")
return dateComponent
}
}
}
export const App = {
el: '#vue-app',
template: `
Loading filters, please wait...
Not all issues have skills marked on them, especially if they are simple issues that
do not require proficiency in any specific framework or language.Those issues will not
appear when filtering by skill in the Issue Finder
`,
components: {
VueSelect,
IssueCard
},
data() {
return {
options: {
skills: [],
experiences: [
{name: 'Yes, it is', code: 'beginner'},
{name: 'No, it isn\'t', code: 'experienced'}
]
},
filters: {
skills: [],
experience: 'experienced'
},
categories: {},
issues: []
}
},
computed: {
/**
* Get a filtered list of issues matching the chosen skill labels.
*
* @returns {array} the array of filtered issues
*/
filteredIssues() {
return window.issues.filter(issue => {
// Check experience match
if (this.filters.experience === 'beginner' && !issue.labels.includes('good first issue')) {
return false
}
// Check skill set match
const joinedLabels = issue.labels.join(',')
if (this.filters.skills.length && !this.filters.skills.some(skill => joinedLabels.includes(skill))) {
return false
}
return true
}).sort((a, b) => b.createdAt - a.createdAt)
}
},
mounted() {
const BASE_URL = 'https://raw.githubusercontent.com/creativecommons/ccos-scripts/master/normalize_repos'
const FILE_URL = name => `${BASE_URL}/${name}.json`
Promise
.all([
fetch(FILE_URL('skills'))
.then(response => response.json()),
fetch(FILE_URL('labels'))
.then(response => response.json())
])
.then(([skillResponse, labelResponse]) => {
const [skills, categories] = hydrateAppWithData(skillResponse, labelResponse)
this.categories = categories
this.options.skills = skills
})
.catch(err => console.error(err))
}
}