Unverified Commit 10fdbdec authored by Zzm0809's avatar Zzm0809 Committed by GitHub

[Bug] fix job list search and positioning functions's problems (#3481)

parent e16b3010
...@@ -689,3 +689,11 @@ span .mtkb { ...@@ -689,3 +689,11 @@ span .mtkb {
.ant-notification-notice-wrapper { .ant-notification-notice-wrapper {
top: 80px !important; top: 80px !important;
} }
// 组件鼠标悬停时 圆角 50% 背景色灰色
.icon-btn-hover {
:hover {
background-color: #aba4a4;
border-radius: 50%;
}
}
...@@ -232,5 +232,8 @@ export default { ...@@ -232,5 +232,8 @@ export default {
'global.job.status.reconciling': 'Reconciling', 'global.job.status.reconciling': 'Reconciling',
'global.job.status.reconnecting': 'Reconnecting', 'global.job.status.reconnecting': 'Reconnecting',
'global.job.status.unknown': 'Unknown', 'global.job.status.unknown': 'Unknown',
'global.job.status.failed-tip': 'Failed to submit to the cluster, unable to get the task name' 'global.job.status.failed-tip': 'Failed to submit to the cluster, unable to get the task name',
'global.operation.unable': 'Unable to operate',
'global.operation.able': 'Can operate'
}; };
...@@ -228,5 +228,8 @@ export default { ...@@ -228,5 +228,8 @@ export default {
'global.job.status.reconciling': '调节中', 'global.job.status.reconciling': '调节中',
'global.job.status.reconnecting': '重连中', 'global.job.status.reconnecting': '重连中',
'global.job.status.unknown': '未知', 'global.job.status.unknown': '未知',
'global.job.status.failed-tip': '未成功提交到集群,无法获取任务名称/作业ID' 'global.job.status.failed-tip': '未成功提交到集群,无法获取任务名称/作业ID',
'global.operation.unable': '无法操作',
'global.operation.able': '可以操作'
}; };
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
* *
*/ */
import { LeftMenuKey } from '@/pages/DataStudio/data.d';
import { getCurrentData } from '@/pages/DataStudio/function'; import { getCurrentData } from '@/pages/DataStudio/function';
import { isSql } from '@/pages/DataStudio/HeaderContainer/function'; import { isSql } from '@/pages/DataStudio/HeaderContainer/function';
import { BtnRoute, useTasksDispatch } from '@/pages/DataStudio/LeftContainer/BtnContext'; import { BtnRoute, useTasksDispatch } from '@/pages/DataStudio/LeftContainer/BtnContext';
...@@ -74,7 +75,7 @@ const Catalog: React.FC = (props: connect) => { ...@@ -74,7 +75,7 @@ const Catalog: React.FC = (props: connect) => {
const [loading, setLoading] = useState<boolean>(false); const [loading, setLoading] = useState<boolean>(false);
const [columnData, setColumnData] = useState([]); const [columnData, setColumnData] = useState([]);
const btnDispatch = useTasksDispatch(); const btnDispatch = useTasksDispatch();
const currentTabName = 'menu.datastudio.catalog'; const currentTabName = LeftMenuKey.CATALOG_KEY;
const btnEvent = [...BtnRoute[currentTabName]]; const btnEvent = [...BtnRoute[currentTabName]];
btnEvent[0].onClick = () => { btnEvent[0].onClick = () => {
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
*/ */
import { TagAlignLeft } from '@/components/StyledComponents'; import { TagAlignLeft } from '@/components/StyledComponents';
import { LeftMenuKey } from '@/pages/DataStudio/data.d';
import { BtnRoute, useTasksDispatch } from '@/pages/DataStudio/LeftContainer/BtnContext'; import { BtnRoute, useTasksDispatch } from '@/pages/DataStudio/LeftContainer/BtnContext';
import SchemaTree from '@/pages/RegCenter/DataSource/components/DataSourceDetail/SchemaTree'; import SchemaTree from '@/pages/RegCenter/DataSource/components/DataSourceDetail/SchemaTree';
import DataSourceModal from '@/pages/RegCenter/DataSource/components/DataSourceModal'; import DataSourceModal from '@/pages/RegCenter/DataSource/components/DataSourceModal';
...@@ -88,7 +89,7 @@ const DataSource = (props: any) => { ...@@ -88,7 +89,7 @@ const DataSource = (props: any) => {
const onChangeDataBase = (value: number) => { const onChangeDataBase = (value: number) => {
onRefreshTreeData(value); onRefreshTreeData(value);
}; };
const currentTabName = 'menu.datastudio.datasource'; const currentTabName = LeftMenuKey.DATASOURCE_KEY;
const btnEvent = [...BtnRoute[currentTabName]]; const btnEvent = [...BtnRoute[currentTabName]];
......
...@@ -17,12 +17,13 @@ ...@@ -17,12 +17,13 @@
* *
*/ */
import { LeftMenuKey } from '@/pages/DataStudio/data.d';
import { getCurrentTab } from '@/pages/DataStudio/function'; import { getCurrentTab } from '@/pages/DataStudio/function';
import { import {
buildProjectTree, buildProjectTree,
generateList, generateList,
getLeafKeyList, getLeafKeyList,
getParentKey searchInTree
} from '@/pages/DataStudio/LeftContainer/Project/function'; } from '@/pages/DataStudio/LeftContainer/Project/function';
import { import {
StateType, StateType,
...@@ -39,6 +40,7 @@ import { Key } from '@ant-design/pro-components'; ...@@ -39,6 +40,7 @@ import { Key } from '@ant-design/pro-components';
import { useModel } from '@umijs/max'; import { useModel } from '@umijs/max';
import type { MenuProps } from 'antd'; import type { MenuProps } from 'antd';
import { Button, Dropdown, Empty, Space, Tree } from 'antd'; import { Button, Dropdown, Empty, Space, Tree } from 'antd';
import type { ButtonType } from 'antd/es/button/buttonHelpers';
import Search from 'antd/es/input/Search'; import Search from 'antd/es/input/Search';
import { ItemType } from 'rc-menu/es/interface'; import { ItemType } from 'rc-menu/es/interface';
import React, { useEffect, useState } from 'react'; import React, { useEffect, useState } from 'react';
...@@ -65,6 +67,7 @@ const JobTree: React.FC<TreeProps & connect> = (props) => { ...@@ -65,6 +67,7 @@ const JobTree: React.FC<TreeProps & connect> = (props) => {
onNodeClick, onNodeClick,
style, style,
height, height,
leftContainerWidth,
onRightClick, onRightClick,
selectKeyChange, selectKeyChange,
onExpand, onExpand,
...@@ -75,8 +78,14 @@ const JobTree: React.FC<TreeProps & connect> = (props) => { ...@@ -75,8 +78,14 @@ const JobTree: React.FC<TreeProps & connect> = (props) => {
const { initialState, setInitialState } = useModel('@@initialState'); const { initialState, setInitialState } = useModel('@@initialState');
const [searchValue, setSearchValueValue] = useState(''); const [searchValue, setSearchValueValue] = useState('');
const [sortIconType, setSortIconType] = useState(''); const [sortState, setSortState] = useState<{
const [selectedSortValue, setSelectedSortValue] = useState<string[]>([]); sortIconType: ButtonType;
selectedSortValue: string[];
}>({
sortIconType: 'text' as ButtonType,
selectedSortValue: []
});
const [data, setData] = useState<any[]>( const [data, setData] = useState<any[]>(
buildProjectTree( buildProjectTree(
projectData, projectData,
...@@ -106,20 +115,15 @@ const JobTree: React.FC<TreeProps & connect> = (props) => { ...@@ -106,20 +115,15 @@ const JobTree: React.FC<TreeProps & connect> = (props) => {
dispatch({ type: STUDIO_MODEL_ASYNC.queryProject, payload: selectCatalogueSortTypeData }); dispatch({ type: STUDIO_MODEL_ASYNC.queryProject, payload: selectCatalogueSortTypeData });
}, [selectCatalogueSortTypeData]); }, [selectCatalogueSortTypeData]);
function renameTrees(trees: TreeVo[]): ItemType[] { function buildSortTreeOptions(trees: TreeVo[] = []): ItemType[] {
const menuItems: ItemType[] = []; return trees.map((tree) => {
for (let tree of trees) { return {
let menuItem = { key: tree.name + '_' + tree.value,
key: tree['value'], label: tree.name,
label: tree['name'] value: tree.value,
children: tree?.children && buildSortTreeOptions(tree.children)
}; };
if (tree['children']) { });
const subTrees = renameTrees(tree['children']);
menuItem['children'] = subTrees;
}
menuItems.push(menuItem);
}
return menuItems;
} }
// set sort default value // set sort default value
...@@ -131,20 +135,28 @@ const JobTree: React.FC<TreeProps & connect> = (props) => { ...@@ -131,20 +135,28 @@ const JobTree: React.FC<TreeProps & connect> = (props) => {
) { ) {
const initialSortValue = const initialSortValue =
selectCatalogueSortTypeData.sortValue + '_' + selectCatalogueSortTypeData.sortType; selectCatalogueSortTypeData.sortValue + '_' + selectCatalogueSortTypeData.sortType;
setSelectedSortValue([initialSortValue]); setSortState((prevState) => ({
...prevState,
selectedSortValue: [initialSortValue]
}));
} }
}, []); }, []);
// when sorted, change the icon display // when sorted, change the icon display
useEffect(() => { useEffect(() => {
if (selectCatalogueSortTypeData.sortValue && selectCatalogueSortTypeData.sortType) { if (selectCatalogueSortTypeData.sortValue && selectCatalogueSortTypeData.sortType) {
setSortIconType('link'); setSortState((prevState) => ({
...prevState,
sortIconType: 'link'
}));
} else { } else {
setSortIconType('text'); setSortState((prevState) => ({
...prevState,
sortIconType: 'text'
}));
} }
}, [selectCatalogueSortTypeData]); }, [selectCatalogueSortTypeData]);
const [autoExpandParent, setAutoExpandParent] = useState(true);
const onChangeSearch = (e: any) => { const onChangeSearch = (e: any) => {
let { value } = e.target; let { value } = e.target;
if (!value) { if (!value) {
...@@ -155,22 +167,17 @@ const JobTree: React.FC<TreeProps & connect> = (props) => { ...@@ -155,22 +167,17 @@ const JobTree: React.FC<TreeProps & connect> = (props) => {
setSearchValueValue(value); setSearchValueValue(value);
return; return;
} }
value = String(value).trim(); const expandedKeys: string[] = searchInTree(
const expandList: any[] = generateList(data, []); generateList(data, []),
let expandedKeys: any = expandList data,
.map((item: any) => { String(value).trim(),
if (item?.name.indexOf(value) > -1) { 'contain'
return getParentKey(item.key, data); );
}
return null;
})
.filter((item: any, i: number, self: any) => item && self.indexOf(item) === i);
dispatch({ dispatch({
type: STUDIO_MODEL.updateProjectExpandKey, type: STUDIO_MODEL.updateProjectExpandKey,
payload: expandedKeys payload: expandedKeys
}); });
setSearchValueValue(value); setSearchValueValue(value);
setAutoExpandParent(true);
}; };
const expandAll = () => { const expandAll = () => {
...@@ -180,25 +187,16 @@ const JobTree: React.FC<TreeProps & connect> = (props) => { ...@@ -180,25 +187,16 @@ const JobTree: React.FC<TreeProps & connect> = (props) => {
}); });
}; };
const currentTabName = 'menu.datastudio.project'; const currentTabName = LeftMenuKey.PROJECT_KEY;
const btnEvent = [...BtnRoute[currentTabName]]; const btnEvent = [...BtnRoute[currentTabName]];
const positionKey = (panes: TabsItemType[], activeKey: string) => { const positionKey = (panes: TabsItemType[], activeKey: string) => {
const treeKey = getCurrentTab(panes, activeKey)?.treeKey; const treeKey = getCurrentTab(panes, activeKey)?.treeKey;
if (treeKey) { if (treeKey) {
const expandList: any[] = generateList(data, []); const expandedKeys: string[] = searchInTree(generateList(data, []), data, treeKey, 'equal');
let expandedKeys: any = expandList
.map((item: any) => {
if (item?.key === treeKey) {
return getParentKey(item.key, data);
}
return null;
})
.filter((item: any, i: number, self: any) => item && self.indexOf(item) === i);
dispatch({ dispatch({
type: STUDIO_MODEL.updateProjectExpandKey, type: STUDIO_MODEL.updateProjectExpandKey,
payload: expandedKeys payload: expandedKeys
}); });
setAutoExpandParent(true);
selectKeyChange([treeKey]); selectKeyChange([treeKey]);
} }
}; };
...@@ -225,7 +223,10 @@ const JobTree: React.FC<TreeProps & connect> = (props) => { ...@@ -225,7 +223,10 @@ const JobTree: React.FC<TreeProps & connect> = (props) => {
sortField == selectCatalogueSortTypeData.sortValue && sortField == selectCatalogueSortTypeData.sortValue &&
sortType == selectCatalogueSortTypeData.sortType sortType == selectCatalogueSortTypeData.sortType
) { ) {
setSelectedSortValue([]); setSortState((prevState) => ({
...prevState,
selectedSortValue: []
}));
dispatch({ dispatch({
type: STUDIO_MODEL.saveTaskSortTypeData, type: STUDIO_MODEL.saveTaskSortTypeData,
payload: { payload: {
...@@ -234,7 +235,10 @@ const JobTree: React.FC<TreeProps & connect> = (props) => { ...@@ -234,7 +235,10 @@ const JobTree: React.FC<TreeProps & connect> = (props) => {
} }
}); });
} else { } else {
setSelectedSortValue([selectSortValue]); setSortState((prevState) => ({
...prevState,
selectedSortValue: [selectSortValue]
}));
dispatch({ dispatch({
type: STUDIO_MODEL.saveTaskSortTypeData, type: STUDIO_MODEL.saveTaskSortTypeData,
payload: { payload: {
...@@ -247,24 +251,24 @@ const JobTree: React.FC<TreeProps & connect> = (props) => { ...@@ -247,24 +251,24 @@ const JobTree: React.FC<TreeProps & connect> = (props) => {
return ( return (
<> <>
<Space direction='horizontal'> <Space direction='horizontal' size={8}>
<Search <Search
style={{ margin: '8px 0px' }} style={{ margin: '8px 0px', width: leftContainerWidth - 60 }}
placeholder={l('global.search.text')} placeholder={l('global.search.text')}
onChange={onChangeSearch} onChange={onChangeSearch}
allowClear={true} allowClear={true}
/> />
<Dropdown <Dropdown
menu={{ menu={{
items: renameTrees(catalogueSortTypeData), items: buildSortTreeOptions(catalogueSortTypeData),
mode: 'horizontal', mode: 'horizontal',
selectable: true, selectable: true,
onClick: onClick, onClick: onClick,
selectedKeys: selectedSortValue selectedKeys: sortState.selectedSortValue
}} }}
placement='bottomLeft' placement='bottomLeft'
> >
<Button icon={<SortAscendingOutlined />} type={sortIconType}></Button> <Button icon={<SortAscendingOutlined />} type={sortState.sortIconType}></Button>
</Dropdown> </Dropdown>
</Space> </Space>
...@@ -279,7 +283,6 @@ const JobTree: React.FC<TreeProps & connect> = (props) => { ...@@ -279,7 +283,6 @@ const JobTree: React.FC<TreeProps & connect> = (props) => {
selectedKeys={selectKey} selectedKeys={selectKey}
onExpand={onExpand} onExpand={onExpand}
treeData={data} treeData={data}
// autoExpandParent={autoExpandParent}
/> />
) : ( ) : (
<Empty <Empty
...@@ -294,6 +297,7 @@ const JobTree: React.FC<TreeProps & connect> = (props) => { ...@@ -294,6 +297,7 @@ const JobTree: React.FC<TreeProps & connect> = (props) => {
export default connect( export default connect(
({ Studio, SysConfig }: { Studio: StateType; SysConfig: SysConfigStateType }) => ({ ({ Studio, SysConfig }: { Studio: StateType; SysConfig: SysConfigStateType }) => ({
height: Studio.toolContentHeight, height: Studio.toolContentHeight,
leftContainerWidth: Studio.leftContainer.width,
project: Studio.project, project: Studio.project,
taskOwnerLockingStrategy: SysConfig.taskOwnerLockingStrategy, taskOwnerLockingStrategy: SysConfig.taskOwnerLockingStrategy,
users: Studio.users, users: Studio.users,
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
*/ */
import Title from '@/components/Front/Title'; import Title from '@/components/Front/Title';
import { LeftMenuKey } from '@/pages/DataStudio/data.d';
import { BtnRoute, useTasksDispatch } from '@/pages/DataStudio/LeftContainer/BtnContext'; import { BtnRoute, useTasksDispatch } from '@/pages/DataStudio/LeftContainer/BtnContext';
import FolderModal from '@/pages/DataStudio/LeftContainer/Project/FolderModal'; import FolderModal from '@/pages/DataStudio/LeftContainer/Project/FolderModal';
import { StateType, STUDIO_MODEL_ASYNC } from '@/pages/DataStudio/model'; import { StateType, STUDIO_MODEL_ASYNC } from '@/pages/DataStudio/model';
...@@ -68,7 +69,7 @@ const ProjectTitle: React.FC<StateType & connect> = (props) => { ...@@ -68,7 +69,7 @@ const ProjectTitle: React.FC<StateType & connect> = (props) => {
); );
}; };
const currentTabName = 'menu.datastudio.project'; const currentTabName = LeftMenuKey.PROJECT_KEY;
const btn = BtnRoute[currentTabName]; const btn = BtnRoute[currentTabName];
btn[0].onClick = () => handleCreateClick(); btn[0].onClick = () => handleCreateClick();
btnDispatch({ btnDispatch({
......
...@@ -31,6 +31,11 @@ import { LockTwoTone, UnlockTwoTone } from '@ant-design/icons'; ...@@ -31,6 +31,11 @@ import { LockTwoTone, UnlockTwoTone } from '@ant-design/icons';
import { Badge, Space, Tooltip } from 'antd'; import { Badge, Space, Tooltip } from 'antd';
import { Key } from 'react'; import { Key } from 'react';
/**
* generate list of tree node from data
* @param data
* @param list
*/
export const generateList = (data: any, list: any[]) => { export const generateList = (data: any, list: any[]) => {
for (const element of data) { for (const element of data) {
const node = element; const node = element;
...@@ -43,6 +48,11 @@ export const generateList = (data: any, list: any[]) => { ...@@ -43,6 +48,11 @@ export const generateList = (data: any, list: any[]) => {
return list; return list;
}; };
/**
* get parent key of tree node by key
* @param key
* @param tree
*/
export const getParentKey = (key: number | string, tree: any): any => { export const getParentKey = (key: number | string, tree: any): any => {
let parentKey; let parentKey;
for (const element of tree) { for (const element of tree) {
...@@ -58,6 +68,87 @@ export const getParentKey = (key: number | string, tree: any): any => { ...@@ -58,6 +68,87 @@ export const getParentKey = (key: number | string, tree: any): any => {
return parentKey; return parentKey;
}; };
/**
* Obtain all parent node IDs based on a key
* Note: Note that the data structure returned through the native backend is relatively simple, so here we directly use recursive object traversal to obtain all parent node IDs
* @param key
* @param data
*/
export const getAllParentIdsByOneKey = (
key: number | string,
data: any[] = []
): (number | string)[] => {
let result: (number | string)[] = [];
data.forEach((item) => {
if (item.id === key) {
result.push(item.id);
} else if (item.children) {
const parentIds = getAllParentIdsByOneKey(key, item.children);
if (parentIds.length > 0) {
result = result.concat(parentIds, item.id);
}
}
});
// Invert the result array so that the parent nodes are in order from the root to the direct parent node
return result.reverse();
};
/**
* search in tree node
* @param tree data
* @param data
* @param searchValue
* @param assetType search type 'equal' or 'contain'
*/
export function searchInTree(
tree: any[] = [],
data: any[],
searchValue: string | number,
assetType: 'equal' | 'contain'
): string[] {
const foundKeys: string[] = [];
/**
* Depth-first search algorithm to find the key of the node that meets the search criteria
* @param node tree node
* @param path path of the node
*/
function dfs(node: any, path: string[]) {
if (assetType === 'equal') {
if (node?.key && node.key === searchValue) {
const allParentIdsByOneKey = getAllParentIdsByOneKey(node.key, data);
allParentIdsByOneKey.forEach((key) => {
foundKeys.push(key as string);
});
}
}
if (assetType === 'contain') {
if (node?.name?.indexOf(searchValue) > -1) {
const allParentIdsByOneKey = getAllParentIdsByOneKey(node.key, data);
allParentIdsByOneKey.forEach((key) => {
foundKeys.push(key as string);
});
}
}
if (node.children) {
for (const child of node.children) {
dfs(child, [...path, node.key]);
}
}
}
// Traverse all nodes in the tree to find the key of the node that meets the search criteria
for (const node of tree) {
dfs(node, [node.key]);
}
// Remove duplicate keys from the result
return Array.from(new Set(foundKeys));
}
/**
* get leaf key list from tree
* @param tree
*/
export const getLeafKeyList = (tree: any[]): Key[] => { export const getLeafKeyList = (tree: any[]): Key[] => {
let leafKeyList: Key[] = []; let leafKeyList: Key[] = [];
for (const node of tree) { for (const node of tree) {
...@@ -185,9 +276,9 @@ export const buildProjectTree = ( ...@@ -185,9 +276,9 @@ export const buildProjectTree = (
currentUser, currentUser,
taskOwnerLockingStrategy taskOwnerLockingStrategy
) ? ( ) ? (
<LockTwoTone title={'无法操作'} twoToneColor={'red'} /> <LockTwoTone title={l('global.operation.unable')} twoToneColor={'red'} />
) : ( ) : (
<UnlockTwoTone title={'可操作'} twoToneColor='gray' /> <UnlockTwoTone title={l('global.operation.able')} twoToneColor='gray' />
)} )}
</> </>
); );
......
...@@ -87,8 +87,8 @@ export type EnvType = { ...@@ -87,8 +87,8 @@ export type EnvType = {
}; };
export type TreeVo = { export type TreeVo = {
name?: string; name: string;
value?: string; value: string;
children?: TreeVo[]; children?: TreeVo[];
}; };
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
* *
*/ */
import { CircleBtn } from '@/components/CallBackButton/CircleBtn';
import JobLifeCycleTag from '@/components/JobTags/JobLifeCycleTag'; import JobLifeCycleTag from '@/components/JobTags/JobLifeCycleTag';
import StatusTag from '@/components/JobTags/StatusTag'; import StatusTag from '@/components/JobTags/StatusTag';
import { import {
...@@ -27,9 +28,9 @@ import { ...@@ -27,9 +28,9 @@ import {
import { import {
buildProjectTree, buildProjectTree,
generateList, generateList,
getParentKey getLeafKeyList,
searchInTree
} from '@/pages/DataStudio/LeftContainer/Project/function'; } from '@/pages/DataStudio/LeftContainer/Project/function';
import { getTaskData } from '@/pages/DataStudio/LeftContainer/Project/service';
import { StateType } from '@/pages/DataStudio/model'; import { StateType } from '@/pages/DataStudio/model';
import { DevopContext } from '@/pages/DevOps'; import { DevopContext } from '@/pages/DevOps';
import { JOB_LIFE_CYCLE } from '@/pages/DevOps/constants'; import { JOB_LIFE_CYCLE } from '@/pages/DevOps/constants';
...@@ -45,7 +46,14 @@ import { getTenantByLocalStorage } from '@/utils/function'; ...@@ -45,7 +46,14 @@ import { getTenantByLocalStorage } from '@/utils/function';
import { l } from '@/utils/intl'; import { l } from '@/utils/intl';
import { SplitPane } from '@andrewray/react-multi-split-pane'; import { SplitPane } from '@andrewray/react-multi-split-pane';
import { Pane } from '@andrewray/react-multi-split-pane/dist/lib/Pane'; import { Pane } from '@andrewray/react-multi-split-pane/dist/lib/Pane';
import { ClearOutlined, ClockCircleTwoTone, EyeTwoTone, RedoOutlined } from '@ant-design/icons'; import {
ArrowsAltOutlined,
ClearOutlined,
ClockCircleTwoTone,
EyeTwoTone,
RedoOutlined,
ShrinkOutlined
} from '@ant-design/icons';
import type { ActionType, ProColumns } from '@ant-design/pro-components'; import type { ActionType, ProColumns } from '@ant-design/pro-components';
import { ProCard, ProTable } from '@ant-design/pro-components'; import { ProCard, ProTable } from '@ant-design/pro-components';
import { connect, useModel } from '@umijs/max'; import { connect, useModel } from '@umijs/max';
...@@ -57,7 +65,13 @@ import { history } from 'umi'; ...@@ -57,7 +65,13 @@ import { history } from 'umi';
const { DirectoryTree } = Tree; const { DirectoryTree } = Tree;
const JobList = (props: connect) => { const JobList = (props: connect) => {
const { users, queryUserData, taskOwnerLockingStrategy, queryTaskOwnerLockingStrategy } = props; const {
users,
queryUserData,
taskOwnerLockingStrategy,
queryTaskOwnerLockingStrategy,
projectData
} = props;
const refObject = useRef<HTMLDivElement>(null); const refObject = useRef<HTMLDivElement>(null);
const tableRef = useRef<ActionType>(); const tableRef = useRef<ActionType>();
const { statusFilter, setStatusFilter } = useContext<any>(DevopContext); const { statusFilter, setStatusFilter } = useContext<any>(DevopContext);
...@@ -65,12 +79,37 @@ const JobList = (props: connect) => { ...@@ -65,12 +79,37 @@ const JobList = (props: connect) => {
const [taskFilter, setTaskFilter] = useState<string | undefined>(); const [taskFilter, setTaskFilter] = useState<string | undefined>();
const [taskId, setTaskId] = useState<number>(); const [taskId, setTaskId] = useState<number>();
const [searchValue, setSearchValueValue] = useState(''); const [searchValue, setSearchValueValue] = useState('');
const [data, setData] = useState<any[]>([]);
const [autoExpandParent, setAutoExpandParent] = useState(true);
const [expandedKeys, setExpandedKeys] = useState<Key[]>([]); const [expandedKeys, setExpandedKeys] = useState<Key[]>([]);
const [selectedKey, setSelectedKey] = useState<Key[]>([]); const [selectedKey, setSelectedKey] = useState<Key[]>([]);
const { initialState, setInitialState } = useModel('@@initialState'); const { initialState, setInitialState } = useModel('@@initialState');
const [data, setData] = useState<any[]>(
buildProjectTree(
projectData,
searchValue,
[],
initialState?.currentUser?.user,
taskOwnerLockingStrategy,
users
)
);
useEffect(() => {
setData(
buildProjectTree(
projectData,
searchValue,
[],
initialState?.currentUser?.user,
taskOwnerLockingStrategy,
users
)
);
if (searchValue === '' || searchValue === undefined) {
setExpandedKeys([]);
}
}, [searchValue, projectData, taskOwnerLockingStrategy]);
const jobListColumns: ProColumns<Jobs.JobInstance>[] = [ const jobListColumns: ProColumns<Jobs.JobInstance>[] = [
{ {
title: l('global.table.jobname'), title: l('global.table.jobname'),
...@@ -153,26 +192,6 @@ const JobList = (props: connect) => { ...@@ -153,26 +192,6 @@ const JobList = (props: connect) => {
} }
}, [statusFilter]); }, [statusFilter]);
/**
* 获取任务数据 | query task data
*/
useEffect(() => {
getTaskData({}).then((res) => {
if (res) {
setData(
buildProjectTree(
res,
searchValue,
[],
initialState?.currentUser?.user,
taskOwnerLockingStrategy,
users
)
);
}
});
}, [searchValue, taskOwnerLockingStrategy]);
useEffect(() => { useEffect(() => {
setInterval(() => tableRef.current?.reload(false), 5 * 1000); setInterval(() => tableRef.current?.reload(false), 5 * 1000);
queryUserData({ id: getTenantByLocalStorage() }); queryUserData({ id: getTenantByLocalStorage() });
...@@ -186,18 +205,9 @@ const JobList = (props: connect) => { ...@@ -186,18 +205,9 @@ const JobList = (props: connect) => {
return; return;
} }
value = String(value).trim(); value = String(value).trim();
const expandList: any[] = generateList(data, []); const expandedKeys: string[] = searchInTree(generateList(data, []), data, value, 'contain');
let expandedKeys: any = expandList
.map((item: any) => {
if (item?.name.indexOf(value) > -1) {
return getParentKey(item.key, data);
}
return null;
})
.filter((item: any, i: number, self: any) => item && self.indexOf(item) === i);
setExpandedKeys(expandedKeys); setExpandedKeys(expandedKeys);
setSearchValueValue(value); setSearchValueValue(value);
setAutoExpandParent(true);
}; };
function onNodeClick(info: any) { function onNodeClick(info: any) {
...@@ -238,24 +248,41 @@ const JobList = (props: connect) => { ...@@ -238,24 +248,41 @@ const JobList = (props: connect) => {
size={200} size={200}
split={'horizontal'} split={'horizontal'}
> >
<Search <div style={{ display: 'flex', justifyContent: 'space-evenly', alignItems: 'center' }}>
style={{ margin: '8px 0px', padding: '0 10px' }} <Search
placeholder={l('global.search.text')} style={{ margin: '4px 0px', padding: '0 5px', width: '80%' }}
onChange={onChangeSearch} placeholder={l('global.search.text')}
allowClear={true} onChange={onChangeSearch}
addonAfter={ allowClear={true}
// 如果选中的 key 长度大于 0 则显示清除按钮 | if the length of the selected key is greater than 0, the clear button is displayed autoFocus
selectedKey.length > 0 && ( addonAfter={
<Button // 如果选中的 key 长度大于 0 则显示清除按钮 | if the length of the selected key is greater than 0, the clear button is displayed
title={l('devops.joblist.clear.filtertips')} selectedKey.length > 0 && (
icon={<ClearOutlined />} <Button
onClick={() => resetValue()} title={l('devops.joblist.clear.filtertips')}
> icon={<ClearOutlined />}
{l('devops.joblist.clear.filter')} onClick={() => resetValue()}
</Button> >
) {l('devops.joblist.clear.filter')}
} </Button>
/> )
}
/>
<Button.Group>
<CircleBtn
title={l('button.expand-all')}
icon={<ArrowsAltOutlined />}
onClick={() => setExpandedKeys(getLeafKeyList(data))}
/>
</Button.Group>
<Button.Group>
<CircleBtn
title={l('button.collapse-all')}
icon={<ShrinkOutlined />}
onClick={() => setExpandedKeys([])}
/>
</Button.Group>
</div>
{data.length ? ( {data.length ? (
<DirectoryTree <DirectoryTree
...@@ -268,7 +295,6 @@ const JobList = (props: connect) => { ...@@ -268,7 +295,6 @@ const JobList = (props: connect) => {
selectedKeys={selectedKey} selectedKeys={selectedKey}
onExpand={(expandedKeys: Key[]) => setExpandedKeys(expandedKeys)} onExpand={(expandedKeys: Key[]) => setExpandedKeys(expandedKeys)}
treeData={data} treeData={data}
autoExpandParent={autoExpandParent}
/> />
) : ( ) : (
<Empty className={'code-content-empty'} /> <Empty className={'code-content-empty'} />
...@@ -353,6 +379,7 @@ const JobList = (props: connect) => { ...@@ -353,6 +379,7 @@ const JobList = (props: connect) => {
export default connect( export default connect(
({ Studio, SysConfig }: { Studio: StateType; SysConfig: SysConfigStateType }) => ({ ({ Studio, SysConfig }: { Studio: StateType; SysConfig: SysConfigStateType }) => ({
users: Studio.users, users: Studio.users,
projectData: Studio.project.data,
taskOwnerLockingStrategy: SysConfig.taskOwnerLockingStrategy taskOwnerLockingStrategy: SysConfig.taskOwnerLockingStrategy
}), }),
mapDispatchToProps mapDispatchToProps
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment