Skip to content

Commit 0d585ec

Browse files
rushk014xingzhang-suse
authored andcommitted
fix(Registry Configuration details): Modify Scan History table to keep Steve API reference such that WebSocket updates render automatically
1 parent 9241255 commit 0d585ec

File tree

6 files changed

+77
-56
lines changed

6 files changed

+77
-56
lines changed

pkg/sbombastic-image-vulnerability-scanner/components/RegistryDetailScanTable.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
:namespaced="false"
3030
:row-actions="false"
3131
:table-actions="false"
32+
:sub-rows-description="false"
3233
:search="false"
3334
:headers="headers"
3435
:rows="scanHistory"

pkg/sbombastic-image-vulnerability-scanner/components/RegistryDetails.vue

Lines changed: 10 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -76,28 +76,22 @@
7676
},
7777
methods: {
7878
async loadData(isForceLoading = false) {
79-
await this.$store.dispatch('cluster/find', { type: RESOURCE.REGISTRY, id: `${this.$route.params.ns}/${this.$route.params.id}`, opt: {force: isForceLoading} });
80-
if (this.$store.getters['cluster/canList'](RESOURCE.SCAN_JOB)) {
81-
await this.$store.dispatch('cluster/findAll', { type: RESOURCE.SCAN_JOB, opt: {force: isForceLoading} });
82-
}
83-
this.scanHistory = [];
84-
85-
let registry = this.$store.getters['cluster/byId'](RESOURCE.REGISTRY, `${this.$route.params.ns}/${this.$route.params.id}`);
86-
let scanJobs = this.$store.getters['cluster/all'](RESOURCE.SCAN_JOB).filter((rec) => {
87-
return rec.spec.registry === registry.metadata.name;
79+
this.registry = await this.$store.dispatch('cluster/find', { type: RESOURCE.REGISTRY, id: `${this.$route.params.ns}/${this.$route.params.id}`, opt: {force: isForceLoading} });
80+
this.scanHistory = (await this.$store.dispatch('cluster/findAll', { type: RESOURCE.SCAN_JOB, opt: {force: isForceLoading} })).filter((rec) => {
81+
return rec.spec.registry === this.registry.metadata.name;
8882
});
8983
90-
this.registryStatus = this.getRegistryStatus(registry);
84+
this.registryStatus = this.scanHistory.sort((a, b) => new Date(b.status?.statusResult?.lastTransitionTime) - new Date(a.status?.statusResult?.lastTransitionTime))[0]?.status?.statusResult?.type.toLowerCase();
9185
this.registryMetadata = [
9286
{
9387
type: 'text',
9488
label: this.t('imageScanner.registries.configuration.meta.namespace'),
95-
value: registry.metadata.namespace
89+
value: this.registry.metadata.namespace
9690
},
9791
{
9892
type: 'text',
9993
label: this.t('imageScanner.registries.configuration.meta.repositories'),
100-
value: registry.spec.repositories?.length || 0
94+
value: this.registry.spec.repositories?.length || 0
10195
},
10296
{
10397
type: 'text',
@@ -106,44 +100,18 @@
106100
{
107101
type: 'text',
108102
label: this.t('imageScanner.registries.configuration.meta.uri'),
109-
value: registry.spec.uri
103+
value: this.registry.spec.uri
110104
},
111105
{
112106
type: 'tags',
113-
tags: registry.spec.repositories || []
107+
tags: this.registry.spec.repositories || []
114108
},
115109
{
116110
type: 'text',
117-
value: registry.spec.scanInterval ?
118-
this.t('imageScanner.general.schedule', { i: registry.spec.scanInterval }) : '',
111+
value: this.registry.spec.scanInterval ?
112+
this.t('imageScanner.general.schedule', { i: this.registry.spec.scanInterval }) : '',
119113
}
120114
];
121-
122-
scanJobs.forEach((rec) => {
123-
this.scanHistory.push({
124-
...rec,
125-
progress: rec.status.scannedImagesCount && rec.status.imagesCount ? Math.ceil(rec.status.scannedImagesCount / rec.status.imagesCount * 100) : 0,
126-
status: {
127-
...rec.status,
128-
statusResult: rec.status?.conditions?.filter(condition => {
129-
return condition.status === "True";
130-
})[0] || {
131-
type: "Pending",
132-
lastTransitionTime: null,
133-
}
134-
}
135-
})
136-
});
137-
this.registry = registry;
138-
this.scanHistory = this.scanHistory.sort((a, b) => new Date(b.status?.statusResult?.lastTransitionTime) - new Date(a.status?.statusResult?.lastTransitionTime));
139-
this.registryStatus = this.scanHistory[0]?.status?.statusResult?.type.toLowerCase();
140-
},
141-
getRegistryStatus(registry) {
142-
if (!registry || !registry.status || !registry.status.conditions || !registry.status.conditions.length) {
143-
return null;
144-
}
145-
let status = registry.status.conditions[0].type.toLowerCase() === "discovering" ? "InProgress" : registry.status.conditions[0].type;
146-
return status.toLowerCase();
147115
},
148116
},
149117
}

pkg/sbombastic-image-vulnerability-scanner/config/table-headers.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,17 @@ export const REGISTRY_SCAN_HISTORY_TABLE = [
6060
{
6161
name: "status",
6262
labelKey: "imageScanner.registries.configuration.scanTable.header.status",
63-
value: "status.statusResult.type",
64-
formatter: "RegistryStatusCellBadge",
65-
sort: "status.statusResult.type",
63+
value: "status",
64+
formatter: "ScanHistoryStatusCell",
65+
sort: "status.conditions[?(@.status=='True')].type",
6666
width: 100,
6767
},
6868
{
6969
name: "since",
7070
labelKey: "imageScanner.registries.configuration.scanTable.header.since",
71-
value: "status.statusResult.lastTransitionTime",
72-
formatter: "Date",
73-
sort: "status.statusResult.lastTransitionTime:desc",
71+
value: "status",
72+
formatter: "ScanHistorySinceCell",
73+
sort: "status.conditions[?(@.status=='True')].lastTransitionTime",
7474
width: 210,
7575
},
7676
{
@@ -100,9 +100,8 @@ export const REGISTRY_SCAN_HISTORY_TABLE = [
100100
{
101101
name: "errors",
102102
labelKey: "imageScanner.registries.configuration.scanTable.header.error",
103-
value: "status.statusResult.message",
103+
value: "status",
104104
formatter: "ScanErrorCell",
105-
sort: "errors",
106105
},
107106
];
108107

pkg/sbombastic-image-vulnerability-scanner/formatters/ScanErrorCell.vue

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,21 @@ export default {
1212
required: true
1313
}
1414
},
15-
data() {
16-
return {
17-
failedStatus: REGISTRY_STATUS.FAILED
15+
computed: {
16+
error() {
17+
const statusResult = this.value.conditions.find(condition => {
18+
return condition.status === "True";
19+
});
20+
return statusResult?.type.toLowerCase() === REGISTRY_STATUS.FAILED ? statusResult.message : null;
1821
}
19-
}
22+
},
2023
};
2124
</script>
2225
2326
<template>
24-
<div v-if="row && row.status.statusResult.type.toLowerCase() === failedStatus" class="scan-error-cell">
27+
<div v-if="error" class="scan-error-cell">
2528
<div class="dot failed"></div>
26-
<div class="status">{{ value }}</div>
29+
<div class="status">{{ error }}</div>
2730
</div>
2831
<div v-else class="scan-error-cell">
2932
<div class="status text-muted">{{ t('imageScanner.general.none') }}</div>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<script>
2+
import Date from "@shell/components/formatter/Date";
3+
export default {
4+
components: {
5+
Date
6+
},
7+
props: {
8+
value: {
9+
type: String,
10+
required: true
11+
}
12+
},
13+
computed: {
14+
since() {
15+
return this.value.conditions.find(condition => {
16+
return condition.status === "True";
17+
})?.lastTransitionTime;
18+
}
19+
}
20+
};
21+
</script>
22+
23+
<template>
24+
<Date :value="since" />
25+
</template>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<script>
2+
import RegisterStatusBadge from "@pkg/components/common/RegisterStatusBadge";
3+
export default {
4+
components: {
5+
RegisterStatusBadge,
6+
},
7+
props: {
8+
value: {
9+
type: String,
10+
required: true
11+
}
12+
},
13+
computed: {
14+
status() {
15+
return this.value.conditions.find(condition => {
16+
return condition.status === "True";
17+
})?.type || "Pending";
18+
}
19+
}
20+
};
21+
</script>
22+
23+
<template>
24+
<RegisterStatusBadge :status="status.toLowerCase()" />
25+
</template>

0 commit comments

Comments
 (0)