Skip to content

fix(traceview): Allow raw text on additional data when set #72038

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

Merged
merged 2 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions static/app/components/events/contexts/contextCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ interface ContextCardProps {
interface ContextCardContentConfig {
// Omit error styling from being displayed, even if context is invalid
disableErrors?: boolean;
// Displays tag value as plain text, rather than a hyperlink if applicable
disableRichValue?: boolean;
// Displays value as plain text, rather than a hyperlink if applicable
disableLink?: boolean;
// Includes the Context Type as a prefix to the key. Useful if displaying a single Context key
// apart from the rest of that Context. E.g. 'Email' -> 'User: Email'
includeAliasInSubject?: boolean;
Expand Down Expand Up @@ -60,7 +60,7 @@ export function ContextCardContent({
item={{...item, subject: contextSubject}}
meta={contextMeta}
errors={config?.disableErrors ? [] : contextErrors}
disableRichValue={config?.disableRichValue ?? false}
disableLink={config?.disableLink ?? false}
{...props}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function EditPreviewHighlightSection({
config={{
includeAliasInSubject: true,
disableErrors: true,
disableRichValue: true,
disableLink: true,
}}
data-test-id="highlights-preview-ctx"
/>
Expand Down
24 changes: 21 additions & 3 deletions static/app/components/keyValueData/card.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,13 @@ export default storyBook('KeyValueData', story => {
<code>item.action.link</code>.
</li>
<li>
<code>displayRichValue</code> - Disable automatic links from{' '}
<code>disableLink</code> - Disable automatic links from{' '}
<code>item.action.link</code>
</li>
<li>
<code>disableFormattedData</code> - Disable structured data and forces
string/component
</li>
<li>
<code>errors</code> - Errors to display at the end of the row
</li>
Expand Down Expand Up @@ -146,14 +150,28 @@ const contentItems: KeyValueData.ContentProps[] = [
value: 20481027,
},
},

{
item: {
key: 'array',
subject: 'array',
value: ['entry 0', 1, null, ['3'], {value: 4}] as any,
},
},
{
item: {
key: 'dict',
subject: 'dict',
value: {primary: 'alpha', secondary: 2} as any,
},
},
{
item: {
key: 'disabled-formatted-dict',
subject: 'raw dict',
value: {primary: 'alpha', secondary: 2} as any,
},
disableFormattedData: true,
},
{
item: {
key: 'null',
Expand Down Expand Up @@ -194,7 +212,7 @@ const contentItems: KeyValueData.ContentProps[] = [
link: 'https://sentry.io',
},
},
disableRichValue: true,
disableLink: true,
},
{
item: {
Expand Down
23 changes: 18 additions & 5 deletions static/app/components/keyValueData/card.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import {Children, isValidElement, type ReactNode, useRef, useState} from 'react';
import React from 'react';
import styled from '@emotion/styled';

import {useIssueDetailsColumnCount} from 'sentry/components/events/eventTags/util';
import {AnnotatedText} from 'sentry/components/events/meta/annotatedText';
import {AnnotatedTextErrors} from 'sentry/components/events/meta/annotatedText/annotatedTextErrors';
import Link from 'sentry/components/links/link';
import Panel from 'sentry/components/panels/panel';
Expand All @@ -20,9 +22,13 @@ export interface ContentProps {
*/
item: KeyValueListDataItem;
/**
* Displays tag value as plain text, rather than a hyperlink if applicable.
* If enabled, renders raw value instead of formatted structured data
*/
disableRichValue?: boolean;
disableFormattedData?: boolean;
/**
* If enabled, avoids rendering links, even if provided via `item.action.link`.
*/
disableLink?: boolean;
/**
* Errors pertaining to content item
*/
Expand All @@ -37,14 +43,21 @@ export function Content({
item,
meta,
errors = [],
disableRichValue = false,
disableLink = false,
disableFormattedData = false,
...props
}: ContentProps) {
const {subject, subjectNode, value: contextValue, action = {}} = item;

const hasErrors = errors.length > 0;

const dataComponent = (
const dataComponent = disableFormattedData ? (
React.isValidElement(contextValue) ? (
contextValue
) : (
<AnnotatedText value={contextValue as string} meta={meta} />
)
) : (
<StructuredData
value={contextValue}
depth={0}
Expand All @@ -60,7 +73,7 @@ export function Content({
{subjectNode !== undefined ? subjectNode : <Subject>{subject}</Subject>}
<ValueSection hasErrors={hasErrors} hasEmptySubject={subjectNode === null}>
<ValueWrapper hasErrors={hasErrors}>
{!disableRichValue && defined(action?.link) ? (
{!disableLink && defined(action?.link) ? (
<ValueLink to={action.link}>{dataComponent}</ValueLink>
) : (
dataComponent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -523,13 +523,15 @@ function SectionCard({
title,
disableTruncate,
sortAlphabetically = false,
itemProps = {},
}: {
items: SectionCardKeyValueList;
title: React.ReactNode;
disableTruncate?: boolean;
itemProps?: Partial<KeyValueData.ContentProps>;
sortAlphabetically?: boolean;
}) {
const contentItems = items.map(item => ({item}));
const contentItems = items.map(item => ({item, ...itemProps}));

return (
<KeyValueData.Card
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export function AdditionalData({event}: {event: EventTransaction}) {
items={formattedDataItems}
title={title}
sortAlphabetically
itemProps={{disableFormattedData: raw}}
/>
);
}
Expand Down
Loading