Skip to content

Commit a070929

Browse files
NickChungSUSExingzhang-suse
authored andcommitted
Rewrite customization for the standard SteveModel written
1 parent 81a8870 commit a070929

File tree

3 files changed

+84
-39
lines changed

3 files changed

+84
-39
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,10 @@ export const VEX_MANAGEMENT_TABLE = [
131131
{
132132
name: "createdBy",
133133
labelKey: "imageScanner.vexManagement.table.headers.createdBy",
134-
value: (row: any) =>
135-
row?.metadata?.generation === 1 ? "Rancher" : "Manual entry",
134+
value: (row: any) => {
135+
const gen = Number(row?.metadata?.generation);
136+
return (gen === 1) ? 'Rancher' : 'Manual entry';
137+
},
136138
sort: "metadata.generation",
137139
},
138140
{
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import SteveModel from '@shell/plugins/steve/steve-class';
2+
import { insertAt } from '@shell/utils/array';
3+
4+
export default class SbombasticRancherIoVexhub extends SteveModel {
5+
get _availableActions() {
6+
let out = super._availableActions || [];
7+
8+
// Remove download actions and View in API, keep edit YAML and clone
9+
const remove = new Set([
10+
'download',
11+
'downloadYaml',
12+
'downloadyaml',
13+
'viewYaml',
14+
'goToViewYaml',
15+
'viewInApi'
16+
]);
17+
out = out.filter((a) => !a?.action || !remove.has(a.action));
18+
19+
const isEnabled = !!this.spec?.enabled;
20+
21+
const toggle = isEnabled
22+
? {
23+
action: 'disable',
24+
label: this.t('imageScanner.vexManagement.buttons.disable') || 'Disable',
25+
icon: 'icon-pause',
26+
enabled: true,
27+
bulkable: true,
28+
invoke: async() => {
29+
this.spec = { ...(this.spec || {}), enabled: false };
30+
await this.save();
31+
}
32+
}
33+
: {
34+
action: 'enable',
35+
label: this.t('imageScanner.vexManagement.buttons.enable') || 'Enable',
36+
icon: 'icon-play',
37+
enabled: true,
38+
bulkable: true,
39+
invoke: async() => {
40+
this.spec = { ...(this.spec || {}), enabled: true };
41+
await this.save();
42+
}
43+
};
44+
45+
if (isEnabled) {
46+
// For enabled items: Disable, then other actions
47+
const reordered = [toggle]; // Only the disable action
48+
49+
// Add other actions except delete (which goes last)
50+
const otherActions = out.filter(a => a && a.action !== 'promptRemove');
51+
reordered.push(...otherActions);
52+
53+
// Add delete at the end
54+
const deleteAction = out.find((a) => a?.action === 'promptRemove');
55+
if (deleteAction) {
56+
reordered.push(deleteAction);
57+
}
58+
59+
// Ensure all actions are enabled
60+
return reordered.map(action => {
61+
if (action && action.enabled === false) {
62+
return { ...action, enabled: true };
63+
}
64+
return action;
65+
});
66+
}
67+
68+
// When disabled: Enable, then Delete
69+
const deleteAction = out.find((a) => a?.action === 'promptRemove');
70+
return [toggle, ...(deleteAction ? [deleteAction] : [])];
71+
}
72+
73+
get canDelete() {
74+
return !this.spec?.enabled;
75+
}
76+
}

pkg/sbombastic-image-vulnerability-scanner/pages/c/_cluster/sbombastic-image-vulnerability-scanner/VexManagement.vue

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -64,48 +64,15 @@ export default {
6464
},
6565
async fetch() {
6666
await this.$store.dispatch('cluster/findAll', { type: RESOURCE.VEX_HUB });
67-
let vexhubsCRD = this.$store.getters['cluster/all']?.(RESOURCE.VEX_HUB);
68-
this.rows = (vexhubsCRD || []).map((r) => this.rowWithActions(r));
67+
const vexhubsCRD = this.$store.getters['cluster/all']?.(RESOURCE.VEX_HUB);
68+
this.rows = vexhubsCRD || [];
6969
},
7070
methods: {
71-
rowWithActions(r) {
72-
const isEnabled = !!r?.spec?.enabled;
73-
const toggleAction = isEnabled
74-
? { action: 'disable', label: this.t('imageScanner.vexManagement.buttons.disable') || 'Disable', icon: 'icon-pause', enabled: true, bulkable: true, invoke: ({}, resources) => this.switchStatus(false, resources) }
75-
: { action: 'enable', label: this.t('imageScanner.vexManagement.buttons.enable') || 'Enable', icon: 'icon-play', enabled: true, bulkable: true, invoke: ({}, resources) => this.switchStatus(true, resources) };
76-
77-
const actions = Array.isArray(r.availableActions) ? r.availableActions.filter(a => !['download','downloadYaml'].includes(a.action)): [];
78-
79-
if (isEnabled && !actions.find(a => a && (a.action === 'edit' || a.action === 'goToEdit'))) {
80-
const editAction = {
81-
action: 'goToEdit',
82-
label: this.t('imageScanner.vexManagement.actions.editConfig') || 'Edit configuration',
83-
icon: 'icon-edit',
84-
enabled: true,
85-
bulkable: false,
86-
invoke: ({}, res = []) => {
87-
const target = (res && res.length ? res[0] : r);
88-
const model = target._model || target;
89-
if (model && typeof model.goToEdit === 'function') {
90-
model.goToEdit();
91-
}
92-
}
93-
};
94-
actions.unshift(editAction);
95-
}
96-
const deleteAction = actions.find(a => a.action === 'promptRemove');
97-
98-
const availableActions = isEnabled
99-
? [toggleAction, ...actions]
100-
: [toggleAction, deleteAction]; // when disabled show only Enable + Delete
101-
102-
return { ...r, _model: r, availableActions };
103-
},
71+
rowWithActions(r) { return r; },
10472
async switchStatus(desired, selected) {
10573
const resources = selected && selected.length ? selected : (this.selectedRows || []);
10674
if (!resources.length) return;
107-
const models = resources.map((r) => r._model || r).filter(Boolean);
108-
await Promise.all(models.map(async (m) => {
75+
await Promise.all(resources.map(async (m) => {
10976
m.spec = { ...(m.spec || {}), enabled: desired };
11077
await m.save();
11178
}));

0 commit comments

Comments
 (0)