Skip to content

Commit

Permalink
[Feature-4139] Support data studio catalog tree list scroll interacti…
Browse files Browse the repository at this point in the history
…on and search (#4141)
  • Loading branch information
MactavishCui authored Jan 13, 2025
1 parent 5c1e93e commit 7f6faa1
Showing 1 changed file with 36 additions and 9 deletions.
45 changes: 36 additions & 9 deletions dinky-web/src/pages/DataStudio/Toolbar/Catalog/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@ import { Button, Col, Empty, Flex, Modal, Row, Select, Spin } from 'antd';
import { DataNode } from 'antd/es/tree';
import DirectoryTree from 'antd/es/tree/DirectoryTree';
import { DefaultOptionType } from 'rc-select/lib/Select';
import React, { useEffect, useState } from 'react';
import React, { useCallback, useEffect, useState } from 'react';
import { getMSCatalogs, getMSColumns, getMSSchemaInfo } from './service';
import { useAsyncEffect } from 'ahooks';
import { CenterTab, DataStudioState } from '@/pages/DataStudio/model';
import { mapDispatchToProps } from '@/pages/DataStudio/DvaFunction';
import { isSql } from '@/pages/DataStudio/utils';
import { TableDataNode } from '@/pages/DataStudio/Toolbar/Catalog/data';
import { DataStudioActionType } from '@/pages/DataStudio/data.d';
import Search from "antd/es/input/Search";

type CatalogState = {
envId?: number;
Expand All @@ -65,6 +66,7 @@ const Catalog = (props: {
const [row, setRow] = useState<TableDataNode>();
const [loading, setLoading] = useState<boolean>(false);
const [currentState, setCurrentState] = useState<CatalogState>();
const [searchValue, setSearchValue] = useState('');

const currentData = tabs.find((tab) => activeTab == tab.id);

Expand Down Expand Up @@ -335,6 +337,22 @@ const Catalog = (props: {
setModalVisit(false);
setTable('');
};

const buildCatalogTree = (data: any, searchValue = ''): any =>
data.map((item: any) => {
return {
...item,
children: item.children.filter((child: any) => child.title.indexOf(searchValue) > -1)
};
});

const onSearchChange = useCallback(
(e: { target: { value: React.SetStateAction<string> } }) => {
setSearchValue(e.target.value);
},
[searchValue]
);

// <Empty description={l('pages.datastudio.catalog.openMission')}/>;
return (
<Spin spinning={loading} style={{ height: 'inherit' }}>
Expand All @@ -351,15 +369,24 @@ const Catalog = (props: {
/>
</Col>
</Row>

{treeData.length > 0 ? (
<DirectoryTree
showIcon
switcherIcon={<DownOutlined />}
treeData={treeData}
onRightClick={({ node }: any) => openColumnInfo(node)}
onSelect={(_, info: any) => openColumnInfo(info.node)}
/>
<>
<Search
style={{ margin: '8px 0px' }}
placeholder={l('global.search.text')}
onChange={onSearchChange}
allowClear={true}
defaultValue={searchValue}
/>
<DirectoryTree
showIcon
switcherIcon={<DownOutlined />}
className={'treeList'}
treeData={buildCatalogTree(treeData, searchValue)}
onRightClick={({ node }: any) => openColumnInfo(node)}
onSelect={(_, info: any) => openColumnInfo(info.node)}
/>
</>
) : (
<Empty image={Empty.PRESENTED_IMAGE_SIMPLE} />
)}
Expand Down

0 comments on commit 7f6faa1

Please sign in to comment.