* feat(tracker): add support for multi tab sessions
* feat(backend): added support of multitabs
* fix(backend): added support of deprecated batch meta message to pre-decoder
* fix(backend): fixed nil meta issue for TabData messages in sink
* feat(player): add tabmanager
* feat(player): basic tabchange event support
* feat(player): pick tabstate for console panel and timeline
* fix(player): only display tabs that are created
* feat(player): connect performance, xray and events to tab state
* feat(player): merge all tabs data for overview
* feat(backend/tracker): extract tabdata into separate message from batchmeta
* fix(tracker): fix new session check
* fix(backend): remove batchmetadeprecated
* fix(backend): fix switch case
* fix(player): fix for tab message size
* feat(tracker): check for active tabs with broadcast channel
* feat(tracker): prevent multiple messages
* fix(tracker): ignore beacons from same tab, only ask if token isnt present yet, add small delay before start to wait for answer
* feat(player): support new msg struct in assist player
* fix(player): fix some livepl components for multi tab states
* feat(tracker): add option to disable multitab
* feat(tracker): add multitab to assist plugin
* feat(player): back compat for tab id
* fix(ui): fix missing list in controls
* fix(ui): optional list update
* feat(ui): fix visuals for multitab; use window focus event for tabs
* fix(tracker): fix for dying tests (added tabid to writer, refactored other tests)
* feat(ui): update LivePlayerSubHeader.tsx to support tabs
* feat(backend): added tabs support to devtools mob files
* feat(ui): connect state to current tab properly
* feat(backend): added multitab support to assits
* feat(backend): removed data check in agent message
* feat(backend): debug on
* fix(backend): fixed typo in message broadcast
* feat(backend): fixed issue in connect method
* fix(assist): fixed typo
* feat(assist): added more debug logs
* feat(assist): removed one log
* feat(assist): more logs
* feat(assist): use query.peerId
* feat(assist): more logs
* feat(assist): fixed session update
* fix(assist): fixed getSessions
* fix(assist): fixed request_control broadcast
* fix(assist): fixed typo
* fix(assist): added missed line
* fix(assist): fix typo
* feat(tracker): multitab support for assist sessions
* fix(tracker): fix dead tests (tabid prop)
* fix(tracker): fix yaml
* fix(tracker): timers issue
* fix(ui): fix ui E2E tests with magic?
* feat(assist): multitabs support for ee version
* fix(assist): added missed method import
* fix(tracker): fix fix events in assist
* feat(assist): added back compatibility for sessions without tabId
* fix(assist): apply message's top layer structure before broadcast call
* fix(assist): added random tabID for prev version
* fix(assist): added random tabID for prev version (ee)
* feat(assist): added debug logs
* fix(assist): fix typo in sessions_agents_count method
* fix(assist): fixed more typos in copy-pastes
* fix(tracker): fix restart timings
* feat(backend): added tabIDs for some events
* feat(ui): add tab change event to the user steps bar
* Revert "feat(backend): added tabIDs for some events"
This reverts commit 1467ad7f9f.
* feat(ui): revert timeline and xray to grab events from all tabs
* fix(ui): fix typo
---------
Co-authored-by: Alexander Zavorotynskiy <zavorotynskiy@pm.me>
224 lines
6.9 KiB
TypeScript
224 lines
6.9 KiB
TypeScript
import React, { useEffect, useRef, useState, useMemo } from 'react';
|
|
import { LogLevel, ILog } from 'Player';
|
|
import BottomBlock from '../BottomBlock';
|
|
import { Tabs, Input, Icon, NoContent } from 'UI';
|
|
import cn from 'classnames';
|
|
import ConsoleRow from '../ConsoleRow';
|
|
import { PlayerContext } from 'App/components/Session/playerContext';
|
|
import { observer } from 'mobx-react-lite';
|
|
import { List, CellMeasurer, AutoSizer } from 'react-virtualized';
|
|
import { useStore } from 'App/mstore';
|
|
import ErrorDetailsModal from 'App/components/Dashboard/components/Errors/ErrorDetailsModal';
|
|
import { useModal } from 'App/components/Modal';
|
|
import useAutoscroll, { getLastItemTime } from '../useAutoscroll';
|
|
import { useRegExListFilterMemo, useTabListFilterMemo } from '../useListFilter'
|
|
import useCellMeasurerCache from 'App/hooks/useCellMeasurerCache'
|
|
import { toJS } from 'mobx'
|
|
|
|
const ALL = 'ALL';
|
|
const INFO = 'INFO';
|
|
const WARNINGS = 'WARNINGS';
|
|
const ERRORS = 'ERRORS';
|
|
|
|
const LEVEL_TAB = {
|
|
[LogLevel.INFO]: INFO,
|
|
[LogLevel.LOG]: INFO,
|
|
[LogLevel.WARN]: WARNINGS,
|
|
[LogLevel.ERROR]: ERRORS,
|
|
[LogLevel.EXCEPTION]: ERRORS,
|
|
} as const
|
|
|
|
const TABS = [ALL, ERRORS, WARNINGS, INFO].map((tab) => ({ text: tab, key: tab }));
|
|
|
|
function renderWithNL(s: string | null = '') {
|
|
if (typeof s !== 'string') return '';
|
|
return s.split('\n').map((line, i) => <div key={i + line.slice(0, 6)} className={cn({ 'ml-20': i !== 0 })}>{line}</div>);
|
|
}
|
|
|
|
const getIconProps = (level: any) => {
|
|
switch (level) {
|
|
case LogLevel.INFO:
|
|
case LogLevel.LOG:
|
|
return {
|
|
name: 'console/info',
|
|
color: 'blue2',
|
|
};
|
|
case LogLevel.WARN:
|
|
return {
|
|
name: 'console/warning',
|
|
color: 'red2',
|
|
};
|
|
case LogLevel.ERROR:
|
|
return {
|
|
name: 'console/error',
|
|
color: 'red',
|
|
};
|
|
}
|
|
return null;
|
|
};
|
|
|
|
|
|
const INDEX_KEY = 'console';
|
|
|
|
function ConsolePanel({ isLive }: { isLive: boolean }) {
|
|
const {
|
|
sessionStore: { devTools },
|
|
} = useStore()
|
|
|
|
const filter = devTools[INDEX_KEY].filter;
|
|
const activeTab = devTools[INDEX_KEY].activeTab;
|
|
// Why do we need to keep index in the store? if we could get read of it it would simplify the code
|
|
const activeIndex = devTools[INDEX_KEY].index;
|
|
const [ isDetailsModalActive, setIsDetailsModalActive ] = useState(false);
|
|
const { showModal } = useModal();
|
|
|
|
const { player, store } = React.useContext(PlayerContext)
|
|
const jump = (t: number) => player.jump(t)
|
|
|
|
const { currentTab, tabStates } = store.get()
|
|
const { logList = [], exceptionsList = [], logListNow = [], exceptionsListNow = [] } = tabStates[currentTab]
|
|
|
|
const list = isLive ?
|
|
useMemo(() => logListNow.concat(exceptionsListNow).sort((a, b) => a.time - b.time),
|
|
[logListNow.length, exceptionsListNow.length]
|
|
) as ILog[]
|
|
: useMemo(() => logList.concat(exceptionsList).sort((a, b) => a.time - b.time),
|
|
[ logList.length, exceptionsList.length ],
|
|
) as ILog[]
|
|
let filteredList = useRegExListFilterMemo(list, l => l.value, filter)
|
|
filteredList = useTabListFilterMemo(filteredList, l => LEVEL_TAB[l.level], ALL, activeTab)
|
|
|
|
React.useEffect(() => {
|
|
setTimeout(() => {
|
|
cache.clearAll();
|
|
_list.current?.recomputeRowHeights();
|
|
}, 0)
|
|
}, [activeTab, filter])
|
|
const onTabClick = (activeTab: any) => devTools.update(INDEX_KEY, { activeTab })
|
|
const onFilterChange = ({ target: { value } }: any) => devTools.update(INDEX_KEY, { filter: value })
|
|
|
|
// AutoScroll
|
|
const [
|
|
timeoutStartAutoscroll,
|
|
stopAutoscroll,
|
|
] = useAutoscroll(
|
|
filteredList,
|
|
getLastItemTime(logListNow, exceptionsListNow),
|
|
activeIndex,
|
|
index => devTools.update(INDEX_KEY, { index })
|
|
)
|
|
const onMouseEnter = stopAutoscroll
|
|
const onMouseLeave = () => {
|
|
if (isDetailsModalActive) { return }
|
|
timeoutStartAutoscroll()
|
|
}
|
|
|
|
const _list = useRef<List>(null); // TODO: fix react-virtualized types & encapsulate scrollToRow logic
|
|
useEffect(() => {
|
|
if (_list.current) {
|
|
// @ts-ignore
|
|
_list.current.scrollToRow(activeIndex);
|
|
}
|
|
}, [activeIndex]);
|
|
|
|
const cache = useCellMeasurerCache()
|
|
|
|
const showDetails = (log: any) => {
|
|
setIsDetailsModalActive(true);
|
|
showModal(
|
|
<ErrorDetailsModal errorId={log.errorId} />,
|
|
{
|
|
right: true,
|
|
width: 1200,
|
|
onClose: () => {
|
|
setIsDetailsModalActive(false)
|
|
timeoutStartAutoscroll()
|
|
}
|
|
});
|
|
devTools.update(INDEX_KEY, { index: filteredList.indexOf(log) });
|
|
stopAutoscroll()
|
|
}
|
|
const _rowRenderer = ({ index, key, parent, style }: any) => {
|
|
const item = filteredList[index];
|
|
|
|
return (
|
|
// @ts-ignore
|
|
<CellMeasurer cache={cache} columnIndex={0} key={key} rowIndex={index} parent={parent}>
|
|
{({ measure, registerChild }) => (
|
|
<div ref={registerChild} style={style}>
|
|
<ConsoleRow
|
|
log={item}
|
|
jump={jump}
|
|
iconProps={getIconProps(item.level)}
|
|
renderWithNL={renderWithNL}
|
|
onClick={() => showDetails(item)}
|
|
recalcHeight={measure}
|
|
/>
|
|
</div>
|
|
)}
|
|
</CellMeasurer>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<BottomBlock
|
|
style={{ height: '300px' }}
|
|
onMouseEnter={onMouseEnter}
|
|
onMouseLeave={onMouseLeave}
|
|
>
|
|
{/* @ts-ignore */}
|
|
<BottomBlock.Header>
|
|
<div className="flex items-center">
|
|
<span className="font-semibold color-gray-medium mr-4">Console</span>
|
|
<Tabs tabs={TABS} active={activeTab} onClick={onTabClick} border={false} />
|
|
</div>
|
|
<Input
|
|
className="input-small h-8"
|
|
placeholder="Filter by keyword"
|
|
icon="search"
|
|
name="filter"
|
|
height={28}
|
|
onChange={onFilterChange}
|
|
value={filter}
|
|
/>
|
|
{/* @ts-ignore */}
|
|
</BottomBlock.Header>
|
|
{/* @ts-ignore */}
|
|
<BottomBlock.Content className="overflow-y-auto">
|
|
<NoContent
|
|
title={
|
|
<div className="capitalize flex items-center mt-16">
|
|
<Icon name="info-circle" className="mr-2" size="18" />
|
|
No Data
|
|
</div>
|
|
}
|
|
size="small"
|
|
show={filteredList.length === 0}
|
|
>
|
|
{/* @ts-ignore */}
|
|
<AutoSizer>
|
|
{({ height, width }: any) => (
|
|
// @ts-ignore
|
|
<List
|
|
ref={_list}
|
|
deferredMeasurementCache={cache}
|
|
overscanRowCount={5}
|
|
estimatedRowSize={36}
|
|
rowCount={Math.ceil(filteredList.length || 1)}
|
|
rowHeight={cache.rowHeight}
|
|
rowRenderer={_rowRenderer}
|
|
width={width}
|
|
height={height}
|
|
// scrollToIndex={activeIndex}
|
|
scrollToAlignment="center"
|
|
/>
|
|
)}
|
|
</AutoSizer>
|
|
</NoContent>
|
|
{/* @ts-ignore */}
|
|
</BottomBlock.Content>
|
|
</BottomBlock>
|
|
);
|
|
}
|
|
|
|
export default observer(ConsolePanel);
|