Skip to content

Commit

Permalink
feat: update visualizer to support v3 (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
bbrzoska authored Jan 6, 2025
1 parent c17ffab commit a8d7133
Show file tree
Hide file tree
Showing 23 changed files with 1,965 additions and 2,214 deletions.
11 changes: 6 additions & 5 deletions .storybook/preview.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
import type { Preview } from '@storybook/react';
import type { Preview } from '@storybook/react'
// import type { IndexEntry } from '@storybook/types';

const preview: Preview = {
parameters: {
actions: { argTypesRegex: "^on[A-Z].*" },
actions: { argTypesRegex: '^on[A-Z].*' },
layout: 'fullscreen',
options: {
// a and b are of type IndexEntry, but adding the type annotations generates a syntax warning in the console for some reason
storySort: (a, b) => {
if (a.title.includes('Visualizer')) return -1
if (b.title.includes('Visualizer')) return 1
return 0
}
},
},
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/,
},
},
}
},
}

export default preview
export default preview
79 changes: 40 additions & 39 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@
"tagFormat": "${version}"
},
"devDependencies": {
"@dnd-kit/core": "^6.1.0",
"@dnd-kit/modifiers": "^6.0.1",
"@dnd-kit/core": "^6.3.1",
"@dnd-kit/modifiers": "^9.0.0",
"@mdx-js/react": "^3.1.0",
"@niieani/scaffold": "^1.7.38",
"@patternfly/patternfly": "^5.3.1",
Expand All @@ -124,46 +124,47 @@
"@swc/core": "1.10.1",
"@swc/types": "^0.1.17",
"@types/lodash.debounce": "^4.0.9",
"@types/react": "^18.3.17",
"@types/react-dom": "^18.3.5",
"@types/react-test-renderer": "^18.3.1",
"@types/react": "^19.0.2",
"@types/react-dom": "^19.0.2",
"@types/react-test-renderer": "^19.0.0",
"@types/webpack-sources": "^3.2.3",
"@visx/annotation": "^3.3.0",
"@visx/axis": "^3.10.1",
"@visx/curve": "^3.3.0",
"@visx/event": "^3.3.0",
"@visx/gradient": "^3.3.0",
"@visx/group": "^3.3.0",
"@visx/legend": "^3.10.3",
"@visx/mock-data": "^3.3.0",
"@visx/responsive": "^3.10.2",
"@visx/scale": "^3.5.0",
"@visx/shape": "^3.5.0",
"@visx/stats": "^3.5.0",
"@visx/tooltip": "^3.3.0",
"@visx/vendor": "^3.5.0",
"@visx/visx": "^3.11.0",
"@zendeskgarden/react-accordions": "^9.1.2",
"@zendeskgarden/react-avatars": "^9.1.2",
"@zendeskgarden/react-buttons": "^9.1.2",
"@zendeskgarden/react-chrome": "^9.1.2",
"@zendeskgarden/react-dropdowns": "^9.1.2",
"@zendeskgarden/react-dropdowns.next": "^8.76.8",
"@zendeskgarden/react-grid": "^9.1.2",
"@zendeskgarden/react-loaders": "^9.1.2",
"@zendeskgarden/react-notifications": "^9.1.2",
"@zendeskgarden/react-tables": "^9.1.2",
"@zendeskgarden/react-theming": "^9.1.2",
"@zendeskgarden/react-typography": "^9.1.2",
"@zendeskgarden/svg-icons": "^7.3.0",
"@visx/annotation": "^3.12.0",
"@visx/axis": "^3.12.0",
"@visx/brush": "^3.12.0",
"@visx/curve": "^3.12.0",
"@visx/event": "^3.12.0",
"@visx/gradient": "^3.12.0",
"@visx/group": "^3.12.0",
"@visx/legend": "^3.12.0",
"@visx/mock-data": "^3.12.0",
"@visx/pattern": "^3.12.0",
"@visx/responsive": "^3.12.0",
"@visx/scale": "^3.12.0",
"@visx/shape": "^3.12.0",
"@visx/stats": "^3.12.0",
"@visx/tooltip": "^3.12.0",
"@visx/vendor": "^3.12.0",
"@visx/visx": "^3.12.0",
"@zendeskgarden/css-bedrock": "^10.0.1",
"@zendeskgarden/react-accordions": "^9.4.0",
"@zendeskgarden/react-avatars": "^9.4.0",
"@zendeskgarden/react-buttons": "^9.4.0",
"@zendeskgarden/react-chrome": "^9.4.0",
"@zendeskgarden/react-dropdowns": "^9.4.0",
"@zendeskgarden/react-grid": "^9.4.0",
"@zendeskgarden/react-loaders": "^9.4.0",
"@zendeskgarden/react-notifications": "^9.4.0",
"@zendeskgarden/react-tables": "^9.4.0",
"@zendeskgarden/react-theming": "^9.4.0",
"@zendeskgarden/react-typography": "^9.4.0",
"@zendeskgarden/svg-icons": "^7.5.0",
"css-loader": "^7.1.2",
"lodash.debounce": "^4.0.8",
"prettier-2": "npm:prettier@^2",
"re-resizable": "^6.9.17",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-test-renderer": "^18.3.1",
"remark-gfm": "^3.0.1",
"re-resizable": "^6.10.3",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"react-test-renderer": "^19.0.0",
"require-from-string": "^2.0.2",
"storybook": "^8.4.7",
"style-loader": "^4.0.0",
Expand All @@ -172,7 +173,7 @@
"typescript": "^5.7.2",
"url-loader": "^4.1.1",
"webpack": "5.97.1",
"webpack-cli": "^5.1.4",
"webpack-cli": "^6.0.0",
"webpack-sources": "^3.2.3"
},
"peerDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion src/2024/globalTypes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-redundant-type-constituents */
import type { SpanKind, SpanMetadata } from './types'
import type { SpanKind, SpanMetadata } from './legacyTypes'

