Skip to content

Commit

Permalink
[#5042] fix(ui): show the expend arrow when reload tree node (#5043)
Browse files Browse the repository at this point in the history
### What changes were proposed in this pull request?

show the expend arrow when reload tree node
<img width="707" alt="image"
src="https://github.com/user-attachments/assets/338655e6-03ac-4fec-a6fd-05756cfcaced">
<img width="614" alt="image"
src="https://github.com/user-attachments/assets/70e1669c-4faa-45ed-aa86-c6ff7195a091">
<img width="633" alt="image"
src="https://github.com/user-attachments/assets/df09f9a5-18b0-4b47-a4e8-418c88a6cff8">


### Why are the changes needed?
show the correct info after reload tree node

Fix: #5042

### Does this PR introduce _any_ user-facing change?
N/A

### How was this patch tested?
manually
  • Loading branch information
LauraXia123 authored Sep 30, 2024
1 parent 328efb8 commit 2e5bdbf
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
2 changes: 1 addition & 1 deletion web/web/src/app/metalakes/metalake/MetalakeTree.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ const MetalakeTree = props => {
break
}
default:
dispatch(setIntoTreeNodeWithFetch({ key: nodeProps.data.key }))
dispatch(setIntoTreeNodeWithFetch({ key: nodeProps.data.key, reload: true }))
}
}

Expand Down
26 changes: 24 additions & 2 deletions web/web/src/lib/store/metalakes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export const updateMetalake = createAsyncThunk('appMetalakes/updateMetalake', as

export const setIntoTreeNodeWithFetch = createAsyncThunk(
'appMetalakes/setIntoTreeNodeWithFetch',
async ({ key }, { getState, dispatch }) => {
async ({ key, reload }, { getState, dispatch }) => {
let result = {
key,
data: [],
Expand Down Expand Up @@ -137,20 +137,42 @@ export const setIntoTreeNodeWithFetch = createAsyncThunk(
}

const { identifiers = [] } = res
const expandedKeys = getState().metalakes.expandedNodes
const loadedNodes = getState().metalakes.loadedNodes
let reloadedEpxpandedKeys = []
let reloadedKeys = []

result.data = identifiers.map(schemaItem => {
if (reload) {
if (expandedKeys.includes(`{{${metalake}}}{{${catalog}}}{{${type}}}{{${schemaItem.name}}}`)) {
reloadedEpxpandedKeys.push(`{{${metalake}}}{{${catalog}}}{{${type}}}{{${schemaItem.name}}}`)
}
if (loadedNodes.includes(`{{${metalake}}}{{${catalog}}}{{${type}}}{{${schemaItem.name}}}`)) {
reloadedKeys.push(`{{${metalake}}}{{${catalog}}}{{${type}}}{{${schemaItem.name}}}`)
}
}

return {
...schemaItem,
node: 'schema',
id: `{{${metalake}}}{{${catalog}}}{{${type}}}{{${schemaItem.name}}}`,
key: `{{${metalake}}}{{${catalog}}}{{${type}}}{{${schemaItem.name}}}`,
path: `?${new URLSearchParams({ metalake, catalog, type, schema: schemaItem.name }).toString()}`,
isLeaf: reload ? false : undefined,
name: schemaItem.name,
title: schemaItem.name,
tables: [],
children: []
}
})
if (reloadedEpxpandedKeys.length > 0) {
const epxpanded = expandedKeys.filter(key => !reloadedEpxpandedKeys.includes(key))
dispatch(resetExpandNode(epxpanded))
}
if (reloadedKeys.length > 0) {
const loaded = loadedNodes.filter(key => !reloadedKeys.includes(key))
dispatch(setLoadedNodes(loaded))
}
} else if (pathArr.length === 4 && type === 'relational') {
const [err, res] = await to(getTablesApi({ metalake, catalog, schema }))

Expand Down Expand Up @@ -933,7 +955,7 @@ export const appMetalakesSlice = createSlice({
state.expandedNodes = expandedNodes
},
resetExpandNode(state, action) {
state.expandedNodes = []
state.expandedNodes = action.payload || []
},
resetTableData(state, action) {
state.tableData = []
Expand Down
4 changes: 3 additions & 1 deletion web/web/src/lib/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,14 @@ export const updateTreeData = (list = [], key, children = []) => {
if (node.key === key) {
return {
...node,
isLeaf: children?.length === 0,
children
}
}
if (node.children) {
if (node.children && node.children.length > 0) {
return {
...node,
isLeaf: node.children.length === 0,
children: updateTreeData(node.children, key, children)
}
}
Expand Down

0 comments on commit 2e5bdbf

Please sign in to comment.