Fixed page size stale state on LogTable component (#3516)

This commit is contained in:
Aziz Rmadi 2024-01-22 22:31:23 -06:00 committed by GitHub
parent 841c300431
commit 6c644330e7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 17 additions and 8 deletions

View File

@ -1,7 +1,7 @@
import React, { FC } from 'react';
import React, { FC, useState } from 'react';
import { Table, Tag, Typography } from 'antd';
import Linkify from 'react-linkify';
import { SortOrder } from 'antd/lib/table/interface';
import { SortOrder, TablePaginationConfig } from 'antd/lib/table/interface';
import format from 'date-fns/format';
const { Title } = Typography;
@ -24,13 +24,19 @@ function renderMessage(text) {
export type LogTableProps = {
logs: object[];
pageSize: number;
initialPageSize: number;
};
export const LogTable: FC<LogTableProps> = ({ logs, pageSize }) => {
export const LogTable: FC<LogTableProps> = ({ logs, initialPageSize }) => {
if (!logs?.length) {
return null;
}
const [pageSize, setPageSize] = useState(initialPageSize);
const handleTableChange = (pagination: TablePaginationConfig) => {
setPageSize(pagination.pageSize);
};
const columns = [
{
title: 'Level',
@ -81,7 +87,10 @@ export const LogTable: FC<LogTableProps> = ({ logs, pageSize }) => {
dataSource={logs}
columns={columns}
rowKey={row => row.time}
pagination={{ pageSize: pageSize || 20 }}
pagination={{
pageSize,
}}
onChange={handleTableChange}
/>
</div>
);

View File

@ -170,7 +170,7 @@ export const Offline: FC<OfflineProps> = ({ logs = [], config }) => {
<NewsFeed />
</Col>
</Row>
<LogTable logs={logs} pageSize={5} />
<LogTable logs={logs} initialPageSize={5} />
</>
);
};

View File

@ -187,7 +187,7 @@ export default function Home() {
</Row>
</div>
<br />
<LogTable logs={logsData} pageSize={5} />
<LogTable logs={logsData} initialPageSize={5} />
</div>
);
}

View File

@ -32,7 +32,7 @@ export default function Logs() {
};
}, []);
return <LogTable logs={logs} pageSize={20} />;
return <LogTable logs={logs} initialPageSize={20} />;
}
Logs.getLayout = function getLayout(page: ReactElement) {