From 2a6fbbd696162769acff84c84df181ebd388b671 Mon Sep 17 00:00:00 2001 From: Kyle Sammons Date: Tue, 13 Feb 2024 11:40:40 -0800 Subject: [PATCH] Moved from a hardcoded string to a dynamic one --- src/datasource/components/Logs/LogsCell.tsx | 13 ++++++++----- src/datasource/components/Logs/LogsTable.tsx | 5 +++-- src/datasource/components/Logs/LogsView.tsx | 4 +++- src/pages/explore.tsx | 6 ++++++ 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/datasource/components/Logs/LogsCell.tsx b/src/datasource/components/Logs/LogsCell.tsx index d0bb241..3a9e1ee 100644 --- a/src/datasource/components/Logs/LogsCell.tsx +++ b/src/datasource/components/Logs/LogsCell.tsx @@ -56,10 +56,11 @@ interface ExpandedDocumentProps { datasourceUid: string, datasourceName: string, datasourceField: string, + logMessageField: string, } -const ExpandedDocument = ({ log, index, datasourceUid, datasourceName, datasourceField }: ExpandedDocumentProps) => { +const ExpandedDocument = ({ log, index, datasourceUid, datasourceName, datasourceField, logMessageField }: ExpandedDocumentProps) => { // The index in the logs is off by one from the index in the table (due to the header row). In this // case we care about the index in the table, so add one to it. index += 1; @@ -119,7 +120,7 @@ const ExpandedDocument = ({ log, index, datasourceUid, datasourceName, datasour { Array.from(log.keys()).map((key) => ( - key !== '_source' ? + key !== logMessageField ? ( +const DocumentCell = (log: Log, style: any, rowIndex: number, expanded: boolean, datasourceUid: string, datasourceName: string, datasourceField: string, logMessageField: string) => (
{ Array.from(log.keys()).map((key) => ( - key !== '_source' ? + key !== logMessageField ? ) : '' @@ -275,6 +277,7 @@ const LogCell = ({ columnIndex, rowIndex, style, data }) => { const datasourceUid: string = data.datasourceUid; const datasourceName: string = data.datasourceName; const datasourceField: string = data.datasourceField; + const logMessageField: string = data.logMessageField; const { setSize } = getLogTableContext(); const darkModeEnabled = useTheme2().isDark ; @@ -324,7 +327,7 @@ const LogCell = ({ columnIndex, rowIndex, style, data }) => { if (column.logColumnType === LogColumnType.TIME) { return TimestampCell(timestamp, style, rowIndex, expandedRows, handleOnClick); } else if (column.logColumnType === LogColumnType.DOCUMENT) { - return DocumentCell(log, style, rowIndex, expandedRows[rowIndex], datasourceUid, datasourceName, datasourceField); + return DocumentCell(log, style, rowIndex, expandedRows[rowIndex], datasourceUid, datasourceName, datasourceField, logMessageField); } else { return FieldCell(); } diff --git a/src/datasource/components/Logs/LogsTable.tsx b/src/datasource/components/Logs/LogsTable.tsx index 72924ae..6946fef 100644 --- a/src/datasource/components/Logs/LogsTable.tsx +++ b/src/datasource/components/Logs/LogsTable.tsx @@ -33,9 +33,10 @@ interface LogsTableProps { setExpandedRows: ((value: boolean[] | ((preVar: boolean[]) => boolean[])) => void); setColumns: ((value: LogColumn[] | ((preVar: LogColumn[]) => LogColumn[])) => void); datasourceField: string; + logMessageField: string; } -const LogsTable = ({ logs, timeField, columns, timestamps, expandedRows, setColumns, setExpandedRows, datasourceUid, datasourceName, datasourceField }: LogsTableProps) => { +const LogsTable = ({ logs, timeField, columns, timestamps, expandedRows, setColumns, setExpandedRows, datasourceUid, datasourceName, datasourceField, logMessageField }: LogsTableProps) => { let gridRef: React.RefObject = React.createRef(); // In order to get highly variable (and unknown at the time of rendering) row heights in a virtualized environment @@ -79,7 +80,7 @@ const LogsTable = ({ logs, timeField, columns, timestamps, expandedRows, setColu rowCount={logs.length + 1} rowHeight={getSize} width={width} - itemData={{logs, timestamps, columns, timeField, setColumns, setExpandedRowsAndReRender, expandedRows, datasourceUid, datasourceName, datasourceField}} + itemData={{logs, timestamps, columns, timeField, setColumns, setExpandedRowsAndReRender, expandedRows, datasourceUid, datasourceName, datasourceField, logMessageField}} > {LogCell} diff --git a/src/datasource/components/Logs/LogsView.tsx b/src/datasource/components/Logs/LogsView.tsx index 7357557..46c3530 100644 --- a/src/datasource/components/Logs/LogsView.tsx +++ b/src/datasource/components/Logs/LogsView.tsx @@ -11,9 +11,10 @@ interface LogsViewProps { datasourceUid: string; datasourceName: string; datasourceField: string; + logMessageField: string; } -const LogsView = ({ logs, timeField, timestamps, datasourceUid, datasourceName, datasourceField }: LogsViewProps) => { +const LogsView = ({ logs, timeField, timestamps, datasourceUid, datasourceName, datasourceField, logMessageField }: LogsViewProps) => { const [columns, setColumns] = React.useState([ { logColumnType: LogColumnType.TIME, @@ -46,6 +47,7 @@ const LogsView = ({ logs, timeField, timestamps, datasourceUid, datasourceName, datasourceUid={datasourceUid} datasourceName={datasourceName} datasourceField={datasourceField} + logMessageField={logMessageField} /> ) diff --git a/src/pages/explore.tsx b/src/pages/explore.tsx index db6b327..b5d25e7 100644 --- a/src/pages/explore.tsx +++ b/src/pages/explore.tsx @@ -428,6 +428,11 @@ const KalDBLogsRenderer = ({ model }: SceneComponentProps) => { let linkedDatasource = null; let linkedDatasourceName = ''; let linkedDatasourceField = ''; + let logMessageField = ''; + + if (currentDataSource) { + logMessageField = currentDataSource.jsonData.logMessageField; + } if (currentDataSource && currentDataSource.jsonData.dataLinks?.length > 0) { linkedDatasourceUid = currentDataSource.jsonData.dataLinks[0].datasourceUid; @@ -455,6 +460,7 @@ const KalDBLogsRenderer = ({ model }: SceneComponentProps) => { datasourceUid={linkedDatasourceUid} datasourceName={linkedDatasourceName} datasourceField={linkedDatasourceField} + logMessageField={logMessageField} />
)}