Skip to content

Commit f21c6d5

Browse files
rushk014xingzhang-suse
authored andcommitted
Feat: Registries configuration - Detail: Implement action buttons
1 parent 857627a commit f21c6d5

File tree

2 files changed

+66
-101
lines changed

2 files changed

+66
-101
lines changed

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

Lines changed: 2 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<script>
22
import { REGISTRY_SCAN_HISTORY_TABLE } from "@sbombastic-image-vulnerability-scanner/config/table-headers";
3-
import { RESOURCE } from "@sbombastic-image-vulnerability-scanner/types";
43
import ResourceTable from "@shell/components/ResourceTable";
54
65
export default {
@@ -9,59 +8,15 @@
98
ResourceTable
109
},
1110
props: {
12-
registry: {
13-
type: Object,
11+
scanHistory: {
12+
type: Array,
1413
required: true
1514
}
1615
},
1716
data() {
1817
return {
19-
scanHistory: [],
2018
headers: REGISTRY_SCAN_HISTORY_TABLE
2119
}
22-
},
23-
async mounted() {
24-
await this.$store.dispatch('cluster/findAll', { type: RESOURCE.SCAN_JOB });
25-
26-
if (this.registry) {
27-
let scanJobs = this.$store.getters['cluster/all'](RESOURCE.SCAN_JOB).filter((rec) => {
28-
return rec.spec.registry === this.registry.metadata.name;
29-
});
30-
31-
this.scanHistory = scanJobs.map((rec) => {
32-
rec.status.statusResult = rec.status.conditions.filter(condition => {
33-
return condition.status === "True";
34-
})[0] || {
35-
type: "Pending",
36-
lastTransitionTime: null,
37-
};
38-
return rec;
39-
});
40-
}
41-
},
42-
watch: {
43-
async registry(newRegistry) {
44-
if (newRegistry) {
45-
let scanJobs = this.$store.getters['cluster/all'](RESOURCE.SCAN_JOB).filter((rec) => {
46-
return rec.spec.registry === newRegistry.metadata.name;
47-
});
48-
49-
scanJobs.forEach((rec) => {
50-
this.scanHistory.push({
51-
...rec,
52-
status: {
53-
...rec.status,
54-
statusResult: rec.status.conditions.filter(condition => {
55-
return condition.status === "True";
56-
})[0] || {
57-
type: "Pending",
58-
lastTransitionTime: null,
59-
}
60-
}
61-
})
62-
});
63-
}
64-
}
6520
}
6621
}
6722
</script>

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

Lines changed: 64 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,20 @@
1515
</span>
1616
</div>
1717
<div class="resource-header-actions">
18-
<button class="btn role-secondary">
18+
<button
19+
class="btn role-secondary"
20+
aria-label="Refresh data"
21+
type="button"
22+
@click="loadData(true)">
1923
<i class="icon icon-refresh"></i>
2024
{{ t('imageScanner.general.refresh') }}
2125
</button>
22-
<button class="btn role-primary">
23-
<i class="icon icon-play"></i>
24-
{{ t('imageScanner.registries.configuration.scan') }}
25-
</button>
26+
<ScanButton :selectedRegistries="[{name: $route.params.id, namespace: $route.params.ns}]" :reloadFn="loadData" />
2627
</div>
2728
</div>
2829
<RancherMeta :properties="registryMetadata" />
2930
</div>
30-
<RegistryDetailScanTable :registry="registry" />
31+
<RegistryDetailScanTable :scanHistory="scanHistory" />
3132
</div>
3233
</template>
3334

