Skip to content

Commit 7453a86

Browse files
authored
fix(issueDetailsPage/contextSummary): Prefer client_os over os for eventContextSummary (#14515)
* fix(issueDetailsPage/contextSummary): Prefer client_os over os for eventContextSummary * feat: Add annotation where OS is from * ref: Apply suggestions from jauer * Revert "feat: Add annotation where OS is from" This reverts commit ca993ac.
1 parent 9a7ceb0 commit 7453a86

File tree

3 files changed

+153
-11
lines changed

3 files changed

+153
-11
lines changed

src/sentry/static/sentry/app/components/events/contextSummary.jsx

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -234,12 +234,12 @@ export class GpuSummary extends React.Component {
234234
const MIN_CONTEXTS = 3;
235235
const MAX_CONTEXTS = 4;
236236
const KNOWN_CONTEXTS = [
237-
{key: 'user', Component: UserSummary},
238-
{key: 'browser', Component: GenericSummary, unknownTitle: t('Unknown Browser')},
239-
{key: 'runtime', Component: GenericSummary, unknownTitle: t('Unknown Runtime')},
240-
{key: 'os', Component: OsSummary},
241-
{key: 'device', Component: DeviceSummary},
242-
{key: 'gpu', Component: GpuSummary},
237+
{keys: ['user'], Component: UserSummary},
238+
{keys: ['browser'], Component: GenericSummary, unknownTitle: t('Unknown Browser')},
239+
{keys: ['runtime'], Component: GenericSummary, unknownTitle: t('Unknown Runtime')},
240+
{keys: ['client_os', 'os'], Component: OsSummary},
241+
{keys: ['device'], Component: DeviceSummary},
242+
{keys: ['gpu'], Component: GpuSummary},
243243
];
244244

245245
class EventContextSummary extends React.Component {
@@ -253,14 +253,19 @@ class EventContextSummary extends React.Component {
253253

254254
// Add defined contexts in the declared order, until we reach the limit
255255
// defined by MAX_CONTEXTS.
256-
let contexts = KNOWN_CONTEXTS.map(({key, Component, ...props}) => {
256+
let contexts = KNOWN_CONTEXTS.map(({keys, Component, ...props}) => {
257257
if (contextCount >= MAX_CONTEXTS) {
258258
return null;
259259
}
260-
const data = evt.contexts[key] || evt[key];
261-
if (objectIsEmpty(data)) {
260+
261+
const [key, data] = keys
262+
.map(k => [k, evt.contexts[k] || evt[k]])
263+
.find(([_k, d]) => !objectIsEmpty(d)) || [null, null];
264+
265+
if (!key) {
262266
return null;
263267
}
268+
264269
contextCount += 1;
265270
return <Component key={key} data={data} {...props} />;
266271
});
@@ -273,15 +278,15 @@ class EventContextSummary extends React.Component {
273278
if (contextCount < MIN_CONTEXTS) {
274279
// Add contents in the declared order until we have at least MIN_CONTEXTS
275280
// contexts in our list.
276-
contexts = KNOWN_CONTEXTS.map(({key, Component, ...props}, index) => {
281+
contexts = KNOWN_CONTEXTS.map(({keys, Component, ...props}, index) => {
277282
if (contexts[index]) {
278283
return contexts[index];
279284
}
280285
if (contextCount >= MIN_CONTEXTS) {
281286
return null;
282287
}
283288
contextCount += 1;
284-
return <Component key={key} data={{}} {...props} />;
289+
return <Component key={keys[0]} data={{}} {...props} />;
285290
});
286291
}
287292

tests/js/spec/components/events/__snapshots__/contextSummary.spec.jsx.snap

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,55 @@
22

33
exports[`ContextSummary render() should bail out with empty contexts 1`] = `""`;
44

5+
exports[`ContextSummary render() should prefer client_os over os 1`] = `
6+
<div
7+
className="context-summary"
8+
>
9+
<UserSummary
10+
data={
11+
Object {
12+
"email": "[email protected]",
13+
"id": "1",
14+
}
15+
}
16+
key="user"
17+
/>
18+
<GenericSummary
19+
data={
20+
Object {
21+
"name": "Chrome",
22+
"version": "65.0.3325",
23+
}
24+
}
25+
key="browser"
26+
unknownTitle="Unknown Browser"
27+
/>
28+
<GenericSummary
29+
data={
30+
Object {
31+
"name": "Electron",
32+
"type": "runtime",
33+
"version": "1.7.13",
34+
}
35+
}
36+
key="runtime"
37+
unknownTitle="Unknown Runtime"
38+
/>
39+
<OsSummary
40+
data={
41+
Object {
42+
"build": "17E199",
43+
"kernel_version": "17.5.0",
44+
"name": "Mac OS X",
45+
"type": "os",
46+
"version": "10.13.4",
47+
}
48+
}
49+
key="client_os"
50+
/>
51+
</div>
52+
`;
53+
554
exports[`ContextSummary render() should render at least three contexts 1`] = `
655
<div
756
className="context-summary"
@@ -34,6 +83,55 @@ exports[`ContextSummary render() should render at least three contexts 1`] = `
3483
</div>
3584
`;
3685

86+
exports[`ContextSummary render() should render client_os too 1`] = `
87+
<div
88+
className="context-summary"
89+
>
90+
<UserSummary
91+
data={
92+
Object {
93+
"email": "[email protected]",
94+
"id": "1",
95+
}
96+
}
97+
key="user"
98+
/>
99+
<GenericSummary
100+
data={
101+
Object {
102+
"name": "Chrome",
103+
"version": "65.0.3325",
104+
}
105+
}
106+
key="browser"
107+
unknownTitle="Unknown Browser"
108+
/>
109+
<GenericSummary
110+
data={
111+
Object {
112+
"name": "Electron",
113+
"type": "runtime",
114+
"version": "1.7.13",
115+
}
116+
}
117+
key="runtime"
118+
unknownTitle="Unknown Runtime"
119+
/>
120+
<OsSummary
121+
data={
122+
Object {
123+
"build": "17E199",
124+
"kernel_version": "17.5.0",
125+
"name": "Mac OS X",
126+
"type": "os",
127+
"version": "10.13.4",
128+
}
129+
}
130+
key="client_os"
131+
/>
132+
</div>
133+
`;
134+
37135
exports[`ContextSummary render() should render nothing with a single user context 1`] = `""`;
38136

39137
exports[`ContextSummary render() should render nothing without contexts 1`] = `""`;

tests/js/spec/components/events/contextSummary.spec.jsx

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ const CONTEXT_OS = {
2626
name: 'Mac OS X',
2727
};
2828

29+
const CONTEXT_OS_SERVER = {
30+
kernel_version: '4.3.0',
31+
version: '4.3.0',
32+
type: 'os',
33+
build: '123123123',
34+
name: 'Linux',
35+
};
36+
2937
const CONTEXT_RUNTIME = {
3038
version: '1.7.13',
3139
type: 'runtime',
@@ -103,6 +111,37 @@ describe('ContextSummary', function() {
103111
expect(wrapper).toMatchSnapshot();
104112
});
105113

114+
it('should prefer client_os over os', () => {
115+
const event = {
116+
id: '',
117+
user: CONTEXT_USER,
118+
contexts: {
119+
client_os: CONTEXT_OS,
120+
os: CONTEXT_OS_SERVER,
121+
browser: CONTEXT_BROWSER,
122+
runtime: CONTEXT_RUNTIME,
123+
},
124+
};
125+
126+
const wrapper = shallow(<ContextSummary event={event} />);
127+
expect(wrapper).toMatchSnapshot();
128+
});
129+
130+
it('should render client_os too', () => {
131+
const event = {
132+
id: '',
133+
user: CONTEXT_USER,
134+
contexts: {
135+
client_os: CONTEXT_OS,
136+
browser: CONTEXT_BROWSER,
137+
runtime: CONTEXT_RUNTIME,
138+
},
139+
};
140+
141+
const wrapper = shallow(<ContextSummary event={event} />);
142+
expect(wrapper).toMatchSnapshot();
143+
});
144+
106145
it('should skip non-default named contexts', () => {
107146
const event = {
108147
id: '',

0 commit comments

Comments
 (0)