Refactor ObjectSelect component to improve code clarity and maintainability
- Removed unnecessary whitespace to enhance code readability. - Streamlined data handling logic for better performance and consistency. - Improved structure of the loadData function for clearer data fetching and processing.
This commit is contained in:
parent
e423f32493
commit
dcf90469f4
@ -52,7 +52,6 @@ const ObjectSelect = ({
|
||||
} else {
|
||||
setObjectPropertiesTree((prev) => merge({}, prev, data))
|
||||
}
|
||||
|
||||
setInitialLoading(false)
|
||||
setError(false)
|
||||
return data
|
||||
@ -96,7 +95,6 @@ const ObjectSelect = ({
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
if (typeof data == 'object') {
|
||||
const property = properties[pIdx] || null
|
||||
return Object.entries(data)
|
||||
@ -131,7 +129,6 @@ const ObjectSelect = ({
|
||||
const loadData = async (node) => {
|
||||
// node.property is the property name, node.value is the value
|
||||
if (!node.property) return
|
||||
|
||||
// Build filter for this node by merging all parent property-value pairs
|
||||
const customFilter = { ...filter }
|
||||
if (Array.isArray(node.filterPath)) {
|
||||
@ -140,18 +137,15 @@ const ObjectSelect = ({
|
||||
})
|
||||
}
|
||||
customFilter[node.property] = node.value
|
||||
|
||||
// Fetch children for this node
|
||||
const data = await handleFetchObjectsProperties(customFilter)
|
||||
if (!data) return
|
||||
|
||||
// Extract only the children for the specific node that was expanded
|
||||
let nodeSpecificData = data
|
||||
if (typeof data === 'object' && !Array.isArray(data)) {
|
||||
// If the API returns an object with multiple keys, get only the data for this node
|
||||
nodeSpecificData = data[node.value] || {}
|
||||
}
|
||||
|
||||
// Build new children only for this specific node
|
||||
const children = buildTreeData(
|
||||
nodeSpecificData,
|
||||
@ -162,7 +156,6 @@ const ObjectSelect = ({
|
||||
value: node.value
|
||||
})
|
||||
)
|
||||
|
||||
// Update treeData with new children for this node only
|
||||
setTreeData((prevTreeData) => {
|
||||
// Helper to recursively update the correct node
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user