fix: hide error message (#305)

Signed-off-by: Yi-Ya Chen <yiya.chen@suse.com>
This commit is contained in:
Yiya Chen 2025-05-22 11:07:20 +08:00 committed by GitHub
parent 6d8f6579c7
commit 3dcec52aff
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 38 additions and 11 deletions

View File

@ -1,4 +1,5 @@
<script>
import { NORMAN } from '@shell/config/types';
import { HCI } from '../types';
export default {
@ -13,10 +14,24 @@ export default {
const harvesterSettings = await this.$store.dispatch('harvester/findAll', { type: HCI.SETTING });
this.harvesterSettings = harvesterSettings;
const clusterRoleTemplateBindingSchema = this.$store.getters['rancher/schemaFor'](NORMAN.CLUSTER_ROLE_TEMPLATE_BINDING);
if (clusterRoleTemplateBindingSchema) {
const normanBindings = await this.$store.dispatch('rancher/findAll', { type: NORMAN.CLUSTER_ROLE_TEMPLATE_BINDING }, { root: true });
this.clusterRoleTemplateBinding = normanBindings;
}
},
data() {
return { harvesterSettings: [] };
const user = this.$store.getters['auth/v3User'];
return {
harvesterSettings: [],
clusterRoleTemplateBinding: [],
user,
};
},
computed: {
@ -31,19 +46,28 @@ export default {
} catch (e) {}
return isMatch;
},
isClusterOwner() {
const template = this.clusterRoleTemplateBinding.find((template) => {
return template.userId === this.user?.id;
});
return template?.roleTemplateId === 'cluster-owner';
},
shouldShowError() {
return this.isClusterOwner && !this.isMatch && this.value;
}
}
};
</script>
<template>
<div v-if="isMatch">
{{ value }}
</div>
<div v-else>
<div>
{{ value }}
<p
v-if="value"
v-if="shouldShowError"
class="text-error"
>
{{ t('harvester.backup.matchTarget') }}

View File

@ -112,15 +112,18 @@ export default class HciSetting extends HarvesterResource {
}
get parseValue() {
let parseDefaultValue = {};
try {
parseDefaultValue = JSON.parse(this.value);
if (this.value) {
return JSON.parse(this.value);
} else if (this.default) {
return JSON.parse(this.default);
}
} catch (err) {
parseDefaultValue = JSON.parse(this.default);
// eslint-disable-next-line no-console
console.error('Failed to parse setting value or default:', err);
}
return parseDefaultValue;
return {};
}
get isS3() {