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