Skip to content

Commit cd457a6

Browse files
authored
ref(poc): composition (#36703)
* ref(poc): composition * feat(PermalinkTitle): use children for props * fix(evendatasection): add the title back * fix(permalinkTitle): add back title
1 parent 194096f commit cd457a6

File tree

5 files changed

+59
-72
lines changed

5 files changed

+59
-72
lines changed

static/app/components/events/interfaces/exceptionV2.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
import styled from '@emotion/styled';
2-
31
import {t} from 'sentry/locale';
42
import {ExceptionType, Group, PlatformType, Project} from 'sentry/types';
53
import {Event} from 'sentry/types/event';
64
import {STACK_TYPE, STACK_VIEW} from 'sentry/types/stacktrace';
75

8-
import {TraceEventDataSection} from '../traceEventDataSection';
6+
import {PermalinkTitle, TraceEventDataSection} from '../traceEventDataSection';
97

108
import CrashContentException from './crashContent/exception';
119
import NoStackTraceMessage from './noStackTraceMessage';
@@ -59,7 +57,7 @@ function Exception({
5957

6058
return (
6159
<TraceEventDataSection
62-
title={<Title>{t('Exception')}</Title>}
60+
title={<PermalinkTitle>{t('Exception')}</PermalinkTitle>}
6361
type={type}
6462
stackType={STACK_TYPE.ORIGINAL}
6563
projectId={projectId}
@@ -98,7 +96,6 @@ function Exception({
9896
!!data.values?.some(value => (value.stacktrace?.frames ?? []).length > 1)
9997
}
10098
stackTraceNotFound={stackTraceNotFound}
101-
showPermalink
10299
wrapTitle={false}
103100
>
104101
{({recentFirst, display, fullStackTrace}) =>
@@ -131,7 +128,3 @@ function Exception({
131128
}
132129

133130
export default Exception;
134-
135-
const Title = styled('h3')`
136-
margin-bottom: 0;
137-
`;

static/app/components/events/interfaces/stackTraceV2.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
import styled from '@emotion/styled';
2-
31
import CrashContent from 'sentry/components/events/interfaces/crashContent';
42
import {t} from 'sentry/locale';
53
import {Group, PlatformType, Project} from 'sentry/types';
64
import {Event} from 'sentry/types/event';
75
import {STACK_TYPE, STACK_VIEW} from 'sentry/types/stacktrace';
86

9-
import {TraceEventDataSection} from '../traceEventDataSection';
7+
import {PermalinkTitle, TraceEventDataSection} from '../traceEventDataSection';
108

119
import CrashContentStackTrace from './crashContent/stackTrace';
1210
import NoStackTraceMessage from './noStackTraceMessage';
@@ -52,7 +50,7 @@ function StackTrace({
5250
stackTraceNotFound={stackTraceNotFound}
5351
recentFirst={isStacktraceNewestFirst()}
5452
fullStackTrace={!data.hasSystemFrames}
55-
title={<Title>{t('Stack Trace')}</Title>}
53+
title={<PermalinkTitle>{t('Stack Trace')}</PermalinkTitle>}
5654
wrapTitle={false}
5755
hasMinified={false}
5856
hasVerboseFunctionNames={
@@ -67,7 +65,6 @@ function StackTrace({
6765
hasAbsoluteAddresses={!!data.frames?.some(frame => !!frame.instructionAddr)}
6866
hasAppOnlyFrames={!!data.frames?.some(frame => frame.inApp !== true)}
6967
hasNewestFirst={(data.frames ?? []).length > 1}
70-
showPermalink
7168
>
7269
{({recentFirst, display, fullStackTrace}) =>
7370
stackTraceNotFound ? (
@@ -96,7 +93,3 @@ function StackTrace({
9693
}
9794

9895
export default StackTrace;
99-
100-
const Title = styled('h3')`
101-
margin-bottom: 0;
102-
`;

static/app/components/events/interfaces/threads/index.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {t} from 'sentry/locale';
77
import {Event, Project, STACK_TYPE, STACK_VIEW, Thread} from 'sentry/types';
88
import {defined} from 'sentry/utils';
99

10+
import {PermalinkTitle} from '../../traceEventDataSection';
1011
import {isStacktraceNewestFirst} from '../utils';
1112

1213
import findBestThread from './threadSelector/findBestThread';
@@ -133,12 +134,14 @@ function Threads({
133134
}
134135
/>
135136
) : (
136-
<CrashTitle
137-
title={t('Stack Trace')}
138-
newestFirst={newestFirst}
139-
hideGuide={hideGuide}
140-
onChange={!stackTraceNotFound ? handleChangeNewestFirst : undefined}
141-
/>
137+
<PermalinkTitle>
138+
<CrashTitle
139+
title={t('Stack Trace')}
140+
newestFirst={newestFirst}
141+
hideGuide={hideGuide}
142+
onChange={!stackTraceNotFound ? handleChangeNewestFirst : undefined}
143+
/>
144+
</PermalinkTitle>
142145
)
143146
}
144147
actions={
@@ -155,7 +158,6 @@ function Threads({
155158
/>
156159
)
157160
}
158-
showPermalink={!hasMoreThanOneThread}
159161
wrapTitle={false}
160162
>
161163
<Content

static/app/components/events/interfaces/threadsV2.tsx

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {Fragment, useState} from 'react';
2-
import styled from '@emotion/styled';
32
import isNil from 'lodash/isNil';
43

54
import Pill from 'sentry/components/pill';
@@ -15,7 +14,7 @@ import {
1514
Thread,
1615
} from 'sentry/types';
1716

18-
import {TraceEventDataSection} from '../traceEventDataSection';
17+
import {PermalinkTitle, TraceEventDataSection} from '../traceEventDataSection';
1918

2019
import Exception from './crashContent/exception';
2120
import StackTrace from './crashContent/stackTrace';
@@ -186,28 +185,6 @@ function Threads({
186185
);
187186
}
188187

189-
function getTitle() {
190-
if (hasMoreThanOneThread && activeThread) {
191-
return (
192-
<ThreadSelector
193-
threads={threads}
194-
activeThread={activeThread}
195-
event={event}
196-
onChange={thread => {
197-
setState({
198-
...state,
199-
activeThread: thread,
200-
});
201-
}}
202-
exception={exception}
203-
fullWidth
204-
/>
205-
);
206-
}
207-
208-
return <Title>{t('Stack Trace')}</Title>;
209-
}
210-
211188
const platform = getPlatform();
212189

213190
return (
@@ -218,9 +195,26 @@ function Threads({
218195
eventId={event.id}
219196
recentFirst={isStacktraceNewestFirst()}
220197
fullStackTrace={stackView === STACK_VIEW.FULL}
221-
title={getTitle()}
198+
title={
199+
hasMoreThanOneThread && activeThread ? (
200+
<ThreadSelector
201+
threads={threads}
202+
activeThread={activeThread}
203+
event={event}
204+
onChange={thread => {
205+
setState({
206+
...state,
207+
activeThread: thread,
208+
});
209+
}}
210+
exception={exception}
211+
fullWidth
212+
/>
213+
) : (
214+
<PermalinkTitle>{t('Stack Trace')}</PermalinkTitle>
215+
)
216+
}
222217
platform={platform}
223-
showPermalink={!hasMoreThanOneThread}
224218
hasMinified={
225219
!!exception?.values?.find(value => value.rawStacktrace) ||
226220
!!activeThread?.rawStacktrace
@@ -275,7 +269,3 @@ function Threads({
275269
}
276270

277271
export default Threads;
278-
279-
const Title = styled('h3')`
280-
margin-bottom: 0;
281-
`;

static/app/components/events/traceEventDataSection.tsx

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import {createContext, Fragment, useState} from 'react';
1+
import {
2+
AnchorHTMLAttributes,
3+
cloneElement,
4+
createContext,
5+
Fragment,
6+
useState,
7+
} from 'react';
28
import styled from '@emotion/styled';
39

410
import Button from 'sentry/components/button';
@@ -54,9 +60,8 @@ type Props = {
5460
recentFirst: boolean;
5561
stackTraceNotFound: boolean;
5662
stackType: STACK_TYPE;
57-
title: React.ReactNode;
63+
title: React.ReactElement<any, any>;
5864
type: string;
59-
showPermalink?: boolean;
6065
wrapTitle?: boolean;
6166
};
6267

@@ -67,7 +72,6 @@ export const TraceEventDataSectionContext = createContext<ChildProps | undefined
6772
export function TraceEventDataSection({
6873
type,
6974
title,
70-
showPermalink,
7175
wrapTitle,
7276
stackTraceNotFound,
7377
fullStackTrace,
@@ -192,18 +196,7 @@ export function TraceEventDataSection({
192196
type={type}
193197
title={
194198
<Header>
195-
<Title>
196-
{showPermalink ? (
197-
<div>
198-
<Permalink href={'#' + type} className="permalink">
199-
<StyledIconAnchor />
200-
{title}
201-
</Permalink>
202-
</div>
203-
) : (
204-
title
205-
)}
206-
</Title>
199+
<Title>{cloneElement(title, {type})}</Title>
207200
{!stackTraceNotFound && (
208201
<Fragment>
209202
{!state.display.includes('raw-stack-trace') && (
@@ -282,6 +275,21 @@ export function TraceEventDataSection({
282275
);
283276
}
284277

278+
interface PermalinkTitleProps
279+
extends React.DetailedHTMLProps<
280+
AnchorHTMLAttributes<HTMLAnchorElement>,
281+
HTMLAnchorElement
282+
> {}
283+
284+
export function PermalinkTitle(props: PermalinkTitleProps) {
285+
return (
286+
<Permalink {...props} href={'#' + props.type} className="permalink">
287+
<StyledIconAnchor />
288+
<h3>{props.children}</h3>
289+
</Permalink>
290+
);
291+
}
292+
285293
const StyledIconAnchor = styled(IconAnchor)`
286294
display: none;
287295
position: absolute;
@@ -292,7 +300,8 @@ const StyledIconAnchor = styled(IconAnchor)`
292300
const Permalink = styled('a')`
293301
display: inline-flex;
294302
justify-content: flex-start;
295-
:hover ${StyledIconAnchor} {
303+
304+
&:hover ${StyledIconAnchor} {
296305
display: block;
297306
color: ${p => p.theme.gray300};
298307
}

0 commit comments

Comments
 (0)