feat: added custom title handling in gridtablecomponent

This commit is contained in:
sawhil 2025-04-26 08:28:08 +05:30 committed by Sahil Khan
parent 21d239ce68
commit b24095236f
5 changed files with 27 additions and 1 deletions

View File

@ -3555,6 +3555,12 @@ export const getAllEndpointsWidgetData = (
);
widget.renderColumnCell = {
'http.url': (url: any): ReactNode => {
const { endpoint } = extractPortAndEndpoint(url);
return (
<span>{endpoint === 'n/a' || url === undefined ? '-' : endpoint}</span>
);
},
A: (numOfCalls: any): ReactNode => (
<span>
{numOfCalls === 'n/a' || numOfCalls === undefined ? '-' : numOfCalls}
@ -3604,6 +3610,11 @@ export const getAllEndpointsWidgetData = (
),
};
widget.customColTitles = {
'http.url': 'Endpoint',
'net.peer.port': 'Port',
};
return widget;
};

View File

@ -227,6 +227,18 @@ function GridTableComponent({
[newColumnData, props.renderColumnCell],
);
const newColumnsWithCustomColTitles = useMemo(
() =>
newColumnsWithRenderColumnCell.map((column) => ({
...column,
...('dataIndex' in column &&
props.customColTitles?.[column.dataIndex as string]
? { title: props.customColTitles[column.dataIndex as string] }
: {}),
})),
[newColumnsWithRenderColumnCell, props.customColTitles],
);
useEffect(() => {
eventEmitter.emit(Events.TABLE_COLUMNS_DATA, {
columns: newColumnData,
@ -243,7 +255,7 @@ function GridTableComponent({
columns={
openTracesButton
? columnDataWithOpenTracesButton
: newColumnsWithRenderColumnCell
: newColumnsWithCustomColTitles
}
dataSource={dataSource}
sticky={sticky}

View File

@ -21,6 +21,7 @@ export type GridTableComponentProps = {
customOnRowClick?: (record: RowData) => void;
widgetId?: string;
renderColumnCell?: QueryTableProps['renderColumnCell'];
customColTitles?: Record<string, string>;
} & Pick<LogsExplorerTableProps, 'data'> &
Omit<TableProps<RowData>, 'columns' | 'dataSource'>;

View File

@ -30,6 +30,7 @@ function TablePanelWrapper({
customOnRowClick={customOnRowClick}
widgetId={widget.id}
renderColumnCell={widget.renderColumnCell}
customColTitles={widget.customColTitles}
// eslint-disable-next-line react/jsx-props-no-spreading
{...GRID_TABLE_CONFIG}
/>

View File

@ -115,6 +115,7 @@ export interface IBaseWidget {
export interface Widgets extends IBaseWidget {
query: Query;
renderColumnCell?: QueryTableProps['renderColumnCell'];
customColTitles?: Record<string, string>;
}
export interface PromQLWidgets extends IBaseWidget {