Skip to content

Commit

Permalink
Fix expand link in related resource panel (#8515)
Browse files Browse the repository at this point in the history
  • Loading branch information
ccschmitz committed May 15, 2024
1 parent 72395a1 commit 69fbe8d
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 31 deletions.
11 changes: 1 addition & 10 deletions frontend/src/components/RelatedResources/Panel.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Box, Dialog } from '@highlight-run/ui/components'
import { useCallback, useEffect, useRef, useState } from 'react'
import { useLocation } from 'react-router-dom'

import { useRelatedResource } from '@/components/RelatedResources/hooks'
import {
Expand Down Expand Up @@ -28,8 +27,7 @@ type PanelComponent = React.FC<Props> & {
export const Panel: PanelComponent = ({ children, open }) => {
const dragHandleRef = useRef<HTMLDivElement>(null)
const [dragging, setDragging] = useState(false)
const { resource, remove, panelWidth, setPanelWidth } = useRelatedResource()
const location = useLocation()
const { remove, panelWidth, setPanelWidth } = useRelatedResource()
const dialogStore = Dialog.useStore({
open,
setOpen: (open) => {
Expand Down Expand Up @@ -77,13 +75,6 @@ export const Panel: PanelComponent = ({ children, open }) => {
}
}, [dragging, handleMouseMove, handleMouseUp])

useEffect(() => {
if (resource) {
remove()
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [location.pathname])

return (
<Dialog
store={dialogStore}
Expand Down
22 changes: 12 additions & 10 deletions frontend/src/components/RelatedResources/PanelHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ import {
import { message } from 'antd'
import { useCallback } from 'react'
import { useHotkeys } from 'react-hotkeys-hook'
import { useNavigate } from 'react-router-dom'
import { Link, useNavigate } from 'react-router-dom'

import { Button } from '@/components/Button'
import { PreviousNextGroup } from '@/components/PreviousNextGroup/PreviousNextGroup'
import { useRelatedResource } from '@/components/RelatedResources/hooks'

type Props = React.PropsWithChildren & {
path: string
path?: string
}

export const PanelHeader: React.FC<Props> = ({ children, path }) => {
Expand Down Expand Up @@ -62,14 +62,16 @@ export const PanelHeader: React.FC<Props> = ({ children, path }) => {
{children}
</Stack>

<ButtonIcon
icon={<IconSolidArrowsExpand />}
emphasis="low"
kind="secondary"
onClick={() => {
navigate(path)
}}
/>
{path && (
<Link to={path}>
<ButtonIcon
icon={<IconSolidArrowsExpand />}
emphasis="low"
kind="secondary"
onClick={() => null}
/>
</Link>
)}

<ButtonIcon
icon={<IconSolidX />}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const RelatedResourcePanel: React.FC<Props> = ({}) => {
traceId={resource.id}
spanId={resource.spanID}
>
<TracePanel resource={resource} />
<TracePanel />
</TraceProvider>
)}
</Panel>
Expand Down
11 changes: 3 additions & 8 deletions frontend/src/components/RelatedResources/TracePanel.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
import { Box, Callout, Text } from '@highlight-run/ui/components'

import LoadingBox from '@/components/LoadingBox'
import { RelatedTrace } from '@/components/RelatedResources/hooks'
import { Panel } from '@/components/RelatedResources/Panel'
import { useNumericProjectId } from '@/hooks/useProjectId'
import { TraceHeader } from '@/pages/Traces/TraceHeader'
import { useTrace } from '@/pages/Traces/TraceProvider'
import { TraceSpanAttributes } from '@/pages/Traces/TraceSpanAttributes'
import { TraceVisualizer } from '@/pages/Traces/TraceVisualizer'

export const TracePanel: React.FC<{ resource: RelatedTrace }> = ({
resource,
}) => {
const { projectId } = useNumericProjectId()
const path = `/${projectId}/traces/${resource.id}`
export const TracePanel: React.FC = () => {
const { highlightedSpan, loading, selectedSpan, traces } = useTrace()
const span = selectedSpan || highlightedSpan
const path = `${window.location.pathname}${window.location.search}`

return (
<>
<Panel.Header path={path}>
<Panel.Header>
<Panel.HeaderCopyLinkButton path={path} />
<Panel.HeaderDivider />
</Panel.Header>
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/RelatedResources/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export type RelatedResource =
| RelatedLogs

const LOCAL_STORAGE_WIDTH_KEY = 'related-resource-panel-width'
const RELATED_RESOURCE_PARAM = 'related_resource'
export const RELATED_RESOURCE_PARAM = 'related_resource'

const localStorageWidth = localStorage.getItem(LOCAL_STORAGE_WIDTH_KEY)
const panelWidthVar = makeVar<number>(
Expand Down Expand Up @@ -112,7 +112,7 @@ export const useRelatedResource = () => {

searchParams.set(
RELATED_RESOURCE_PARAM,
encodeURI(JSON.stringify(newResource)),
JSON.stringify(newResource), // setSearchParams encodes the string
)

setSearchParams(Object.fromEntries(searchParams.entries()))
Expand Down

0 comments on commit 69fbe8d

Please sign in to comment.