type Writeable<T> = {
-readonly [P in keyof T]: T[P]
Expand Down
14 changes: 7 additions & 7 deletions src/2024/types.ts → src/2024/legacyTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ export interface TaskDataEmbeddedInOperation
detail?: Record<string, unknown>
}

export type Span<Metadata extends SpanMetadata<SpanKind>> =
export type LegacySpan<Metadata extends SpanMetadata<SpanKind>> =
AnyPerformanceEntry & {
// duration: number
// entryType: string
// name: string
// startTime: number
duration: number
entryType: string
name: string
startTime: number
operations: Record<string, Metadata>
}
/**
Expand All @@ -67,10 +67,10 @@ export type Span<Metadata extends SpanMetadata<SpanKind>> =
* and ending once the the page settles into the expected user experience
* (ex. loading the page),
*/
export type Operation = Span<OperationSpanMetadata>
export type LegacyOperation = LegacySpan<OperationSpanMetadata>

/**
* a Child Span representing the underlying process that is being tracked
* e.g. a fetch, rendering a component, computing a value
*/
export type Task = Span<TaskSpanMetadata>
export type LegacyTask = LegacySpan<TaskSpanMetadata>
28 changes: 17 additions & 11 deletions src/2024/operationTracking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import { type Subscription, Observable, share } from 'rxjs'
import { getCommonUrlForTracing } from '../v2/getCommonUrlForTracing'
import type { AnyPerformanceEntry, PerformanceEntryType } from './globalTypes'
import type {
Operation,
LegacyOperation,
OperationSpanMetadata,
PerformanceEntryLike,
Task,
LegacyTask,
TaskDataEmbeddedInOperation,
TaskSpanKind,
TaskSpanMetadata,
} from './types'
} from './legacyTypes'

