-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Chore: Refactor AppLogs to TS (#26938)
- Loading branch information
1 parent
3953fea
commit 022b64e
Showing
8 changed files
with
85 additions
and
77 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { Accordion, Box } from '@rocket.chat/fuselage'; | ||
import { useTranslation } from '@rocket.chat/ui-contexts'; | ||
import React, { ReactElement } from 'react'; | ||
|
||
import { useFormatDateAndTime } from '../../../hooks/useFormatDateAndTime'; | ||
import AccordionLoading from './AccordionLoading'; | ||
import LogItem from './LogItem'; | ||
import { useLogs } from './hooks/useLogs'; | ||
|
||
const AppLogs = ({ id }: { id: string }): ReactElement => { | ||
const t = useTranslation(); | ||
const formatDateAndTime = useFormatDateAndTime(); | ||
const { data, isSuccess, isError, isLoading } = useLogs(id); | ||
|
||
return ( | ||
<> | ||
{isLoading && <AccordionLoading />} | ||
{isError && ( | ||
<Box maxWidth='x600' alignSelf='center'> | ||
{t('App_not_found')} | ||
</Box> | ||
)} | ||
{isSuccess && ( | ||
<Accordion width='100%' alignSelf='center'> | ||
{data?.logs?.map((log) => ( | ||
<LogItem | ||
key={log._createdAt} | ||
title={`${formatDateAndTime(log._createdAt)}: "${log.method}" (${log.totalTime}ms)`} | ||
instanceId={log.instanceId} | ||
entries={log.entries} | ||
/> | ||
))} | ||
</Accordion> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
export default AppLogs; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { OperationResult } from '@rocket.chat/rest-typings'; | ||
import { useEndpoint } from '@rocket.chat/ui-contexts'; | ||
import { useQuery, UseQueryResult } from '@tanstack/react-query'; | ||
|
||
export const useLogs = (appId: string): UseQueryResult<OperationResult<'GET', '/apps/:id/logs'>> => { | ||
const logs = useEndpoint('GET', `/apps/${appId}/logs`); | ||
|
||
return useQuery(['MarketplaceAppLogs'], () => logs()); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
export interface ILogEntry { | ||
args: string[]; | ||
caller: string; | ||
severity: string; | ||
timestamp: string; | ||
} | ||
|
||
export interface ILogItem { | ||
appId: string; | ||
endTime: string; | ||
entries: ILogEntry[]; | ||
instanceId: string; | ||
method: string; | ||
startTime: string; | ||
totalTime: number; | ||
_createdAt: string; | ||
_id: string; | ||
_updatedAt: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters