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

View File

@ -227,6 +227,18 @@ function GridTableComponent({
[newColumnData, props.renderColumnCell], [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(() => { useEffect(() => {
eventEmitter.emit(Events.TABLE_COLUMNS_DATA, { eventEmitter.emit(Events.TABLE_COLUMNS_DATA, {
columns: newColumnData, columns: newColumnData,
@ -243,7 +255,7 @@ function GridTableComponent({
columns={ columns={
openTracesButton openTracesButton
? columnDataWithOpenTracesButton ? columnDataWithOpenTracesButton
: newColumnsWithRenderColumnCell : newColumnsWithCustomColTitles
} }
dataSource={dataSource} dataSource={dataSource}
sticky={sticky} sticky={sticky}

View File

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

View File

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

View File

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