Http response events (#326)

This commit is contained in:
Gregory Schier
2025-12-21 14:34:37 -08:00
committed by GitHub
parent 7e0aa919fb
commit 089c7e8dce
18 changed files with 779 additions and 74 deletions

View File

@@ -41,10 +41,12 @@ export function HttpMethodTagRaw({
className,
method,
short,
forceColor,
}: {
method: string;
className?: string;
short?: boolean;
forceColor?: boolean;
}) {
let label = method.toUpperCase();
if (short) {
@@ -54,7 +56,8 @@ export function HttpMethodTagRaw({
const m = method.toUpperCase();
const colored = useAtomValue(settingsAtom).coloredMethods;
const settings = useAtomValue(settingsAtom);
const colored = forceColor || settings.coloredMethods;
return (
<span

View File

@@ -1,4 +1,5 @@
import type { HttpResponse } from '@yaakapp-internal/models';
import type { HttpResponseState } from '@yaakapp-internal/models';
import classNames from 'classnames';
interface Props {
@@ -8,25 +9,40 @@ interface Props {
short?: boolean;
}
export function HttpStatusTag({ response, className, showReason, short }: Props) {
const { status, state } = response;
export function HttpStatusTag({ response, ...props }: Props) {
const { status, state, statusReason } = response;
return <HttpStatusTagRaw status={status} state={state} statusReason={statusReason} {...props} />;
}
export function HttpStatusTagRaw({
status,
state,
className,
showReason,
statusReason,
short,
}: Omit<Props, 'response'> & {
status: number | string;
state?: HttpResponseState;
statusReason?: string | null;
}) {
let colorClass: string;
let label = `${status}`;
const statusN = typeof status === 'number' ? status : parseInt(status, 10);
if (state === 'initialized') {
label = short ? 'CONN' : 'CONNECTING';
colorClass = 'text-text-subtle';
} else if (status < 100) {
} else if (statusN < 100) {
label = short ? 'ERR' : 'ERROR';
colorClass = 'text-danger';
} else if (status < 200) {
} else if (statusN < 200) {
colorClass = 'text-info';
} else if (status < 300) {
} else if (statusN < 300) {
colorClass = 'text-success';
} else if (status < 400) {
} else if (statusN < 400) {
colorClass = 'text-primary';
} else if (status < 500) {
} else if (statusN < 500) {
colorClass = 'text-warning';
} else {
colorClass = 'text-danger';
@@ -34,7 +50,7 @@ export function HttpStatusTag({ response, className, showReason, short }: Props)
return (
<span className={classNames(className, 'font-mono min-w-0', colorClass)}>
{label} {showReason && 'statusReason' in response ? response.statusReason : null}
{label} {showReason && statusReason}
</span>
);
}