Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/red-cherries-grin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": minor
---

Adds pagination to the App/Logs list, allowing the user to see all logs, instead of a subset of the most recent ones
Original file line number Diff line number Diff line change
@@ -1,37 +1,51 @@
import { Accordion, Box } from '@rocket.chat/fuselage';
import { Accordion, Box, Pagination } from '@rocket.chat/fuselage';
import type { ReactElement } from 'react';
import { useTranslation } from 'react-i18next';

import AppLogsItem from './AppLogsItem';
import { GenericTable } from '../../../../../components/GenericTable';
import { usePagination } from '../../../../../components/GenericTable/hooks/usePagination';
import { useFormatDateAndTime } from '../../../../../hooks/useFormatDateAndTime';
import AccordionLoading from '../../../components/AccordionLoading';
import { useLogs } from '../../../hooks/useLogs';

const AppLogs = ({ id }: { id: string }): ReactElement => {
const { t } = useTranslation();
const formatDateAndTime = useFormatDateAndTime();
const { data, isSuccess, isError, isLoading } = useLogs(id);
const { current, itemsPerPage, setItemsPerPage: onSetItemsPerPage, setCurrent: onSetCurrent, ...paginationProps } = usePagination();
const { data, isSuccess, isError, isLoading } = useLogs({ appId: id, current, itemsPerPage });

return (
<>
{isLoading && <AccordionLoading />}
{isError && (
<Box maxWidth='x600' alignSelf='center'>
{t('App_not_found')}
</Box>
)}
{isSuccess && (
<Accordion width='100%' alignSelf='center'>
{data?.logs?.map((log) => (
<AppLogsItem
key={log._createdAt}
title={`${formatDateAndTime(log._createdAt)}: "${log.method}" (${log.totalTime}ms)`}
instanceId={log.instanceId}
entries={log.entries}
/>
))}
</Accordion>
)}
<GenericTable>
Comment thread
MartinSchoeler marked this conversation as resolved.
Outdated
{isLoading && <AccordionLoading />}
{isError && (
<Box maxWidth='x600' alignSelf='center'>
{t('App_not_found')}
</Box>
)}
{isSuccess && (
<Accordion width='100%' alignSelf='center'>
{data?.logs?.map((log) => (
<AppLogsItem
key={log._createdAt}
title={`${formatDateAndTime(log._createdAt)}: "${log.method}" (${log.totalTime}ms)`}
instanceId={log.instanceId}
entries={log.entries}
/>
))}
</Accordion>
)}
</GenericTable>
<Pagination
divider
current={current}
itemsPerPage={itemsPerPage}
count={data?.total || 0}
onSetItemsPerPage={onSetItemsPerPage}
onSetCurrent={onSetCurrent}
{...paginationProps}
/>
</>
);
};
Expand Down
22 changes: 19 additions & 3 deletions apps/meteor/client/views/marketplace/hooks/useLogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,28 @@ import type { OperationResult } from '@rocket.chat/rest-typings';
import { useEndpoint } from '@rocket.chat/ui-contexts';
import type { UseQueryResult } from '@tanstack/react-query';
import { useQuery } from '@tanstack/react-query';
import { useMemo } from 'react';

export const useLogs = (appId: string): UseQueryResult<OperationResult<'GET', '/apps/:id/logs'>> => {
export const useLogs = ({
appId,
current,
itemsPerPage,
}: {
appId: string;
current: number;
itemsPerPage: number;
}): UseQueryResult<OperationResult<'GET', '/apps/:id/logs'>> => {
const query = useMemo(
() => ({
count: itemsPerPage,
offset: current,
}),
[itemsPerPage, current],
);
const logs = useEndpoint('GET', '/apps/:id/logs', { id: appId });

return useQuery({
queryKey: ['marketplace', 'apps', appId, 'logs'],
queryFn: () => logs({}),
queryKey: ['marketplace', 'apps', appId, query, 'logs'],
Comment thread
MartinSchoeler marked this conversation as resolved.
Outdated
queryFn: () => logs(query),
});
};