Skip to content

Commit 5c7f896

Browse files
committed
1 parent 0113985 commit 5c7f896

File tree

5 files changed

+80
-66
lines changed

5 files changed

+80
-66
lines changed

src/components/TracePage/TraceTimelineViewer/SpanDetail/AccordianKeyValues.js

+13-27
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @flow
12
// Copyright (c) 2017 Uber Technologies, Inc.
23
//
34
// Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -19,22 +20,17 @@
1920
// THE SOFTWARE.
2021

2122
import React from 'react';
22-
import PropTypes from 'prop-types';
2323

2424
import KeyValuesTable from './KeyValuesTable';
2525
import toggleEnhancer from './toggle-enhancer';
2626

2727
import './AccordianKeyValues.css';
2828

29-
const dataPropType = PropTypes.arrayOf(
30-
PropTypes.shape({
31-
key: PropTypes.string,
32-
type: PropTypes.string,
33-
value: PropTypes.value,
34-
})
35-
);
29+
type KeyValuesSummaryProps = {
30+
data: { key: string, value: any }[],
31+
};
3632

37-
function KeyValuesSummary(props) {
33+
function KeyValuesSummary(props: KeyValuesSummaryProps) {
3834
const { data } = props;
3935
return (
4036
<ul className="AccordianKeyValues--summary">
@@ -53,15 +49,16 @@ function KeyValuesSummary(props) {
5349
);
5450
}
5551

56-
KeyValuesSummary.propTypes = {
57-
data: dataPropType,
58-
};
59-
60-
KeyValuesSummary.defaultProps = {
61-
data: [],
52+
type AccordianKeyValuesProps = {
53+
compact?: boolean,
54+
data: { key: string, value: any }[],
55+
highContrast?: boolean,
56+
isOpen: boolean,
57+
label: string,
58+
onToggle: () => void,
6259
};
6360

64-
function AccordianKeyValues(props) {
61+
function AccordianKeyValues(props: AccordianKeyValuesProps) {
6562
const { compact, data, highContrast, isOpen, label, onToggle } = props;
6663
return (
6764
<div className={`AccordianKeyValues ${compact ? 'is-compact' : ''}`}>
@@ -83,20 +80,9 @@ function AccordianKeyValues(props) {
8380
);
8481
}
8582

86-
AccordianKeyValues.propTypes = {
87-
compact: PropTypes.bool,
88-
data: dataPropType,
89-
highContrast: PropTypes.bool,
90-
isOpen: PropTypes.bool.isRequired,
91-
label: PropTypes.string,
92-
onToggle: PropTypes.func.isRequired,
93-
};
94-
9583
AccordianKeyValues.defaultProps = {
9684
compact: false,
97-
data: [],
9885
highContrast: false,
99-
label: null,
10086
};
10187

10288
export default toggleEnhancer(AccordianKeyValues);

src/components/TracePage/TraceTimelineViewer/SpanDetail/AccordianLogs.js

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @flow
12
// Copyright (c) 2017 Uber Technologies, Inc.
23
//
34
// Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -20,15 +21,26 @@
2021

2122
import React from 'react';
2223
import _sortBy from 'lodash/sortBy';
23-
import PropTypes from 'prop-types';
2424

2525
import AccordianKeyValues from './AccordianKeyValues';
2626
import toggleEnhancer from './toggle-enhancer';
2727
import { formatDuration } from '../utils';
2828

2929
import './AccordianLogs.css';
3030

31-
function AccordianLogs(props) {
31+
type LogMessage = {
32+
timestamp: number,
33+
fields: { key: string, value: any }[],
34+
};
35+
36+
type AccordianLogsProps = {
37+
isOpen: boolean,
38+
logs: LogMessage[],
39+
onToggle: () => void,
40+
timestamp: number,
41+
};
42+
43+
function AccordianLogs(props: AccordianLogsProps) {
3244
const { logs, timestamp, isOpen, onToggle } = props;
3345
return (
3446
<div className="ui segment">
@@ -61,16 +73,4 @@ function AccordianLogs(props) {
6173
);
6274
}
6375

64-
AccordianLogs.propTypes = {
65-
isOpen: PropTypes.bool.isRequired,
66-
onToggle: PropTypes.func.isRequired,
67-
logs: PropTypes.arrayOf(
68-
PropTypes.shape({
69-
timestamp: PropTypes.number,
70-
fields: PropTypes.array,
71-
})
72-
).isRequired,
73-
timestamp: PropTypes.number.isRequired,
74-
};
75-
7676
export default toggleEnhancer(AccordianLogs);

src/components/TracePage/TraceTimelineViewer/SpanDetail/KeyValuesTable.js

+6-11
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @flow
12
// Copyright (c) 2017 Uber Technologies, Inc.
23
//
34
// Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -20,7 +21,6 @@
2021

2122
import React from 'react';
2223
import jsonMarkup from 'json-markup';
23-
import PropTypes from 'prop-types';
2424

2525
import './KeyValuesTable.css';
2626

@@ -32,7 +32,11 @@ function parseOrPass(value) {
3232
}
3333
}
3434

35-
export default function KeyValuesTable(props) {
35+
type KeyValuesTableProps = {
36+
data: { key: string, value: any }[],
37+
};
38+
39+
export default function KeyValuesTable(props: KeyValuesTableProps) {
3640
const { data } = props;
3741
return (
3842
<div className="KeyValueTable">
@@ -55,12 +59,3 @@ export default function KeyValuesTable(props) {
5559
</div>
5660
);
5761
}
58-
59-
KeyValuesTable.propTypes = {
60-
data: PropTypes.arrayOf(
61-
PropTypes.shape({
62-
key: PropTypes.string,
63-
value: PropTypes.any,
64-
})
65-
).isRequired,
66-
};

src/components/TracePage/TraceTimelineViewer/SpanDetail/index.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,20 @@
1919
// THE SOFTWARE.
2020

2121
import React from 'react';
22-
import PropTypes from 'prop-types';
2322

2423
import AccordianKeyValues from './AccordianKeyValues';
2524
import AccordianLogs from './AccordianLogs';
2625
import { formatDuration } from '../utils';
26+
import type { XformedSpan, XformedTrace } from '../transforms';
2727

2828
import './index.css';
2929

30-
export default function SpanDetail(props) {
30+
type SpanDetailProps = {
31+
span: XformedSpan,
32+
trace: XformedTrace,
33+
};
34+
35+
export default function SpanDetail(props: SpanDetailProps) {
3136
const { span, trace } = props;
3237
return (
3338
<div>
@@ -74,7 +79,3 @@ export default function SpanDetail(props) {
7479
</div>
7580
);
7681
}
77-
SpanDetail.propTypes = {
78-
span: PropTypes.object,
79-
trace: PropTypes.object,
80-
};

src/components/TracePage/TraceTimelineViewer/transforms.js

+40-8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @flow
12
// Copyright (c) 2017 Uber Technologies, Inc.
23
//
34
// Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -25,23 +26,50 @@ import {
2526
getTraceSpansAsMap,
2627
getTraceTimestamp,
2728
} from '../../../selectors/trace';
29+
import type { Process, Span } from '../../../types';
2830

29-
const cache = new Map();
31+
type SpanWithProcess = Span & { process: Process };
3032

31-
export function transformTrace(trace) {
32-
if (cache.has(trace.traceID)) {
33-
return cache.get(trace.traceID);
33+
export type XformedSpan = SpanWithProcess & {
34+
depth: number,
35+
hasChildren: boolean,
36+
relativeStartTime: number,
37+
};
38+
39+
type TracePartial = {
40+
processes: { [string]: Process },
41+
traceID: string,
42+
};
43+
44+
export type XformedTrace = TracePartial & {
45+
duration: number,
46+
endTime: number,
47+
spans: XformedSpan[],
48+
startTime: number,
49+
};
50+
51+
const cache: Map<string, ?XformedTrace> = new Map();
52+
53+
// eslint-disable-next-line import/prefer-default-export
54+
export function transformTrace(trace: TracePartial & { spans: SpanWithProcess[] }): XformedTrace {
55+
const cached = cache.get(trace.traceID);
56+
if (cached) {
57+
return cached;
3458
}
3559
const traceStartTime = getTraceTimestamp(trace);
3660
const traceEndTime = getTraceEndTimestamp(trace);
37-
const spanMap = getTraceSpansAsMap(trace);
61+
const spanMap: Map<string, ?SpanWithProcess> = getTraceSpansAsMap(trace);
3862
const tree = getTraceSpanIdsAsTree(trace);
39-
const spans = [];
63+
const spans: XformedSpan[] = [];
64+
4065
tree.walk((spanID, node, depth) => {
4166
if (spanID === '__root__') {
4267
return;
4368
}
44-
const span = spanMap.get(spanID);
69+
const span: ?SpanWithProcess = spanMap.get(spanID);
70+
if (!span) {
71+
return;
72+
}
4573
spans.push({
4674
...span,
4775
relativeStartTime: span.startTime - traceStartTime,
@@ -50,8 +78,12 @@ export function transformTrace(trace) {
5078
});
5179
});
5280
const transform = {
53-
...trace,
5481
spans,
82+
// can't use spread operator for intersection types
83+
// repl: https://goo.gl/4Z23MJ
84+
// issue: https://github.com/facebook/flow/issues/1511
85+
processes: trace.processes,
86+
traceID: trace.traceID,
5587
duration: getTraceDuration(trace),
5688
startTime: traceStartTime,
5789
endTime: traceEndTime,

0 commit comments

Comments
 (0)