Skip to content

Commit 85786b1

Browse files
authored
feat(trace viewer): fix UI issues (#6890)
1 parent cfcf6a8 commit 85786b1

File tree

6 files changed

+58
-30
lines changed

6 files changed

+58
-30
lines changed

src/web/traceViewer/ui/actionList.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
color: red;
7070
position: relative;
7171
margin-right: 2px;
72+
flex: none;
7273
}
7374

7475
.action-selector {

src/web/traceViewer/ui/filmStrip.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ export const FilmStrip: React.FunctionComponent<{
3737
}
3838

3939
const screencastFrames = context.pages[pageIndex]?.screencastFrames;
40-
// TODO: pick file from the Y position.
4140
let previewImage = undefined;
4241
if (previewPoint !== undefined && screencastFrames) {
4342
const previewTime = boundaries.minimum + (boundaries.maximum - boundaries.minimum) * previewPoint.x / measure.width;

src/web/traceViewer/ui/logsTab.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@
2323
user-select: text;
2424
}
2525

26+
.logs-error {
27+
border-bottom: 1px solid var(--background);
28+
padding: 3px 0 3px 12px;
29+
}
30+
31+
.logs-error .codicon {
32+
color: red;
33+
position: relative;
34+
top: 2px;
35+
margin-right: 2px;
36+
}
37+
2638
.log-line {
2739
flex: none;
2840
padding: 3px 0 3px 12px;

src/web/traceViewer/ui/logsTab.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ import { ActionTraceEvent } from '../../../server/trace/common/traceEvents';
2121
export const LogsTab: React.FunctionComponent<{
2222
action: ActionTraceEvent | undefined,
2323
}> = ({ action }) => {
24-
let logs: string[] = [];
25-
if (action) {
26-
logs = action.metadata.log || [];
27-
if (action.metadata.error)
28-
logs = [action.metadata.error, ...logs];
29-
}
24+
const logs = action?.metadata.log || [];
25+
const error = action?.metadata.error;
3026
return <div className='logs-tab'>{
27+
<div className='logs-error' key='error' hidden={!error}>
28+
<div className='codicon codicon-issues'/>
29+
{error}
30+
</div>}{
3131
logs.map((logLine, index) => {
3232
return <div key={index} className='log-line'>
3333
{logLine}

src/web/traceViewer/ui/timeline.css

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@
7070
.timeline-bar {
7171
position: absolute;
7272
height: 9px;
73-
top: 11px;
7473
border-radius: 2px;
7574
min-width: 3px;
7675
--action-color: gray;
@@ -125,13 +124,8 @@
125124
--action-color: var(--blue);
126125
}
127126

128-
.timeline-bar.event {
129-
top: 22px;
130-
}
131-
132-
.timeline-bar.frame_waitforeventinfo {
133-
bottom: inherit;
134-
top: 0;
127+
.timeline-bar.frame_waitforeventinfo,
128+
.timeline-bar.page_waitforeventinfo {
135129
--action-color: var(--gray);
136130
}
137131

src/web/traceViewer/ui/timeline.tsx

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ export const Timeline: React.FunctionComponent<{
4545
onHighlighted: (action: ActionTraceEvent | undefined) => void,
4646
}> = ({ context, boundaries, selectedAction, highlightedAction, onSelected, onHighlighted }) => {
4747
const [measure, ref] = useMeasure<HTMLDivElement>();
48+
const barsRef = React.useRef<HTMLDivElement | null>(null);
49+
4850
const [previewPoint, setPreviewPoint] = React.useState<{ x: number, clientY: number } | undefined>();
4951
const [hoveredBarIndex, setHoveredBarIndex] = React.useState<number | undefined>();
5052

@@ -58,9 +60,9 @@ export const Timeline: React.FunctionComponent<{
5860
for (const entry of page.actions) {
5961
if (!entry.metadata.params)
6062
console.log(entry);
61-
let detail = entry.metadata.params.selector || '';
63+
let detail = trimRight(entry.metadata.params.selector || '', 50);
6264
if (entry.metadata.method === 'goto')
63-
detail = entry.metadata.params.url || '';
65+
detail = trimRight(entry.metadata.params.url || '', 50);
6466
bars.push({
6567
action: entry,
6668
leftTime: entry.metadata.startTime,
@@ -94,32 +96,41 @@ export const Timeline: React.FunctionComponent<{
9496
let targetBar: TimelineBar | undefined = bars.find(bar => bar.action === (highlightedAction || selectedAction));
9597
targetBar = hoveredBar || targetBar;
9698

97-
const findHoveredBarIndex = (x: number) => {
99+
const findHoveredBarIndex = (x: number, y: number) => {
98100
const time = positionToTime(measure.width, boundaries, x);
99101
const time1 = positionToTime(measure.width, boundaries, x - 5);
100102
const time2 = positionToTime(measure.width, boundaries, x + 5);
101103
let index: number | undefined;
102-
let distance: number | undefined;
104+
let yDistance: number | undefined;
105+
let xDistance: number | undefined;
103106
for (let i = 0; i < bars.length; i++) {
104107
const bar = bars[i];
108+
const yMiddle = kBarHeight / 2 + barTop(bar);
105109
const left = Math.max(bar.leftTime, time1);
106110
const right = Math.min(bar.rightTime, time2);
107-
const middle = (bar.leftTime + bar.rightTime) / 2;
108-
const d = Math.abs(time - middle);
109-
if (left <= right && (index === undefined || d < distance!)) {
111+
const xMiddle = (bar.leftTime + bar.rightTime) / 2;
112+
const xd = Math.abs(time - xMiddle);
113+
const yd = Math.abs(y - yMiddle);
114+
if (left > right)
115+
continue;
116+
// Prefer closest yDistance (the same bar), among those prefer the closest xDistance.
117+
if (index === undefined ||
118+
(yd < yDistance!) ||
119+
(Math.abs(yd - yDistance!) < 1e-2 && xd < xDistance!)) {
110120
index = i;
111-
distance = d;
121+
xDistance = xd;
122+
yDistance = yd;
112123
}
113124
}
114125
return index;
115126
};
116127

117128
const onMouseMove = (event: React.MouseEvent) => {
118-
if (!ref.current)
129+
if (!ref.current || !barsRef.current)
119130
return;
120-
const bounds = ref.current.getBoundingClientRect();
121-
const x = event.clientX - bounds.left;
122-
const index = findHoveredBarIndex(x);
131+
const x = event.clientX - ref.current.getBoundingClientRect().left;
132+
const y = event.clientY - barsRef.current.getBoundingClientRect().top;
133+
const index = findHoveredBarIndex(x, y);
123134
setPreviewPoint({ x, clientY: event.clientY });
124135
setHoveredBarIndex(index);
125136
if (typeof index === 'number')
@@ -134,10 +145,11 @@ export const Timeline: React.FunctionComponent<{
134145

135146
const onClick = (event: React.MouseEvent) => {
136147
setPreviewPoint(undefined);
137-
if (!ref.current)
148+
if (!ref.current || !barsRef.current)
138149
return;
139150
const x = event.clientX - ref.current.getBoundingClientRect().left;
140-
const index = findHoveredBarIndex(x);
151+
const y = event.clientY - barsRef.current.getBoundingClientRect().top;
152+
const index = findHoveredBarIndex(x, y);
141153
if (index === undefined)
142154
return;
143155
const entry = bars[index].action;
@@ -166,13 +178,14 @@ export const Timeline: React.FunctionComponent<{
166178
</div>;
167179
})
168180
}</div>
169-
<div className='timeline-lane timeline-bars'>{
181+
<div className='timeline-lane timeline-bars' ref={barsRef}>{
170182
bars.map((bar, index) => {
171183
return <div key={index}
172184
className={'timeline-bar ' + (bar.action ? 'action ' : '') + (bar.event ? 'event ' : '') + bar.className + (targetBar === bar ? ' selected' : '')}
173185
style={{
174186
left: bar.leftPosition + 'px',
175187
width: Math.max(1, bar.rightPosition - bar.leftPosition) + 'px',
188+
top: barTop(bar) + 'px',
176189
}}
177190
></div>;
178191
})
@@ -222,3 +235,12 @@ function timeToPosition(clientWidth: number, boundaries: Boundaries, time: numbe
222235
function positionToTime(clientWidth: number, boundaries: Boundaries, x: number): number {
223236
return x / clientWidth * (boundaries.maximum - boundaries.minimum) + boundaries.minimum;
224237
}
238+
239+
function trimRight(s: string, maxLength: number): string {
240+
return s.length <= maxLength ? s : s.substring(0, maxLength - 1) + '\u2026';
241+
}
242+
243+
const kBarHeight = 11;
244+
function barTop(bar: TimelineBar): number {
245+
return bar.event ? 22 : (bar.action?.metadata.method === 'waitForEventInfo' ? 0 : 11);
246+
}

0 commit comments

Comments
 (0)