Skip to content

Commit 408d2d9

Browse files
authored
ref(keyvaluedata): Change names and exports for better autocomplete (#72939)
Adds an explicit export to help with autocomplete (from [a separate code review](#72874 (comment))), and changes `Group` -> `Container` since the former has a meaning at Sentry.
1 parent 43c6e3c commit 408d2d9

File tree

5 files changed

+54
-36
lines changed

5 files changed

+54
-36
lines changed

static/app/components/events/contexts/contextCard.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@ import {
88
getContextTitle,
99
getFormattedContextData,
1010
} from 'sentry/components/events/contexts/utils';
11-
import * as KeyValueData from 'sentry/components/keyValueData/card';
12-
import type {Event, Group, KeyValueListDataItem, Project} from 'sentry/types';
11+
import KeyValueData, {
12+
type KeyValueDataContentProps,
13+
} from 'sentry/components/keyValueData';
14+
import type {Event} from 'sentry/types/event';
15+
import type {Group, KeyValueListDataItem} from 'sentry/types/group';
16+
import type {Project} from 'sentry/types/project';
1317
import {isEmptyObject} from 'sentry/utils/object/isEmptyObject';
1418
import {useLocation} from 'sentry/utils/useLocation';
1519
import useOrganization from 'sentry/utils/useOrganization';
@@ -90,9 +94,9 @@ export default function ContextCard({
9094
location,
9195
});
9296

93-
const contentItems = contextItems.map<KeyValueData.ContentProps>(item => {
94-
const itemMeta: KeyValueData.ContentProps['meta'] = meta?.[item?.key];
95-
const itemErrors: KeyValueData.ContentProps['errors'] = itemMeta?.['']?.err ?? [];
97+
const contentItems = contextItems.map<KeyValueDataContentProps>(item => {
98+
const itemMeta: KeyValueDataContentProps['meta'] = meta?.[item?.key];
99+
const itemErrors: KeyValueDataContentProps['errors'] = itemMeta?.['']?.err ?? [];
96100
return {
97101
item,
98102
meta: itemMeta,

static/app/components/events/contexts/contextDataSection.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ import {getOrderedContextItems} from 'sentry/components/events/contexts';
33
import ContextCard from 'sentry/components/events/contexts/contextCard';
44
import {CONTEXT_DOCS_LINK} from 'sentry/components/events/contexts/utils';
55
import {EventDataSection} from 'sentry/components/events/eventDataSection';
6-
import * as KeyValueData from 'sentry/components/keyValueData/card';
6+
import KeyValueData from 'sentry/components/keyValueData';
77
import ExternalLink from 'sentry/components/links/externalLink';
88
import {t, tct} from 'sentry/locale';
9-
import type {Event, Group, Project} from 'sentry/types';
9+
import type {Event} from 'sentry/types/event';
10+
import type {Group} from 'sentry/types/group';
11+
import type {Project} from 'sentry/types/project';
1012

1113
interface ContextDataSectionProps {
1214
event: Event;
@@ -47,7 +49,7 @@ export default function ContextDataSection({
4749
isHelpHoverable
4850
>
4951
<ErrorBoundary mini message={t('There was a problem loading event context.')}>
50-
<KeyValueData.Group>{cards}</KeyValueData.Group>
52+
<KeyValueData.Container>{cards}</KeyValueData.Container>
5153
</ErrorBoundary>
5254
</EventDataSection>
5355
);

static/app/components/keyValueData/card.stories.tsx renamed to static/app/components/keyValueData/index.stories.tsx

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@ import {Fragment} from 'react';
22

33
import Alert from 'sentry/components/alert';
44
import {CodeSnippet} from 'sentry/components/codeSnippet';
5-
import * as KeyValueData from 'sentry/components/keyValueData/card';
5+
import KeyValueData, {
6+
type KeyValueDataContentProps,
7+
} from 'sentry/components/keyValueData';
68
import {IconCodecov, IconSentry, IconSettings} from 'sentry/icons';
79
import storyBook from 'sentry/stories/storyBook';
810
import theme from 'sentry/utils/theme';
911

1012
export default storyBook('KeyValueData', story => {
1113
story('Usage', () => (
12-
<Fragment>
13-
<CodeSnippet language="js">
14-
import * as KeyValueData from 'sentry/components/keyValueData/card';
15-
</CodeSnippet>
16-
</Fragment>
14+
<CodeSnippet language="js">
15+
import KeyValueData from 'sentry/components/keyValueData';
16+
</CodeSnippet>
1717
));
1818
story('<KeyValueData.Content />', () => (
1919
<Fragment>
@@ -57,7 +57,7 @@ export default storyBook('KeyValueData', story => {
5757
Display a set of key-value data as a card. Creates structured data for lists/dicts
5858
and changes format based on value type. Any of the customization from{' '}
5959
<code>KeyValueData.Content</code> is available here, and display many of these
60-
cards using <code>KeyValueData.Group</code>.
60+
cards using <code>KeyValueData.Container</code>.
6161
</p>
6262
<h4>Props</h4>
6363
<ul>
@@ -76,7 +76,7 @@ export default storyBook('KeyValueData', story => {
7676
<code>subject</code>
7777
</li>
7878
</ul>
79-
<KeyValueData.Group>
79+
<KeyValueData.Container>
8080
<KeyValueData.Card
8181
title="Dataset Title"
8282
contentItems={contentItems.slice(0, 3)}
@@ -99,43 +99,45 @@ export default storyBook('KeyValueData', story => {
9999
contentItems={contentItems}
100100
truncateLength={4}
101101
/>
102-
</KeyValueData.Group>
102+
</KeyValueData.Container>
103103
</Fragment>
104104
));
105105

106-
story('<KeyValueData.Group />', () => (
106+
story('<KeyValueData.Container />', () => (
107107
<Fragment>
108108
<p>
109-
<code>{'<KeyValueData.Group/>'}</code> can be used in combination with{' '}
109+
<code>{'<KeyValueData.Container/>'}</code> can be used in combination with{' '}
110110
<code>{'<KeyValueData.Card/>'}</code> components to create a 'masonry' style
111111
layout for space efficiency. They leverage the{' '}
112112
<code>useIssueDetailsColumnCount</code> hook to distribute cards into the
113113
available space evenly. They don't accept any props, and just require{' '}
114114
<code>children</code>.
115115
</p>
116-
<CodeSnippet language="jsx">
117-
{`<KeyValueData.Group>
116+
<p>
117+
<CodeSnippet language="jsx">
118+
{`<KeyValueData.Container>
118119
<KeyValueData.Card ... />
119120
<KeyValueData.Card ... />
120121
<KeyValueData.Card ... />
121-
</KeyValueData.Group>`}
122-
</CodeSnippet>
122+
</KeyValueData.Container>`}
123+
</CodeSnippet>
124+
</p>
123125
<p>
124126
It should be noted that the number of items per card, or content size is not
125127
factored in, and can lead to some inconsistencies.
126128
</p>
127-
<KeyValueData.Group>
129+
<KeyValueData.Container>
128130
<KeyValueData.Card contentItems={contentItems.slice(0, 2)} />
129131
<KeyValueData.Card contentItems={contentItems.slice(4, 6)} />
130132
<KeyValueData.Card contentItems={contentItems.slice(1, 6)} />
131133
<KeyValueData.Card contentItems={contentItems.slice(0, 8)} />
132134
<KeyValueData.Card contentItems={contentItems.slice(2, 5)} />
133-
</KeyValueData.Group>
135+
</KeyValueData.Container>
134136
</Fragment>
135137
));
136138
});
137139

138-
const contentItems: KeyValueData.ContentProps[] = [
140+
const contentItems: KeyValueDataContentProps[] = [
139141
{
140142
item: {
141143
key: 'string',

static/app/components/keyValueData/card.tsx renamed to static/app/components/keyValueData/index.tsx

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {space} from 'sentry/styles/space';
1313
import type {KeyValueListDataItem, MetaError} from 'sentry/types/group';
1414
import {defined} from 'sentry/utils';
1515

16-
export interface ContentProps {
16+
export interface KeyValueDataContentProps {
1717
/**
1818
* Specifies the item to display.
1919
* - If set, item.subjectNode will override displaying item.subject.
@@ -46,7 +46,7 @@ export function Content({
4646
disableLink = false,
4747
disableFormattedData = false,
4848
...props
49-
}: ContentProps) {
49+
}: KeyValueDataContentProps) {
5050
const {subject, subjectNode, value: contextValue, action = {}} = item;
5151

5252
const hasErrors = errors.length > 0;
@@ -89,11 +89,11 @@ export function Content({
8989
);
9090
}
9191

92-
export interface CardProps {
92+
export interface KeyValueDataCardProps {
9393
/**
9494
* ContentProps items to be rendered in this card.
9595
*/
96-
contentItems: ContentProps[];
96+
contentItems: KeyValueDataContentProps[];
9797
/**
9898
* Flag to enable alphabetical sorting by item subject. Uses given item ordering if false.
9999
*/
@@ -113,7 +113,7 @@ export function Card({
113113
title,
114114
truncateLength = Infinity,
115115
sortAlphabetically = false,
116-
}: CardProps) {
116+
}: KeyValueDataCardProps) {
117117
const [isTruncated, setIsTruncated] = useState(contentItems.length > truncateLength);
118118

119119
if (contentItems.length === 0) {
@@ -145,7 +145,7 @@ export function Card({
145145
);
146146
}
147147

148-
type ReactFCWithProps = React.FC<CardProps>;
148+
type ReactFCWithProps = React.FC<KeyValueDataCardProps>;
149149

150150
const isReactComponent = (type): type is ReactFCWithProps => {
151151
return (
@@ -175,7 +175,7 @@ const filterChildren = (children: ReactNode): ReactNode[] => {
175175
// Note: When rendered children have hooks, we need to ensure that there are no hook count mismatches between renders.
176176
// Instead of rendering rendering {condition ? <Component/> : null}, we should render
177177
// if(!condition) return null inside Component itself, where Component renders a Card.
178-
export function Group({children}: {children: React.ReactNode}) {
178+
export function Container({children}: {children: React.ReactNode}) {
179179
const containerRef = useRef<HTMLDivElement>(null);
180180
const columnCount = useIssueDetailsColumnCount(containerRef);
181181

@@ -272,3 +272,11 @@ const CardColumn = styled('div')`
272272
const ValueLink = styled(Link)`
273273
text-decoration: ${p => p.theme.linkUnderline} underline dotted;
274274
`;
275+
276+
export const KeyValueData = {
277+
Content,
278+
Card,
279+
Container,
280+
};
281+
282+
export default KeyValueData;

static/app/views/performance/newTraceDetails/traceDrawer/details/styles.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ import {DropdownMenu, type MenuItemProps} from 'sentry/components/dropdownMenu';
99
import Tags from 'sentry/components/events/eventTagsAndScreenshot/tags';
1010
import {DataSection} from 'sentry/components/events/styles';
1111
import FileSize from 'sentry/components/fileSize';
12-
import * as KeyValueData from 'sentry/components/keyValueData/card';
12+
import KeyValueData, {
13+
type KeyValueDataContentProps,
14+
} from 'sentry/components/keyValueData';
1315
import {LazyRender, type LazyRenderProps} from 'sentry/components/lazyRender';
1416
import Link from 'sentry/components/links/link';
1517
import {normalizeDateTimeParams} from 'sentry/components/organizations/pageFilters/parse';
@@ -528,7 +530,7 @@ function SectionCard({
528530
items: SectionCardKeyValueList;
529531
title: React.ReactNode;
530532
disableTruncate?: boolean;
531-
itemProps?: Partial<KeyValueData.ContentProps>;
533+
itemProps?: Partial<KeyValueDataContentProps>;
532534
sortAlphabetically?: boolean;
533535
}) {
534536
const contentItems = items.map(item => ({item, ...itemProps}));
@@ -544,7 +546,7 @@ function SectionCard({
544546
}
545547

546548
function SectionCardGroup({children}: {children: React.ReactNode}) {
547-
return <KeyValueData.Group>{children}</KeyValueData.Group>;
549+
return <KeyValueData.Container>{children}</KeyValueData.Container>;
548550
}
549551

550552
function CopyableCardValueWithLink({

0 commit comments

Comments
 (0)