Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(logs): make every configured column reorderable, removable, and resizable (#69617)

Jon McCallum4f0d615ff5b3
diff --git a/products/logs/frontend/components/LogsViewer/config/LogsColumnConfigurator.tsx b/products/logs/frontend/components/LogsViewer/config/LogsColumnConfigurator.tsx
index d80f7f600741..41e2530734ca 100644
--- a/products/logs/frontend/components/LogsViewer/config/LogsColumnConfigurator.tsx
+++ b/products/logs/frontend/components/LogsViewer/config/LogsColumnConfigurator.tsx
@@ -48,16 +48,27 @@ function SelectedColumnRow({ column }: { column: LogsColumnConfig }): JSX.Elemen
const { id } = useValues(logsViewerLogic)
const { editingColumnId } = useValues(logsColumnConfiguratorLogic({ id }))
const { updateDraftColumn, removeDraftColumn, setEditingColumnId } = useActions(logsColumnConfiguratorLogic({ id }))
- const { setNodeRef, attributes, transform, transition, listeners } = useSortable({ id: column.id })
+ const { setNodeRef, attributes, transform, transition, listeners } = useSortable({
+ id: column.id,
+ disabled: column.type === 'message',
+ })
const isEditing = editingColumnId === column.id
return (
<div ref={setNodeRef} style={{ transform: CSS.Transform.toString(transform), transition }} {...attributes}>
<div className="flex items-center justify-start px-2 py-1 my-1 rounded bg-accent-highlight-secondary">
- <span {...listeners} className="pr-2 text-secondary cursor-move">
- <SortableDragIcon />
- </span>
+ {column.type === 'message' ? (
+ <Tooltip title="Message is always the last column">
+ <span className="pr-2 text-muted">
+ <SortableDragIcon />
+ </span>
+ </Tooltip>
+ ) : (
+ <span {...listeners} className="pr-2 text-secondary cursor-move">
+ <SortableDragIcon />
+ </span>
+ )}
<span className="truncate">{columnLabel(column)}</span>
{column.type === 'custom' && column.name && column.expression && column.expression !== column.name && (
<span className="ml-2 text-xs text-muted font-mono truncate">{column.expression}</span>
diff --git a/products/logs/frontend/components/LogsViewer/config/columns.test.ts b/products/logs/frontend/components/LogsViewer/config/columns.test.ts
index dfb6d27c1cfb..4f5db77dcdb8 100644
--- a/products/logs/frontend/components/LogsViewer/config/columns.test.ts
+++ b/products/logs/frontend/components/LogsViewer/config/columns.test.ts
@@ -1,6 +1,6 @@
import { AttributeColumnConfig } from 'products/logs/frontend/types'
-import { columnsToCustomColumns, LogsColumnConfig, migrateAttributeColumns } from './columns'
+import { columnsToCustomColumns, LogsColumnConfig, migrateAttributeColumns, normalizeColumns } from './columns'
describe('logs column config', () => {
describe('columnsToCustomColumns', () => {
@@ -53,4 +53,27 @@ describe('logs column config', () => {
expect(migrated.expression).toContain("we\\'ird\\\\key")
})
})
+
+ describe('normalizeColumns', () => {
+ it('pins message columns last, preserving relative order of the rest', () => {
+ const columns: LogsColumnConfig[] = [
+ { id: 'm', type: 'message' },
+ { id: 't', type: 'timestamp' },
+ { id: 'c', type: 'custom', expression: 'attributes.a' },
+ ]
+ expect(normalizeColumns(columns).map((c) => c.id)).toEqual(['t', 'c', 'm'])
+ })
+
+ it('returns the same reference when message is already last or absent', () => {
+ // Identity matters: reducers call this on every mutation, and a fresh array in the
+ // steady state would defeat referential-equality checks downstream
+ const alreadyLast: LogsColumnConfig[] = [
+ { id: 't', type: 'timestamp' },
+ { id: 'm', type: 'message' },
+ ]
+ expect(normalizeColumns(alreadyLast)).toBe(alreadyLast)
+ const noMessage: LogsColumnConfig[] = [{ id: 't', type: 'timestamp' }]
+ expect(normalizeColumns(noMessage)).toBe(noMessage)
+ })
+ })
})
diff --git a/products/logs/frontend/components/LogsViewer/config/columns.ts b/products/logs/frontend/components/LogsViewer/config/columns.ts
index 21d6279c134f..ba68754aa400 100644
--- a/products/logs/frontend/components/LogsViewer/config/columns.ts
+++ b/products/logs/frontend/components/LogsViewer/config/columns.ts
@@ -45,6 +45,24 @@ export const DEFAULT_LOGS_COLUMNS: LogsColumnConfig[] = [
{ id: 'message', type: 'message' },
]
+/**
+ * Message is pinned to the end: it's the flex fill column, and the row FAB (whose scroll
+ * buttons drive the message cell) anchors to the row's right edge.
+ */
+export function isPinnedColumn(column: LogsColumnConfig): boolean {
+ return column.type === 'message'
+}
+
+/** Sort pinned columns last, stable otherwise. Returns the input untouched when already normalized. */
+export function normalizeColumns(columns: LogsColumnConfig[]): LogsColumnConfig[] {
+ const firstPinnedIndex = columns.findIndex(isPinnedColumn)
+ if (firstPinnedIndex === -1 || columns.slice(firstPinnedIndex).every(isPinnedColumn)) {
+ return columns
+ }
+ const rest = columns.filter((column) => !isPinnedColumn(column))
+ return [...rest, ...columns.filter(isPinnedColumn)]
+}
+
export function columnLabel(column: LogsColumnConfig): string {
if (column.name) {
return column.name
diff --git a/products/logs/frontend/components/LogsViewer/config/logsColumnConfiguratorLogic.test.ts b/products/logs/frontend/components/LogsViewer/config/logsColumnConfiguratorLogic.test.ts
index 11ae317393ca..99f3b5b56de9 100644
--- a/products/logs/frontend/components/LogsViewer/config/logsColumnConfiguratorLogic.test.ts
+++ b/products/logs/frontend/components/LogsViewer/config/logsColumnConfiguratorLogic.test.ts
@@ -31,7 +31,8 @@ describe('logsColumnConfiguratorLogic', () => {
it('draft edits do not touch the applied columns until applyDraft', async () => {
const before = configLogic.values.columns
logic.actions.addDraftColumn({ type: 'custom' })
- const draftId = logic.values.draft[logic.values.draft.length - 1].id
+ // Normalization pins message last, so the new custom column sits just before it
+ const draftId = logic.values.draft.find((c) => c.type === 'custom')!.id
logic.actions.updateDraftColumn(draftId, { expression: 'attributes.http.url' })
// Still uncommitted — this is what keeps per-keystroke edits from firing logs queries
@@ -42,7 +43,9 @@ describe('logsColumnConfiguratorLogic', () => {
}).toFinishAllListeners()
expect(configLogic.values.columns).toHaveLength(before.length + 1)
- expect(configLogic.values.columns.at(-1)?.expression).toBe('attributes.http.url')
+ expect(configLogic.values.columns.find((c) => c.type === 'custom')?.expression).toBe('attributes.http.url')
+ // Message stays pinned last through apply
+ expect(configLogic.values.columns.at(-1)?.type).toBe('message')
expect(logic.values.isOpen).toBe(false)
})
@@ -68,10 +71,15 @@ describe('logsColumnConfiguratorLogic', () => {
expect(configLogic.values.columns).toEqual(before)
})
- it('moveDraftColumn reorders by index', () => {
+ it('moveDraftColumn reorders by index but keeps message pinned last', () => {
logic.actions.addDraftColumn({ type: 'custom', expression: 'attributes.a' })
+ // Draft is [timestamp, custom, message] after normalization
const ids = logic.values.draft.map((c) => c.id)
+ logic.actions.moveDraftColumn(0, 1)
+ expect(logic.values.draft.map((c) => c.id)).toEqual([ids[1], ids[0], ids[2]])
+
+ // Dragging a column onto/past message re-normalizes message back to the end
logic.actions.moveDraftColumn(0, 2)
- expect(logic.values.draft.map((c) => c.id)).toEqual([ids[1], ids[2], ids[0]])
+ expect(logic.values.draft.at(-1)?.type).toBe('message')
})
})
diff --git a/products/logs/frontend/components/LogsViewer/config/logsColumnConfiguratorLogic.ts b/products/logs/frontend/components/LogsViewer/config/logsColumnConfiguratorLogic.ts
index b30c7ed2b468..6417d3a07f59 100644
--- a/products/logs/frontend/components/LogsViewer/config/logsColumnConfiguratorLogic.ts
+++ b/products/logs/frontend/components/LogsViewer/config/logsColumnConfiguratorLogic.ts
@@ -4,7 +4,7 @@ import { uuid } from 'lib/utils/dom'
import { logsViewerConfigLogic } from 'products/logs/frontend/components/LogsViewer/config/logsViewerConfigLogic'
-import { LogsColumnConfig } from './columns'
+import { LogsColumnConfig, normalizeColumns } from './columns'
import type { logsColumnConfiguratorLogicType } from './logsColumnConfiguratorLogicType'
export interface LogsColumnConfiguratorLogicProps {
@@ -58,10 +58,10 @@ export const logsColumnConfiguratorLogic = kea<logsColumnConfiguratorLogicType>(
draft: [
[] as LogsColumnConfig[],
{
- setDraft: (_, { draft }) => draft,
+ setDraft: (_, { draft }) => normalizeColumns(draft),
updateDraftColumn: (state, { id, patch }) =>
state.map((column) => (column.id === id ? { ...column, ...patch } : column)),
- addDraftColumn: (state, { column }) => [...state, { ...column, id: uuid() }],
+ addDraftColumn: (state, { column }) => normalizeColumns([...state, { ...column, id: uuid() }]),
removeDraftColumn: (state, { id }) => state.filter((column) => column.id !== id),
moveDraftColumn: (state, { fromIndex, toIndex }) => {
if (fromIndex === toIndex || !state[fromIndex] || toIndex < 0 || toIndex >= state.length) {
@@ -70,7 +70,7 @@ export const logsColumnConfiguratorLogic = kea<logsColumnConfiguratorLogicType>(
const next = [...state]
const [moved] = next.splice(fromIndex, 1)
next.splice(toIndex, 0, moved)
- return next
+ return normalizeColumns(next)
},
},
],
diff --git a/products/logs/frontend/components/LogsViewer/config/logsViewerConfigLogic.ts b/products/logs/frontend/components/LogsViewer/config/logsViewerConfigLogic.ts
index 580f53fce905..9387ec0ccc04 100644
--- a/products/logs/frontend/components/LogsViewer/config/logsViewerConfigLogic.ts
+++ b/products/logs/frontend/components/LogsViewer/config/logsViewerConfigLogic.ts
@@ -8,6 +8,7 @@ import {
DEFAULT_LOGS_COLUMNS,
LogsColumnConfig,
migrateAttributeColumns,
+ normalizeColumns,
} from 'products/logs/frontend/components/LogsViewer/config/columns'
import { LogsViewerConfig, LogsViewerFilters } from 'products/logs/frontend/components/LogsViewer/config/types'
import type { GroupBySourceEnumApi } from 'products/logs/frontend/generated/api.schemas'
@@ -118,8 +119,8 @@ export const logsViewerConfigLogic = kea<logsViewerConfigLogicType>([
DEFAULT_LOGS_COLUMNS,
{ persist: true },
{
- setColumns: (_, { columns }) => columns,
- addColumn: (state, { column }) => [...state, column],
+ setColumns: (_, { columns }) => normalizeColumns(columns),
+ addColumn: (state, { column }) => normalizeColumns([...state, column]),
removeColumn: (state, { id }) => state.filter((column) => column.id !== id),
setColumnWidth: (state, { id, width }) =>
state.map((column) => (column.id === id ? { ...column, width } : column)),
@@ -131,7 +132,7 @@ export const logsViewerConfigLogic = kea<logsViewerConfigLogicType>([
}
const next = [...state]
;[next[index], next[targetIndex]] = [next[targetIndex], next[index]]
- return next
+ return normalizeColumns(next)
},
},
],
diff --git a/products/logs/frontend/components/LogsViewer/logsViewerLogic.test.ts b/products/logs/frontend/components/LogsViewer/logsViewerLogic.test.ts
index e082c6eceffb..b568e9661943 100644
--- a/products/logs/frontend/components/LogsViewer/logsViewerLogic.test.ts
+++ b/products/logs/frontend/components/LogsViewer/logsViewerLogic.test.ts
@@ -619,7 +619,7 @@ describe('logsViewerLogic', () => {
it.each<['left' | 'right', string, string[]]>([
['left', 'c1', ['c1', 'timestamp', 'message']],
- ['right', 'c1', ['timestamp', 'message', 'c1']],
+ ['right', 'c1', ['timestamp', 'c1', 'message']], // message pinned last, so a no-op
['left', 'timestamp', ['timestamp', 'c1', 'message']], // first, no-op
['right', 'message', ['timestamp', 'c1', 'message']], // last, no-op
['left', 'missing', ['timestamp', 'c1', 'message']], // unknown id, no-op
diff --git a/products/logs/frontend/components/VirtualizedLogsList/LogRow.tsx b/products/logs/frontend/components/VirtualizedLogsList/LogRow.tsx
index b914193fd626..6ec0ac5a418a 100644
--- a/products/logs/frontend/components/VirtualizedLogsList/LogRow.tsx
+++ b/products/logs/frontend/components/VirtualizedLogsList/LogRow.tsx
@@ -17,6 +17,7 @@ export interface LogRowProps {
pinned: boolean
showPinnedWithOpacity: boolean
wrapBody: boolean
+ hasMessageColumn: boolean
onTogglePin: (log: ParsedLogMessage) => void
onClick?: () => void
rowWidth?: number
@@ -41,6 +42,7 @@ export function LogRow({
pinned,
showPinnedWithOpacity,
wrapBody,
+ hasMessageColumn,
onTogglePin,
onClick,
rowWidth,
@@ -103,7 +105,9 @@ export function LogRow({
isPrettified={isPrettified}
onTogglePin={onTogglePin}
onTogglePrettify={onTogglePrettify}
- showScrollButtons={!wrapBody}
+ // Scroll buttons drive the message cell's inner scroll — pointless without
+ // a message column or when wrapping already shows everything
+ showScrollButtons={!wrapBody && hasMessageColumn}
/>
</div>
{isExpanded && <ExpandedLogContent log={log} />}
diff --git a/products/logs/frontend/components/VirtualizedLogsList/VirtualizedLogsList.tsx b/products/logs/frontend/components/VirtualizedLogsList/VirtualizedLogsList.tsx
index 67e2ef900a60..2339a4b3a5e4 100644
--- a/products/logs/frontend/components/VirtualizedLogsList/VirtualizedLogsList.tsx
+++ b/products/logs/frontend/components/VirtualizedLogsList/VirtualizedLogsList.tsx
@@ -12,14 +12,13 @@ import { AutoSizer } from 'lib/components/AutoSizer'
import { SizeProps } from 'lib/components/AutoSizer/AutoSizer'
import { TZLabelProps } from 'lib/components/TZLabel'
+import { isPinnedColumn } from 'products/logs/frontend/components/LogsViewer/config/columns'
import { logsViewerDataLogic } from 'products/logs/frontend/components/LogsViewer/data/logsViewerDataLogic'
import { logDetailsModalLogic } from 'products/logs/frontend/components/LogsViewer/LogDetailsModal/logDetailsModalLogic'
import { logsViewerLogic } from 'products/logs/frontend/components/LogsViewer/logsViewerLogic'
import {
createConfiguredColumn,
createControlsColumn,
- createMessageColumn,
- createTimestampColumn,
} from 'products/logs/frontend/components/VirtualizedLogsList/columnDefinitions'
import {
LOG_ROW_HEADER_HEIGHT,
@@ -64,6 +63,7 @@ interface LogsListRowProps {
showPinnedWithOpacity: boolean
disableCursor: boolean
wrapBody: boolean
+ hasMessageColumn: boolean
togglePinLog: (log: ParsedLogMessage) => void
handleLogRowClick: (log: ParsedLogMessage, index: number) => void
rowWidth?: number
@@ -87,6 +87,7 @@ function LogsListRow({
showPinnedWithOpacity,
disableCursor,
wrapBody,
+ hasMessageColumn,
togglePinLog,
handleLogRowClick,
rowWidth,
@@ -122,6 +123,7 @@ function LogsListRow({
pinned={!!pinnedLogs[log.uuid]}
showPinnedWithOpacity={showPinnedWithOpacity}
wrapBody={wrapBody}
+ hasMessageColumn={hasMessageColumn}
onTogglePin={togglePinLog}
onClick={() => handleLogRowClick(log, index)}
rowWidth={rowWidth}
@@ -207,26 +209,24 @@ export function VirtualizedLogsList({
}, [columnConfigs, customColumnAliases])
// Columns memoized on structural deps only — per-row state (selection,
- // expansion, prettify) is read from kea inside cell components.
+ // expansion, prettify) is read from kea inside cell components. Everything after the
+ // pinned controls column is a configured column; there are no special cases here.
const columns = useMemo(() => {
- const managed = columnConfigs.filter((config) => config.type !== 'timestamp' && config.type !== 'message')
+ const rendering = { tzLabelFormat, orderBy, onChangeOrderBy, wrapBody, prettifyJson, flexWidthRef }
+ // Move bounds range over movable columns only — pinned columns sort last and never swap
+ const movable = columnConfigs.filter((config) => !isPinnedColumn(config))
return [
createControlsColumn({ dataSourceRef }),
- ...columnConfigs.map((config) => {
- if (config.type === 'timestamp') {
- return createTimestampColumn({ tzLabelFormat, orderBy, onChangeOrderBy })
- }
- if (config.type === 'message') {
- return createMessageColumn({ wrapBody, prettifyJson, flexWidthRef })
- }
- return createConfiguredColumn({
+ ...columnConfigs.map((config) =>
+ createConfiguredColumn({
config,
alias: aliasById.get(config.id),
callbacks: { onResize: setColumnWidth, onRemove: removeColumn, onMove: moveColumn },
- isFirst: managed.indexOf(config) === 0,
- isLast: managed.indexOf(config) === managed.length - 1,
+ rendering,
+ isFirst: config === movable[0],
+ isLast: config === movable[movable.length - 1],
})
- }),
+ ),
]
}, [
tzLabelFormat,
@@ -307,6 +307,7 @@ export function VirtualizedLogsList({
showPinnedWithOpacity,
disableCursor,
wrapBody,
+ hasMessageColumn: columnConfigs.some((config) => config.type === 'message'),
togglePinLog,
handleLogRowClick,
rowWidth,
@@ -321,6 +322,7 @@ export function VirtualizedLogsList({
[
dataSource,
columns,
+ columnConfigs,
cursorIndex,
expandedLogIds,
pinnedLogs,
diff --git a/products/logs/frontend/components/VirtualizedLogsList/columnDefinitions.tsx b/products/logs/frontend/components/VirtualizedLogsList/columnDefinitions.tsx
index e6f0a3465752..7bb451f3f4f2 100644
--- a/products/logs/frontend/components/VirtualizedLogsList/columnDefinitions.tsx
+++ b/products/logs/frontend/components/VirtualizedLogsList/columnDefinitions.tsx
@@ -147,56 +147,22 @@ export function createControlsColumn(params: {
}
}
-export function createTimestampColumn(params: {
- tzLabelFormat: Pick<TZLabelProps, 'formatDate' | 'formatTime' | 'displayTimezone'>
- orderBy?: LogsOrderBy
- onChangeOrderBy?: (orderBy: LogsOrderBy) => void
-}): VirtualizedTableColumn<ParsedLogMessage> {
- const { tzLabelFormat, orderBy, onChangeOrderBy } = params
-
- return {
- key: 'timestamp',
- title: 'Timestamp',
- sizing: { type: 'fixed', width: TIMESTAMP_WIDTH },
- render: (log) => (
- <div className="flex items-center shrink-0" style={{ width: TIMESTAMP_WIDTH }}>
- <span className="text-xs text-muted font-mono">
- <TZLabel time={log.timestamp} {...tzLabelFormat} timestampStyle="absolute" />
- </span>
- </div>
- ),
- renderHeader: () => (
- <div
- className="flex items-center justify-between pr-3 gap-1 h-full border-r"
- style={{ width: TIMESTAMP_WIDTH, flexShrink: 0 }}
- >
- Timestamp
- <LemonButton
- size="xsmall"
- className="h-full"
- icon={orderBy === 'latest' ? <IconArrowDown /> : <IconArrowUp />}
- tooltip={
- orderBy === 'latest'
- ? 'Showing latest first. Click to show earliest first (reloads).'
- : 'Showing earliest first. Click to show latest first (reloads).'
- }
- onClick={() => {
- const newOrderBy = orderBy === 'latest' ? 'earliest' : 'latest'
- onChangeOrderBy?.(newOrderBy)
- }}
- disabled={!orderBy || !onChangeOrderBy}
- />
- </div>
- ),
- }
-}
-
export interface ConfiguredColumnCallbacks {
onResize?: (id: string, width: number) => void
onRemove?: (id: string) => void
onMove?: (id: string, direction: 'left' | 'right') => void
}
+/** Presentation context shared by every configured column, resolved once per table render. */
+export interface ConfiguredColumnRendering {
+ tzLabelFormat: Pick<TZLabelProps, 'formatDate' | 'formatTime' | 'displayTimezone'>
+ orderBy?: LogsOrderBy
+ onChangeOrderBy?: (orderBy: LogsOrderBy) => void
+ wrapBody: boolean
+ prettifyJson: boolean
+ flexWidthRef: RefObject<number | undefined | null>
+}
+
/** Read a server-computed custom column value off the raw row by its canonical alias. */
function customColumnValue(log: ParsedLogMessage, alias: string | undefined): string {
if (!alias) {
@@ -206,42 +172,162 @@ function customColumnValue(log: ParsedLogMessage, alias: string | undefined): st
return value == null ? '' : String(value)
}
+function ColumnHeaderMenu({
+ config,
+ callbacks,
+ isFirst,
+ isLast,
+}: {
+ config: LogsColumnConfig
+ callbacks: ConfiguredColumnCallbacks
+ isFirst: boolean
+ isLast: boolean
+}): JSX.Element | null {
+ const { onRemove, onMove } = callbacks
+ if (!onRemove && !onMove) {
+ return null
+ }
+ return (
+ <LemonMenu
+ items={[
+ onMove
+ ? {
+ label: 'Move left',
+ icon: <IconArrowLeft />,
+ disabledReason: isFirst ? 'Already at the start' : undefined,
+ onClick: () => onMove(config.id, 'left'),
+ }
+ : null,
+ onMove
+ ? {
+ label: 'Move right',
+ icon: <IconArrowRight />,
+ disabledReason: isLast ? 'Already at the end' : undefined,
+ onClick: () => onMove(config.id, 'right'),
+ }
+ : null,
+ onRemove
+ ? {
+ label: 'Remove column',
+ icon: <IconTrash />,
+ status: 'danger' as const,
+ onClick: () => onRemove(config.id),
+ }
+ : null,
+ ]}
+ >
+ <LemonButton size="xsmall" noPadding icon={<IconEllipsis className="text-muted" />} className="shrink-0" />
+ </LemonMenu>
+ )
+}
+
+function TimestampSortButton({
+ orderBy,
+ onChangeOrderBy,
+}: Pick<ConfiguredColumnRendering, 'orderBy' | 'onChangeOrderBy'>): JSX.Element {
+ return (
+ <LemonButton
+ size="xsmall"
+ className="h-full"
+ icon={orderBy === 'latest' ? <IconArrowDown /> : <IconArrowUp />}
+ tooltip={
+ orderBy === 'latest'
+ ? 'Showing latest first. Click to show earliest first (reloads).'
+ : 'Showing earliest first. Click to show latest first (reloads).'
+ }
+ onClick={() => onChangeOrderBy?.(orderBy === 'latest' ? 'earliest' : 'latest')}
+ disabled={!orderBy || !onChangeOrderBy}
+ />
+ )
+}
+
/**
- * Generic resizable column driven by a LogsColumnConfig: built-in types resolve client-side
- * from row fields via the registry; custom columns read the server-computed value keyed by
- * `alias`. Custom values render through AttributeCell so the special-case renderers
- * (PersonDisplay for distinct-id keys, ViewRecordingButton for session-id keys) keep working.
+ * The single column factory: every configured column — built-in or custom — renders through
+ * here, so all of them are reorderable, removable, and resizable. Message is the one layout
+ * exception (the flex fill column, so no resizer). Type differences are confined to the cell
+ * renderer (timestamp -> TZLabel, message -> MessageCell, rest -> AttributeCell, which keeps
+ * the PersonDisplay / ViewRecordingButton special cases) plus timestamp's sort toggle.
*/
export function createConfiguredColumn(params: {
config: LogsColumnConfig
alias?: string
callbacks: ConfiguredColumnCallbacks
+ rendering: ConfiguredColumnRendering
isFirst: boolean
isLast: boolean
}): VirtualizedTableColumn<ParsedLogMessage> {
- const { config, alias, callbacks, isFirst, isLast } = params
- const { onResize, onRemove, onMove } = callbacks
+ const { config, alias, callbacks, rendering, isFirst, isLast } = params
const title = columnLabel(config)
- const width = config.width ?? DEFAULT_ATTRIBUTE_COLUMN_WIDTH
+
+ if (config.type === 'message') {
+ return {
+ key: `col:${config.id}`,
+ title,
+ sizing: { type: 'flex', minWidth: MESSAGE_MIN_WIDTH },
+ render: (log) => (
+ <MessageColumnCell
+ log={log}
+ wrapBody={rendering.wrapBody}
+ prettifyJson={rendering.prettifyJson}
+ flexWidthRef={rendering.flexWidthRef}
+ />
+ ),
+ renderHeader: () => (
+ <div
+ className="flex items-center justify-between px-1 gap-1"
+ style={getMessageStyle(rendering.flexWidthRef.current ?? undefined)}
+ >
+ <span className="truncate" title={title}>
+ {title}
+ </span>
+ {/* Pinned to the end (see normalizeColumns) — removable, but never movable */}
+ <ColumnHeaderMenu
+ config={config}
+ callbacks={{ ...callbacks, onMove: undefined }}
+ isFirst={isFirst}
+ isLast={isLast}
+ />
+ </div>
+ ),
+ }
+ }
+
+ const width = config.width ?? (config.type === 'timestamp' ? TIMESTAMP_WIDTH : DEFAULT_ATTRIBUTE_COLUMN_WIDTH)
const totalWidth = width + RESIZER_HANDLE_WIDTH
const semanticKey = config.type === 'custom' ? (config.name ?? config.expression ?? '') : config.type
- const getValue =
- config.type === 'custom'
- ? (log: ParsedLogMessage): string => customColumnValue(log, alias)
- : LOGS_COLUMN_REGISTRY[config.type].getValue
+ const renderValue =
+ config.type === 'timestamp'
+ ? (log: ParsedLogMessage): JSX.Element => (
+ <div className="flex items-center shrink-0" style={{ width: totalWidth }}>
+ <span className="text-xs text-muted font-mono">
+ <TZLabel time={log.timestamp} {...rendering.tzLabelFormat} timestampStyle="absolute" />
+ </span>
+ </div>
+ )
+ : (log: ParsedLogMessage): JSX.Element => (
+ <AttributeCell
+ attributeKey={semanticKey}
+ value={
+ config.type === 'custom'
+ ? customColumnValue(log, alias)
+ : LOGS_COLUMN_REGISTRY[config.type].getValue(log)
+ }
+ width={totalWidth}
+ />
+ )
return {
key: `col:${config.id}`,
title,
sizing: { type: 'resizable', width, minWidth: MIN_ATTRIBUTE_COLUMN_WIDTH },
- render: (log) => <AttributeCell attributeKey={semanticKey} value={getValue(log)} width={totalWidth} />,
+ render: renderValue,
renderHeader: () => (
<ResizableElement
defaultWidth={totalWidth}
minWidth={MIN_ATTRIBUTE_COLUMN_WIDTH + RESIZER_HANDLE_WIDTH}
maxWidth={Infinity}
- onResize={(newWidth) => onResize?.(config.id, newWidth - RESIZER_HANDLE_WIDTH)}
+ onResize={(newWidth) => callbacks.onResize?.(config.id, newWidth - RESIZER_HANDLE_WIDTH)}
className="flex items-center h-full shrink-0 group/header"
innerClassName="h-full"
>
@@ -249,67 +335,12 @@ export function createConfiguredColumn(params: {
<span className="truncate flex-1" title={title}>
{title}
</span>
- {(onRemove || onMove) && (
- <LemonMenu
- items={[
- onMove
- ? {
- label: 'Move left',
- icon: <IconArrowLeft />,
- disabledReason: isFirst ? 'Already at the start' : undefined,
- onClick: () => onMove(config.id, 'left'),
- }
- : null,
- onMove
- ? {
- label: 'Move right',
- icon: <IconArrowRight />,
- disabledReason: isLast ? 'Already at the end' : undefined,
- onClick: () => onMove(config.id, 'right'),
- }
- : null,
- onRemove
- ? {
- label: 'Remove column',
- icon: <IconTrash />,
- status: 'danger' as const,
- onClick: () => onRemove(config.id),
- }
- : null,
- ]}
- >
- <LemonButton
- size="xsmall"
- noPadding
- icon={<IconEllipsis className="text-muted" />}
- className="shrink-0"
- />
- </LemonMenu>
+ {config.type === 'timestamp' && (
+ <TimestampSortButton orderBy={rendering.orderBy} onChangeOrderBy={rendering.onChangeOrderBy} />
)}
+ <ColumnHeaderMenu config={config} callbacks={callbacks} isFirst={isFirst} isLast={isLast} />
</div>
</ResizableElement>
),
}
}
-
-export function createMessageColumn(params: {
- wrapBody: boolean
- prettifyJson: boolean
- flexWidthRef: RefObject<number | undefined | null>
-}): VirtualizedTableColumn<ParsedLogMessage> {
- const { wrapBody, prettifyJson, flexWidthRef } = params
-
- return {
- key: 'message',
- title: 'Message',
- sizing: { type: 'flex', minWidth: MESSAGE_MIN_WIDTH },
- render: (log) => (
- <MessageColumnCell log={log} wrapBody={wrapBody} prettifyJson={prettifyJson} flexWidthRef={flexWidthRef} />
- ),
- renderHeader: () => (
- <div className="flex items-center px-1" style={getMessageStyle(flexWidthRef.current ?? undefined)}>
- Message
- </div>
- ),
- }
-}