|
| 1 | +import React, { useEffect } from "react"; |
| 2 | +import Head from "next/head"; |
| 3 | +import { InferGetServerSidePropsType } from "next"; |
| 4 | +import styled from "@emotion/styled"; |
| 5 | +import { Client, NodeReportCoverage } from "@codetest/editor-client"; |
| 6 | +import { CircleIcon, LightningBoltIcon, CodeIcon } from "@radix-ui/react-icons"; |
| 7 | +import { IconButton } from "@code-editor/ui"; |
| 8 | +type P = InferGetServerSidePropsType<typeof getServerSideProps>; |
| 9 | + |
| 10 | +export default function ReportPage({ _key, data }: P) { |
| 11 | + const onRegenerate = () => { |
| 12 | + alert("regenerate (not implemented)"); |
| 13 | + }; |
| 14 | + |
| 15 | + return ( |
| 16 | + <> |
| 17 | + <Head> |
| 18 | + <title>Report Coverages - @codetest/reports</title> |
| 19 | + {/* */} |
| 20 | + </Head> |
| 21 | + <Main> |
| 22 | + <header className="header"> |
| 23 | + <span> |
| 24 | + <code>@codetest/reports</code> |
| 25 | + <h1>{_key}</h1> |
| 26 | + </span> |
| 27 | + <div> |
| 28 | + <IconButton title="regenerate" onClick={onRegenerate}> |
| 29 | + <LightningBoltIcon /> |
| 30 | + </IconButton> |
| 31 | + </div> |
| 32 | + </header> |
| 33 | + {/* <code> |
| 34 | + <pre>{JSON.stringify(data, null, 2)}</pre> |
| 35 | + </code> */} |
| 36 | + <div className="nodes"> |
| 37 | + {Object.keys(data).map((k) => { |
| 38 | + const record: NodeReportCoverage = data[k]; |
| 39 | + return <Item key={k} id={k} {...record} />; |
| 40 | + })} |
| 41 | + </div> |
| 42 | + <footer /> |
| 43 | + </Main> |
| 44 | + </> |
| 45 | + ); |
| 46 | +} |
| 47 | + |
| 48 | +const Main = styled.main` |
| 49 | + color: white; |
| 50 | + font-family: monospace; |
| 51 | + width: 400px; |
| 52 | + margin: auto; |
| 53 | +
|
| 54 | + /* */ |
| 55 | + .nodes { |
| 56 | + display: flex; |
| 57 | + flex-direction: column; |
| 58 | + gap: 16px; |
| 59 | + } |
| 60 | +
|
| 61 | + header.header { |
| 62 | + margin: 120px 0 40px 0; |
| 63 | + display: flex; |
| 64 | + align-items: center; |
| 65 | + justify-content: space-between; |
| 66 | +
|
| 67 | + h1 { |
| 68 | + margin: 0; |
| 69 | + } |
| 70 | +
|
| 71 | + .actions { |
| 72 | + display: flex; |
| 73 | + align-items: center; |
| 74 | + gap: 4px; |
| 75 | + } |
| 76 | + } |
| 77 | +
|
| 78 | + footer { |
| 79 | + height: 200px; |
| 80 | + } |
| 81 | +`; |
| 82 | + |
| 83 | +function Item({ id, a, b, diff, report }: NodeReportCoverage & { id: string }) { |
| 84 | + const [focus, setFocus] = React.useState<"a" | "b" | null>(null); |
| 85 | + |
| 86 | + const onInspect = () => { |
| 87 | + alert("inspect (not implemented)"); |
| 88 | + }; |
| 89 | + |
| 90 | + const onRegenerate = () => { |
| 91 | + alert("regenerate (not implemented)"); |
| 92 | + }; |
| 93 | + |
| 94 | + return ( |
| 95 | + <ItemContainer> |
| 96 | + <header> |
| 97 | + <p className="title"> |
| 98 | + <CircleIcon /> |
| 99 | + {id} {focus && <span>({focus})</span>} |
| 100 | + </p> |
| 101 | + <div className="actions"> |
| 102 | + <IconButton title="inspect" onClick={onInspect}> |
| 103 | + <CodeIcon /> |
| 104 | + </IconButton> |
| 105 | + <IconButton title="regenerate" onClick={onRegenerate}> |
| 106 | + <LightningBoltIcon /> |
| 107 | + </IconButton> |
| 108 | + </div> |
| 109 | + </header> |
| 110 | + <div className="view" data-focus={focus}> |
| 111 | + <img className="a" src={a} alt="A" /> |
| 112 | + <img className="b" src={b} alt="B" /> |
| 113 | + <img className="c" src={diff} alt="C" /> |
| 114 | + <div |
| 115 | + className="hover-area hover-area-left" |
| 116 | + onMouseEnter={() => setFocus("a")} |
| 117 | + onMouseLeave={() => setFocus(null)} |
| 118 | + /> |
| 119 | + <div |
| 120 | + className="hover-area hover-area-right" |
| 121 | + onMouseEnter={() => setFocus("b")} |
| 122 | + onMouseLeave={() => setFocus(null)} |
| 123 | + /> |
| 124 | + </div> |
| 125 | + </ItemContainer> |
| 126 | + ); |
| 127 | +} |
| 128 | + |
| 129 | +const ItemContainer = styled.div` |
| 130 | + display: flex; |
| 131 | + flex-direction: column; |
| 132 | +
|
| 133 | + border-radius: 2px; |
| 134 | + border: 1px solid rgba(255, 255, 255, 0.1); |
| 135 | + overflow: hidden; |
| 136 | +
|
| 137 | + width: 400px; |
| 138 | + height: 100%; |
| 139 | +
|
| 140 | + header { |
| 141 | + color: white; |
| 142 | + display: flex; |
| 143 | + flex-direction: row; |
| 144 | + align-items: center; |
| 145 | + justify-content: space-between; |
| 146 | + padding: 16px; |
| 147 | + .title { |
| 148 | + display: flex; |
| 149 | + align-items: center; |
| 150 | + gap: 8px; |
| 151 | + } |
| 152 | +
|
| 153 | + .actions { |
| 154 | + display: flex; |
| 155 | + align-items: center; |
| 156 | + gap: 4px; |
| 157 | + } |
| 158 | + } |
| 159 | +
|
| 160 | + .view { |
| 161 | + position: relative; |
| 162 | + display: flex; |
| 163 | + flex-direction: row; |
| 164 | + align-items: center; |
| 165 | +
|
| 166 | + .a, |
| 167 | + .b, |
| 168 | + .c { |
| 169 | + position: relative; |
| 170 | + z-index: 1; |
| 171 | + flex: 1 0 auto; |
| 172 | + width: 100%; |
| 173 | + height: auto; |
| 174 | + } |
| 175 | +
|
| 176 | + .a, |
| 177 | + .b { |
| 178 | + pointer-events: none; |
| 179 | + position: absolute; |
| 180 | + top: 0; |
| 181 | + left: 0; |
| 182 | + right: 0; |
| 183 | + bottom: 0; |
| 184 | + width: 100%; |
| 185 | + height: 100%; |
| 186 | + opacity: 0.5; |
| 187 | + transition: opacity 0.1s ease-in-out; |
| 188 | + } |
| 189 | +
|
| 190 | + &[data-focus="a"] .a { |
| 191 | + z-index: 9; |
| 192 | + opacity: 1; |
| 193 | + } |
| 194 | +
|
| 195 | + &[data-focus="b"] .b { |
| 196 | + z-index: 9; |
| 197 | + opacity: 1; |
| 198 | + } |
| 199 | +
|
| 200 | + .hover-area { |
| 201 | + position: absolute; |
| 202 | + top: 0; |
| 203 | + bottom: 0; |
| 204 | + width: 50%; |
| 205 | + height: 100%; |
| 206 | + z-index: 2; |
| 207 | + } |
| 208 | +
|
| 209 | + .hover-area-left { |
| 210 | + cursor: w-resize; |
| 211 | + left: 0; |
| 212 | + } |
| 213 | +
|
| 214 | + .hover-area-right { |
| 215 | + cursor: e-resize; |
| 216 | + right: 0; |
| 217 | + } |
| 218 | + } |
| 219 | +`; |
| 220 | + |
| 221 | +export async function getServerSideProps(context: any) { |
| 222 | + const key = context.params.key; |
| 223 | + |
| 224 | + const client = Client({ |
| 225 | + baseURL: "http://localhost:6627", |
| 226 | + }); |
| 227 | + |
| 228 | + try { |
| 229 | + const { data } = await client.file({ file: key }); |
| 230 | + |
| 231 | + return { |
| 232 | + props: { |
| 233 | + _key: key, |
| 234 | + data, |
| 235 | + }, |
| 236 | + }; |
| 237 | + } catch (e) { |
| 238 | + return { |
| 239 | + notFound: true, |
| 240 | + }; |
| 241 | + } |
| 242 | +} |
0 commit comments