Unverified Commit 91120a64 authored by Licho's avatar Licho Committed by GitHub

fix: continuous click task item will open multiply tabs problem. (#1204)

parent 06e66f51
......@@ -63,8 +63,8 @@ type RightClickMenu = {
//将树形节点改为一维数组
const generateList = (data: any, list: any[]) => {
for (let i = 0; i < data.length; i++) {
const node = data[i];
for (const element of data) {
const node = element;
const {name, id, parentId, level} = node;
list.push({name, id, key: id, title: name, parentId, level});
if (node.children) {
......@@ -77,8 +77,8 @@ const generateList = (data: any, list: any[]) => {
// tree树 匹配方法
const getParentKey = (key: number | string, tree: any): any => {
let parentKey;
for (let i = 0; i < tree.length; i++) {
const node = tree[i];
for (const element of tree) {
const node = element;
if (node.children) {
if (node.children.some((item: any) => item.id === key)) {
parentKey = node.id;
......@@ -140,8 +140,7 @@ const StudioTree: React.FC<StudioTreeProps> = (props) => {
const expandList: any[] = generateList(treeData, []);
let expandedKeys: any = expandList.map((item: any) => {
if (item && item.name.indexOf(value) > -1) {
let key = getParentKey(item.key, treeData);
return key;
return getParentKey(item.key, treeData);
}
return null;
})
......@@ -155,11 +154,11 @@ const StudioTree: React.FC<StudioTreeProps> = (props) => {
const result = await getCatalogueTreeData();
let data = result.datas;
let list = data;
for (let i = 0; i < list.length; i++) {
list[i].title = list[i].name;
list[i].key = list[i].id;
if (list[i].isLeaf) {
list[i].icon = getIcon(list[i].type);
for (const element of list) {
element.title = element.name;
element.key = element.id;
if (element.isLeaf) {
element.icon = getIcon(element.type);
}
}
data = convertToTreeData(list, 0);
......@@ -207,43 +206,56 @@ const StudioTree: React.FC<StudioTreeProps> = (props) => {
setIsUploadModalVisible(true);
};
const activeTabCall = (node: TreeDataNode) => {
dispatch && dispatch({
type: "Studio/saveToolHeight",
payload: toolHeight - 0.0001,
});
dispatch && dispatch({
type: "Studio/changeActiveKey",
payload: node.taskId,
});
};
const checkInPans = (node: TreeDataNode) => {
for (let item of tabs?.panes!) {
if (item.key == node.taskId) {
return true;
}
}
return false;
}
const toOpen = (node: TreeDataNode | undefined) => {
if (!available) {
return
}
setAvailable(false);
setTimeout(() => {
setAvailable(true);
}, 200);
if (node?.isLeaf && node.taskId) {
for (let item of tabs.panes) {
if (item.key == node.taskId) {
dispatch && dispatch({
type: "Studio/saveToolHeight",
payload: toolHeight - 0.0001,
});
dispatch && dispatch({
type: "Studio/changeActiveKey",
payload: node.taskId,
});
return;
}
if(checkInPans(node)) {
activeTabCall(node);
return;
}
const result = getInfoById('/api/task', node.taskId);
result.then(result => {
let newTabs = tabs;
let newPane: any = {
title: node!.name,
key: node!.taskId,
title: node.name,
key: node.taskId,
value: (result.datas.statement ? result.datas.statement : ''),
icon: node!.icon,
icon: node.icon,
closable: true,
path: node!.path,
path: node.path,
task: {
session: '',
maxRowNum: 100,
jobName: node!.name,
jobName: node.name,
useResult: true,
useChangeLog: false,
useAutoCancel: false,
......@@ -258,7 +270,11 @@ const StudioTree: React.FC<StudioTreeProps> = (props) => {
monaco: React.createRef(),
metaStore: []
};
newTabs!.activeKey = node!.taskId;
newTabs!.activeKey = node.taskId;
if (checkInPans(node)) {
return;
}
newTabs!.panes!.push(newPane);
dispatch && dispatch({
type: "Studio/saveTabs",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment