* start moving ui to redux tlk * remove unused reducer * changes for gdpr and site types * ui: migrating duck/roles to mobx * ui: drop unreferenced types * ui: drop unreferenced types * ui: move player slice reducer to mobx family * ui: move assignments to issueReportingStore.ts * remove issues store * some fixes after issues store * remove errors reducer, drop old components * finish removing errors reducer * start moving integrations state to mobx * change(ui): funnel duck cleanup * change(ui): custom fields * change(ui): customMetrics cleanup * change(ui): customMetrics cleanup * change(ui): duck/filters minor cleanup * change(ui): duck/filters cleanup * change(ui): duck/customMetrics cleanup and upgrades * fix integrations service, fix babel config to >.25 + not ie * refactoring integrations reducers etc WIP * finish removing integrations state * some fixes for integrated check * start of projects refactoring * move api and "few" files to new project store * new batch for site -> projects * fix setid context * move all critical components, drop site duck * remove all duck/site refs, remove old components * fixup for SessionTags.tsx, remove duck/sources (?) * move session store * init sessionstore outside of context * fix userfilter * replace simple actions for session store * sessions sotre * Rtm temp (#2597) * change(ui): duck/search wip * change(ui): duck/search wip * change(ui): duck/search wip * change(ui): duck/searchLive wip * change(ui): duck/searchLive wip * change(ui): duck/searchLive wip * change(ui): duck/searchLive wip * change(ui): search states * change(ui): search states * change(ui): search states * change(ui): fix savedSearch store * change(ui): fix savedSearch store * some fixes for session connector * change(ui): fix savedSearch store * change(ui): fix searchLive * change(ui): fix searchLive * fixes for session replay * change(ui): bookmark fetch * last components for sessions * add fetchautoplaylist * finish session reducer, remove deleted reducers * change(ui): fix the search fetch * change(ui): fix the search fetch * fix integrations call ctx * ensure ctx for sessionstore * fix(ui): checking for latest sessions path * start removing user reducer * removing user reducer pt2... * finish user store * remove rand log * fix crashes * tinkering workflow file for tracker test * making sure prefetched sessions work properly * fix conflict * fix router redirects during loading --------- Co-authored-by: Shekar Siri <sshekarsiri@gmail.com>
224 lines
6.5 KiB
TypeScript
224 lines
6.5 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 { 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 { VList, VListHandle } from "virtua";
|
|
|
|
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,
|
|
[LogLevel.DEBUG]: INFO,
|
|
} as const;
|
|
|
|
export const TABS = [ALL, ERRORS, WARNINGS, INFO].map((tab) => ({ text: tab, key: tab }));
|
|
|
|
const urlRegex = /(https?:\/\/[^\s)]+)/g;
|
|
|
|
export function renderWithNL(s: string | null = '') {
|
|
if (typeof s !== 'string') return '';
|
|
|
|
return s.split('\n').map((line, i) => {
|
|
const parts = line.split(urlRegex);
|
|
|
|
const formattedLine = parts.map((part, index) => {
|
|
if (urlRegex.test(part)) {
|
|
return (
|
|
<a key={`link-${index}`} className={'link text-main'} href={part} target="_blank" rel="noopener noreferrer">
|
|
{part}
|
|
</a>
|
|
);
|
|
}
|
|
return part;
|
|
});
|
|
|
|
return (
|
|
<div key={i + line.slice(0, 6)} className={cn({ 'ml-20': i !== 0 })}>
|
|
{formattedLine}
|
|
</div>
|
|
);
|
|
});
|
|
}
|
|
|
|
|
|
export const getIconProps = (level: LogLevel) => {
|
|
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',
|
|
};
|
|
default:
|
|
return {
|
|
name: 'console/info',
|
|
};
|
|
}
|
|
};
|
|
|
|
const INDEX_KEY = 'console';
|
|
|
|
function ConsolePanel({
|
|
isLive,
|
|
}: {
|
|
isLive?: boolean;
|
|
}) {
|
|
const {
|
|
sessionStore: { devTools },
|
|
uiPlayerStore,
|
|
} = useStore();
|
|
const zoomEnabled = uiPlayerStore.timelineZoom.enabled;
|
|
const zoomStartTs = uiPlayerStore.timelineZoom.startTs;
|
|
const zoomEndTs = uiPlayerStore.timelineZoom.endTs;
|
|
|
|
const _list = useRef<VListHandle>(null);
|
|
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]
|
|
).filter((l) =>
|
|
zoomEnabled ? l.time >= zoomStartTs && l.time <= zoomEndTs : true
|
|
) as ILog[]);
|
|
let filteredList = useRegExListFilterMemo(list, (l) => l.value, filter);
|
|
filteredList = useTabListFilterMemo(filteredList, (l) => LEVEL_TAB[l.level], ALL, activeTab);
|
|
|
|
React.useEffect(() => {
|
|
}, [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();
|
|
};
|
|
|
|
useEffect(() => {
|
|
if (_list.current) {
|
|
// @ts-ignore
|
|
_list.current.scrollToIndex(activeIndex);
|
|
}
|
|
}, [activeIndex]);
|
|
|
|
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();
|
|
};
|
|
|
|
return (
|
|
<BottomBlock style={{ height: '100%' }} 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}
|
|
>
|
|
<VList ref={_list} itemSize={25}>
|
|
{filteredList.map((log) => (
|
|
<ConsoleRow
|
|
log={log}
|
|
jump={jump}
|
|
iconProps={getIconProps(log.level)}
|
|
renderWithNL={renderWithNL}
|
|
onClick={() => showDetails(log)}
|
|
/>
|
|
))}
|
|
</VList>
|
|
</NoContent>
|
|
{/* @ts-ignore */}
|
|
</BottomBlock.Content>
|
|
</BottomBlock>
|
|
);
|
|
}
|
|
|
|
export default observer(ConsolePanel);
|