Skip to content

Commit 55c2d38

Browse files
committed
fix: fix history tree sort
1 parent a1ff7a8 commit 55c2d38

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

console/atest-ui/src/views/TestingHistoryPanel.vue

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ const handleNodeClick = (data: Tree) => {
6464
}
6565
}
6666
67-
const data = ref([] as Tree[])
67+
const treeData = ref([] as Tree[])
6868
const treeRef = ref<InstanceType<typeof ElTree>>()
6969
const currentNodekey = ref('')
7070
@@ -83,7 +83,8 @@ function loadHistoryTestSuites(storeName: string) {
8383
if (!d.data) {
8484
return
8585
}
86-
Object.keys(d.data).map((k) => {
86+
const sortedKeys = Object.keys(d.data).sort((a, b) => new Date(a) - new Date(b));
87+
sortedKeys.map((k) => {
8788
let suite = {
8889
id: k,
8990
label: k,
@@ -102,12 +103,16 @@ function loadHistoryTestSuites(storeName: string) {
102103
parentID: suite.id
103104
} as Tree)
104105
})
105-
data.value.push(suite)
106+
treeData.value.push(suite)
106107
})
107108
})
108109
}
109110
}
110111
112+
function generateTestCaseID(suiteName: string, caseName: string) {
113+
return suiteName + caseName
114+
}
115+
111116
interface Store {
112117
name: string,
113118
description: string,
@@ -116,19 +121,23 @@ interface Store {
116121
const loginDialogVisible = ref(false)
117122
const stores = ref([] as Store[])
118123
const storesLoading = ref(false)
119-
function loadStores() {
124+
function loadStores(lastSuitName?: string, lastCaseName?: string) {
125+
if (lastSuitName && lastCaseName && lastSuitName !== '' && lastCaseName !== '') {
126+
// get data from emit event
127+
Cache.SetLastTestCaseLocation(lastSuitName, generateTestCaseID(lastSuitName, lastCaseName))
128+
}
129+
120130
storesLoading.value = true
121131
const requestOptions = {
122-
method: 'POST',
123132
headers: {
124133
'X-Auth': API.getToken()
125134
}
126135
}
127-
fetch('/server.Runner/GetStores', requestOptions)
136+
fetch('/api/v1/stores', requestOptions)
128137
.then(API.DefaultResponseProcess)
129138
.then(async (d) => {
130139
stores.value = d.data
131-
data.value = [] as Tree[]
140+
treeData.value = [] as Tree[]
132141
Cache.SetStores(d.data)
133142
134143
for (const item of d.data) {
@@ -137,13 +146,14 @@ function loadStores() {
137146
}
138147
}
139148
140-
if (data.value.length > 0) {
149+
if (treeData.value.length > 0) {
141150
const key = Cache.GetLastTestCaseLocation()
151+
142152
let targetSuite = {} as Tree
143153
let targetChild = {} as Tree
144154
if (key.suite !== '' && key.testcase !== '') {
145-
for (var i = 0; i < data.value.length; i++) {
146-
const item = data.value[i]
155+
for (var i = 0; i < treeData.value.length; i++) {
156+
const item = treeData.value[i]
147157
if (item.id === key.suite && item.children) {
148158
for (var j = 0; j < item.children.length; j++) {
149159
const child = item.children[j]
@@ -158,16 +168,18 @@ function loadStores() {
158168
}
159169
}
160170
if (!targetChild.id || targetChild.id === '') {
161-
targetSuite = data.value[0]
171+
targetSuite = treeData.value[0]
162172
if (targetSuite.children && targetSuite.children.length > 0) {
163173
targetChild = targetSuite.children[0]
164174
}
165175
}
166176
167177
viewName.value = 'testsuite'
168178
currentNodekey.value = targetChild.id
179+
169180
treeRef.value!.setCurrentKey(targetChild.id)
170181
treeRef.value!.setCheckedKeys([targetChild.id], false)
182+
171183
testSuite.value = targetSuite.label
172184
Cache.SetCurrentStore(targetSuite.store)
173185
testKind.value = targetChild.kind
@@ -233,7 +245,7 @@ const deviceAuthNext = () => {
233245

234246
<el-tree
235247
v-loading="storesLoading"
236-
:data=data
248+
:data=treeData
237249
highlight-current
238250
:check-on-click-node="true"
239251
:expand-on-click-node="false"

0 commit comments

Comments
 (0)