fix: autosort
This commit is contained in:
parent
aed7562acb
commit
19c4668b3c
|
@ -18,6 +18,15 @@ const decorate = compose(
|
||||||
|
|
||||||
const rootUri = '/resources/cha0s/initial';
|
const rootUri = '/resources/cha0s/initial';
|
||||||
|
|
||||||
|
const sortTree = (tree) => {
|
||||||
|
tree.sort((l, r) => l.title.localeCompare(r.title));
|
||||||
|
if (tree.children) {
|
||||||
|
// eslint-disable-next-line no-param-reassign
|
||||||
|
tree.children = sortTree(tree.children);
|
||||||
|
}
|
||||||
|
return tree;
|
||||||
|
};
|
||||||
|
|
||||||
const Sidebar = () => {
|
const Sidebar = () => {
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const [treeData, setTreeData] = useState([]);
|
const [treeData, setTreeData] = useState([]);
|
||||||
|
@ -51,14 +60,6 @@ const Sidebar = () => {
|
||||||
visited[node.id] = true;
|
visited[node.id] = true;
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
const sortTree = (tree) => {
|
|
||||||
tree.sort((l, r) => l.title.localeCompare(r.title));
|
|
||||||
if (tree.children) {
|
|
||||||
// eslint-disable-next-line no-param-reassign
|
|
||||||
tree.children = sortTree(tree.children);
|
|
||||||
}
|
|
||||||
return tree;
|
|
||||||
};
|
|
||||||
setTreeData(sortTree(getTreeFromFlatData({
|
setTreeData(sortTree(getTreeFromFlatData({
|
||||||
flatData: nodes,
|
flatData: nodes,
|
||||||
rootKey: '',
|
rootKey: '',
|
||||||
|
@ -87,7 +88,8 @@ const Sidebar = () => {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
})}
|
})}
|
||||||
onChange={setTreeData}
|
// eslint-disable-next-line no-shadow
|
||||||
|
onChange={(treeData) => setTreeData(sortTree(treeData))}
|
||||||
theme={FileExplorerTheme}
|
theme={FileExplorerTheme}
|
||||||
treeData={treeData}
|
treeData={treeData}
|
||||||
/>
|
/>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user