generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: CallList component and update usage (#431)
- Loading branch information
1 parent
d4d5455
commit dee120e
Showing
5 changed files
with
148 additions
and
95 deletions.
There are no files selected for viewing
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,96 @@ | ||
import React from 'react' | ||
import { CallEvent } from '../../protos/xyz/block/ftl/v1/console/console_pb' | ||
import { SidePanelContext } from '../../providers/side-panel-provider' | ||
import { formatDuration, formatTimestampShort } from '../../utils' | ||
import { TimelineCallDetails } from '../timeline/details/TimelineCallDetails' | ||
import { verbRefString } from '../verbs/verb.utils' | ||
|
||
interface Props { | ||
calls: CallEvent[] | undefined | ||
} | ||
|
||
export const CallList = ({ calls }: Props) => { | ||
const { openPanel, closePanel } = React.useContext(SidePanelContext) | ||
const [selectedCall, setSelectedCall] = React.useState<CallEvent | undefined>() | ||
|
||
const handleCallClicked = (call: CallEvent) => { | ||
if (selectedCall?.equals(call)) { | ||
setSelectedCall(undefined) | ||
closePanel() | ||
return | ||
} | ||
setSelectedCall(call) | ||
openPanel(<TimelineCallDetails timestamp={call.timeStamp!} call={call} />) | ||
} | ||
|
||
return ( | ||
<div className='flex flex-col h-full relative'> | ||
<div className='border border-gray-100 dark:border-slate-700 rounded h-full absolute inset-0'> | ||
<table className={`w-full table-fixed text-gray-600 dark:text-gray-300`}> | ||
<thead> | ||
<tr className='flex text-xs'> | ||
<th className='p-1 text-left border-b w-40 border-gray-100 dark:border-slate-700 flex-none sticky top-0 z-10'> | ||
Date | ||
</th> | ||
<th className='p-1 text-left border-b w-14 border-gray-100 dark:border-slate-700 flex-none sticky top-0 z-10'> | ||
Dur. | ||
</th> | ||
<th className='p-1 text-left border-b w-40 border-gray-100 dark:border-slate-700 flex-none sticky top-0 z-10'> | ||
Source | ||
</th> | ||
<th className='p-1 text-left border-b w-40 border-gray-100 dark:border-slate-700 flex-none sticky top-0 z-10'> | ||
Destination | ||
</th> | ||
<th className='p-1 text-left border-b border-gray-100 dark:border-slate-700 flex-1 flex-grow sticky top-0 z-10'> | ||
Request | ||
</th> | ||
<th className='p-1 text-left border-b border-gray-100 dark:border-slate-700 flex-1 flex-grow sticky top-0 z-10'> | ||
Response | ||
</th> | ||
<th className='p-1 text-left border-b border-gray-100 dark:border-slate-700 flex-1 flex-grow sticky top-0 z-10'> | ||
Error | ||
</th> | ||
</tr> | ||
</thead> | ||
</table> | ||
<div className='overflow-y-auto h-[calc(100%-1.5rem)]'> | ||
<table className={`w-full table-fixed text-gray-600 dark:text-gray-300`}> | ||
<tbody className='text-xs'> | ||
{calls?.map((call, index) => ( | ||
<tr | ||
key={`${index}-${call.timeStamp?.toDate().toUTCString()}`} | ||
className={`border-b border-gray-100 dark:border-slate-700 font-roboto-mono ${ | ||
selectedCall?.equals(call) ? 'bg-indigo-50 dark:bg-slate-700' : '' | ||
} relative flex cursor-pointer hover:bg-indigo-50 dark:hover:bg-slate-700`} | ||
onClick={() => handleCallClicked(call)} | ||
> | ||
<td className='p-1 w-40 items-center flex-none text-gray-400 dark:text-gray-400'> | ||
{formatTimestampShort(call.timeStamp)} | ||
</td> | ||
<td className='p-1 w-14 items-center flex-none text-gray-400 dark:text-gray-400 truncate'> | ||
{formatDuration(call.duration)} | ||
</td> | ||
<td className='p-1 w-40 flex-none text-indigo-500 dark:text-indigo-300'> | ||
{call.sourceVerbRef && verbRefString(call.sourceVerbRef)} | ||
</td> | ||
<td className='p-1 w-40 flex-none text-indigo-500 dark:text-indigo-300'> | ||
{call.destinationVerbRef && verbRefString(call.destinationVerbRef)} | ||
</td> | ||
<td className='p-1 flex-1 flex-grow truncate' title={call.request}> | ||
{call.request} | ||
</td> | ||
<td className='p-1 flex-1 flex-grow truncate' title={call.response}> | ||
{call.response} | ||
</td> | ||
<td className='p-1 flex-1 flex-grow truncate' title={call.error}> | ||
{call.error} | ||
</td> | ||
</tr> | ||
))} | ||
</tbody> | ||
</table> | ||
</div> | ||
</div> | ||
</div> | ||
) | ||
} |
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
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