rentgen/report-window/report-window.tsx

91 lines
2.8 KiB
TypeScript
Raw Normal View History

2021-11-08 20:14:28 +01:00
import React from "react";
2021-11-07 13:57:24 +01:00
import ReactDOM from "react-dom";
2021-11-07 17:23:48 +01:00
import { getMemory } from "../memory";
import { Classifications } from "../stolen-data-entry";
import { reduceConcat, useEmitter } from "../util";
2021-11-08 20:14:28 +01:00
import EmailTemplate from "./email-template";
import HARConverter from "./har-converter";
2021-11-07 13:57:24 +01:00
function Report() {
2021-11-07 15:45:26 +01:00
const origin = new URL(document.location.toString()).searchParams.get(
"origin"
);
const [counter, setCounter] = useEmitter(getMemory());
function refresh() {
setCounter((c) => c + 1);
}
2021-11-07 15:45:26 +01:00
const clusters = getMemory().getClustersForOrigin(origin);
2021-11-22 17:54:15 +01:00
const entries = Object.values(clusters)
.map((cluster) => cluster.getRepresentativeStolenData())
.reduce(reduceConcat, [])
.filter((entry) => entry.isMarked);
2021-11-07 13:57:24 +01:00
return (
<div {...{ "data-version": counter }}>
2021-11-07 15:45:26 +01:00
<h1>Generuj treść maila dla {origin}</h1>
<table>
<thead>
<tr>
<th>Adres docelowy</th>
<th>Źródło danych</th>
<th>Treść danych</th>
2021-11-07 17:44:22 +01:00
<th>Klasyfikacja</th>
2021-11-07 15:45:26 +01:00
</tr>
</thead>
<tbody>
2021-11-22 17:54:15 +01:00
{entries.map((entry) => (
2021-11-07 17:51:30 +01:00
<tr
2021-11-22 17:54:15 +01:00
key={entry.id}
2021-11-07 17:51:30 +01:00
style={{
backgroundColor:
2021-11-22 17:54:15 +01:00
entry.classification == "id" ? "yellow" : "white",
2021-11-07 17:51:30 +01:00
}}
>
2021-11-22 17:54:15 +01:00
<td>{entry.request.shorthost}</td>
2021-11-07 17:44:22 +01:00
<td style={{ overflowWrap: "anywhere" }}>
2021-11-22 17:54:15 +01:00
{entry.source}:{entry.name}
2021-11-07 15:45:26 +01:00
</td>
2021-11-07 17:51:30 +01:00
<td
style={{
width: "400px",
overflowWrap: "anywhere",
2021-11-22 17:54:15 +01:00
backgroundColor: entry.isRelatedToID()
? "#ffff0054"
: "white",
2021-11-07 17:51:30 +01:00
}}
>
2021-11-22 17:54:15 +01:00
{entry.getValuePreview()}
{/* always gonna have
one key, because unwrapEntry is called above */}
2021-11-07 17:44:22 +01:00
</td>
2021-11-07 15:45:26 +01:00
<td>
<select
2021-11-22 17:54:15 +01:00
value={entry.classification}
onChange={(e) => {
2021-11-22 17:54:15 +01:00
entry.classification = e.target
.value as keyof typeof Classifications;
refresh();
}}
>
2021-11-07 15:45:26 +01:00
{[
["history", "Historia przeglądania"],
["id", "Sztucznie nadane id"],
["location", "Lokalizacja"],
2021-11-07 15:45:26 +01:00
].map(([key, name]) => (
<option key={key} value={key}>
{name}
</option>
))}
</select>
</td>
</tr>
))}
</tbody>
</table>
2021-11-22 17:54:15 +01:00
<EmailTemplate {...{ entries, clusters, version: counter }} />
<HARConverter {...{ entries }} />
2021-11-07 13:57:24 +01:00
</div>
);
}
ReactDOM.render(<Report />, document.getElementById("app"));