fix: model list duplicate

This commit is contained in:
jialin
2024-07-09 16:59:35 +08:00
parent 734368dd49
commit fe14edbb4e
22 changed files with 247 additions and 69 deletions
+8 -5
View File
@@ -31,11 +31,14 @@ const DropdownButtons: React.FC<DropdownButtonsProps> = ({
return (
<>
{items?.length === 1 ? (
<Button
icon={_.get(items, '0.icon')}
size={size}
onClick={handleButtonClick}
></Button>
<Tooltip title={_.head(items)?.label}>
<Button
{..._.head(items)}
icon={_.get(items, '0.icon')}
size={size}
onClick={handleButtonClick}
></Button>
</Tooltip>
) : (
<Dropdown.Button
menu={{
-1
View File
@@ -1,6 +1,5 @@
// footer all styles
.footer {
position: fixed;
bottom: 0;
width: 100%;
background-color: transparent;
+1 -1
View File
@@ -1,7 +1,7 @@
import { createFromIconfontCN } from '@ant-design/icons';
const IconFont = createFromIconfontCN({
scriptUrl: '//at.alicdn.com/t/c/font_4613488_clxjnjvlf6m.js'
scriptUrl: '//at.alicdn.com/t/c/font_4613488_n8fe7jbl7n.js'
});
export default IconFont;
@@ -17,6 +17,7 @@ const TableRow: React.FC<
rowIndex,
expandable,
rowSelection,
expandedRowKeys,
rowKey,
columns,
pollingChildren,
@@ -31,12 +32,14 @@ const TableRow: React.FC<
const [checked, setChecked] = useState(false);
const [childrenData, setChildrenData] = useState<any[]>([]);
const [loading, setLoading] = useState(false);
const [firstLoad, setFirstLoad] = useState(true);
const pollTimer = useRef<any>(null);
const chunkRequestRef = useRef<any>(null);
console.log('table row====');
const { updateChunkedList } = useUpdateChunkedList(childrenData, {
setDataList: setChildrenData
setDataList: setChildrenData,
callback: (list) => renderChildren?.(list)
});
useEffect(() => {
@@ -50,6 +53,14 @@ const TableRow: React.FC<
}
}, [rowSelection]);
useEffect(() => {
if (expandedRowKeys?.includes(record[rowKey])) {
setExpanded(true);
} else {
setExpanded(false);
}
}, [expandedRowKeys]);
useEffect(() => {
return () => {
if (pollTimer.current) {
@@ -75,6 +86,7 @@ const TableRow: React.FC<
};
const handleLoadChildren = async () => {
console.log('first load=====', firstLoad);
try {
setLoading(true);
const data = await loadChildren?.(record);
@@ -83,6 +95,8 @@ const TableRow: React.FC<
} catch (error) {
setChildrenData([]);
setLoading(false);
} finally {
setFirstLoad(false);
}
};
@@ -113,9 +127,9 @@ const TableRow: React.FC<
const handleRowExpand = async () => {
setExpanded(!expanded);
onExpand?.(!expanded, record);
onExpand?.(!expanded, record, record[rowKey]);
console.log('expanded=====', record);
chunkRequestRef.current?.current?.cancel?.();
if (pollTimer.current) {
clearInterval(pollTimer.current);
}
@@ -149,10 +163,15 @@ const TableRow: React.FC<
};
useEffect(() => {
if (childrenData.length) {
if (!firstLoad && expanded) {
createChunkRequest();
} else {
chunkRequestRef.current?.current?.cancel?.();
}
}, [childrenData]);
return () => {
chunkRequestRef.current?.current?.cancel?.();
};
}, [firstLoad, expanded]);
const renderRowPrefix = () => {
if (expandable && rowSelection) {
+2
View File
@@ -12,6 +12,7 @@ const SealTable: React.FC<SealTableProps> = (props) => {
children,
rowKey,
onExpand,
expandedRowKeys,
loading,
expandable,
pollingChildren,
@@ -144,6 +145,7 @@ const SealTable: React.FC<SealTableProps> = (props) => {
loadChildren={loadChildren}
loadChildrenAPI={loadChildrenAPI}
onExpand={onExpand}
expandedRowKeys={expandedRowKeys}
></TableRow>
);
})}
+2 -1
View File
@@ -24,6 +24,7 @@ export interface RowSelectionProps {
onChange: (selectedRowKeys: React.Key[]) => void;
}
export interface SealTableProps {
expandedRowKeys?: React.Key[];
rowSelection?: RowSelectionProps;
children: React.ReactNode[];
empty?: React.ReactNode;
@@ -32,7 +33,7 @@ export interface SealTableProps {
pollingChildren?: boolean;
watchChildren?: boolean;
loading?: boolean;
onExpand?: (expanded: boolean, record: any) => void;
onExpand?: (expanded: boolean, record: any, rowKey: any) => void;
renderChildren?: (data: any) => React.ReactNode;
loadChildren?: (record: any) => Promise<any[]>;
loadChildrenAPI?: (record: any) => string;