From f5b38891c075e49059fdd09983dda94a3ce62917 Mon Sep 17 00:00:00 2001 From: Mahmoud Shahrokni Date: Mon, 16 Mar 2026 12:54:43 +0100 Subject: [PATCH 1/2] [FEATURE] logstable: add json export to the logs table Signed-off-by: Mahmoud Shahrokni --- logstable/src/LogsTable.ts | 2 ++ logstable/src/LogsTableExportAction.tsx | 47 +++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 logstable/src/LogsTableExportAction.tsx diff --git a/logstable/src/LogsTable.ts b/logstable/src/LogsTable.ts index a5e39a760..ed63e65d6 100644 --- a/logstable/src/LogsTable.ts +++ b/logstable/src/LogsTable.ts @@ -16,6 +16,7 @@ import { LogsTableComponent } from './LogsTableComponent'; import { LogsTableItemSelectionActionsEditor } from './LogsTableItemSelectionActionsEditor'; import { LogsTableSettingsEditor } from './LogsTableSettingsEditor'; import { LogsTableOptions, LogsTableProps } from './model'; +import { LogsTableExportAction } from './LogsTableExportAction'; export const LogsTable: PanelPlugin = { PanelComponent: LogsTableComponent, @@ -29,4 +30,5 @@ export const LogsTable: PanelPlugin = { allowWrap: true, enableDetails: true, }), + actions: [{ component: LogsTableExportAction, location: 'header' }], }; diff --git a/logstable/src/LogsTableExportAction.tsx b/logstable/src/LogsTableExportAction.tsx new file mode 100644 index 000000000..04790c63c --- /dev/null +++ b/logstable/src/LogsTableExportAction.tsx @@ -0,0 +1,47 @@ +import { InfoTooltip } from '@perses-dev/components'; +import { IconButton } from '@mui/material'; +import DownloadIcon from 'mdi-material-ui/Download'; +import { sanitizeFilename } from '@perses-dev/plugin-system'; +import { useCallback, useMemo } from 'react'; +import { LogsTableProps } from './model'; + +export const LogsTableExportAction: React.FC = ({ queryResults, definition }) => { + const exportedResult = useMemo(() => { + return queryResults.flatMap((q) => q.data?.logs?.entries ?? []); + }, [queryResults]); + + const isDisabled = !exportedResult.length; + + const handleDownload = useCallback((): void => { + if (isDisabled) return; + try { + const jsonString = JSON.stringify(exportedResult, null, 2); + const blob = new Blob([jsonString], { type: 'application/json' }); + const url = URL.createObjectURL(blob); + const link = document.createElement('a'); + link.href = url; + const title = definition?.spec?.display?.name || 'Logs Table Data'; + const baseFilename = sanitizeFilename(title); + link.download = `${baseFilename}_data.json`; + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); + URL.revokeObjectURL(url); + } catch (error) { + console.error('Logs table export failed:', error); + } + }, [definition, exportedResult, isDisabled]); + + return ( + + + + + + ); +}; From 4ce8bec4bf03cccd8ee0df2e8cb7248281b32f7d Mon Sep 17 00:00:00 2001 From: Mahmoud Shahrokni Date: Mon, 16 Mar 2026 13:04:56 +0100 Subject: [PATCH 2/2] [IGNORE] add license header Signed-off-by: Mahmoud Shahrokni --- logstable/src/LogsTableExportAction.tsx | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/logstable/src/LogsTableExportAction.tsx b/logstable/src/LogsTableExportAction.tsx index 04790c63c..42d0bc850 100644 --- a/logstable/src/LogsTableExportAction.tsx +++ b/logstable/src/LogsTableExportAction.tsx @@ -1,3 +1,16 @@ +// Copyright The Perses Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + import { InfoTooltip } from '@perses-dev/components'; import { IconButton } from '@mui/material'; import DownloadIcon from 'mdi-material-ui/Download';