mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-11-30 12:03:59 +01:00
Proxy viewer extraction: response viewers into packages/ui (#754)
This commit is contained in:
1 parent
b5508e6bb1
commit
b6c1f700f1
137 files changed
+3498
-2890
No files matched your search
@@ -0,0 +1,58 @@
|
||||
import type { ReactNode } from "react";
|
||||
import { useMemo } from "react";
|
||||
import type { UseStoredValue } from "../hooks/useStoredValue";
|
||||
import { CountBadge } from "./CountBadge";
|
||||
import { DetailsBanner } from "./DetailsBanner";
|
||||
import { KeyValueRow, type KeyValueRowProps, KeyValueRows } from "./KeyValueRow";
|
||||
|
||||
export interface HeadersTableProps {
|
||||
title: ReactNode;
|
||||
headers: { name: string; value: string }[];
|
||||
labelColor?: KeyValueRowProps["labelColor"];
|
||||
defaultOpen?: boolean;
|
||||
storageKey?: string;
|
||||
useStoredValue?: UseStoredValue;
|
||||
}
|
||||
|
||||
export function HeadersTable({
|
||||
title,
|
||||
headers,
|
||||
labelColor,
|
||||
defaultOpen,
|
||||
storageKey,
|
||||
useStoredValue,
|
||||
}: HeadersTableProps) {
|
||||
const sortedHeaders = useMemo(
|
||||
() =>
|
||||
[...headers].sort((a, b) =>
|
||||
a.name.toLocaleLowerCase().localeCompare(b.name.toLocaleLowerCase()),
|
||||
),
|
||||
[headers],
|
||||
);
|
||||
|
||||
return (
|
||||
<DetailsBanner
|
||||
defaultOpen={defaultOpen}
|
||||
storageKey={storageKey}
|
||||
useStoredValue={useStoredValue}
|
||||
summary={
|
||||
<h2 className="flex items-center">
|
||||
{title} <CountBadge showZero count={sortedHeaders.length} />
|
||||
</h2>
|
||||
}
|
||||
>
|
||||
{sortedHeaders.length === 0 ? (
|
||||
<span className="text-text-subtlest text-sm italic">No Headers</span>
|
||||
) : (
|
||||
<KeyValueRows>
|
||||
{sortedHeaders.map((h, i) => (
|
||||
// oxlint-disable-next-line react/no-array-index-key
|
||||
<KeyValueRow labelColor={labelColor} key={i} label={h.name}>
|
||||
{h.value}
|
||||
</KeyValueRow>
|
||||
))}
|
||||
</KeyValueRows>
|
||||
)}
|
||||
</DetailsBanner>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user