Skip to content

Commit 41c89be

Browse files
rushk014xingzhang-suse
authored andcommitted
Feat: Registries configuration - Detail: Refactor Scan History table
1 parent de77bc6 commit 41c89be

File tree

5 files changed

+179
-95
lines changed

5 files changed

+179
-95
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"dependencies": {
99
"@kubernetes/client-node": "^1.3.0",
1010
"@rancher/components": "^0.3.0-alpha.1",
11-
"@rancher/shell": "^3.0.4",
11+
"@rancher/shell": "3.0.5-rc.7",
1212
"vue": "^3.5.17",
1313
"vue-router": "^4.5.0",
1414
"vuex": "^4.1.0"
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<script>
2+
import { REGISTRY_SCAN_HISTORY_TABLE } from "@sbombastic-image-vulnerability-scanner/config/table-headers";
3+
import { RESOURCE } from "@sbombastic-image-vulnerability-scanner/types";
4+
import ResourceTable from "@shell/components/ResourceTable";
5+
6+
export default {
7+
name: 'RegistryDetailScanTable',
8+
components: {
9+
ResourceTable
10+
},
11+
props: {
12+
registry: {
13+
type: Object,
14+
required: true
15+
}
16+
},
17+
data() {
18+
return {
19+
scanHistory: [],
20+
headers: REGISTRY_SCAN_HISTORY_TABLE
21+
}
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+
rec.status['scannedImagesCount'] = this.$route.params.id === 'kw-controller' ? 1000 : 500;
39+
rec.status['imagesCount'] = 2000;
40+
return rec;
41+
});
42+
}
43+
},
44+
watch: {
45+
async registry(newRegistry) {
46+
if (newRegistry) {
47+
let scanJobs = this.$store.getters['cluster/all'](RESOURCE.SCAN_JOB).filter((rec) => {
48+
return rec.spec.registry === newRegistry.metadata.name;
49+
});
50+
51+
this.scanHistory = scanJobs.map((rec) => {
52+
rec.status.statusResult = rec.status.conditions.filter(condition => {
53+
return condition.status === "True";
54+
})[0] || {
55+
type: "Pending",
56+
lastTransitionTime: null,
57+
};
58+
rec.status['scannedImagesCount'] = this.$route.params.id === 'kw-controller' ? 1000 : 500;
59+
rec.status['imagesCount'] = 2000;
60+
return rec;
61+
});
62+
}
63+
}
64+
}
65+
}
66+
</script>
67+
68+
<template>
69+
<div class="registry-detail-scan-table">
70+
Recent scans
71+
<ResourceTable
72+
:headers="headers"
73+
:rows="scanHistory"
74+
:namespaced="false"
75+
:rowActions="false"
76+
:search="false"
77+
/>
78+
</div>
79+
</template>
80+
81+
<style lang="scss" scoped>
82+
.registry-detail-scan-table {
83+
display: flex;
84+
flex-direction: column;
85+
gap: 24px;
86+
width: 100%;
87+
}
88+
</style>

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

Lines changed: 7 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,7 @@
2727
</div>
2828
<RancherMeta :properties="registryMetadata" />
2929
</div>
30-
Recent scans
31-
<ResourceTable
32-
:headers="headers"
33-
:rows="scanHistory"
34-
:namespaced="false"
35-
:rowActions="false"
36-
:search="false"
37-
class="table"
38-
/>
30+
<RegistryDetailScanTable :registry="registry" />
3931
</div>
4032
</template>
4133

