Skip to content

Commit

Permalink
feat: Select the tree node to display the background color infiniflow…
Browse files Browse the repository at this point in the history
  • Loading branch information
cike8899 committed Oct 31, 2024
1 parent 520372f commit 14af712
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 50 deletions.
37 changes: 7 additions & 30 deletions gui/app/(dashboard)/database/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,14 @@ export const useHandleClickTreeName = () => {
name: string;
parent: TreeParentId;
data: INode[];
}) =>
() => {
if (level === 3) {
const databaseId = getParentIdById(data, parent);
if (databaseId) {
router.push(`/database/${databaseId}/table/${parent}?tab=${name}`);
}
}) => {
if (level === 3) {
const databaseId = getParentIdById(data, parent);
if (databaseId) {
router.push(`/database/${databaseId}/table/${parent}?tab=${name}`);
}
},
}
},
[router]
);

Expand Down Expand Up @@ -132,28 +131,6 @@ export const useBuildTreeData = () => {
await fetchTables(element.id as string);

return undefined;
// return new Promise((resolve) => {
// setTimeout(() => {
// setData((value) =>
// updateTreeData(value, element.id, [
// {
// name: `Child Node ${value.length}`,
// children: [],
// id: value.length,
// parent: element.id,
// isBranch: true
// },
// {
// name: 'Another child Node',
// children: [],
// id: value.length + 1,
// parent: element.id
// }
// ])
// );
// resolve(undefined);
// }, 1000);
// });
};

const wrappedOnLoadData = async (props: ITreeViewOnLoadDataProps) => {
Expand Down
10 changes: 7 additions & 3 deletions gui/app/(dashboard)/database/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,15 @@
}

.tree-node:hover {
background: rgba(255, 255, 255, 0.1);
background: rgb(240, 244, 254);
}

.tree-node--focused {
background-color: #d7d7d7;
.tree .tree-node--focused {
background: rgba(255, 255, 255, 0.2);
}

.tree .tree-node--selected {
background: rgb(213, 222, 249);
}

.arrow--open {
Expand Down
36 changes: 19 additions & 17 deletions gui/app/(dashboard)/database/tree.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use client';

import cx from 'classnames';
import TreeView, { INode } from 'react-accessible-treeview';
import TreeView, { EventCallback, INode } from 'react-accessible-treeview';
import { AiOutlineLoading } from 'react-icons/ai';
import { IoMdArrowDropright } from 'react-icons/io';
import { Leaf, LeafIconMap } from './constants';
Expand Down Expand Up @@ -40,22 +40,31 @@ function AsyncTree() {
></div>
<TreeView
data={data}
aria-label="Checkbox tree"
aria-label="directory tree"
onLoadData={wrappedOnLoadData}
propagateSelect
togglableSelect
propagateSelectUpwards
nodeRenderer={({
element,
isBranch,
isExpanded,
// isSelected,
// isHalfSelected,
// handleSelect,
getNodeProps,
level,
handleExpand
handleExpand,
handleSelect
}) => {
const handleNodeClick: EventCallback = (e) => {
handleSelect(e);
if (isBranch) {
handleExpand(e);
} else {
handleClickTreeName({
level,
name: element.name,
parent: element.parent,
data
});
}
};

const branchNode = (isExpanded: boolean, element: INode) => {
return isExpanded &&
!element.metadata?.isEmpty &&
Expand All @@ -77,14 +86,7 @@ function AsyncTree() {
return (
<div
{...getNodeProps({
onClick: isBranch
? handleExpand
: handleClickTreeName({
level,
name: element.name,
parent: element.parent,
data
})
onClick: handleNodeClick
})}
style={{ marginLeft: 40 * (level - 1) }}
>
Expand Down

0 comments on commit 14af712

Please sign in to comment.