feat: add expand all rows
This commit is contained in:
@@ -45,7 +45,7 @@ const AutoImage: React.FC<
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const { ratio } = await getImgRatio(props.src || '');
|
const { ratio } = await getImgRatio(props.src || '');
|
||||||
console.log('ratio', ratio);
|
|
||||||
if (typeof height === 'number') {
|
if (typeof height === 'number') {
|
||||||
setWidth(height * ratio);
|
setWidth(height * ratio);
|
||||||
} else {
|
} else {
|
||||||
@@ -53,7 +53,7 @@ const AutoImage: React.FC<
|
|||||||
}
|
}
|
||||||
}, [getImgRatio, height, props.src]);
|
}, [getImgRatio, height, props.src]);
|
||||||
|
|
||||||
const onDownload = () => {
|
const onDownload = useCallback(() => {
|
||||||
const url = props.src || '';
|
const url = props.src || '';
|
||||||
const filename = Date.now() + '';
|
const filename = Date.now() + '';
|
||||||
|
|
||||||
@@ -63,16 +63,16 @@ const AutoImage: React.FC<
|
|||||||
document.body.appendChild(link);
|
document.body.appendChild(link);
|
||||||
link.click();
|
link.click();
|
||||||
link.remove();
|
link.remove();
|
||||||
};
|
}, [props.src]);
|
||||||
|
|
||||||
const handleImgLoad = useCallback(() => {
|
const handleImgLoad = useCallback(() => {
|
||||||
props.onLoad?.();
|
props.onLoad?.();
|
||||||
setIsError(false);
|
setIsError(false);
|
||||||
}, [props.onLoad]);
|
}, [props.onLoad]);
|
||||||
|
|
||||||
const handleOnError = () => {
|
const handleOnError = useCallback(() => {
|
||||||
setIsError(true);
|
setIsError(true);
|
||||||
};
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
handleOnLoad();
|
handleOnLoad();
|
||||||
@@ -127,4 +127,4 @@ const AutoImage: React.FC<
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default AutoImage;
|
export default React.memo(AutoImage);
|
||||||
|
|||||||
@@ -197,4 +197,4 @@ const SingleImage: React.FC<SingleImageProps> = (props) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default React.memo(SingleImage);
|
export default SingleImage;
|
||||||
|
|||||||
@@ -34,9 +34,9 @@ const LogsList: React.FC<LogsListProps> = forwardRef((props, ref) => {
|
|||||||
theme: 'os-theme-light'
|
theme: 'os-theme-light'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const viewportHeight = window.innerHeight;
|
const [innerHieght, setInnerHeight] = useState(
|
||||||
const viewHeight = viewportHeight - diffHeight;
|
window.innerHeight - diffHeight
|
||||||
const [innerHieght, setInnerHeight] = useState(viewHeight);
|
);
|
||||||
const scroller = useRef<any>({});
|
const scroller = useRef<any>({});
|
||||||
const stopScroll = useRef(false);
|
const stopScroll = useRef(false);
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import './styles/index.less';
|
|||||||
import useLogsPagination from './use-logs-pagination';
|
import useLogsPagination from './use-logs-pagination';
|
||||||
|
|
||||||
interface LogsViewerProps {
|
interface LogsViewerProps {
|
||||||
height: number;
|
height?: number;
|
||||||
content?: string;
|
content?: string;
|
||||||
url: string;
|
url: string;
|
||||||
params?: object;
|
params?: object;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { RightOutlined } from '@ant-design/icons';
|
import { DownOutlined, RightOutlined } from '@ant-design/icons';
|
||||||
import { Button, Checkbox } from 'antd';
|
import { Button, Checkbox } from 'antd';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
@@ -7,6 +7,8 @@ interface HeaderPrefixProps {
|
|||||||
expandable?: boolean | React.ReactNode;
|
expandable?: boolean | React.ReactNode;
|
||||||
enableSelection?: boolean;
|
enableSelection?: boolean;
|
||||||
onSelectAll?: (e: any) => void;
|
onSelectAll?: (e: any) => void;
|
||||||
|
onExpandAll?: (e: any) => void;
|
||||||
|
expandAll?: boolean;
|
||||||
indeterminate?: boolean;
|
indeterminate?: boolean;
|
||||||
selectAll?: boolean;
|
selectAll?: boolean;
|
||||||
hasColumns?: boolean;
|
hasColumns?: boolean;
|
||||||
@@ -18,16 +20,31 @@ const HeaderPrefix: React.FC<HeaderPrefixProps> = (props) => {
|
|||||||
expandable,
|
expandable,
|
||||||
enableSelection,
|
enableSelection,
|
||||||
onSelectAll,
|
onSelectAll,
|
||||||
|
onExpandAll,
|
||||||
indeterminate,
|
indeterminate,
|
||||||
selectAll
|
selectAll,
|
||||||
|
expandAll
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
|
const handleToggleExpand = () => {
|
||||||
|
onExpandAll?.(!expandAll);
|
||||||
|
};
|
||||||
|
|
||||||
if (!hasColumns) {
|
if (!hasColumns) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (expandable && enableSelection) {
|
if (expandable && enableSelection) {
|
||||||
return (
|
return (
|
||||||
<div className="header-row-prefix-wrapper">
|
<div className="header-row-prefix-wrapper flex-center">
|
||||||
<span style={{ marginRight: 5, padding: '0 14px' }}></span>
|
<span style={{ marginRight: 5 }}>
|
||||||
|
{_.isBoolean(expandable) ? (
|
||||||
|
<Button type="text" size="small" onClick={handleToggleExpand}>
|
||||||
|
{expandAll ? <DownOutlined /> : <RightOutlined />}
|
||||||
|
</Button>
|
||||||
|
) : (
|
||||||
|
expandable
|
||||||
|
)}
|
||||||
|
</span>
|
||||||
<Checkbox
|
<Checkbox
|
||||||
onChange={onSelectAll}
|
onChange={onSelectAll}
|
||||||
indeterminate={indeterminate}
|
indeterminate={indeterminate}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ const SealTable: React.FC<SealTableProps & { pagination: PaginationProps }> = (
|
|||||||
rowKey,
|
rowKey,
|
||||||
childParentKey,
|
childParentKey,
|
||||||
onExpand,
|
onExpand,
|
||||||
|
onExpandAll,
|
||||||
onSort,
|
onSort,
|
||||||
onCell,
|
onCell,
|
||||||
expandedRowKeys,
|
expandedRowKeys,
|
||||||
@@ -51,6 +52,12 @@ const SealTable: React.FC<SealTableProps & { pagination: PaginationProps }> = (
|
|||||||
});
|
});
|
||||||
}, [columns, children]);
|
}, [columns, children]);
|
||||||
|
|
||||||
|
const expandAll = useMemo(() => {
|
||||||
|
const allKeys = new Set(expandedRowKeys);
|
||||||
|
const currentDataKeys = props.dataSource.map((record) => record[rowKey]);
|
||||||
|
return currentDataKeys.every((key) => allKeys.has(key));
|
||||||
|
}, [props.dataSource, expandedRowKeys]);
|
||||||
|
|
||||||
const selectState = useMemo(() => {
|
const selectState = useMemo(() => {
|
||||||
const selectedRowKeys = rowSelection?.selectedRowKeys || [];
|
const selectedRowKeys = rowSelection?.selectedRowKeys || [];
|
||||||
const selectedKeys = new Set(selectedRowKeys);
|
const selectedKeys = new Set(selectedRowKeys);
|
||||||
@@ -99,6 +106,10 @@ const SealTable: React.FC<SealTableProps & { pagination: PaginationProps }> = (
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleExpandAll = (value: boolean) => {
|
||||||
|
onExpandAll?.(value);
|
||||||
|
};
|
||||||
|
|
||||||
const handlePageChange = (page: number, pageSize: number) => {
|
const handlePageChange = (page: number, pageSize: number) => {
|
||||||
pagination?.onChange?.(page, pageSize);
|
pagination?.onChange?.(page, pageSize);
|
||||||
};
|
};
|
||||||
@@ -115,6 +126,8 @@ const SealTable: React.FC<SealTableProps & { pagination: PaginationProps }> = (
|
|||||||
selectAll={selectState.selectAll}
|
selectAll={selectState.selectAll}
|
||||||
indeterminate={selectState.indeterminate}
|
indeterminate={selectState.indeterminate}
|
||||||
onSelectAll={handleSelectAllChange}
|
onSelectAll={handleSelectAllChange}
|
||||||
|
onExpandAll={handleExpandAll}
|
||||||
|
expandAll={expandAll}
|
||||||
expandable={expandable}
|
expandable={expandable}
|
||||||
enableSelection={rowSelection?.enableSelection}
|
enableSelection={rowSelection?.enableSelection}
|
||||||
hasColumns={parsedColumns.length > 0}
|
hasColumns={parsedColumns.length > 0}
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ export interface SealTableProps {
|
|||||||
onCell?: (record: any, dataIndex: string) => void;
|
onCell?: (record: any, dataIndex: string) => void;
|
||||||
onSort?: (dataIndex: string, order: 'ascend' | 'descend') => void;
|
onSort?: (dataIndex: string, order: 'ascend' | 'descend') => void;
|
||||||
onExpand?: (expanded: boolean, record: any, rowKey: any) => void;
|
onExpand?: (expanded: boolean, record: any, rowKey: any) => void;
|
||||||
|
onExpandAll?: (expanded: boolean) => void;
|
||||||
renderChildren?: (data: any, parent?: any) => React.ReactNode;
|
renderChildren?: (data: any, parent?: any) => React.ReactNode;
|
||||||
loadChildren?: (record: any, options?: any) => Promise<any[]>;
|
loadChildren?: (record: any, options?: any) => Promise<any[]>;
|
||||||
loadChildrenAPI?: (record: any) => string;
|
loadChildrenAPI?: (record: any) => string;
|
||||||
|
|||||||
@@ -15,6 +15,18 @@ export default function useExpandedRowKeys(defaultKeys: React.Key[] = []) {
|
|||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const handleExpandAll = useCallback(
|
||||||
|
(expanded: boolean, keys: React.Key[] = []) => {
|
||||||
|
if (!expanded) {
|
||||||
|
setExpandedRowKeys([]);
|
||||||
|
}
|
||||||
|
if (expanded) {
|
||||||
|
setExpandedRowKeys((prevKeys) => [...new Set([...prevKeys, ...keys])]);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
|
||||||
const updateExpandedRowKeys = (keys: React.Key[]) => {
|
const updateExpandedRowKeys = (keys: React.Key[]) => {
|
||||||
setExpandedRowKeys(keys);
|
setExpandedRowKeys(keys);
|
||||||
};
|
};
|
||||||
@@ -36,6 +48,7 @@ export default function useExpandedRowKeys(defaultKeys: React.Key[] = []) {
|
|||||||
clearExpandedRowKeys,
|
clearExpandedRowKeys,
|
||||||
updateExpandedRowKeys,
|
updateExpandedRowKeys,
|
||||||
removeExpandedRowKey,
|
removeExpandedRowKey,
|
||||||
handleExpandChange
|
handleExpandChange,
|
||||||
|
handleExpandAll
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-8
@@ -348,6 +348,16 @@ export default (props: any) => {
|
|||||||
[userInfo?.require_password_change, initialState?.currentUser]
|
[userInfo?.require_password_change, initialState?.currentUser]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const onMenuHeaderClick = useCallback((e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
e.preventDefault();
|
||||||
|
navigate('/dashboard');
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const onCollapse = (value) => {
|
||||||
|
setCollapsed(value);
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// 先清除旧的性能标记
|
// 先清除旧的性能标记
|
||||||
performance.clearMarks();
|
performance.clearMarks();
|
||||||
@@ -403,14 +413,8 @@ export default (props: any) => {
|
|||||||
title: <div style={{ fontSize: 36 }}> gpuStack </div>
|
title: <div style={{ fontSize: 36 }}> gpuStack </div>
|
||||||
}}
|
}}
|
||||||
siderWidth={220}
|
siderWidth={220}
|
||||||
onCollapse={(collapsed) => {
|
onCollapse={onCollapse}
|
||||||
setCollapsed(collapsed);
|
onMenuHeaderClick={onMenuHeaderClick}
|
||||||
}}
|
|
||||||
onMenuHeaderClick={(e) => {
|
|
||||||
e.stopPropagation();
|
|
||||||
e.preventDefault();
|
|
||||||
navigate('/dashboard');
|
|
||||||
}}
|
|
||||||
menuHeaderRender={renderMenuHeader}
|
menuHeaderRender={renderMenuHeader}
|
||||||
collapsed={collapsed}
|
collapsed={collapsed}
|
||||||
onPageChange={onPageChange}
|
onPageChange={onPageChange}
|
||||||
|
|||||||
@@ -84,6 +84,7 @@ interface ModelsProps {
|
|||||||
handleCategoryChange: (val: any) => void;
|
handleCategoryChange: (val: any) => void;
|
||||||
onViewLogs: () => void;
|
onViewLogs: () => void;
|
||||||
onCancelViewLogs: () => void;
|
onCancelViewLogs: () => void;
|
||||||
|
handleOnToggleExpandAll: () => void;
|
||||||
queryParams: {
|
queryParams: {
|
||||||
page: number;
|
page: number;
|
||||||
perPage: number;
|
perPage: number;
|
||||||
@@ -172,6 +173,7 @@ const Models: React.FC<ModelsProps> = ({
|
|||||||
onViewLogs,
|
onViewLogs,
|
||||||
onCancelViewLogs,
|
onCancelViewLogs,
|
||||||
handleCategoryChange,
|
handleCategoryChange,
|
||||||
|
handleOnToggleExpandAll,
|
||||||
deleteIds,
|
deleteIds,
|
||||||
dataSource,
|
dataSource,
|
||||||
workerList,
|
workerList,
|
||||||
@@ -202,6 +204,7 @@ const Models: React.FC<ModelsProps> = ({
|
|||||||
const rowSelection = useTableRowSelection();
|
const rowSelection = useTableRowSelection();
|
||||||
const {
|
const {
|
||||||
handleExpandChange,
|
handleExpandChange,
|
||||||
|
handleExpandAll,
|
||||||
updateExpandedRowKeys,
|
updateExpandedRowKeys,
|
||||||
removeExpandedRowKey,
|
removeExpandedRowKey,
|
||||||
expandedRowKeys
|
expandedRowKeys
|
||||||
@@ -843,6 +846,18 @@ const Models: React.FC<ModelsProps> = ({
|
|||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleToggleExpandAll = useCallback(
|
||||||
|
(expanded: boolean) => {
|
||||||
|
const keys = dataSource.map((item) => item.id);
|
||||||
|
handleExpandAll(expanded, keys);
|
||||||
|
if (expanded) {
|
||||||
|
handleOnToggleExpandAll();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[dataSource]
|
||||||
|
);
|
||||||
|
|
||||||
const renderEmpty = useMemo(() => {
|
const renderEmpty = useMemo(() => {
|
||||||
if (dataSource.length || !isFirstLogin || !catalogList?.length) {
|
if (dataSource.length || !isFirstLogin || !catalogList?.length) {
|
||||||
return null;
|
return null;
|
||||||
@@ -990,6 +1005,7 @@ const Models: React.FC<ModelsProps> = ({
|
|||||||
rowSelection={rowSelection}
|
rowSelection={rowSelection}
|
||||||
expandedRowKeys={expandedRowKeys}
|
expandedRowKeys={expandedRowKeys}
|
||||||
onExpand={handleExpandChange}
|
onExpand={handleExpandChange}
|
||||||
|
onExpandAll={handleToggleExpandAll}
|
||||||
loading={loading}
|
loading={loading}
|
||||||
loadend={loadend}
|
loadend={loadend}
|
||||||
rowKey="id"
|
rowKey="id"
|
||||||
|
|||||||
@@ -15,15 +15,10 @@ type ViewModalProps = {
|
|||||||
onCancel: () => void;
|
onCancel: () => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
const ViewCodeModal: React.FC<ViewModalProps> = (props) => {
|
const ViewLogsModal: React.FC<ViewModalProps> = (props) => {
|
||||||
const viewportHeight = window.innerHeight;
|
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
const { setChunkRequest } = useSetChunkRequest();
|
const { setChunkRequest } = useSetChunkRequest();
|
||||||
const { open, url, onCancel, tail } = props || {};
|
const { open, url, onCancel, tail } = props || {};
|
||||||
const [modalSize] = useState<any>({
|
|
||||||
width: '100%',
|
|
||||||
height: viewportHeight - 86
|
|
||||||
});
|
|
||||||
const [enableScorllLoad, setEnableScorllLoad] = useState(true);
|
const [enableScorllLoad, setEnableScorllLoad] = useState(true);
|
||||||
const logsViewerRef = React.useRef<any>(null);
|
const logsViewerRef = React.useRef<any>(null);
|
||||||
const requestRef = React.useRef<any>(null);
|
const requestRef = React.useRef<any>(null);
|
||||||
@@ -106,13 +101,12 @@ const ViewCodeModal: React.FC<ViewModalProps> = (props) => {
|
|||||||
borderRadius: 0
|
borderRadius: 0
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
width={modalSize.width}
|
width="100%"
|
||||||
footer={null}
|
footer={null}
|
||||||
>
|
>
|
||||||
<div className="viewer-wrapper" ref={contentRef}>
|
<div className="viewer-wrapper" ref={contentRef}>
|
||||||
<LogsViewer
|
<LogsViewer
|
||||||
ref={logsViewerRef}
|
ref={logsViewerRef}
|
||||||
height={modalSize.height}
|
|
||||||
diffHeight={93}
|
diffHeight={93}
|
||||||
url={url}
|
url={url}
|
||||||
tail={tail}
|
tail={tail}
|
||||||
@@ -126,4 +120,4 @@ const ViewCodeModal: React.FC<ViewModalProps> = (props) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default React.memo(ViewCodeModal);
|
export default ViewLogsModal;
|
||||||
|
|||||||
@@ -349,6 +349,7 @@ const Models: React.FC = () => {
|
|||||||
handleSearch={handleSearch}
|
handleSearch={handleSearch}
|
||||||
handlePageChange={handlePageChange}
|
handlePageChange={handlePageChange}
|
||||||
handleDeleteSuccess={fetchData}
|
handleDeleteSuccess={fetchData}
|
||||||
|
handleOnToggleExpandAll={createModelsInstanceChunkRequest}
|
||||||
onViewLogs={handleOnViewLogs}
|
onViewLogs={handleOnViewLogs}
|
||||||
onCancelViewLogs={handleOnCancelViewLogs}
|
onCancelViewLogs={handleOnCancelViewLogs}
|
||||||
queryParams={queryParams}
|
queryParams={queryParams}
|
||||||
|
|||||||
Reference in New Issue
Block a user