feat: add expand all rows
This commit is contained in:
@@ -45,7 +45,7 @@ const AutoImage: React.FC<
|
||||
return;
|
||||
}
|
||||
const { ratio } = await getImgRatio(props.src || '');
|
||||
console.log('ratio', ratio);
|
||||
|
||||
if (typeof height === 'number') {
|
||||
setWidth(height * ratio);
|
||||
} else {
|
||||
@@ -53,7 +53,7 @@ const AutoImage: React.FC<
|
||||
}
|
||||
}, [getImgRatio, height, props.src]);
|
||||
|
||||
const onDownload = () => {
|
||||
const onDownload = useCallback(() => {
|
||||
const url = props.src || '';
|
||||
const filename = Date.now() + '';
|
||||
|
||||
@@ -63,16 +63,16 @@ const AutoImage: React.FC<
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
link.remove();
|
||||
};
|
||||
}, [props.src]);
|
||||
|
||||
const handleImgLoad = useCallback(() => {
|
||||
props.onLoad?.();
|
||||
setIsError(false);
|
||||
}, [props.onLoad]);
|
||||
|
||||
const handleOnError = () => {
|
||||
const handleOnError = useCallback(() => {
|
||||
setIsError(true);
|
||||
};
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
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'
|
||||
}
|
||||
});
|
||||
const viewportHeight = window.innerHeight;
|
||||
const viewHeight = viewportHeight - diffHeight;
|
||||
const [innerHieght, setInnerHeight] = useState(viewHeight);
|
||||
const [innerHieght, setInnerHeight] = useState(
|
||||
window.innerHeight - diffHeight
|
||||
);
|
||||
const scroller = useRef<any>({});
|
||||
const stopScroll = useRef(false);
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ import './styles/index.less';
|
||||
import useLogsPagination from './use-logs-pagination';
|
||||
|
||||
interface LogsViewerProps {
|
||||
height: number;
|
||||
height?: number;
|
||||
content?: string;
|
||||
url: string;
|
||||
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 _ from 'lodash';
|
||||
import React from 'react';
|
||||
@@ -7,6 +7,8 @@ interface HeaderPrefixProps {
|
||||
expandable?: boolean | React.ReactNode;
|
||||
enableSelection?: boolean;
|
||||
onSelectAll?: (e: any) => void;
|
||||
onExpandAll?: (e: any) => void;
|
||||
expandAll?: boolean;
|
||||
indeterminate?: boolean;
|
||||
selectAll?: boolean;
|
||||
hasColumns?: boolean;
|
||||
@@ -18,16 +20,31 @@ const HeaderPrefix: React.FC<HeaderPrefixProps> = (props) => {
|
||||
expandable,
|
||||
enableSelection,
|
||||
onSelectAll,
|
||||
onExpandAll,
|
||||
indeterminate,
|
||||
selectAll
|
||||
selectAll,
|
||||
expandAll
|
||||
} = props;
|
||||
|
||||
const handleToggleExpand = () => {
|
||||
onExpandAll?.(!expandAll);
|
||||
};
|
||||
|
||||
if (!hasColumns) {
|
||||
return null;
|
||||
}
|
||||
if (expandable && enableSelection) {
|
||||
return (
|
||||
<div className="header-row-prefix-wrapper">
|
||||
<span style={{ marginRight: 5, padding: '0 14px' }}></span>
|
||||
<div className="header-row-prefix-wrapper flex-center">
|
||||
<span style={{ marginRight: 5 }}>
|
||||
{_.isBoolean(expandable) ? (
|
||||
<Button type="text" size="small" onClick={handleToggleExpand}>
|
||||
{expandAll ? <DownOutlined /> : <RightOutlined />}
|
||||
</Button>
|
||||
) : (
|
||||
expandable
|
||||
)}
|
||||
</span>
|
||||
<Checkbox
|
||||
onChange={onSelectAll}
|
||||
indeterminate={indeterminate}
|
||||
|
||||
@@ -16,6 +16,7 @@ const SealTable: React.FC<SealTableProps & { pagination: PaginationProps }> = (
|
||||
rowKey,
|
||||
childParentKey,
|
||||
onExpand,
|
||||
onExpandAll,
|
||||
onSort,
|
||||
onCell,
|
||||
expandedRowKeys,
|
||||
@@ -51,6 +52,12 @@ const SealTable: React.FC<SealTableProps & { pagination: PaginationProps }> = (
|
||||
});
|
||||
}, [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 selectedRowKeys = rowSelection?.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) => {
|
||||
pagination?.onChange?.(page, pageSize);
|
||||
};
|
||||
@@ -115,6 +126,8 @@ const SealTable: React.FC<SealTableProps & { pagination: PaginationProps }> = (
|
||||
selectAll={selectState.selectAll}
|
||||
indeterminate={selectState.indeterminate}
|
||||
onSelectAll={handleSelectAllChange}
|
||||
onExpandAll={handleExpandAll}
|
||||
expandAll={expandAll}
|
||||
expandable={expandable}
|
||||
enableSelection={rowSelection?.enableSelection}
|
||||
hasColumns={parsedColumns.length > 0}
|
||||
|
||||
@@ -58,6 +58,7 @@ export interface SealTableProps {
|
||||
onCell?: (record: any, dataIndex: string) => void;
|
||||
onSort?: (dataIndex: string, order: 'ascend' | 'descend') => void;
|
||||
onExpand?: (expanded: boolean, record: any, rowKey: any) => void;
|
||||
onExpandAll?: (expanded: boolean) => void;
|
||||
renderChildren?: (data: any, parent?: any) => React.ReactNode;
|
||||
loadChildren?: (record: any, options?: any) => Promise<any[]>;
|
||||
loadChildrenAPI?: (record: any) => string;
|
||||
|
||||
Reference in New Issue
Block a user