-
Notifications
You must be signed in to change notification settings - Fork 58
/
selectors.js
70 lines (55 loc) · 2.37 KB
/
selectors.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
import * as util from './util.js'
export const keys = {
count: '.count',
trend: '.history',
id: 'id',
}
export const overrides = {
'status.conclusion': (metadata, data, row, ...args) => {
if (row.name === 'statusboard') {
const fetchData = metadata['fetch-data']
const anyError = Object.values(metadata).find(d => d.error)
const status = anyError ? 'failure' : 'success'
const url = `${row.url}/actions/runs/${anyError?.id || fetchData?.id}`
// Return same shape as the render function in datatables is expecting
return [
status,
{ ...row, status: { status, url } },
...args,
]
}
},
}
// this assumes that the repo also maintains a copy of template-oss
// this is not portable but for now the template/node version checks
// can be changed here or removed in the columns.js file
export const templateOSS = (projects) => projects.find((p) => p.name === 'template-oss')
export const templateVersion = (projects) => templateOSS(projects)?.version
export const nodeVersion = (projects) => templateOSS(projects)?.node
export const colId = (col) => `${typeof col === 'string' ? col : col.name}:name`
export const rowId = (row) => `#${typeof row === 'string' ? row : row.id}`
export const noArchived = (projects) => projects.every((p) => !p.archived)
export const isWorkspace = (p) => !!p.path
export const isPrivate = (p) => !!p.pkgPrivate
export const isPublished = (p) => !!p.lastPublished
export const wsDir = (p) => isWorkspace(p) ? p.path.substring(p.path.lastIndexOf('/') + 1) : null
export const names = (project) => {
const pkgName = project.pkgName || ''
// all our scopes should be the same or similar so dont use those for filtering/sorting
const noScope = pkgName.split('/')[1] || pkgName
// the repo name is the name of the folder for workspaces or the name of the repo
const repoName = isWorkspace(project) ? wsDir(project) : project.name
const allNames = util.uniq([pkgName, noScope, repoName])
const noScopeNames = util.uniq([noScope, repoName])
// a private pkg should only be looked up by repo name since the package.json might not be
// relavant and for everything else display the full pkgname but filter without scope
return !pkgName ? {
display: repoName,
filter: repoName,
sort: repoName,
} : {
display: allNames[0],
filter: noScopeNames,
sort: noScopeNames[0],
}
}