Finish moving navigating nested values to class

This commit is contained in:
Kuba Orlik 2021-11-07 11:33:51 +01:00
parent ee96659aa0
commit eea9808d09

View File

@ -1,24 +1,24 @@
import React from "react"; import React from "react";
import memory from "./memory"; import memory from "./memory";
import { Sources, StolenDataEntry } from "./request-cluster"; import { MergedStolenDataEntry, Sources } from "./request-cluster";
import { hyphenate } from "./util"; import { hyphenate } from "./util";
function StolenDataValueTable({ function StolenDataValueTable({
object, entry,
prefixKey = "", prefixKey = "",
}: { }: {
object: Record<string, unknown>; entry: MergedStolenDataEntry;
prefixKey: string; prefixKey: string;
}) { }) {
return ( return (
<table> <table>
<tbody> <tbody>
{Object.entries(object).map(([key, value]) => ( {Object.keys(entry.getParsedValues(prefixKey)[0]).map((key) => (
<tr key={`${prefixKey}.${key}`}> <tr key={`${prefixKey}.${key}`}>
<th>{hyphenate(key)}</th> <th>{hyphenate(key)}</th>
<td> <td>
<StolenDataValue <StolenDataValue
value={StolenDataEntry.parseValue(value)} entry={entry}
prefixKey={`${prefixKey}.${key}`} prefixKey={`${prefixKey}.${key}`}
/> />
</td> </td>
@ -30,19 +30,20 @@ function StolenDataValueTable({
} }
function StolenDataValue({ function StolenDataValue({
value, entry,
prefixKey = "", prefixKey = "",
}: { }: {
value: string | Record<string, unknown>; entry: MergedStolenDataEntry;
prefixKey?: string; prefixKey?: string;
}) { }) {
const value = entry.getParsedValues(prefixKey)[0];
if (!value) { if (!value) {
return <></>; return <></>;
} }
if (typeof value === "string") { if (typeof value === "string") {
return <>{value}</>; return <>{entry.getParsedValues(prefixKey)[0] as string}</>;
} }
return <StolenDataValueTable object={value} prefixKey={prefixKey} />; return <StolenDataValueTable entry={entry} prefixKey={prefixKey} />;
} }
export default function StolenDataCluster({ export default function StolenDataCluster({
@ -91,7 +92,7 @@ export default function StolenDataCluster({
</th> </th>
<td>{entry.getSources().map((source) => icons[source])}</td> <td>{entry.getSources().map((source) => icons[source])}</td>
<td style={{ wordWrap: "anywhere" as any }}> <td style={{ wordWrap: "anywhere" as any }}>
<StolenDataValue value={entry.getParsedValues()[0]} /> <StolenDataValue entry={entry} />
</td> </td>
</tr> </tr>
))} ))}