-
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ISSUE-178 - added instant exports to explore tab
- Loading branch information
Showing
10 changed files
with
209 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
import PrimaryHeader from "./PrimaryHeader"; | ||
import SecondaryHeader from "./SecondaryHeader"; | ||
|
||
export { | ||
PrimaryHeader, | ||
SecondaryHeader | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// import { useEffect, useState } from 'react'; | ||
import type { Log } from '@/@types/parseable/api/query'; | ||
import { useHeaderContext } from '@/layouts/MainLayout/Context'; | ||
import { useLogsPageContext } from '@/pages/Logs/Context'; | ||
|
||
type Data = Log[] | null; | ||
|
||
const downloadDataAsJson = (data: Data, filename: string) => { | ||
if (data === null || data.length === 0) return; | ||
|
||
const jsonString = JSON.stringify(data, null, 2); | ||
const blob = new Blob([jsonString], { type: 'application/json' }); | ||
const downloadLink = document.createElement('a'); | ||
downloadLink.href = URL.createObjectURL(blob); | ||
downloadLink.download = `${filename}.json`; | ||
document.body.appendChild(downloadLink); | ||
downloadLink.click(); | ||
document.body.removeChild(downloadLink); | ||
}; | ||
|
||
const downloadDataAsCSV = (data: Data, filename: string) => { | ||
if (data === null || data.length === 0) return; | ||
|
||
const csvString = data | ||
.map((row) => | ||
Object.values(row) | ||
.map((value) => (value !== null ? value : '')) | ||
.join(','), | ||
) | ||
.join('\n'); | ||
const blob = new Blob([csvString], { type: 'text/csv;charset=utf-8;' }); | ||
const downloadLink = document.createElement('a'); | ||
downloadLink.href = URL.createObjectURL(blob); | ||
downloadLink.download = `${filename}.csv`; | ||
document.body.appendChild(downloadLink); | ||
downloadLink.click(); | ||
document.body.removeChild(downloadLink); | ||
}; | ||
|
||
export const useExportData = () => { | ||
const { | ||
state: { subLogQueryData }, | ||
} = useLogsPageContext(); | ||
const { | ||
state: { subLogQuery }, | ||
} = useHeaderContext(); | ||
const exportLogsHandler = (type: string) => { | ||
const { rawData, filteredData: _filteredData } = subLogQueryData.get(); // filteredData - records filtered with in-page search | ||
const query = subLogQuery.get(); | ||
const filename = `${query.streamName}-logs`; | ||
type === 'JSON' | ||
? downloadDataAsJson(rawData, filename) | ||
: type === 'CSV' | ||
? downloadDataAsCSV(rawData, filename) | ||
: null; | ||
}; | ||
|
||
return { exportLogsHandler }; | ||
}; |
Oops, something went wrong.