-
Notifications
You must be signed in to change notification settings - Fork 282
feat: Add click + sidepanel support to items within surrounding context #989
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
teeohhem
wants to merge
6
commits into
main
Choose a base branch
from
tom/surrounding-context-click-2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d3d2f45
feat: Allow surrounding context items to be clicked + show breadcrumbs
teeohhem 48e03ed
cleaner breadcumb component
teeohhem 5c1c255
Moar cleanup/refactor
teeohhem 8c3bf60
Add changeset
teeohhem 096b3b5
Add real tooltip component
teeohhem 1a70cf7
cleanup
teeohhem File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@hyperdx/app": patch | ||
--- | ||
|
||
feat: Add click + sidepanel support to items within surrounding context |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import { useCallback, useMemo, useState } from 'react'; | ||
import { sq } from 'date-fns/locale'; | ||
import ms from 'ms'; | ||
import { parseAsString, useQueryState } from 'nuqs'; | ||
import { useForm } from 'react-hook-form'; | ||
import { tcFromSource } from '@hyperdx/common-utils/dist/metadata'; | ||
import { | ||
|
@@ -13,8 +14,11 @@ import { useDebouncedValue } from '@mantine/hooks'; | |
import { SQLInlineEditorControlled } from '@/components/SQLInlineEditor'; | ||
import WhereLanguageControlled from '@/components/WhereLanguageControlled'; | ||
import SearchInputV2 from '@/SearchInputV2'; | ||
import { useSource } from '@/source'; | ||
import { formatAttributeClause } from '@/utils'; | ||
|
||
import DBRowSidePanel from './DBRowSidePanel'; | ||
import { BreadcrumbPath } from './DBRowSidePanelHeader'; | ||
import { DBSqlRowTable } from './DBRowTable'; | ||
|
||
enum ContextBy { | ||
|
@@ -31,13 +35,40 @@ interface ContextSubpanelProps { | |
dbSqlRowTableConfig: ChartConfigWithDateRange | undefined; | ||
rowData: Record<string, any>; | ||
rowId: string | undefined; | ||
breadcrumbPath?: BreadcrumbPath; | ||
} | ||
|
||
// Custom hook to manage nested panel state | ||
function useNestedPanelState(isNested: boolean) { | ||
// Query state (URL-based) for root level | ||
const queryState = { | ||
contextRowId: useQueryState('contextRowId', parseAsString), | ||
contextRowSource: useQueryState('contextRowSource', parseAsString), | ||
}; | ||
|
||
// Local state for nested levels | ||
const localState = { | ||
contextRowId: useState<string | null>(null), | ||
contextRowSource: useState<string | null>(null), | ||
}; | ||
|
||
// Choose which state to use based on nesting level | ||
const activeState = isNested ? localState : queryState; | ||
|
||
return { | ||
contextRowId: activeState.contextRowId[0], | ||
contextRowSource: activeState.contextRowSource[0], | ||
setContextRowId: activeState.contextRowId[1], | ||
setContextRowSource: activeState.contextRowSource[1], | ||
}; | ||
} | ||
|
||
export default function ContextSubpanel({ | ||
source, | ||
dbSqlRowTableConfig, | ||
rowData, | ||
rowId, | ||
breadcrumbPath = [], | ||
}: ContextSubpanelProps) { | ||
const QUERY_KEY_PREFIX = 'context'; | ||
const { Timestamp: origTimestamp } = rowData; | ||
|
@@ -55,6 +86,33 @@ export default function ContextSubpanel({ | |
const formWhere = watch('where'); | ||
const [debouncedWhere] = useDebouncedValue(formWhere, 1000); | ||
|
||
// State management for nested panels | ||
const isNested = breadcrumbPath.length > 0; | ||
|
||
const { | ||
contextRowId, | ||
contextRowSource, | ||
setContextRowId, | ||
setContextRowSource, | ||
} = useNestedPanelState(isNested); | ||
|
||
const { data: contextRowSidePanelSource } = useSource({ | ||
id: contextRowSource || '', | ||
}); | ||
|
||
const handleContextSidePanelClose = useCallback(() => { | ||
setContextRowId(null); | ||
setContextRowSource(null); | ||
}, [setContextRowId, setContextRowSource]); | ||
|
||
const handleRowExpandClick = useCallback( | ||
(rowWhere: string) => { | ||
setContextRowId(rowWhere); | ||
setContextRowSource(source.id); | ||
}, | ||
[source.id, setContextRowId, setContextRowSource], | ||
); | ||
|
||
const date = useMemo(() => new Date(origTimestamp), [origTimestamp]); | ||
|
||
const newDateRange = useMemo( | ||
|
@@ -175,89 +233,109 @@ export default function ContextSubpanel({ | |
contextBy, | ||
]); | ||
|
||
return ( | ||
config && ( | ||
<Flex direction="column" mih="0px" style={{ flexGrow: 1 }}> | ||
<Group justify="space-between" p="sm"> | ||
<SegmentedControl | ||
bg="dark.7" | ||
color="dark.5" | ||
size="xs" | ||
data={generateSegmentedControlData()} | ||
value={contextBy} | ||
onChange={v => setContextBy(v as ContextBy)} | ||
/> | ||
{contextBy === ContextBy.Custom && ( | ||
<WhereLanguageControlled | ||
name="whereLanguage" | ||
control={control} | ||
sqlInput={ | ||
originalLanguage === 'lucene' ? null : ( | ||
<SQLInlineEditorControlled | ||
tableConnections={tcFromSource(source)} | ||
control={control} | ||
name="where" | ||
placeholder="SQL WHERE clause (ex. column = 'foo')" | ||
language="sql" | ||
enableHotkey | ||
size="sm" | ||
/> | ||
) | ||
} | ||
luceneInput={ | ||
originalLanguage === 'sql' ? null : ( | ||
<SearchInputV2 | ||
tableConnections={tcFromSource(source)} | ||
control={control} | ||
name="where" | ||
language="lucene" | ||
placeholder="Lucene where clause (ex. column:value)" | ||
enableHotkey | ||
size="sm" | ||
/> | ||
) | ||
} | ||
/> | ||
)} | ||
<SegmentedControl | ||
bg="dark.7" | ||
color="dark.5" | ||
size="xs" | ||
data={[ | ||
{ label: '100ms', value: ms('100ms').toString() }, | ||
{ label: '500ms', value: ms('500ms').toString() }, | ||
{ label: '1s', value: ms('1s').toString() }, | ||
{ label: '5s', value: ms('5s').toString() }, | ||
{ label: '30s', value: ms('30s').toString() }, | ||
{ label: '1m', value: ms('1m').toString() }, | ||
{ label: '5m', value: ms('5m').toString() }, | ||
{ label: '15m', value: ms('15m').toString() }, | ||
]} | ||
value={range.toString()} | ||
onChange={value => setRange(Number(value))} | ||
const contextComponent = config && ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just moving this into its own component for readability |
||
<Flex direction="column" mih="0px" style={{ flexGrow: 1 }}> | ||
<Group justify="space-between" p="sm"> | ||
<SegmentedControl | ||
bg="dark.7" | ||
color="dark.5" | ||
size="xs" | ||
data={generateSegmentedControlData()} | ||
value={contextBy} | ||
onChange={v => setContextBy(v as ContextBy)} | ||
/> | ||
{contextBy === ContextBy.Custom && ( | ||
<WhereLanguageControlled | ||
name="whereLanguage" | ||
control={control} | ||
sqlInput={ | ||
originalLanguage === 'lucene' ? null : ( | ||
<SQLInlineEditorControlled | ||
tableConnections={tcFromSource(source)} | ||
control={control} | ||
name="where" | ||
placeholder="SQL WHERE clause (ex. column = 'foo')" | ||
language="sql" | ||
enableHotkey | ||
size="sm" | ||
/> | ||
) | ||
} | ||
luceneInput={ | ||
originalLanguage === 'sql' ? null : ( | ||
<SearchInputV2 | ||
tableConnections={tcFromSource(source)} | ||
control={control} | ||
name="where" | ||
language="lucene" | ||
placeholder="Lucene where clause (ex. column:value)" | ||
enableHotkey | ||
size="sm" | ||
/> | ||
) | ||
} | ||
/> | ||
</Group> | ||
<Group p="sm"> | ||
<div> | ||
{contextBy !== ContextBy.All && ( | ||
<Badge size="md" variant="default"> | ||
{contextBy}:{CONTEXT_MAPPING[contextBy].value} | ||
</Badge> | ||
)} | ||
)} | ||
<SegmentedControl | ||
bg="dark.7" | ||
color="dark.5" | ||
size="xs" | ||
data={[ | ||
{ label: '100ms', value: ms('100ms').toString() }, | ||
{ label: '500ms', value: ms('500ms').toString() }, | ||
{ label: '1s', value: ms('1s').toString() }, | ||
{ label: '5s', value: ms('5s').toString() }, | ||
{ label: '30s', value: ms('30s').toString() }, | ||
{ label: '1m', value: ms('1m').toString() }, | ||
{ label: '5m', value: ms('5m').toString() }, | ||
{ label: '15m', value: ms('15m').toString() }, | ||
]} | ||
value={range.toString()} | ||
onChange={value => setRange(Number(value))} | ||
/> | ||
</Group> | ||
<Group p="sm"> | ||
<div> | ||
{contextBy !== ContextBy.All && ( | ||
<Badge size="md" variant="default"> | ||
Time range: ±{ms(range / 2)} | ||
{contextBy}:{CONTEXT_MAPPING[contextBy].value} | ||
</Badge> | ||
</div> | ||
</Group> | ||
<div style={{ height: '100%', overflow: 'auto' }}> | ||
<DBSqlRowTable | ||
highlightedLineId={rowId} | ||
isLive={false} | ||
config={config} | ||
queryKeyPrefix={QUERY_KEY_PREFIX} | ||
/> | ||
)} | ||
<Badge size="md" variant="default"> | ||
Time range: ±{ms(range / 2)} | ||
</Badge> | ||
</div> | ||
</Flex> | ||
) | ||
</Group> | ||
<div style={{ height: '100%', overflow: 'auto' }}> | ||
<DBSqlRowTable | ||
highlightedLineId={rowId} | ||
isLive={false} | ||
config={config} | ||
queryKeyPrefix={QUERY_KEY_PREFIX} | ||
onRowExpandClick={handleRowExpandClick} | ||
/> | ||
</div> | ||
</Flex> | ||
); | ||
|
||
return ( | ||
<> | ||
{contextComponent} | ||
{contextRowId && contextRowSidePanelSource && ( | ||
<DBRowSidePanel | ||
source={contextRowSidePanelSource} | ||
rowId={contextRowId} | ||
onClose={handleContextSidePanelClose} | ||
isNestedPanel={true} | ||
breadcrumbPath={[ | ||
...breadcrumbPath, | ||
{ | ||
label: `Surrounding Context`, | ||
rowData, | ||
}, | ||
]} | ||
/> | ||
)} | ||
</> | ||
); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TL;DR: URL state is used for the side panel. This allows us to expand into local state for nested panels as to not add additional complexity into url state