openreplay/frontend/app/components/Session_/BugReport/BugReportModal.tsx
Delirium 2ed4bba33e
feat(tracker/ui): support for multi tab sessions (#1236)
* 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>
2023-06-07 10:40:32 +02:00

224 lines
6.9 KiB
TypeScript

import React from 'react';
import { connect } from 'react-redux';
import { countries } from 'App/constants';
import { useStore } from 'App/mstore';
import { Button } from 'UI';
import { session as sessionRoute } from 'App/routes';
import { ReportDefaults, EnvData, Activity } from './types';
import Session from './components/Session';
import MetaInfo from './components/MetaInfo';
import Title from './components/Title';
import Comments from './components/Comments';
import Steps from './components/Steps';
import { mapEvents } from './utils';
import { fetchList as fetchMembers } from 'Duck/member';
interface Props {
hideModal: () => void;
session: Record<string, any>;
account: Record<string, any>;
width: number;
height: number;
xrayProps: {
currentLocation: Record<string, any>[];
resourceList: Record<string, any>[];
exceptionsList: Record<string, any>[];
eventsList: Record<string, any>[];
endTime: number;
};
fetchMembers: () => void
members: any;
}
function BugReportModal({ hideModal, session, width, height, account, xrayProps, fetchMembers, members }: Props) {
const reportRef = React.createRef<HTMLDivElement>();
const [isRendering, setRendering] = React.useState(false);
const { bugReportStore } = useStore();
const {
userBrowser,
userDevice,
userCountry,
userBrowserVersion,
userOs,
userOsVersion,
userDisplayName,
userDeviceType,
revId,
metadata,
sessionId,
events,
notes,
} = session;
const envObject: EnvData = {
Device: `${userDevice}${userDeviceType !== userDevice ? ` ${userDeviceType}` : ''}`,
Resolution: `${width}x${height}`,
Browser: `${userBrowser} v${userBrowserVersion}`,
OS: `${userOs} v${userOsVersion}`,
// @ts-ignore
Country: countries[userCountry],
};
if (revId) {
Object.assign(envObject, { Rev: revId });
}
const sessionUrl = `${window.location.origin}/${
window.location.pathname.split('/')[1]
}${sessionRoute(sessionId)}`;
const defaults: ReportDefaults = {
author: account.name,
env: envObject,
meta: metadata,
session: {
user: userDisplayName,
id: sessionId,
url: sessionUrl,
},
};
React.useEffect(() => {
fetchMembers()
bugReportStore.updateReportDefaults(defaults);
bugReportStore.setDefaultSteps(mapEvents(events));
}, []);
const onClose = () => {
hideModal();
return bugReportStore.clearStore();
}
const onGen = () => {
// @ts-ignore
import('html2canvas').then(({ default: html2canvas }) => {
// @ts-ignore
window.html2canvas = html2canvas;
// @ts-ignore
import('jspdf').then(({ jsPDF }) => {
setRendering(true);
const doc = new jsPDF('p', 'mm', 'a4');
const now = new Date().toISOString();
doc.addMetadata('Author', account.name);
doc.addMetadata('Title', 'OpenReplay Bug Report');
doc.addMetadata('Subject', 'OpenReplay Bug Report');
doc.addMetadata('Keywords', 'OpenReplay Bug Report');
doc.addMetadata('Creator', 'OpenReplay');
doc.addMetadata('Producer', 'OpenReplay');
doc.addMetadata('CreationDate', now);
// DO NOT DELETE UNUSED RENDER FUNCTION
// REQUIRED FOR FUTURE USAGE AND AS AN EXAMPLE OF THE FUNCTIONALITY
function buildPng() {
html2canvas(reportRef.current!, {
scale: 2,
ignoreElements: (e) => e.id.includes('pdf-ignore'),
}).then((canvas) => {
const imgData = canvas.toDataURL('img/png');
let imgWidth = 200;
let pageHeight = 295;
let imgHeight = (canvas.height * imgWidth) / canvas.width;
let heightLeft = imgHeight - pageHeight;
let position = 0;
doc.addImage(imgData, 'PNG', 5, 5, imgWidth, imgHeight);
doc.addImage('/assets/img/report-head.png', 'png', 210/2 - 40/2, 2, 45, 5);
if (position === 0 && heightLeft === 0) doc.addImage('/assets/img/report-head.png', 'png', 210/2 - 40/2, pageHeight - 5, 45, 5);
while (heightLeft >= 0) {
position = heightLeft - imgHeight;
doc.addPage();
doc.addImage(imgData, 'PNG', 5, position, imgWidth, imgHeight);
doc.addImage('/assets/img/report-head.png', 'png', 210/2 - 40/2, pageHeight - 5, 45, 5);
heightLeft -= pageHeight;
}
doc.link(5, 295 - Math.abs(heightLeft) - 25, 200, 30, { url: sessionUrl });
doc.save('Bug Report: ' + sessionId + '.pdf');
setRendering(false);
});
}
function buildText() {
doc
.html(reportRef.current!, {
x: 0,
y: 0,
width: 210,
windowWidth: reportRef.current!.getBoundingClientRect().width,
autoPaging: 'text',
html2canvas: {
ignoreElements: (e) => e.id.includes('pdf-ignore') || e instanceof SVGElement,
},
})
.save('html.pdf')
.then(() => {
setRendering(false);
})
.catch((e) => {
console.error(e);
setRendering(false);
});
}
// buildText();
buildPng();
const activity = {
network: xrayProps.resourceList,
console: xrayProps.exceptionsList,
clickRage: xrayProps.eventsList.filter((item: any) => item.type === 'CLICKRAGE'),
}
bugReportStore.composeReport(activity as unknown as Activity)
});
});
};
return (
<div
className="bg-white overflow-y-scroll"
style={{ height: '100vh' }}
>
<div className="flex flex-col p-4 gap-8 bg-white relative" ref={reportRef}>
<Title userName={account.name} />
<MetaInfo envObject={envObject} metadata={metadata} />
<Steps xrayProps={xrayProps} notes={notes} members={members} />
<Comments />
<Session user={userDisplayName} sessionUrl={sessionUrl} />
<div id="pdf-ignore" className="flex items-center gap-2 mt-4">
<Button icon="file-pdf" variant="primary" onClick={onGen} loading={isRendering}>
Download Bug Report
</Button>
<Button variant="text-primary" onClick={onClose}>
Close
</Button>
</div>
</div>
{isRendering ? (
<div
className="fixed min-h-screen flex text-xl items-center justify-center top-0 right-0 cursor-wait"
style={{ background: 'rgba(0,0,0, 0.2)', zIndex: 9999, width: 620, maxWidth: '70vw' }}
id="pdf-ignore"
>
<div>Rendering PDF Report</div>
</div>
) : null}
</div>
);
}
const WithUIState = connect((state) => ({
// @ts-ignore
session: state.getIn(['sessions', 'current']),
// @ts-ignore
account: state.getIn(['user', 'account']),
// @ts-ignore
members: state.getIn(['members', 'list']),
}), { fetchMembers })(BugReportModal);
export default WithUIState;