Skip to content

Commit 63d0032

Browse files
feat: Add Pagination to App logs page (#36067)
1 parent b4090e3 commit 63d0032

File tree

3 files changed

+50
-15
lines changed

3 files changed

+50
-15
lines changed

.changeset/red-cherries-grin.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@rocket.chat/meteor": minor
3+
---
4+
5+
Adds pagination to the App/Logs list, allowing the user to see all logs, instead of a subset of the most recent ones

apps/meteor/client/views/marketplace/AppDetailsPage/tabs/AppLogs/AppLogs.tsx

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1-
import { Accordion, Box } from '@rocket.chat/fuselage';
1+
import { Accordion, Box, Pagination } from '@rocket.chat/fuselage';
22
import type { ReactElement } from 'react';
33
import { useTranslation } from 'react-i18next';
44

55
import AppLogsItem from './AppLogsItem';
6+
import { CustomScrollbars } from '../../../../../components/CustomScrollbars';
7+
import { usePagination } from '../../../../../components/GenericTable/hooks/usePagination';
68
import { useFormatDateAndTime } from '../../../../../hooks/useFormatDateAndTime';
79
import AccordionLoading from '../../../components/AccordionLoading';
810
import { useLogs } from '../../../hooks/useLogs';
911

1012
const AppLogs = ({ id }: { id: string }): ReactElement => {
1113
const { t } = useTranslation();
1214
const formatDateAndTime = useFormatDateAndTime();
13-
const { data, isSuccess, isError, isLoading } = useLogs(id);
15+
const { current, itemsPerPage, setItemsPerPage: onSetItemsPerPage, setCurrent: onSetCurrent, ...paginationProps } = usePagination();
16+
const { data, isSuccess, isError, isLoading } = useLogs({ appId: id, current, itemsPerPage });
1417

1518
return (
1619
<>
@@ -21,17 +24,28 @@ const AppLogs = ({ id }: { id: string }): ReactElement => {
2124
</Box>
2225
)}
2326
{isSuccess && (
24-
<Accordion width='100%' alignSelf='center'>
25-
{data?.logs?.map((log) => (
26-
<AppLogsItem
27-
key={log._createdAt}
28-
title={`${formatDateAndTime(log._createdAt)}: "${log.method}" (${log.totalTime}ms)`}
29-
instanceId={log.instanceId}
30-
entries={log.entries}
31-
/>
32-
))}
33-
</Accordion>
27+
<CustomScrollbars>
28+
<Accordion width='100%' alignSelf='center'>
29+
{data?.logs?.map((log) => (
30+
<AppLogsItem
31+
key={log._createdAt}
32+
title={`${formatDateAndTime(log._createdAt)}: "${log.method}" (${log.totalTime}ms)`}
33+
instanceId={log.instanceId}
34+
entries={log.entries}
35+
/>
36+
))}
37+
</Accordion>
38+
</CustomScrollbars>
3439
)}
40+
<Pagination
41+
divider
42+
current={current}
43+
itemsPerPage={itemsPerPage}
44+
count={data?.total || 0}
45+
onSetItemsPerPage={onSetItemsPerPage}
46+
onSetCurrent={onSetCurrent}
47+
{...paginationProps}
48+
/>
3549
</>
3650
);
3751
};

apps/meteor/client/views/marketplace/hooks/useLogs.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,28 @@ import type { OperationResult } from '@rocket.chat/rest-typings';
22
import { useEndpoint } from '@rocket.chat/ui-contexts';
33
import type { UseQueryResult } from '@tanstack/react-query';
44
import { useQuery } from '@tanstack/react-query';
5+
import { useMemo } from 'react';
56

6-
export const useLogs = (appId: string): UseQueryResult<OperationResult<'GET', '/apps/:id/logs'>> => {
7+
export const useLogs = ({
8+
appId,
9+
current,
10+
itemsPerPage,
11+
}: {
12+
appId: string;
13+
current: number;
14+
itemsPerPage: number;
15+
}): UseQueryResult<OperationResult<'GET', '/apps/:id/logs'>> => {
16+
const query = useMemo(
17+
() => ({
18+
count: itemsPerPage,
19+
offset: current,
20+
}),
21+
[itemsPerPage, current],
22+
);
723
const logs = useEndpoint('GET', '/apps/:id/logs', { id: appId });
824

925
return useQuery({
10-
queryKey: ['marketplace', 'apps', appId, 'logs'],
11-
queryFn: () => logs({}),
26+
queryKey: ['marketplace', 'apps', appId, 'logs', query],
27+
queryFn: () => logs(query),
1228
});
1329
};

0 commit comments

Comments
 (0)