-
Notifications
You must be signed in to change notification settings - Fork 141
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
✨ Developer Extension improvements #2516
Merged
Merged
Changes from 16 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
27708cb
✨ sticky header
BenoitZugmeyer d5004b1
🐛 fix light theme border color
BenoitZugmeyer e3f5828
✨ add icons
BenoitZugmeyer 7e529f7
✨ add a menu to "copy event as curl/fetch"
BenoitZugmeyer 7d2dbab
🐛 fix row collapsing when clicking on a menu
BenoitZugmeyer 09f3542
🐛 fix crash when the cookie is missing some values
BenoitZugmeyer 7fa7374
🐛 fix wrapping of large text columns
BenoitZugmeyer cadfefe
🐛 fix clear events on refresh
BenoitZugmeyer 95855df
👌 add a shadow behind the table header when scrolled
BenoitZugmeyer 61d5e76
👌 add tests for copyEvent module
BenoitZugmeyer 645e8f7
🚚 move AddColumnPopover to its own module
BenoitZugmeyer 893f87d
🚚 move the events list header to its own module
BenoitZugmeyer 0e38490
✨ harmonized event list columns
BenoitZugmeyer 7ccf5c9
✅ fix unit tests when packages are not built
BenoitZugmeyer 29d1b20
👌 set the api tag to 'manual' for copied events
BenoitZugmeyer 7eb1dee
💄 improve header shadow color on light themes
BenoitZugmeyer 60d098a
Merge remote-tracking branch 'origin/main' into benoit/devext-enhance…
BenoitZugmeyer f00de3a
✅ disable failing tests on IE
BenoitZugmeyer 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 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 |
---|---|---|
|
@@ -6,6 +6,7 @@ file,tracekit,MIT,Copyright 2013 Onur Can Cakmak and all TraceKit contributors | |
file,web-vitals,Apache-2.0,Copyright 2020 Google LLC | ||
prod,@mantine/core,MIT,Copyright (c) 2021 Vitaly Rtishchev | ||
prod,@mantine/hooks,MIT,Copyright (c) 2021 Vitaly Rtishchev | ||
prod,@tabler/icons-react,MIT,Copyright (c) 2020-2023 Paweł Kuna | ||
prod,clsx,MIT,Copyright (c) Luke Edwards <[email protected]> (lukeed.com) | ||
prod,react,MIT,Copyright (c) Facebook, Inc. and its affiliates. | ||
prod,react-dom,MIT,Copyright (c) Facebook, Inc. and its affiliates. | ||
|
This file contains 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
This file contains 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
This file contains 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
This file contains 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
13 changes: 13 additions & 0 deletions
13
developer-extension/src/panel/components/tabs/eventsTab/addColumnPopover.module.css
This file contains 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,13 @@ | ||
.addFieldColumn { | ||
display: flex; | ||
align-items: flex-end; | ||
gab: var(--mantine-spacing-md); | ||
} | ||
|
||
.addFieldAutocomplete { | ||
flex: 1; | ||
} | ||
|
||
.addFilterAutocompleteHighlight { | ||
text-decoration: underline; | ||
} |
158 changes: 158 additions & 0 deletions
158
developer-extension/src/panel/components/tabs/eventsTab/addColumnPopover.tsx
This file contains 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,158 @@ | ||
import type { OptionsFilter } from '@mantine/core' | ||
import { Autocomplete, Button, Flex, Popover, Text } from '@mantine/core' | ||
import { IconColumnInsertRight } from '@tabler/icons-react' | ||
import React, { useMemo, useState } from 'react' | ||
import type { FacetRegistry } from '../../../hooks/useEvents' | ||
import type { EventListColumn } from './columnUtils' | ||
import { getColumnTitle, includesColumn, DEFAULT_COLUMNS } from './columnUtils' | ||
import { RowButton } from './rowButton' | ||
import classes from './addColumnPopover.module.css' | ||
|
||
export function AddColumnPopover({ | ||
columns, | ||
onColumnsChange, | ||
facetRegistry, | ||
}: { | ||
columns: EventListColumn[] | ||
onColumnsChange: (columns: EventListColumn[]) => void | ||
facetRegistry: FacetRegistry | ||
}) { | ||
return ( | ||
<Popover width={300} trapFocus position="bottom" withArrow shadow="md"> | ||
<Popover.Target> | ||
<RowButton title="Add column" icon={IconColumnInsertRight} /> | ||
</Popover.Target> | ||
<Popover.Dropdown> | ||
<Flex direction="column" gap="sm"> | ||
{DEFAULT_COLUMNS.map((column) => ( | ||
<AddDefaultColumnButton | ||
key={column.type} | ||
column={column} | ||
columns={columns} | ||
onColumnsChange={onColumnsChange} | ||
/> | ||
))} | ||
<AddFieldColumn columns={columns} onColumnsChange={onColumnsChange} facetRegistry={facetRegistry} /> | ||
</Flex> | ||
</Popover.Dropdown> | ||
</Popover> | ||
) | ||
} | ||
|
||
function AddDefaultColumnButton({ | ||
column, | ||
columns, | ||
onColumnsChange, | ||
}: { | ||
column: EventListColumn | ||
columns: EventListColumn[] | ||
onColumnsChange: (columns: EventListColumn[]) => void | ||
}) { | ||
if (includesColumn(columns, column)) { | ||
return null | ||
} | ||
return ( | ||
<Flex justify="space-between" align="center" gap="sm"> | ||
<Text>{getColumnTitle(column)}</Text> | ||
<Button | ||
onClick={() => { | ||
onColumnsChange(columns.concat(column)) | ||
}} | ||
> | ||
Add | ||
</Button> | ||
</Flex> | ||
) | ||
} | ||
|
||
function AddFieldColumn({ | ||
columns, | ||
onColumnsChange, | ||
facetRegistry, | ||
}: { | ||
columns: EventListColumn[] | ||
onColumnsChange: (columns: EventListColumn[]) => void | ||
facetRegistry: FacetRegistry | ||
}) { | ||
const [input, setInput] = useState('') | ||
|
||
function addFieldColumn(path: string) { | ||
const newColumn: EventListColumn = { path, type: 'field' } | ||
if (!includesColumn(columns, newColumn)) { | ||
onColumnsChange(columns.concat(newColumn)) | ||
} | ||
} | ||
|
||
const allPaths = useMemo( | ||
() => | ||
Array.from(facetRegistry.getAllFieldPaths()).sort((a, b) => { | ||
// Sort private fields last | ||
if (a.startsWith('_dd') !== b.startsWith('_dd')) { | ||
if (a.startsWith('_dd')) { | ||
return 1 | ||
} | ||
if (b.startsWith('_dd')) { | ||
return -1 | ||
} | ||
} | ||
return a < b ? -1 : 1 | ||
}), | ||
[] | ||
) | ||
|
||
return ( | ||
<form | ||
onSubmit={(event) => { | ||
event.preventDefault() | ||
addFieldColumn(input) | ||
}} | ||
className={classes.addFieldColumn} | ||
> | ||
<Autocomplete | ||
className={classes.addFieldAutocomplete} | ||
value={input} | ||
label="Field" | ||
onChange={setInput} | ||
data={allPaths} | ||
filter={filterColumns} | ||
placeholder="foo.bar" | ||
onOptionSubmit={addFieldColumn} | ||
/> | ||
<Button type="submit">Add</Button> | ||
</form> | ||
) | ||
} | ||
|
||
function filterColumns(filterOptions: Parameters<OptionsFilter>[0]): ReturnType<OptionsFilter> { | ||
if (!filterOptions.search) { | ||
return filterOptions.options | ||
} | ||
const filteredOptions = filterOptions.options.flatMap((option) => { | ||
if (!('value' in option)) { | ||
return [] | ||
} | ||
|
||
const inputIndex = option.value.indexOf(filterOptions.search) | ||
if (inputIndex < 0) { | ||
return [] | ||
} | ||
|
||
return [ | ||
{ | ||
value: option.value, | ||
label: ( | ||
<span> | ||
{option.value.slice(0, inputIndex)} | ||
<span className={classes.addFilterAutocompleteHighlight}> | ||
{option.value.slice(inputIndex, inputIndex + filterOptions.search.length)} | ||
</span> | ||
{option.value.slice(inputIndex + filterOptions.search.length)} | ||
</span> | ||
) as unknown as string, | ||
// Mantime types expect a string as label, but to support highlighting we need to return a | ||
// ReactNode. This is the simplest way to achieve this, but it might break in the future | ||
}, | ||
] | ||
}) | ||
return filteredOptions | ||
} |
This file contains 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
122 changes: 122 additions & 0 deletions
122
developer-extension/src/panel/components/tabs/eventsTab/copyEvent.spec.ts
This file contains 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,122 @@ | ||
import type { TelemetryEvent } from '../../../../../../packages/core/src/domain/telemetry' | ||
import type { LogsEvent } from '../../../../../../packages/logs/src/logsEvent.types' | ||
import type { RumEvent } from '../../../../../../packages/rum-core/src/rumEvent.types' | ||
import { getIntakeUrlForEvent, escapeShellParameter } from './copyEvent' | ||
|
||
const RUM_ERROR_EVENT = { type: 'error' } as RumEvent | ||
const TELEMETRY_EVENT = { | ||
type: 'telemetry', | ||
telemetry: { type: 'log' }, | ||
} as TelemetryEvent | ||
const LOG_EVENT = { | ||
status: 'info', | ||
} as LogsEvent | ||
|
||
describe('getIntakeUrlForEvent', () => { | ||
it('should return undefined when RUM is not present', () => { | ||
expect(getIntakeUrlForEvent({} as any, RUM_ERROR_EVENT)).toBeUndefined() | ||
}) | ||
|
||
it('should return undefined when no RUM config', () => { | ||
expect(getIntakeUrlForEvent({ rum: {} } as any, RUM_ERROR_EVENT)).toBeUndefined() | ||
}) | ||
|
||
it('should return undefined when no RUM version', () => { | ||
expect(getIntakeUrlForEvent({ rum: { config: {} } } as any, RUM_ERROR_EVENT)).toBeUndefined() | ||
}) | ||
|
||
it('should return the URL with the right parameters', () => { | ||
const url = new URL( | ||
getIntakeUrlForEvent( | ||
{ | ||
rum: { | ||
config: { | ||
clientToken: 'client-token', | ||
}, | ||
version: '1.2.3', | ||
}, | ||
} as any, | ||
RUM_ERROR_EVENT | ||
)! | ||
) | ||
|
||
expect(url.host).toBe('browser-intake-datadoghq.com') | ||
expect(url.pathname).toBe('/api/v2/rum') | ||
expect(url.searchParams.get('ddsource')).toBe('browser') | ||
expect(url.searchParams.get('ddtags')).toBe('sdk_version:1.2.3,api:manual') | ||
expect(url.searchParams.get('dd-api-key')).toBe('client-token') | ||
expect(url.searchParams.get('dd-evp-origin-version')).toBe('1.2.3') | ||
expect(url.searchParams.get('dd-evp-origin')).toBe('browser') | ||
expect(url.searchParams.get('dd-request-id')).toMatch(/[a-f0-9-]+/) | ||
expect(url.searchParams.get('batch_time')).toMatch(/[0-9]+/) | ||
}) | ||
|
||
it('should escape the version URL parameter', () => { | ||
const url = new URL( | ||
getIntakeUrlForEvent( | ||
{ | ||
rum: { | ||
config: { | ||
clientToken: 'client-token', | ||
}, | ||
version: '1.2.3&4', | ||
}, | ||
} as any, | ||
RUM_ERROR_EVENT | ||
)! | ||
) | ||
|
||
expect(url.searchParams.get('ddtags')).toBe('sdk_version:1.2.3&4,api:manual') | ||
expect(url.searchParams.get('dd-evp-origin-version')).toBe('1.2.3&4') | ||
}) | ||
|
||
it('should use the RUM intake for telemetry events', () => { | ||
const url = new URL( | ||
getIntakeUrlForEvent( | ||
{ | ||
rum: { | ||
config: { | ||
clientToken: 'client-token', | ||
}, | ||
version: '1.2.3', | ||
}, | ||
} as any, | ||
TELEMETRY_EVENT | ||
)! | ||
) | ||
|
||
expect(url.pathname).toBe('/api/v2/rum') | ||
}) | ||
|
||
it('should use the Logs intake for Log events', () => { | ||
const url = new URL( | ||
getIntakeUrlForEvent( | ||
{ | ||
logs: { | ||
config: { | ||
clientToken: 'client-token', | ||
}, | ||
version: '1.2.3', | ||
}, | ||
} as any, | ||
LOG_EVENT | ||
)! | ||
) | ||
|
||
expect(url.pathname).toBe('/api/v2/logs') | ||
}) | ||
}) | ||
|
||
describe('escapeShellParameter', () => { | ||
it('should escape simple strings', () => { | ||
expect(escapeShellParameter('foo bar')).toBe("$'foo bar'") | ||
}) | ||
|
||
it('should escape backslashes', () => { | ||
expect(escapeShellParameter('foo\\bar')).toBe("$'foo\\\\bar'") | ||
}) | ||
|
||
it('should escape single quotes', () => { | ||
expect(escapeShellParameter("foo'bar")).toBe("$'foo\\'bar'") | ||
}) | ||
}) |
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.
praise:
kudos 🎉