Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added session downloader for chrome extension #1522

Merged
merged 3 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/wicked-dolphins-tie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rrweb/web-extension": minor
---

Added session downloader for chrome extension
52 changes: 33 additions & 19 deletions packages/web-extension/src/pages/SessionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { VscTriangleDown, VscTriangleUp } from 'react-icons/vsc';
import { useNavigate } from 'react-router-dom';
import { type Session, EventName } from '~/types';
import Channel from '~/utils/channel';
import { deleteSessions, getAllSessions } from '~/utils/storage';
import { deleteSessions, getAllSessions, downloadSessions } from '~/utils/storage';
import {
FiChevronLeft,
FiChevronRight,
Expand Down Expand Up @@ -292,24 +292,38 @@ export function SessionList() {
))}
</Select>
{Object.keys(rowSelection).length > 0 && (
<Button
mr={4}
size="md"
colorScheme="red"
onClick={() => {
if (table.getSelectedRowModel().flatRows.length === 0) return;
const ids = table
.getSelectedRowModel()
.flatRows.map((row) => row.original.id);
void deleteSessions(ids).then(() => {
setRowSelection({});
void updateSessions();
channel.emit(EventName.SessionUpdated, {});
});
}}
>
Delete
</Button>
<Flex gap={1}>
<Button
mr={4}
size="md"
colorScheme="red"
onClick={() => {
if (table.getSelectedRowModel().flatRows.length === 0) return;
const ids = table
.getSelectedRowModel()
.flatRows.map((row) => row.original.id);
void deleteSessions(ids).then(() => {
setRowSelection({});
void updateSessions();
channel.emit(EventName.SessionUpdated, {});
});
}}
>
Delete
</Button>
<Button
mr={4}
size="md"
colorScheme="green"
onClick={() => {
const selectedRows = table.getSelectedRowModel().flatRows;
if (selectedRows.length === 0) return;
void downloadSessions(selectedRows.map((row) => row.original.id));
}}
>
Download
</Button>
</Flex>
)}
</Flex>
</Flex>
Expand Down
19 changes: 19 additions & 0 deletions packages/web-extension/src/utils/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,22 @@ export async function deleteSessions(ids: string[]) {
return Promise.all([eventTransition.done, sessionTransition.done]);
});
}

export async function downloadSessions(ids: string[]) {
for (const sessionId of ids) {
const events = await getEvents(sessionId);
const session = await getSession(sessionId);
const blob = new Blob([JSON.stringify({ session, events }, null, 2)], {
type: 'application/json',
});

const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = `${session.name}.json`;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
}
}
Loading