diff --git a/.changeset/shiny-needles-cross.md b/.changeset/shiny-needles-cross.md new file mode 100644 index 00000000..24e23fb2 --- /dev/null +++ b/.changeset/shiny-needles-cross.md @@ -0,0 +1,10 @@ +--- +'@hyperdx/app': patch +--- + +fix(app): negative duration in search + +Duration column in the search interface displayed negative numbers when only a +timestamp was present. This fix changes the behavior to display "N/A" for such +cases, clarifying that the duration is not applicable rather than displaying a +misleading negative number. diff --git a/packages/app/src/LogTable.tsx b/packages/app/src/LogTable.tsx index 03889cca..725b4f32 100644 --- a/packages/app/src/LogTable.tsx +++ b/packages/app/src/LogTable.tsx @@ -13,6 +13,7 @@ import cx from 'classnames'; import { Button, Modal } from 'react-bootstrap'; import stripAnsi from 'strip-ansi'; import { CSVLink } from 'react-csv'; +import curry from 'lodash/curry'; import Checkbox from './Checkbox'; import FieldMultiSelect from './FieldMultiSelect'; @@ -23,6 +24,19 @@ import { usePrevious, useWindowSize } from './utils'; import { useSearchEventStream } from './search'; import { useHotkeys } from 'react-hotkeys-hook'; +type Row = Record & { duration: number }; +type AccessorFn = (row: Row, column: string) => any; + +const ACCESSOR_MAP: Record = { + duration: row => (row.duration >= 0 ? row.duration : 'N/A'), + default: (row, column) => row[column], +}; + +function retrieveColumnValue(column: string, row: Row): any { + const accessor = ACCESSOR_MAP[column] ?? ACCESSOR_MAP.default; + return accessor(row, column); +} + function DownloadCSVButton({ config: { where, dateRange }, extraFields, @@ -351,7 +365,7 @@ export const RawLogTable = memo( size: isSmallScreen ? 70 : 100, }, ...(displayedColumns.map(column => ({ - accessorFn: row => row[column], // Columns can contain '.' and will not work with accessorKey + accessorFn: curry(retrieveColumnValue)(column), // Columns can contain '.' and will not work with accessorKey header: column, cell: info => (