Skip to content

Commit 161ff7f

Browse files
add diff view
1 parent 1e192b0 commit 161ff7f

File tree

1 file changed

+121
-27
lines changed

1 file changed

+121
-27
lines changed

editor/pages/tests/reports/[key]/index.tsx

Lines changed: 121 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,65 +3,160 @@ import Head from "next/head";
33
import { InferGetServerSidePropsType } from "next";
44
import styled from "@emotion/styled";
55
import { Client, NodeReportCoverage } from "@codetest/editor-client";
6+
import { CircleIcon } from "@radix-ui/react-icons";
67

78
type P = InferGetServerSidePropsType<typeof getServerSideProps>;
89

9-
export default function QAEditor({ key, data }: P) {
10+
export default function ReportPage({ data }: P) {
1011
return (
1112
<>
1213
<Head>
13-
<title>QA - {key}</title>
14+
<title>Report Coverages - @codetest/reports</title>
1415
{/* */}
1516
</Head>
1617
<Main>
18+
<h1>
19+
<code>@codetest/reports</code>
20+
</h1>
1721
{/* <code>
1822
<pre>{JSON.stringify(data, null, 2)}</pre>
1923
</code> */}
20-
<div className="frames">
24+
<div className="nodes">
2125
{Object.keys(data).map((k) => {
2226
const record: NodeReportCoverage = data[k];
23-
return (
24-
<div className="item" key={k}>
25-
<p>{k}</p>
26-
<div className="images">
27-
<img src={record.b} alt="B" />
28-
<img src={record.diff} alt="C" />
29-
<img src={record.a} alt="A" />
30-
</div>
31-
</div>
32-
);
27+
return <Item key={k} id={k} {...record} />;
3328
})}
3429
</div>
30+
<footer />
3531
</Main>
3632
</>
3733
);
3834
}
3935

4036
const Main = styled.main`
37+
font-family: monospace;
38+
width: 400px;
39+
margin: auto;
40+
4141
/* */
42-
.frames {
43-
width: 100%;
42+
.nodes {
4443
display: flex;
4544
flex-direction: column;
46-
align-items: center;
47-
flex-wrap: wrap;
45+
gap: 16px;
4846
}
4947
50-
.item {
51-
display: flex;
52-
flex-direction: column;
48+
footer {
49+
height: 200px;
50+
}
51+
`;
52+
53+
function Item({ id, a, b, diff, report }: NodeReportCoverage & { id: string }) {
54+
const [focus, setFocus] = React.useState<"a" | "b" | null>(null);
55+
56+
return (
57+
<ItemContainer>
58+
<header>
59+
<p className="title">
60+
<CircleIcon />
61+
{id} {focus && <span>({focus})</span>}
62+
</p>
63+
</header>
64+
<div className="view" data-focus={focus}>
65+
<img className="a" src={a} alt="A" />
66+
<img className="b" src={b} alt="B" />
67+
<img className="c" src={diff} alt="C" />
68+
<div
69+
className="hover-area hover-area-left"
70+
onMouseEnter={() => setFocus("a")}
71+
onMouseLeave={() => setFocus(null)}
72+
/>
73+
<div
74+
className="hover-area hover-area-right"
75+
onMouseEnter={() => setFocus("b")}
76+
onMouseLeave={() => setFocus(null)}
77+
/>
78+
</div>
79+
</ItemContainer>
80+
);
81+
}
82+
83+
const ItemContainer = styled.div`
84+
display: flex;
85+
flex-direction: column;
86+
87+
border-radius: 2px;
88+
border: 1px solid rgba(255, 255, 255, 0.1);
89+
overflow: hidden;
90+
91+
width: 400px;
92+
height: 100%;
93+
94+
header {
95+
padding: 16px;
96+
.title {
97+
display: flex;
98+
align-items: center;
99+
gap: 8px;
100+
}
101+
}
53102
54-
width: 400px;
55-
height: 400px;
103+
.view {
104+
position: relative;
105+
display: flex;
106+
flex-direction: row;
107+
align-items: center;
56108
57-
img {
109+
.a,
110+
.b,
111+
.c {
112+
position: relative;
113+
z-index: 1;
114+
flex: 1 0 auto;
58115
width: 100%;
59116
height: auto;
60117
}
61118
62-
.images {
63-
display: flex;
64-
flex-direction: row;
119+
.a,
120+
.b {
121+
pointer-events: none;
122+
position: absolute;
123+
top: 0;
124+
left: 0;
125+
right: 0;
126+
bottom: 0;
127+
width: 100%;
128+
height: 100%;
129+
opacity: 0.5;
130+
transition: opacity 0.1s ease-in-out;
131+
}
132+
133+
&[data-focus="a"] .a {
134+
z-index: 9;
135+
opacity: 1;
136+
}
137+
138+
&[data-focus="b"] .b {
139+
z-index: 9;
140+
opacity: 1;
141+
}
142+
143+
.hover-area {
144+
position: absolute;
145+
top: 0;
146+
bottom: 0;
147+
width: 50%;
148+
height: 100%;
149+
z-index: 2;
150+
}
151+
152+
.hover-area-left {
153+
cursor: w-resize;
154+
left: 0;
155+
}
156+
157+
.hover-area-right {
158+
cursor: e-resize;
159+
right: 0;
65160
}
66161
}
67162
`;
@@ -78,7 +173,6 @@ export async function getServerSideProps(context: any) {
78173

79174
return {
80175
props: {
81-
key,
82176
data,
83177
},
84178
};

0 commit comments

Comments
 (0)