Skip to content

Commit fbfbd29

Browse files
author
Guillaume Chau
committed
feat: vulnerability audit widget
1 parent c4bd1ab commit fbfbd29

File tree

10 files changed

+520
-131
lines changed

10 files changed

+520
-131
lines changed

packages/@vue/cli-ui-addon-widgets/src/components/StatusWidget.vue

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<div v-if="false" class="status-widget">
2+
<div v-if="implemented" class="status-widget">
33
<div class="header">
44
<div class="icon-wrapper">
55
<ItemLogo
@@ -14,9 +14,10 @@
1414
<div class="last-updated">
1515
<template v-if="status.lastUpdate">
1616
<div class="label">
17-
{{ $t('org.vue.widgets.status-widget.last-updated') }}
17+
{{ message || $t('org.vue.widgets.status-widget.last-updated') }}
1818
</div>
1919
<VueTimeago
20+
v-if="!message"
2021
:datetime="status.lastUpdate"
2122
:auto-update="60"
2223
/>
@@ -73,6 +74,17 @@ export default {
7374
status: {
7475
type: Object,
7576
required: true
77+
},
78+
79+
message: {
80+
type: String,
81+
default: null
82+
},
83+
84+
// TODO remove
85+
implemented: {
86+
type: Boolean,
87+
default: false
7688
}
7789
},
7890

packages/@vue/cli-ui-addon-widgets/src/components/Vulnerability.vue

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,23 @@
22
<div class="vulnerability">
33
<StatusWidget
44
v-if="status"
5-
:icon="icons[status.status]"
6-
:icon-class="iconClasses[status.status]"
5+
:icon="status.status === 'attention' ? severity.icon : icons[status.status]"
6+
:icon-class="status.status === 'attention' ? severity.class : iconClasses[status.status]"
77
:title="$t(`org.vue.widgets.vulnerability.messages.${status.status}`, { n: status.count })"
88
:status="status"
9+
:message="status.message"
10+
implemented
911
@check="checkForUpdates()"
10-
/>
12+
>
13+
<template #more-actions>
14+
<VueButton
15+
v-if="status.status !== 'loading'"
16+
:label="$t('org.vue.widgets.vulnerability.recheck')"
17+
icon-left="refresh"
18+
@click="refresh()"
19+
/>
20+
</template>
21+
</StatusWidget>
1122
</div>
1223
</template>
1324

@@ -18,8 +29,28 @@ import StatusWidget from './StatusWidget.vue'
1829
1930
const UPDATES_ICONS = {
2031
'ok': 'verified_user',
21-
'loading': 'hourglass_full',
22-
'attention': 'error'
32+
'loading': 'hourglass_empty',
33+
'attention': 'error',
34+
'error': 'error'
35+
}
36+
37+
export const SEVERITIES = {
38+
critical: {
39+
class: 'danger',
40+
icon: 'new_releases'
41+
},
42+
high: {
43+
class: 'danger',
44+
icon: 'error'
45+
},
46+
moderate: {
47+
class: 'warning',
48+
icon: 'error'
49+
},
50+
low: {
51+
class: '',
52+
icon: 'error'
53+
}
2354
}
2455
2556
export default {
@@ -33,14 +64,20 @@ export default {
3364
})
3465
},
3566
67+
computed: {
68+
severity () {
69+
return this.status && SEVERITIES[this.status.severity]
70+
}
71+
},
72+
3673
created () {
3774
this.icons = UPDATES_ICONS
3875
this.iconClasses = UPDATES_ICON_CLASSES
3976
},
4077
4178
methods: {
42-
checkForUpdates () {
43-
// TODO
79+
refresh () {
80+
this.$callPluginAction('org.vue.widgets.actions.check-vunerability')
4481
}
4582
}
4683
}

packages/@vue/cli-ui-addon-widgets/src/components/VulnerabilityDetails.vue

Lines changed: 85 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,57 @@
1212
<div class="title">
1313
{{ $t('org.vue.widgets.vulnerability.messages.attention', { n: details.vulnerabilities.length }) }}
1414
</div>
15-
</div>
1615

17-
<div class="items">
18-
<VulnerabilityItem
19-
v-for="(item, index) of details.vulnerabilities"
20-
:key="index"
21-
:item="item"
22-
/>
16+
<div class="summary">
17+
<div
18+
v-for="(severity, key) of severities"
19+
:key="key"
20+
:class="`severity-${severity.class}`"
21+
class="summary-item"
22+
>
23+
<VueIcon
24+
:icon="severity.icon"
25+
:class="severity.class"
26+
/>
27+
<span class="count">{{ details.summary[key] }}</span>
28+
{{ $t(`org.vue.widgets.vulnerability.severity.${key}`) }}
29+
</div>
30+
</div>
2331
</div>
32+
33+
<transition name="vue-ui-fade">
34+
<DynamicScroller
35+
v-if="showList"
36+
ref="scroller"
37+
class="items"
38+
:items="details.vulnerabilities"
39+
:min-item-size="75"
40+
v-slot="{ item, active }"
41+
>
42+
<DynamicScrollerItem
43+
:item="item"
44+
:active="active"
45+
:size-dependencies="[
46+
showMoreParentsMap[item.id]
47+
]"
48+
>
49+
<VulnerabilityItem
50+
:item="item"
51+
:show-more-parents="showMoreParentsMap[item.id]"
52+
@toggle-more-parents="$set(showMoreParentsMap, item.id, !showMoreParentsMap[item.id])"
53+
/>
54+
</DynamicScrollerItem>
55+
</DynamicScroller>
56+
</transition>
2457
</template>
2558
</div>
2659
</template>
2760

2861
<script>
2962
import VulnerabilityItem from './VulnerabilityItem.vue'
3063
64+
import { SEVERITIES } from './Vulnerability.vue'
65+
3166
export default {
3267
components: {
3368
VulnerabilityItem
@@ -37,6 +72,24 @@ export default {
3772
return mapSharedData('org.vue.widgets.vulnerability.', {
3873
details: 'details'
3974
})
75+
},
76+
77+
data () {
78+
return {
79+
showList: false,
80+
showMoreParentsMap: {}
81+
}
82+
},
83+
84+
created () {
85+
this.severities = SEVERITIES
86+
},
87+
88+
mounted () {
89+
// Animation breaks scroller item sizes
90+
setTimeout(() => {
91+
this.showList = true
92+
}, 200)
4093
}
4194
}
4295
</script>
@@ -45,9 +98,32 @@ export default {
4598
@import "~@vue/cli-ui/src/style/imports"
4699
47100
.vulnerability-details
48-
overflow-x hidden
49-
overflow-y auto
101+
v-box()
50102
51103
.pane-toolbar
52104
padding-bottom $padding-item
105+
106+
.summary
107+
display flex
108+
padding-right 12px
109+
110+
.summary-item
111+
display flex
112+
align-items center
113+
margin-left 16px
114+
115+
.vue-ui-icon,
116+
.count
117+
margin-right 3px
118+
119+
.count
120+
font-weight bold
121+
122+
.severity-danger
123+
color $vue-ui-color-danger
124+
.severity-warning
125+
color $vue-ui-color-warning
126+
127+
.items
128+
flex 1
53129
</style>

0 commit comments

Comments
 (0)