harvester-ui-extension/pkg/harvester/models/devices.harvesterhci.io.migconfiguration.js
Andy Lee 16a0df8864
refactor: allow editConfig when status is empty
Signed-off-by: Andy Lee <andy.lee@suse.com>
2025-10-26 15:54:07 +08:00

105 lines
2.6 KiB
JavaScript

import SteveModel from '@shell/plugins/steve/steve-class';
import { escapeHtml } from '@shell/utils/string';
import { colorForState } from '@shell/plugins/dashboard-store/resource-class';
/**
* Class representing vGPU MIGConfiguration resource.
* @extends SteveModal
*/
export default class MIGCONFIGURATION extends SteveModel {
get _availableActions() {
let out = super._availableActions;
out = out.map((action) => {
if (action.action === 'goToEditYaml') {
return { ...action, enabled: true };
} else if (action.action === 'goToEdit') {
// need to wait for status to be disabled or empty value, then allow user to editConfig
return { ...action, enabled: !this.spec.enabled && ['disabled', ''].includes(this.configStatus) };
} else {
return action;
}
});
out.push(
{
action: 'enableConfig',
enabled: !this.isEnabled,
icon: 'icon icon-fw icon-dot',
label: 'Enable',
},
{
action: 'disableConfig',
enabled: this.isEnabled,
icon: 'icon icon-fw icon-dot-open',
label: 'Disable',
},
);
return out;
}
get canYaml() {
return false;
}
get canDelete() {
return false;
}
get configStatus() {
// console.log("🚀 ~ MIGCONFIGURATION ~ configStatus ~ this.status.status:", this.status.status)
// console.log('this.status.status.length', this.status.status?.length);
return this.status.status;
}
get actualState() {
return this.isEnabled ? 'Enabled' : 'Disabled';
}
get stateDisplay() {
return this.actualState;
}
get stateColor() {
const state = this.actualState;
return colorForState(state);
}
get isEnabled() {
return this.spec.enabled;
}
async enableConfig() {
try {
this.spec.enabled = true;
await this.save();
} catch (err) {
this.$dispatch('growl/fromError', {
title: this.t('generic.notification.title.error', { name: escapeHtml(this.name) }),
err,
}, { root: true });
}
}
async disableConfig() {
const { enabled: currentEnabled } = this.spec;
try {
this.spec.enabled = false;
await this.save();
} catch (err) {
this.spec.enabled = currentEnabled;
this.$dispatch('growl/fromError', {
title: this.t('generic.notification.title.error', { name: escapeHtml(this.name) }),
err,
}, { root: true });
}
}
// cleanForSave(data, _forNew) {
// console.log("🚀 ~ MIGCONFIGURATION ~ cleanForSave ~ data:", data)
// return data;
// }
}