-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Fixed the problem of directory hiding in test case page and test plan page #161
Closed
sherotree
wants to merge
1
commit into
erda-project:release/1.0
from
sherotree:hotfix/wy-display-first-add-test-set
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,7 @@ const { DirectoryTree, TreeNode } = Tree; | |
interface IActionItem { | ||
key: string; | ||
name: string; | ||
onclick: (prop: any)=>void; | ||
onclick: (prop: any) => void; | ||
} | ||
interface IProps { | ||
mode: TEST_CASE.PageScope | ||
|
@@ -59,7 +59,7 @@ interface ITree { | |
testSetID: number | ||
} | ||
|
||
const mergeTree = (source: IExpandTree[], child:IExpandTree) => { | ||
const mergeTree = (source: IExpandTree[], child: IExpandTree) => { | ||
const curItem = source.find(item => item.id === child.id); | ||
if (!curItem) { | ||
source.push(child); | ||
|
@@ -102,21 +102,20 @@ const TestSet = ({ | |
const projectInfo = projectStore.useStore(s => s.info); | ||
const { getCases } = testCaseStore.effects; | ||
const { triggerChoosenAll: resetChoosenAll } = testCaseStore.reducers; | ||
const isAddNodeFromOuterRef = React.useRef(false); | ||
|
||
const testSet:{[k in TEST_CASE.PageScope]: any} = { | ||
const testSet: { [k in TEST_CASE.PageScope]: any } = { | ||
testCase: projectTestSet, | ||
testPlan: projectTestSet, | ||
caseModal: modalTestSet, | ||
temp: tempTestSet, | ||
}; | ||
const setRef = React.useRef(testSet); | ||
const currentTestSet: TEST_SET.TestSet[] = React.useMemo(() => setRef.current[mode], [setRef, mode]); | ||
const currentTestSet: TEST_SET.TestSet[] = testSet[mode]; | ||
|
||
useMount(() => { | ||
getProjectTestSets({ testPlanID, mode, recycled: false, parentID: rootId, forceUpdate: true }); | ||
}); | ||
|
||
|
||
const loadTreeNode = (arr: string[], isInRecycleBin = false) => { | ||
arr.reduce(async (prev, curr) => { | ||
await prev; | ||
|
@@ -137,6 +136,7 @@ const TestSet = ({ | |
newNode, | ||
...(parent.children || []), | ||
]; | ||
isAddNodeFromOuterRef.current = true; | ||
setTreeData([...treeData]); | ||
}; | ||
const reloadLoadData = (id: number, eventKey: string, recycled: boolean) => { | ||
|
@@ -147,7 +147,7 @@ const TestSet = ({ | |
} | ||
}; | ||
|
||
const updateTree = (tree: IExpandTree[], data:ITree[], newTreeData: TEST_SET.TestSetNode[]) => { | ||
const updateTree = (tree: IExpandTree[], data: ITree[], newTreeData: TEST_SET.TestSetNode[]) => { | ||
tree.forEach(({ id, children }) => { | ||
const newTree = data.find(item => item.testSetID === id); | ||
if (!isEmpty(newTree)) { | ||
|
@@ -167,10 +167,10 @@ const TestSet = ({ | |
}); | ||
}; | ||
|
||
const [expandTree, expandIds] = React.useMemo<[IExpandTree[], Array<{id: number, key: string; pKey: string}>]>(() => { | ||
const [expandTree, expandIds] = React.useMemo<[IExpandTree[], Array<{ id: number, key: string; pKey: string }>]>(() => { | ||
const result: IExpandTree[] = []; | ||
// 展开节点ID,需去重,防止一个节点请求多次 | ||
const temp: Array<{id: number, key: string, pKey: string}> = []; | ||
const temp: Array<{ id: number, key: string, pKey: string }> = []; | ||
// 最深层级路径 | ||
const deepestPath: string[] = []; | ||
const keys = [...expandedKeys]; | ||
|
@@ -210,14 +210,14 @@ const TestSet = ({ | |
} else { | ||
let newActiveKey = rootKey; | ||
let tempIndex = 0; | ||
const promiseArr: Array<PromiseLike<{testSetID: number; key: string;pKey: string; list: TEST_SET.TestSet[]}>> = []; | ||
const promiseArr: Array<PromiseLike<{ testSetID: number; key: string; pKey: string; list: TEST_SET.TestSet[] }>> = []; | ||
expandIds.forEach(({ id, key, pKey }) => { | ||
promiseArr.push(getTestSetChildren({ testPlanID, recycled: false, parentID: id, mode }).then(res => ({ testSetID: id, key, pKey, list: res || [] }))); | ||
}); | ||
// 请求所有展开的节点 | ||
Promise.all(promiseArr).then(data => { | ||
const activeKeys = activeKey.split('-'); | ||
const trees:ITree[] = []; | ||
const trees: ITree[] = []; | ||
data.forEach(({ list, key, pKey, testSetID }) => { | ||
const targetIndex = activeKeys.findIndex(t => t === `${testSetID}`); | ||
if (targetIndex !== -1 && !!list.length) { | ||
|
@@ -264,35 +264,42 @@ const TestSet = ({ | |
// onSelect([rootKey]); | ||
firstBuild.current = false; | ||
} | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [treeData, query.caseId]); | ||
|
||
useEffect(() => { | ||
if (activeOuter) { | ||
onAddNode(rootKey); | ||
clearActiveOuter(); | ||
} | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can u remove these lint disable line? |
||
}, [activeOuter]); | ||
|
||
useEffect(() => { | ||
const normalNodes: TEST_SET.TestSetNode[] = currentTestSet.map(({ id, name, recycled, parentID }: any) => ({ title: name, key: `${rootKey}-${id}`, id, recycled, parentID, isLeaf: false })); | ||
const nextActiveKey = firstBuild.current && query.eventKey && needActiveKey ? query.eventKey : rootKey; | ||
setActiveKey(nextActiveKey); | ||
setExpandedKeys([rootKey]); | ||
setTreeData([ | ||
{ | ||
title: projectInfo.name, | ||
key: rootKey, | ||
id: rootId, | ||
iconType: 'project', | ||
iconClass: 'color-info', | ||
parentID: rootId, | ||
isLeaf: false, | ||
recycled: false, | ||
children: needRecycled ? normalNodes.concat([{ ...recycledRoot }]) : normalNodes, | ||
}, | ||
]); | ||
|
||
// prevent setTreeData while execute addNodeFromOuter | ||
if (!isAddNodeFromOuterRef.current) { | ||
setTreeData([ | ||
{ | ||
title: projectInfo.name, | ||
key: rootKey, | ||
id: rootId, | ||
iconType: 'project', | ||
iconClass: 'color-info', | ||
parentID: rootId, | ||
isLeaf: false, | ||
recycled: false, | ||
children: needRecycled ? normalNodes.concat([{ ...recycledRoot }]) : normalNodes, | ||
}, | ||
]); | ||
} | ||
|
||
// reset isAddNodeFromOuterRef to false | ||
isAddNodeFromOuterRef.current = false; | ||
|
||
if (needBreadcrumb) { | ||
updateBreadcrumb({ | ||
|
@@ -301,10 +308,11 @@ const TestSet = ({ | |
testPlanID, | ||
}); | ||
} | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [currentTestSet, projectInfo]); | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [currentTestSet, projectInfo, isAddNodeFromOuterRef]); | ||
|
||
useEffect(() => { | ||
const expandId:string[] = (query.eventKey || '').split('-'); | ||
const expandId: string[] = (query.eventKey || '').split('-'); | ||
// 是否为回收站内的case | ||
const isInRecycleBin = expandId.includes('recycled'); | ||
// 测试计划测试用例需要打开分享链接 | ||
|
@@ -329,7 +337,7 @@ const TestSet = ({ | |
loadTreeNode(eventKeys.splice(1), isInRecycleBin); | ||
} | ||
} | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [treeData, query.caseId, query.eventKey, mode, query.testSetID, getCases, testPlanID]); | ||
|
||
// 复制/移动/引入测试集 | ||
|
@@ -354,7 +362,7 @@ const TestSet = ({ | |
onRemoveNode(currentNode.key); | ||
} | ||
} | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [reloadTestSetInfo]); | ||
|
||
const renderTreeNodes = (data: any[]) => data.map((item) => { | ||
|
@@ -618,8 +626,8 @@ const TestSet = ({ | |
}); | ||
updateSearch({ pageNo: 1, recycled, testSetID, eventKey }); | ||
|
||
// 页面刚刚进来时保持当前 query 不进行更新 | ||
if (!_extra.keepCurrentSearch) { | ||
// 页面刚刚进来时保持当前 query 不进行更新 | ||
if (!_extra.keepCurrentSearch) { | ||
updateSearch({ pageNo: 1, recycled, testSetID, eventKey }); | ||
} | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
define ref type