interface ProcessedEntry {
commonName: string
Expand Down Expand Up @@ -193,16 +193,16 @@ class ActiveOperation {
private name: string
private metadata?: Record<string, unknown>
private onEnd?: (values: {
operationMeasure: Operation
tasks: Task[]
operationMeasure: LegacyOperation
tasks: LegacyTask[]
}) => void
private id: string
private tasks: Task[] = []
private tasks: LegacyTask[] = []
private remainingRequiredMeasureNames: Set<string>
private occurrenceCounts = new Map<string, number>()
private globalOccurrenceCounts = new Map<string, number>()
private includedCommonTaskNames = new Set<string>()
private lastRequiredTask: Task | undefined
private lastRequiredTask: LegacyTask | undefined
private lastRequiredTaskEndTime: number | undefined
private subscription: Subscription
private finalizing = false
Expand All @@ -216,7 +216,10 @@ class ActiveOperation {
name: string
requiredMeasureNames: string[]
metadata?: Record<string, unknown>
onEnd?: (values: { operationMeasure: Operation; tasks: Task[] }) => void
onEnd?: (values: {
operationMeasure: LegacyOperation
tasks: LegacyTask[]
}) => void
}) {
console.log(`Starting operation: ${name}`)
this.name = name
Expand Down Expand Up @@ -261,7 +264,7 @@ class ActiveOperation {
start: this.startTime,
end: this.lastRequiredTask!.startTime + this.lastRequiredTask!.duration,
detail: { operationName: this.name },
}) as Operation
}) as LegacyOperation

const embeddedTasksDetails = this.tasks.map(
(rawTask): TaskDataEmbeddedInOperation => {
Expand Down Expand Up @@ -393,7 +396,7 @@ class ActiveOperation {
// eslint-disable-next-line no-param-reassign
entry.operations[this.name] = taskSpanMetadata

const task = entry as Task
const task = entry as LegacyTask

this.tasks.push(task)
this.includedCommonTaskNames.add(commonName)
Expand Down Expand Up @@ -434,7 +437,10 @@ export function startOperation({
name: string
requiredMeasureNames: string[]
metadata?: Record<string, unknown>
onEnd?: (values: { operationMeasure: Operation; tasks: Task[] }) => void
onEnd?: (values: {
operationMeasure: LegacyOperation
tasks: LegacyTask[]
}) => void
}) {
return new ActiveOperation({ name, requiredMeasureNames, metadata, onEnd })
}
3 changes: 3 additions & 0 deletions src/v2/visualizer/TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- When there are multiple overlaying spans on one lane, add a little "+" button to expand the spans into separate lanes. The "+" button should be replaced with a "-" button when clicked, and when clicked again, it will collapse the spans within that lane.
- Show computed render spans
- Create a custom fetch instrumentation, DD is unreliable
54 changes: 54 additions & 0 deletions src/v2/visualizer/components/FilterGroup.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/* eslint-disable import/no-extraneous-dependencies */
import React from 'react'
import styled from 'styled-components'
import { ToggleButton } from '@zendeskgarden/react-buttons'
import { Grid } from '@zendeskgarden/react-grid'
import { Tooltip } from '@zendeskgarden/react-tooltips'
import { FILTER_OPTIONS, FilterOption } from '../constants'
import { Card, CardContent } from './styled/Card'

const FilterContainer = styled(Card)`
min-width: 300px;
`

const ButtonGroup = styled.div`
display: flex;
gap: ${(props) => props.theme.space.sm};
flex-wrap: wrap;
`

interface FilterGroupProps {
state: Record<string, boolean>
setState: React.Dispatch<React.SetStateAction<Record<FilterOption, boolean>>>
}

export const FilterGroup: React.FC<FilterGroupProps> = ({
state,
setState,
}) => (
<FilterContainer>
<CardContent>
<Grid.Row>
<Grid.Col>
<ButtonGroup>
{FILTER_OPTIONS.map((option) => (
<Tooltip key={option} content={option}>
<ToggleButton
isPressed={state[option]}
onClick={() =>
void setState((prev) => ({
...prev,
[option]: !prev[option],
}))
}
>
{option}
</ToggleButton>
</Tooltip>
))}
</ButtonGroup>
</Grid.Col>
</Grid.Row>
</CardContent>
</FilterContainer>
)
Loading

0 comments on commit a8d7133

Please sign in to comment.