@@ -37,8 +38,8 @@
3738
import ResourceTable from "@shell/components/ResourceTable";
3839
import RancherMeta from './common/RancherMeta.vue';
3940
import RegisterStatusBadge from './common/RegisterStatusBadge.vue';
40-
import { REGISTRY_SCAN_HISTORY_TABLE } from '@sbombastic-image-vulnerability-scanner/config/table-headers';
4141
import RegistryDetailScanTable from './RegistryDetailScanTable.vue';
42+
import ScanButton from './common/ScanButton.vue';
4243
4344
export default {
4445
name: 'registryDetails',
@@ -47,66 +48,75 @@
4748
ResourceTable,
4849
RancherMeta,
4950
RegisterStatusBadge,
50-
RegistryDetailScanTable
51+
RegistryDetailScanTable,
52+
ScanButton
5153
},
5254
data() {
5355
return {
5456
PRODUCT_NAME,
5557
RESOURCE,
5658
PAGE,
57-
registry: null,
5859
registryStatus: null,
5960
registryMetadata: [],
61+
scanHistory: [],
6062
}
6163
},
6264
async fetch() {
63-
64-
await this.$store.dispatch('cluster/find', { type: RESOURCE.REGISTRY, id: `${this.$route.params.ns}/${this.$route.params.id}` });
65-
let registry = this.$store.getters['cluster/byId'](RESOURCE.REGISTRY, `${this.$route.params.ns}/${this.$route.params.id}`);
66-
67-
68-
await this.$store.dispatch('cluster/findAll', { type: RESOURCE.SCAN_JOB });
69-
let scanJobs = this.$store.getters['cluster/all'](RESOURCE.SCAN_JOB);
70-
71-
// filter scan jobs for the current registry
72-
scanJobs = scanJobs.filter((job) => {
73-
return job.spec.registry === registry.metadata.name;
74-
});
75-
76-
this.registryStatus = this.getRegistryStatus(registry);
77-
this.registryMetadata = [
78-
{
79-
type: 'text',
80-
label: this.t('imageScanner.registries.configuration.meta.registry'),
81-
value: registry.spec.uri
82-
},
83-
{
84-
type: 'text',
85-
label: this.t('imageScanner.registries.configuration.meta.repositories'),
86-
value: registry.spec.repositories?.length || 0
87-
},
88-
{
89-
type: 'text',
90-
label: this.t('imageScanner.registries.configuration.meta.schedule')
91-
},
92-
{
93-
type: 'text',
94-
label: this.t('imageScanner.registries.configuration.meta.namespace'),
95-
value: registry.metadata.namespace
96-
},
97-
{
98-
type: 'tags',
99-
tags: registry.spec.repositories || []
100-
},
101-
{
102-
type: 'text',
103-
value: registry.metadata.schedule || '',
104-
}
105-
];
106-
107-
this.registry = registry;
65+
await this.loadData();
10866
},
10967
methods: {
68+
async loadData(isForceLoading = false) {
69+
await this.$store.dispatch('cluster/find', { type: RESOURCE.REGISTRY, id: `${this.$route.params.ns}/${this.$route.params.id}`, opt: {force: isForceLoading} });
70+
if (this.$store.getters['cluster/canList'](RESOURCE.SCAN_JOB)) {
71+
await this.$store.dispatch('cluster/findAll', { type: RESOURCE.SCAN_JOB, opt: {force: isForceLoading} });
72+
}
73+
74+
let registry = this.$store.getters['cluster/byId'](RESOURCE.REGISTRY, `${this.$route.params.ns}/${this.$route.params.id}`);
75+
let scanJobs = this.$store.getters['cluster/all'](RESOURCE.SCAN_JOB).filter((rec) => {
76+
return rec.spec.registry === registry.metadata.name;
77+
});
78+
79+
this.registryStatus = this.getRegistryStatus(registry);
80+
this.registryMetadata = [
81+
{
82+
type: 'text',
83+
label: this.t('imageScanner.registries.configuration.meta.registry'),
84+
value: registry.spec.uri
85+
},
86+
{
87+
type: 'text',
88+
label: this.t('imageScanner.registries.configuration.meta.repositories'),
89+
value: registry.spec.repositories?.length || 0
90+
},
91+
{
92+
type: 'text',
93+
label: this.t('imageScanner.registries.configuration.meta.schedule')
94+
},
95+
{
96+
type: 'text',
97+
label: this.t('imageScanner.registries.configuration.meta.namespace'),
98+
value: registry.metadata.namespace
99+
},
100+
{
101+
type: 'tags',
102+
tags: registry.spec.repositories || []
103+
},
104+
{
105+
type: 'text',
106+
value: registry.metadata.schedule || '',
107+
}
108+
];
109+
110+
this.scanHistory = scanJobs.map((rec) => {
111+
rec.status.statusResult = rec.status.conditions.filter(condition => {
112+
return condition.status === "True";
113+
})[0] || {
114+
type: "Pending",
115+
lastTransitionTime: null,
116+
};
117+
return rec;
118+
});
119+
},
110120
getRegistryStatus(registry) {
111121
if (!registry || !registry.status || !registry.status.conditions || !registry.status.conditions.length) {
112122
return null;

0 commit comments

Comments
 (0)