Skip to content

Commit

Permalink
[apache#5042] fix(ui): show the expend arrow when reload tree node
Browse files Browse the repository at this point in the history
  • Loading branch information
LauraXia123 committed Sep 29, 2024
1 parent 3c5d20f commit 6a05b44
Show file tree
Hide file tree
Showing 3 changed files with 27 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
25 changes: 23 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,41 @@ 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 +954,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 6a05b44

Please sign in to comment.