0

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

View File

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

View File

@ -187,7 +187,7 @@ export default function Home() {
</Row> </Row>
</div> </div>
<br /> <br />
<LogTable logs={logsData} pageSize={5} /> <LogTable logs={logsData} initialPageSize={5} />
</div> </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) { Logs.getLayout = function getLayout(page: ReactElement) {