rentgen/report-window/report-window.tsx

95 lines
3.0 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);
const marks = Object.values(clusters)
2021-11-07 15:45:26 +01:00
.map((cluster) => cluster.getMarkedRequests())
.reduce(reduceConcat, [])
2021-11-07 15:45:26 +01:00
.map((request) => request.getMarkedEntries())
.reduce(reduceConcat, [])
.map((entry) => entry.marks)
.reduce(reduceConcat, []);
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>
{marks.map((mark) => (
2021-11-07 17:51:30 +01:00
<tr
key={mark.entry.request.originalURL + ";" + mark.key}
2021-11-07 17:51:30 +01:00
style={{
backgroundColor:
mark.classification == "id" ? "yellow" : "white",
2021-11-07 17:51:30 +01:00
}}
>
<td>{mark.shorthost}</td>
2021-11-07 17:44:22 +01:00
<td style={{ overflowWrap: "anywhere" }}>
{mark.source}:{mark.name}
{mark.key}
2021-11-07 15:45:26 +01:00
</td>
2021-11-07 17:51:30 +01:00
<td
style={{
width: "400px",
overflowWrap: "anywhere",
backgroundColor: mark.entry.isRelatedToID()
? "#ffff0054"
: "white",
2021-11-07 17:51:30 +01:00
}}
>
{mark.valuePreview}
{/* 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
value={mark.classification}
onChange={(e) => {
mark.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>
<EmailTemplate {...{ marks, clusters, version: counter }} />
<HARConverter {...{ marks }} />
2021-11-07 13:57:24 +01:00
</div>
);
}
ReactDOM.render(<Report />, document.getElementById("app"));