Skip to content

Commit

Permalink
Merge pull request #2822 from lhzzforever/dev/develop_ci
Browse files Browse the repository at this point in the history
fix: 修复用户组无资源实例和属性条件时预览差异对比报错
  • Loading branch information
ielgnaw authored Nov 6, 2024
2 parents 793950e + 3f78e5b commit c429bc1
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 124 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@
</div>
<div slot="footer" style="margin-left: 25px;">
<bk-button theme="primary" :disabled="disabled" :loading="sliderLoading" @click="handlerResourceSubmit">{{ $t(`m.common['保存']`) }}</bk-button>
<bk-button style="margin-left: 10px;" :disabled="disabled" @click="handlerResourcePreview" v-if="isShowPreview">{{ $t(`m.common['预览']`) }}</bk-button>
<bk-button style="margin-left: 10px;" :disabled="disabled" @click="handleResourceCancel('cancel')">{{ $t(`m.common['取消']`) }}</bk-button>
</div>
</bk-sideslider>
Expand Down Expand Up @@ -332,12 +331,6 @@
.related_resource_types[this.curResIndex];
return curData.selectionMode;
},
isShowPreview () {
if (this.curIndex === -1) {
return false;
}
return this.tableList[this.curIndex].policy_id !== '';
},
// 处理无限制和聚合后多个tab数据结构不兼容情况
formatDisplayValue () {
return (payload) => {
Expand Down Expand Up @@ -707,35 +700,7 @@
this.curResIndex = -1;
this.curGroupIndex = -1;
},
handlerResourcePreview () {
const { id } = this.tableList[this.curIndex].resource_groups[this.curGroupIndex];
const { system_id, type, name } = this.tableList[this.curIndex].resource_groups[this.curGroupIndex]
.related_resource_types[this.curResIndex];
const condition = [];
const conditionData = this.$refs.renderResourceRef.handleGetPreviewValue();
conditionData.forEach(item => {
const { id, attribute, instance } = item;
condition.push({
id,
attributes: attribute ? attribute.filter(item => item.values.length > 0) : [],
instances: instance ? instance.filter(item => item.path.length > 0) : []
});
});
this.previewResourceParams = {
policy_id: this.tableList[this.curIndex].policy_id,
resource_group_id: id,
related_resource_type: {
system_id,
type,
name,
condition: condition.filter(item => item.attributes.length > 0 || item.instances.length > 0)
}
};
this.previewDialogTitle = this.$t(`m.info['操作侧边栏操作的资源实例差异对比']`, { value: `${this.$t(`m.common['【']`)}${this.tableList[this.curIndex].name}${this.$t(`m.common['】']`)}` });
this.isShowPreviewDialog = true;
},
handlerConditionMouseover (payload) {
if (Object.keys(this.curCopyParams).length < 1 && this.curCopyMode === 'normal') {
return;
Expand Down
13 changes: 9 additions & 4 deletions frontend/src/views/group/components/preview-resource-dialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,27 @@
methods: {
async fetchData () {
// debugger
this.isLoading = true;
const isTemplate = this.params.isTemplate;
const method = isTemplate ? 'groupTemplateCompare' : 'groupPolicyCompare';
const { groupId, related_resource_type, resource_group_id: resourceGroupId } = this.params;
const requestParams = {
id: this.params.groupId,
id: groupId,
data: {
related_resource_type: this.params.related_resource_type,
resource_group_id: this.params.resource_group_id
related_resource_type,
resource_group_id: resourceGroupId
}
};
// 无实例和属性条件不需要调用接口
if (!related_resource_type.condition.length || !resourceGroupId) {
return;
}
if (!isTemplate) {
requestParams.data.policy_id = this.params.policy_id;
} else {
requestParams.templateId = this.params.id;
requestParams.data.action_id = this.params.action_id;
}
this.isLoading = true;
try {
const res = await this.$store.dispatch(`userGroup/${method}`, requestParams);
this.conditionData = res.data.map(item => new CompareCondition(item));
Expand Down
6 changes: 4 additions & 2 deletions frontend/src/views/group/components/render-instance-table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -513,10 +513,12 @@
return curData.selectionMode;
},
isShowPreview () {
if (this.curIndex === -1) {
if (this.curIndex === -1 || this.curGroupIndex === -1) {
return false;
}
return this.tableList[this.curIndex].policy_id !== '';
// 预览模板需要groupId和resourceGroupId
const { policy_id: policyId, resource_groups: resourceGroups } = this.tableList[this.curIndex];
return policyId !== '' && resourceGroups[this.curGroupIndex].id && this.groupId;
},
isShowView () {
return (payload) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@
</div>
<div slot="footer" style="margin-left: 25px;">
<bk-button theme="primary" :disabled="disabled" :loading="sliderLoading" @click="handlerResourceSubmit">{{ $t(`m.common['保存']`) }}</bk-button>
<bk-button style="margin-left: 10px;" :disabled="disabled" @click="handlerResourcePreview" v-if="isShowPreview">{{ $t(`m.common['预览']`) }}</bk-button>
<bk-button style="margin-left: 10px;" :disabled="disabled" @click="handleResourceCancel('cancel')">{{ $t(`m.common['取消']`) }}</bk-button>
</div>
</bk-sideslider>
Expand Down Expand Up @@ -341,12 +340,6 @@
.related_resource_types[this.curResIndex];
return curData.selectionMode;
},
isShowPreview () {
if (this.curIndex === -1) {
return false;
}
return this.tableList[this.curIndex].policy_id !== '';
},
// 处理无限制和聚合后多个tab数据结构不兼容情况
formatDisplayValue () {
return (payload) => {
Expand Down Expand Up @@ -716,40 +709,6 @@
this.curGroupIndex = -1;
},
handlerResourcePreview () {
const { id } = this.tableList[this.curIndex].resource_groups[this.curGroupIndex];
const { system_id, type, name } = this.tableList[this.curIndex].resource_groups[this.curGroupIndex]
.related_resource_types[this.curResIndex];
const condition = [];
const conditionData = this.$refs.renderResourceRef.handleGetPreviewValue();
conditionData.forEach(item => {
const { id, attribute, instance } = item;
condition.push({
id,
attributes: attribute ? attribute.filter(item => item.values.length > 0) : [],
instances: instance ? instance.filter(item => item.path.length > 0) : []
});
});
this.previewResourceParams = {
id: this.templateId,
policy_id: this.tableList[this.curIndex].policy_id,
resource_group_id: id,
related_resource_type: {
system_id,
type,
name,
condition: condition.filter(item => item.attributes.length > 0 || item.instances.length > 0)
},
action_id: this.tableList[this.curIndex].id,
reverse: true,
groupId: this.groupId,
isTemplate: this.tableList[this.curIndex].isTemplate,
isNotLimit: conditionData.length === 0
};
this.previewDialogTitle = this.$t(`m.info['操作侧边栏操作的资源实例差异对比']`, { value: `${this.$t(`m.common['【']`)}${this.tableList[this.curIndex].name}${this.$t(`m.common['】']`)}` });
this.isShowPreviewDialog = true;
},
handlerConditionMouseover (payload) {
if (Object.keys(this.curCopyParams).length < 1 && this.curCopyMode === 'normal') {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@
data-test-id="group_btn_resourceInstanceSubmit">
{{ $t(`m.common['保存']`) }}
</bk-button>
<bk-button style="margin-left: 10px;" :disabled="disabled" v-if="isShowPreview" @click="handleResourcePreview">{{ $t(`m.common['预览']`) }}</bk-button>
<bk-button style="margin-left: 10px;" :disabled="disabled" @click="handleResourceCancel('cancel')">{{ $t(`m.common['取消']`) }}</bk-button>
</div>
</bk-sideslider>
Expand Down Expand Up @@ -457,12 +456,6 @@
.related_resource_types[this.curResIndex];
return curData.selectionMode;
},
isShowPreview () {
if (this.curIndex === -1) {
return false;
}
return this.tableList[this.curIndex].policy_id !== '';
},
isShowView () {
return (payload) => {
return !payload.isEmpty;
Expand Down Expand Up @@ -1221,40 +1214,6 @@
// this.$emit('handleAggregateAction', false)
// }
},
handleResourcePreview () {
// debugger
window.changeDialog = true;
// eslint-disable-next-line max-len
const { system_id, type, name } = this.tableList[this.curIndex].resource_groups[this.curGroupIndex].related_resource_types[this.curResIndex];
const condition = [];
const conditionData = this.$refs.renderResourceRef.handleGetPreviewValue();
conditionData.forEach(item => {
const { id, attribute, instance } = item;
condition.push({
id,
attributes: attribute ? attribute.filter(item => item.values.length > 0) : [],
instances: instance ? instance.filter(item => item.path.length > 0) : []
});
});
this.previewResourceParams = {
id: this.templateId,
action_id: this.tableList[this.curIndex].id,
related_resource_type: {
system_id,
type,
name,
condition: condition.filter(item => item.attributes.length > 0 || item.instances.length > 0)
},
reverse: true,
groupId: this.groupId,
policy_id: this.tableList[this.curIndex].policy_id,
resource_group_id: this.tableList[this.curIndex].resource_groups[this.curGroupIndex].id,
isTemplate: this.tableList[this.curIndex].isTemplate,
isNotLimit: conditionData.length === 0
};
this.previewDialogTitle = this.$t(`m.info['操作侧边栏操作的资源实例差异对比']`, { value: `${this.$t(`m.common['【']`)}${this.tableList[this.curIndex].name}${this.$t(`m.common['】']`)}` });
this.isShowPreviewDialog = true;
},
handlerConditionMouseover (payload) {
if (Object.keys(this.curCopyParams).length < 1 && this.curCopyMode === 'normal') {
return;
Expand Down

0 comments on commit c429bc1

Please sign in to comment.