@@ -46,6 +38,7 @@
4638
import RancherMeta from './common/RancherMeta.vue';
4739
import RegisterStatusBadge from './common/RegisterStatusBadge.vue';
4840
import { REGISTRY_SCAN_HISTORY_TABLE } from '@sbombastic-image-vulnerability-scanner/config/table-headers';
41+
import RegistryDetailScanTable from './RegistryDetailScanTable.vue';
4942
5043
export default {
5144
name: 'registryDetails',
@@ -54,31 +47,22 @@
5447
ResourceTable,
5548
RancherMeta,
5649
RegisterStatusBadge,
50+
RegistryDetailScanTable
5751
},
5852
data() {
5953
return {
6054
PRODUCT_NAME,
6155
RESOURCE,
56+
registry: null,
6257
registryStatus: null,
6358
registryMetadata: [],
64-
scanHistory: [],
65-
headers: REGISTRY_SCAN_HISTORY_TABLE
6659
}
6760
},
6861
async fetch() {
6962
7063
await this.$store.dispatch('cluster/find', { type: RESOURCE.REGISTRY, id: `${this.$route.params.ns}/${this.$route.params.id}` });
7164
let registry = this.$store.getters['cluster/byId'](RESOURCE.REGISTRY, `${this.$route.params.ns}/${this.$route.params.id}`);
7265
73-
74-
await this.$store.dispatch('cluster/findAll', { type: RESOURCE.SCAN_JOB });
75-
let scanJobs = this.$store.getters['cluster/all'](RESOURCE.SCAN_JOB);
76-
77-
// filter scan jobs for the current registry
78-
scanJobs = scanJobs.filter((job) => {
79-
return job.spec.registry === registry.metadata.name;
80-
});
81-
8266
this.registryStatus = this.getRegistryStatus(registry);
8367
this.registryMetadata = [
8468
{
@@ -89,7 +73,7 @@
8973
{
9074
type: 'text',
9175
label: this.t('imageScanner.registries.configuration.meta.repositories'),
92-
value: registry.spec.repositories.length
76+
value: registry.spec.repositories?.length || 0
9377
},
9478
{
9579
type: 'text',
@@ -110,19 +94,7 @@
11094
}
11195
];
11296
113-
this.scanHistory = scanJobs.map((rec) => {
114-
rec.status.statusResult = rec.status.conditions.filter(condition => {
115-
return condition.status === "True";
116-
})[0] || {
117-
type: "Pending",
118-
lastTransitionTime: null,
119-
};
120-
rec.status['scannedImagesCount'] = this.$route.params.id === 'kw-controller' ? 1000 : 500;
121-
rec.status['imagesCount'] = 2000;
122-
return rec;
123-
});
124-
125-
console.log("Scan history:", this.scanHistory);
97+
this.registry = registry;
12698
},
12799
methods: {
128100
getRegistryStatus(registry) {
@@ -150,10 +122,6 @@
150122
gap: 24px;
151123
flex: 1 0 0;
152124
align-self: stretch;
153-
154-
.table {
155-
width: 100%;
156-
}
157125
}
158126
159127
.about {
@@ -202,7 +170,7 @@
202170
.resource-header-description {
203171
/* layout */
204172
display: flex;
205-
width: 900px;
173+
max-width: 900px;
206174
height: 21px;
207175
flex-direction: column;
208176
justify-content: center;
Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,29 @@
11
<script>
2-
import CreateEditView from '@shell/mixins/create-edit-view';
3-
import RegistryDetails from '@sbombastic-image-vulnerability-scanner/components/RegistryDetails.vue';
4-
import { RESOURCE } from '@sbombastic-image-vulnerability-scanner/types';
5-
import { _CREATE } from '@shell/config/query-params';
6-
import Loading from '@shell/components/Loading';
2+
import DetailPage from '@rancher/shell/components/Resource/Detail/Page.vue';
3+
import Metadata from '@rancher/shell/components/Resource/Detail/Metadata/index.vue';
4+
import RegistryDetailScanTable from '@sbombastic-image-vulnerability-scanner/components/RegistryDetailScanTable.vue';
5+
76
87
export default {
98
name: 'CruRegistry',
10-
119
props: {
12-
mode: {
13-
type: String,
14-
default: _CREATE,
15-
},
1610
value: {
17-
type: Object,
18-
required: true,
19-
},
11+
type: Object,
12+
required: true
13+
}
2014
},
21-
22-
components: { RegistryDetails, Loading },
23-
24-
mixins: [CreateEditView],
25-
2615
data() {
27-
return { resource: RESOURCE.REGISTRY };
28-
}
16+
return {
17+
}
18+
},
19+
components: { DetailPage, Metadata, RegistryDetailScanTable },
2920
};
3021
</script>
3122

3223
<template>
33-
<Loading v-if="$fetchState.pending" />
34-
<div v-else>
35-
{{ value | escapeHtml }}
36-
</div>
24+
<DetailPage>
25+
<template #bottom-area>
26+
<RegistryDetailScanTable :registry="value" />
27+
</template>
28+
</DetailPage>
3729
</template>

0 commit comments

Comments
 (0)