From 0df3c26f04fe43cccda2126182ea16b79e555f6b Mon Sep 17 00:00:00 2001 From: Vikrant Gupta Date: Fri, 22 Mar 2024 13:28:38 +0530 Subject: [PATCH] feat: implement download logs feature for logs explorer new design (#4728) * feat: implement download logs feature for logs explorer new design * feat: address review comments * feat: added timestamp and body to the start --------- Co-authored-by: Nityananda Gohain --- .../LogsFormatOptionsMenu.styles.scss | 6 +- .../DownloadV2/DownloadV2.styles.scss | 84 +++++++++++++++++++ .../src/container/DownloadV2/DownloadV2.tsx | 84 +++++++++++++++++++ .../container/DownloadV2/DownloadV2.types.ts | 10 +++ .../src/container/LogsExplorerViews/index.tsx | 27 +++++- 5 files changed, 207 insertions(+), 4 deletions(-) create mode 100644 frontend/src/container/DownloadV2/DownloadV2.styles.scss create mode 100644 frontend/src/container/DownloadV2/DownloadV2.tsx create mode 100644 frontend/src/container/DownloadV2/DownloadV2.types.ts diff --git a/frontend/src/components/LogsFormatOptionsMenu/LogsFormatOptionsMenu.styles.scss b/frontend/src/components/LogsFormatOptionsMenu/LogsFormatOptionsMenu.styles.scss index efd668ffe1..af325a2d25 100644 --- a/frontend/src/components/LogsFormatOptionsMenu/LogsFormatOptionsMenu.styles.scss +++ b/frontend/src/components/LogsFormatOptionsMenu/LogsFormatOptionsMenu.styles.scss @@ -27,7 +27,7 @@ line-height: 18px; letter-spacing: 0.08em; text-align: left; - color: var(--bg-slate-200, #52575c); + color: #52575c; } .menu-items { @@ -65,7 +65,7 @@ padding: 12px; .title { - color: var(--bg-slate-200, #52575c); + color: #52575c; font-family: Inter; font-size: 11px; font-style: normal; @@ -149,7 +149,7 @@ } .title { - color: var(--bg-slate-200, #52575c); + color: #52575c; font-family: Inter; font-size: 11px; font-style: normal; diff --git a/frontend/src/container/DownloadV2/DownloadV2.styles.scss b/frontend/src/container/DownloadV2/DownloadV2.styles.scss new file mode 100644 index 0000000000..850c1c7d16 --- /dev/null +++ b/frontend/src/container/DownloadV2/DownloadV2.styles.scss @@ -0,0 +1,84 @@ +.download-logs-popover { + .ant-popover-inner { + border-radius: 4px; + border: 1px solid var(--bg-slate-400); + background: linear-gradient( + 139deg, + rgba(18, 19, 23, 0.8) 0%, + rgba(18, 19, 23, 0.9) 98.68% + ); + box-shadow: 4px 10px 16px 2px rgba(0, 0, 0, 0.2); + backdrop-filter: blur(20px); + padding: 12px 18px 12px 14px; + + .download-logs-content { + display: flex; + flex-direction: column; + gap: 8px; + align-items: flex-start; + + .action-btns { + padding: 4px 0px !important; + width: 159px; + display: flex; + align-items: center; + color: var(--bg-vanilla-400); + font-size: 14px; + font-style: normal; + font-weight: 400; + line-height: normal; + letter-spacing: 0.14px; + gap: 6px; + + .ant-btn-icon { + margin-inline-end: 0px; + } + } + + .action-btns:hover { + &.ant-btn-text { + background-color: rgba(171, 189, 255, 0.04) !important; + } + } + + .export-heading { + color: #52575c; + font-size: 11px; + font-style: normal; + font-weight: 600; + line-height: 18px; /* 163.636% */ + letter-spacing: 0.88px; + text-transform: uppercase; + } + } + } +} + +.lightMode { + .download-logs-popover { + .ant-popover-inner { + border: 1px solid var(--bg-vanilla-300); + background: linear-gradient( + 139deg, + rgba(255, 255, 255, 0.8) 0%, + rgba(255, 255, 255, 0.9) 98.68% + ); + + box-shadow: 4px 10px 16px 2px rgba(255, 255, 255, 0.2); + + .download-logs-content { + .action-btns { + color: var(--bg-ink-400); + } + .action-btns:hover { + &.ant-btn-text { + background-color: var(--bg-vanilla-300) !important; + } + } + .export-heading { + color: var(--bg-ink-200); + } + } + } + } +} diff --git a/frontend/src/container/DownloadV2/DownloadV2.tsx b/frontend/src/container/DownloadV2/DownloadV2.tsx new file mode 100644 index 0000000000..95630efcb9 --- /dev/null +++ b/frontend/src/container/DownloadV2/DownloadV2.tsx @@ -0,0 +1,84 @@ +import './DownloadV2.styles.scss'; + +import { Button, Popover, Typography } from 'antd'; +import { Excel } from 'antd-table-saveas-excel'; +import { FileDigit, FileDown, Sheet } from 'lucide-react'; +import { unparse } from 'papaparse'; + +import { DownloadProps } from './DownloadV2.types'; + +function Download({ data, isLoading, fileName }: DownloadProps): JSX.Element { + const downloadExcelFile = (): void => { + const headers = Object.keys(Object.assign({}, ...data)).map((item) => { + const updatedTitle = item + .split('_') + .map((word) => word.charAt(0).toUpperCase() + word.slice(1)) + .join(' '); + return { + title: updatedTitle, + dataIndex: item, + }; + }); + const excel = new Excel(); + excel + .addSheet(fileName) + .addColumns(headers) + .addDataSource(data, { + str2Percent: true, + }) + .saveAs(`${fileName}.xlsx`); + }; + + const downloadCsvFile = (): void => { + const csv = unparse(data); + const csvBlob = new Blob([csv], { type: 'text/csv;charset=utf-8;' }); + const csvUrl = URL.createObjectURL(csvBlob); + const downloadLink = document.createElement('a'); + downloadLink.href = csvUrl; + downloadLink.download = `${fileName}.csv`; + downloadLink.click(); + downloadLink.remove(); + }; + + return ( + + Export As + + + + } + > +