diff --git a/.changeset/remaining-badges-click-ui.md b/.changeset/remaining-badges-click-ui.md new file mode 100644 index 0000000000..edd6878dbf --- /dev/null +++ b/.changeset/remaining-badges-click-ui.md @@ -0,0 +1,8 @@ +--- +'@hyperdx/app': patch +--- + +feat: use the click-ui `Badge` for the exception breadcrumb status and level +chips, the AI Assistant "Experimental" label, and the materialized view config +pills. Remove the unused stacktrace, breadcrumb, and source map code from +`LogSidePanelElements`, and the unused `StacktraceFrame` component. diff --git a/packages/app/src/DBChartPage.tsx b/packages/app/src/DBChartPage.tsx index 3c1791fbfe..b182c35d06 100644 --- a/packages/app/src/DBChartPage.tsx +++ b/packages/app/src/DBChartPage.tsx @@ -5,6 +5,7 @@ import Link from 'next/link'; import { parseAsJson, parseAsString, useQueryState } from 'nuqs'; import { useForm } from 'react-hook-form'; import { useHotkeys } from 'react-hotkeys-hook'; +import { Badge } from '@clickhouse/click-ui'; import { SavedChartConfig, SourceKind } from '@hyperdx/common-utils/dist/types'; import { Alert, @@ -15,7 +16,6 @@ import { Divider, Group, Loader, - Pill, Skeleton, Stack, Text, @@ -166,7 +166,7 @@ function AIAssistant({ AI Assistant [A] - Experimental + {opened && ( diff --git a/packages/app/src/LogSidePanelElements.tsx b/packages/app/src/LogSidePanelElements.tsx index 484e890ffc..9a0a0397c8 100644 --- a/packages/app/src/LogSidePanelElements.tsx +++ b/packages/app/src/LogSidePanelElements.tsx @@ -1,35 +1,12 @@ -/* eslint-disable @typescript-eslint/no-unused-vars */ import * as React from 'react'; -import Link from 'next/link'; -import cx from 'classnames'; import { JSONTree } from 'react-json-tree'; -import { - Alert, - Button, - Group, - Kbd, - Modal, - Stack, - Text, - Tooltip, -} from '@mantine/core'; -import { - IconChevronDown, - IconChevronRight, - IconCode, - IconPackage, -} from '@tabler/icons-react'; -import { ColumnDef, Row, Table } from '@tanstack/react-table'; +import { Group, Kbd, Modal, Stack, Text } from '@mantine/core'; +import { IconChevronDown, IconChevronRight } from '@tabler/icons-react'; +import { ColumnDef } from '@tanstack/react-table'; import HyperJson from './components/HyperJson'; -import { StacktraceFrame as StacktraceFrameCmp } from './components/StacktraceFrame'; -import { TableCellButton } from './components/Table'; import type { HttpHeader } from './utils/httpHeaders'; import { UNDEFINED_WIDTH } from './tableUtils'; -import type { StacktraceBreadcrumb, StacktraceFrame } from './types'; -import { FormatTime } from './useFormatTime'; -import { useSourceMappedFrame } from './useSourceMappedFrame'; -import { useLocalStorage } from './utils'; import styles from '@styles/LogSidePanel.module.scss'; @@ -72,307 +49,6 @@ export const SectionWrapper: React.FC< ); -/** - * Stacktrace elements - */ -const StacktraceValue = ({ - label, - value, -}: { - label: React.ReactNode; - value: React.ReactNode; -}) => { - return ( -
-
{label}
-
{value}
-
- ); -}; - -const StacktraceRowExpandButton = ({ - onClick, - isOpen, -}: { - onClick: VoidFunction; - isOpen: boolean; -}) => { - return ( - - ); -}; - -const StacktraceRow = ({ - row, - table, -}: { - row: Row; - table: Table; -}) => { - const tableMeta = table.options.meta as { - firstFrameIndex?: number; - }; - - const [lineContextOpen, setLineContextOpen] = React.useState( - row.index === tableMeta.firstFrameIndex, - ); - - const handleToggleContext = React.useCallback(() => { - setLineContextOpen(!lineContextOpen); - }, [lineContextOpen]); - - const frame = row.original; - - const { isLoading, enrichedFrame } = useSourceMappedFrame(); - - const augmentedFrame = enrichedFrame ?? frame; - const hasContext = !!augmentedFrame.context_line; - - return ( - <> -
-
- {!augmentedFrame.in_app && ( - - - - )} - {augmentedFrame && ( - - )} -
- {hasContext && ( - - )} -
- - {lineContextOpen && hasContext && ( -
-          {augmentedFrame.pre_context?.map((line, i) => (
-            
- - {(augmentedFrame.lineno ?? 0) - - (augmentedFrame.pre_context?.length ?? 0) + - i} - - {line} -
- ))} - {augmentedFrame.context_line && ( -
- - {augmentedFrame.lineno} - - {augmentedFrame.context_line} -
- )} - {augmentedFrame.post_context?.map((line, i) => ( -
- - {augmentedFrame.lineno + i + 1} - - {line} -
- ))} -
- )} - - ); -}; - -const stacktraceColumns: ColumnDef[] = [ - { - accessorKey: 'filename', - cell: StacktraceRow, - }, -]; - -/** - * Breadcrumbs - */ - -const Url = ({ url }: { url?: string }) => {url}; - -const StatusChip = React.memo(({ status }: { status?: number }) => { - if (!status) { - return null; - } - const className = - status >= 500 - ? 'text-danger bg-danger' - : status >= 400 - ? 'text-warning bg-warning' - : 'text-success bg-success'; - return ( - - {status} - - ); -}); - -const LevelChip = React.memo(({ level }: { level?: string }) => { - if (!level) { - return null; - } - const className = level.includes('error') - ? 'text-danger bg-danger' - : level.includes('warn') || level.includes('warning') - ? 'text-warning bg-warning' - : 'bg-muted'; - - return ( - - {level} - - ); -}); - -const breadcrumbColumns: ColumnDef[] = [ - { - accessorKey: 'category', - header: 'Category', - size: 180, - cell: ({ row }) => ( - - {row.original.category} - {row.original.category === 'console' && ( - - )} - {row.original.category === 'fetch' || - row.original.category === 'xhr' ? ( - - ) : null} - - ), - }, - { - accessorKey: 'message', - header: 'Data', - size: UNDEFINED_WIDTH, - cell: ({ row }) => { - // fetch - if ( - row.original.data && - (row.original.category === 'fetch' || row.original.category === 'xhr') - ) { - const { method, url } = row.original.data; - return ( -
- {method} - - - -
- ); - } - - // navigation - if (row.original.category === 'navigation' && row.original.data) { - const { from, to } = row.original.data; - return ( -
- - - - {' → '} - - - -
- ); - } - - // console - if (row.original.category === 'console') { - const { message } = row.original; - return ( -
-            {message}
-          
- ); - } - - if (row.original.message) { - return
{row.original.message}
; - } - - return Empty; - }, - }, - { - header: 'Timestamp', - size: 220, - cell: ({ row }) => ( - - - - ), - }, -]; - -const useShowMoreRows = ({ - rows, - maxRows = 5, -}: { - rows: T[]; - maxRows?: number; -}) => { - const [isExpanded, setIsExpanded] = React.useState(false); - - const visibleRows = React.useMemo(() => { - return isExpanded ? rows : rows.slice(0, maxRows); - }, [rows, isExpanded, maxRows]); - - const hiddenRowsCount = React.useMemo(() => { - const length = rows.length ?? 0; - return length > maxRows ? length - maxRows : null; - }, [rows.length, maxRows]); - - const handleToggleMoreRows = React.useCallback(() => { - setIsExpanded(!isExpanded); - }, [isExpanded]); - - return { visibleRows, hiddenRowsCount, handleToggleMoreRows, isExpanded }; -}; - /** * Request / Response Headers elements */ @@ -519,35 +195,3 @@ export const KeyboardShortcutsModal = ({ ); }; - -const SourceMapsFtux = () => { - const [isDismissed, setIsDismissed] = useLocalStorage( - 'sourceMapsFtuxDismissed', - false, - ); - - if (isDismissed) { - return null; - } - - return ( - setIsDismissed(true)} - > - - Some of the stack frames are pointing to minified - files. Use hyperdx-cli to upload your source maps and see the original - code. - - - - - - ); -}; diff --git a/packages/app/src/components/ExceptionSubpanel.tsx b/packages/app/src/components/ExceptionSubpanel.tsx index 39f69e0d2a..54bb41f13b 100644 --- a/packages/app/src/components/ExceptionSubpanel.tsx +++ b/packages/app/src/components/ExceptionSubpanel.tsx @@ -2,6 +2,7 @@ import React, { useMemo } from 'react'; import cx from 'classnames'; import { ErrorBoundary } from 'react-error-boundary'; +import { Badge } from '@clickhouse/click-ui'; import { Button, Text, Tooltip } from '@mantine/core'; import { Group, Loader } from '@mantine/core'; import { @@ -12,7 +13,10 @@ import { } from '@tabler/icons-react'; import { ColumnDef, Row, Table as TanstackTable } from '@tanstack/react-table'; -import { StacktraceFrame as TStacktraceFrame } from '@/types'; +import type { + StacktraceBreadcrumb, + StacktraceFrame as TStacktraceFrame, +} from '@/types'; import { FormatTime } from '@/useFormatTime'; import { useSourceMappedFrame } from '@/useSourceMappedFrame'; @@ -97,24 +101,6 @@ const StacktraceFrame = ({ ); }; -type StacktraceBreadcrumbCategory = - | 'ui.click' - | 'fetch' - | 'xhr' - | 'console' - | 'navigation' - | string; - -type StacktraceBreadcrumb = { - type?: string; - level?: string; - event_id?: string; - category?: StacktraceBreadcrumbCategory; - message?: string; - data?: { [key: string]: any }; - timestamp: number; -}; - const CollapsibleSection = ({ title, children, @@ -309,38 +295,21 @@ const StatusChip = React.memo(({ status }: { status?: number }) => { if (!status) { return null; } - const className = - status >= 500 - ? 'text-danger bg-danger' - : status >= 400 - ? 'text-warning bg-warning' - : 'text-success bg-success'; - return ( - - {status} - - ); + const state = + status >= 500 ? 'danger' : status >= 400 ? 'warning' : 'success'; + return ; }); const LevelChip = React.memo(({ level }: { level?: string }) => { if (!level) { return null; } - const className = level.includes('error') - ? 'text-danger bg-danger' - : level.includes('warn') || level.includes('warning') - ? 'text-warning bg-warning' - : 'bg-muted'; - - return ( - - {level} - - ); + const state = level.includes('error') + ? 'danger' + : level.includes('warn') + ? 'warning' + : 'neutral'; + return ; }); const breadcrumbColumns: ColumnDef[] = [ diff --git a/packages/app/src/components/MaterializedViews/MVConfigSummary.tsx b/packages/app/src/components/MaterializedViews/MVConfigSummary.tsx index dd8ac33143..6f645aac9f 100644 --- a/packages/app/src/components/MaterializedViews/MVConfigSummary.tsx +++ b/packages/app/src/components/MaterializedViews/MVConfigSummary.tsx @@ -1,7 +1,8 @@ import { useMemo } from 'react'; +import { Badge } from '@clickhouse/click-ui'; import { splitAndTrimWithBracket } from '@hyperdx/common-utils/dist/core/utils'; import { MaterializedViewConfiguration } from '@hyperdx/common-utils/dist/types'; -import { Grid, Group, Pill, Stack, Table, Text, Tooltip } from '@mantine/core'; +import { Grid, Group, Stack, Table, Text, Tooltip } from '@mantine/core'; import { IconInfoCircle } from '@tabler/icons-react'; import { FormatTime } from '@/useFormatTime'; @@ -51,16 +52,18 @@ export default function MVConfigSummary({ - {config.minGranularity} + {config.minDate && ( Minimum Date - - - + } + state="neutral" + /> )} @@ -71,7 +74,7 @@ export default function MVConfigSummary({ {dimensionColumnsSplit.map(col => ( - {col} + ))} @@ -94,7 +97,12 @@ export default function MVConfigSummary({ {aggFns.map(aggFn => ( - {aggFn} + ))} diff --git a/packages/app/src/components/StacktraceFrame.tsx b/packages/app/src/components/StacktraceFrame.tsx deleted file mode 100644 index 5849f646f7..0000000000 --- a/packages/app/src/components/StacktraceFrame.tsx +++ /dev/null @@ -1,45 +0,0 @@ -import { Group, Loader } from '@mantine/core'; - -export const StacktraceFrame = ({ - filename, - function: functionName, - lineno, - colno, - isLoading, -}: { - filename: string; - function?: string; - lineno: number; - colno: number; - isLoading?: boolean; -}) => { - return ( - -
- {filename} - - :{lineno}:{colno} - - {' in '} - {functionName && ( - - {functionName} - - )} -
- {isLoading && } -
- ); -}; diff --git a/packages/app/src/components/__tests__/ExceptionSubpanel.test.tsx b/packages/app/src/components/__tests__/ExceptionSubpanel.test.tsx index 7a8c90b7cd..3b90aafde3 100644 --- a/packages/app/src/components/__tests__/ExceptionSubpanel.test.tsx +++ b/packages/app/src/components/__tests__/ExceptionSubpanel.test.tsx @@ -3,6 +3,17 @@ import { screen } from '@testing-library/react'; import { ExceptionSubpanel } from '@/components/ExceptionSubpanel'; +// click-ui encodes state only in hashed CSS module class names, so the mock +// exposes the props as attributes to assert on. +jest.mock('@clickhouse/click-ui', () => ({ + ...jest.requireActual('@clickhouse/click-ui'), + Badge: ({ text, state }: { text: React.ReactNode; state?: string }) => ( + + {text} + + ), +})); + describe('ExceptionSubpanel', () => { it.each([ [{ type: '', value: 'bad input' }, 'bad input'], @@ -19,3 +30,49 @@ describe('ExceptionSubpanel', () => { expect(screen.queryByText('Breadcrumbs')).not.toBeInTheDocument(); }); }); + +const renderBreadcrumbs = ( + breadcrumbs: React.ComponentProps['breadcrumbs'], +) => + renderWithMantine( + , + ); + +const badgeStates = () => + screen + .getAllByTestId('badge') + .map(b => [b.textContent, b.getAttribute('data-state')]); + +describe('ExceptionSubpanel breadcrumbs', () => { + it.each([ + [503, 'danger'], + [404, 'warning'], + [200, 'success'], + ])('renders status %s with the %s state', (status, state) => { + renderBreadcrumbs([ + { + category: 'fetch', + data: { method: 'GET', url: '/api', status_code: status }, + timestamp: 1700000001, + }, + ]); + expect(badgeStates()).toEqual([[String(status), state]]); + }); + + it.each([ + ['error', 'danger'], + ['warning', 'warning'], + ['info', 'neutral'], + ])('renders console level %s with the %s state', (level, state) => { + renderBreadcrumbs([ + { category: 'console', message: 'hi', level, timestamp: 1700000001 }, + ]); + expect(badgeStates()).toEqual([[level, state]]); + }); +});