Skip to content

Commit

Permalink
Merge pull request TencentBlueKing#2647 from lhzzforever/dev/develop_ci
Browse files Browse the repository at this point in the history
fix: 修复全平台ip选择器不同拓扑下相同类型的子集数据会被去重遗漏
  • Loading branch information
ielgnaw authored May 9, 2024
2 parents aa48d9c + 414bd30 commit 989d0d1
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 26 deletions.
34 changes: 24 additions & 10 deletions frontend/src/components/choose-ip/grade.vue
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,15 @@
const hasNode = {};
const treeData = [...this.treeData];
const list = treeData.reduce((curr, next) => {
// eslint-disable-next-line no-unused-expressions
hasNode[`${next.name}&${next.id}`] ? '' : hasNode[`${next.name}&${next.id}`] = true && curr.push(next);
// hasNode[next.name] ? '' : hasNode[next.name] = true && curr.push(next);
if (next.level > 0 && next.parentChain && next.parentChain.length > 0) {
const chainContent = next.parentChain.map((v) => `${v.id}&${v.name}&${v.type}`).join();
// eslint-disable-next-line no-unused-expressions
hasNode[`${next.id}&${next.name}&${chainContent}`] ? ''
: hasNode[`${next.id}&${next.name}&${chainContent}`] = true && curr.push(next);
} else {
// eslint-disable-next-line no-unused-expressions
hasNode[`${next.name}&${next.id}`] ? '' : hasNode[`${next.name}&${next.id}`] = true && curr.push(next);
}
return curr;
}, []);
return list;
Expand Down Expand Up @@ -422,7 +428,8 @@
handleOnExpanded (index, expanded) {
window.changeAlert = true;
if (!expanded && this.treeData[index + 2].type === 'search-empty') {
const searchEmptyData = this.treeData[index + 2];
if (!expanded && searchEmptyData && searchEmptyData.type === 'search-empty') {
this.treeData.splice(index + 2, 1);
}
},
Expand Down Expand Up @@ -1167,12 +1174,19 @@
removeAsyncNode () {
// 需要过滤掉name为空以及反复切换选中造成的重复数据的节点
const obj = {};
const treeList = _.cloneDeep(this.treeData.filter(item => item.name));
this.treeData = treeList.reduce((pre, item) => {
// eslint-disable-next-line no-unused-expressions
obj[`${item.id}${item.name}`] ? '' : obj[`${item.id}${item.name}`] = true && pre.push(item);
return pre;
const hasNode = {};
const treeList = _.cloneDeep(this.treeData.filter(item => item.name !== ''));
this.treeData = treeList.reduce((curr, next) => {
if (next.level > 0 && next.parentChain && next.parentChain.length > 0) {
const chainContent = next.parentChain.map((v) => `${v.id}&${v.name}&${v.type}`).join();
// eslint-disable-next-line no-unused-expressions
hasNode[`${next.id}&${next.name}&${chainContent}`] ? ''
: hasNode[`${next.id}&${next.name}&${chainContent}`] = true && curr.push(next);
} else {
// eslint-disable-next-line no-unused-expressions
hasNode[`${next.name}&${next.id}`] ? '' : hasNode[`${next.name}&${next.id}`] = true && curr.push(next);
}
return curr;
}, []);
const index = this.treeData.findIndex(item => item.type === 'async');
if (index > -1) this.treeData.splice(index, 1);
Expand Down
35 changes: 25 additions & 10 deletions frontend/src/components/choose-ip/grade/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,15 @@
const hasNode = {};
const treeData = [...this.treeData];
const list = treeData.reduce((curr, next) => {
// eslint-disable-next-line no-unused-expressions
hasNode[`${next.name}&${next.id}`] ? '' : hasNode[`${next.name}&${next.id}`] = true && curr.push(next);
if (next.level > 0 && next.parentChain && next.parentChain.length > 0) {
const chainContent = next.parentChain.map((v) => `${v.id}&${v.name}&${v.type}`).join();
// eslint-disable-next-line no-unused-expressions
hasNode[`${next.id}&${next.name}&${chainContent}`] ? ''
: hasNode[`${next.id}&${next.name}&${chainContent}`] = true && curr.push(next);
} else {
// eslint-disable-next-line no-unused-expressions
hasNode[`${next.name}&${next.id}`] ? '' : hasNode[`${next.name}&${next.id}`] = true && curr.push(next);
}
return curr;
}, []);
return list;
Expand Down Expand Up @@ -603,7 +610,8 @@
handleOnExpanded (index, expanded) {
window.changeAlert = true;
if (!expanded && this.treeData[index + 2].type === 'search-empty') {
const searchEmptyData = this.treeData[index + 2];
if (!expanded && searchEmptyData && searchEmptyData.type === 'search-empty') {
this.treeData.splice(index + 2, 1);
}
},
Expand Down Expand Up @@ -1681,14 +1689,21 @@
removeAsyncNode () {
// 需要过滤掉name为空以及反复切换选中造成的重复数据的节点
const obj = {};
const treeList = _.cloneDeep(this.treeData.filter(item => item.name));
this.treeData = treeList.reduce((pre, item) => {
// eslint-disable-next-line no-unused-expressions
obj[`${item.id}${item.name}`] ? '' : obj[`${item.id}${item.name}`] = true && pre.push(item);
return pre;
const hasNode = {};
const treeList = _.cloneDeep(this.treeData.filter(item => item.name !== ''));
this.treeData = treeList.reduce((curr, next) => {
if (next.level > 0 && next.parentChain && next.parentChain.length > 0) {
const chainContent = next.parentChain.map((v) => `${v.id}&${v.name}&${v.type}`).join();
// eslint-disable-next-line no-unused-expressions
hasNode[`${next.id}&${next.name}&${chainContent}`] ? ''
: hasNode[`${next.id}&${next.name}&${chainContent}`] = true && curr.push(next);
} else {
// eslint-disable-next-line no-unused-expressions
hasNode[`${next.name}&${next.id}`] ? '' : hasNode[`${next.name}&${next.id}`] = true && curr.push(next);
}
return curr;
}, []);
const index = this.treeData.findIndex((item) => item.type === 'async');
const index = this.treeData.findIndex(item => item.type === 'async');
if (index > -1) this.treeData.splice(index, 1);
},
Expand Down
8 changes: 2 additions & 6 deletions frontend/src/components/choose-ip/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,6 @@
renderTopologyData () {
const hasNode = {};
const treeData = [...this.treeData];
console.log(treeData, '去重前的数据');
const list = treeData.reduce((curr, next) => {
if (next.level > 0 && next.parentChain && next.parentChain.length > 0) {
const chainContent = next.parentChain.map((v) => `${v.id}&${v.name}&${v.type}`).join();
Expand All @@ -382,7 +381,6 @@
}
return curr;
}, []);
console.log(list, '去重后的数据');
return list;
},
getSystemParams () {
Expand Down Expand Up @@ -462,7 +460,8 @@
handleOnExpanded (index, expanded) {
window.changeAlert = true;
if (!expanded && this.treeData[index + 2] && this.treeData[index + 2].type === 'search-empty') {
const searchEmptyData = this.treeData[index + 2];
if (!expanded && searchEmptyData && searchEmptyData.type === 'search-empty') {
this.treeData.splice(index + 2, 1);
}
},
Expand Down Expand Up @@ -1299,11 +1298,9 @@
// 需要过滤掉name为空以及反复切换选中造成的重复数据的节点
const hasNode = {};
const treeList = _.cloneDeep(this.treeData.filter(item => item.name !== ''));
console.log(treeList, 'remove前');
this.treeData = treeList.reduce((curr, next) => {
if (next.level > 0 && next.parentChain && next.parentChain.length > 0) {
const chainContent = next.parentChain.map((v) => `${v.id}&${v.name}&${v.type}`).join();
console.log(chainContent, '父级数据');
// eslint-disable-next-line no-unused-expressions
hasNode[`${next.id}&${next.name}&${chainContent}`] ? ''
: hasNode[`${next.id}&${next.name}&${chainContent}`] = true && curr.push(next);
Expand All @@ -1313,7 +1310,6 @@
}
return curr;
}, []);
console.log(this.treeData, 'remove前后');
const index = this.treeData.findIndex(item => item.type === 'async');
if (index > -1) this.treeData.splice(index, 1);
},
Expand Down

0 comments on commit 989d0d1

Please sign in to comment.