mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-23 00:58:32 +02:00
Duration and size tags
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>Yaak App</title>
|
<title>Yaak App</title>
|
||||||
<script src="http://localhost:8097"></script>
|
<!-- <script src="http://localhost:8097"></script>-->
|
||||||
<style>
|
<style>
|
||||||
body {
|
body {
|
||||||
background-color: white;
|
background-color: white;
|
||||||
|
|||||||
@@ -14,8 +14,10 @@ import { pluralize } from '../lib/pluralize';
|
|||||||
import { Banner } from './core/Banner';
|
import { Banner } from './core/Banner';
|
||||||
import { CountBadge } from './core/CountBadge';
|
import { CountBadge } from './core/CountBadge';
|
||||||
import { Dropdown } from './core/Dropdown';
|
import { Dropdown } from './core/Dropdown';
|
||||||
|
import { DurationTag } from './core/DurationTag';
|
||||||
import { Icon } from './core/Icon';
|
import { Icon } from './core/Icon';
|
||||||
import { IconButton } from './core/IconButton';
|
import { IconButton } from './core/IconButton';
|
||||||
|
import { SizeTag } from './core/SizeTag';
|
||||||
import { HStack } from './core/Stacks';
|
import { HStack } from './core/Stacks';
|
||||||
import { StatusTag } from './core/StatusTag';
|
import { StatusTag } from './core/StatusTag';
|
||||||
import type { TabItem } from './core/Tabs/Tabs';
|
import type { TabItem } from './core/Tabs/Tabs';
|
||||||
@@ -108,13 +110,13 @@ export const ResponsePane = memo(function ResponsePane({ style, className }: Pro
|
|||||||
{activeResponse.elapsed > 0 && (
|
{activeResponse.elapsed > 0 && (
|
||||||
<>
|
<>
|
||||||
<span>•</span>
|
<span>•</span>
|
||||||
<span>{activeResponse.elapsed}ms</span>
|
<DurationTag millis={activeResponse.elapsed} />
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
{activeResponse.contentLength && (
|
{!!activeResponse.contentLength && (
|
||||||
<>
|
<>
|
||||||
<span>•</span>
|
<span>•</span>
|
||||||
<span>{(activeResponse.contentLength / 1000).toFixed(1)} KB</span>
|
<SizeTag contentLength={activeResponse.contentLength} />
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</HStack>
|
</HStack>
|
||||||
|
|||||||
25
src-web/components/core/DurationTag.tsx
Normal file
25
src-web/components/core/DurationTag.tsx
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
interface Props {
|
||||||
|
millis: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function DurationTag({ millis }: Props) {
|
||||||
|
let num;
|
||||||
|
let unit;
|
||||||
|
|
||||||
|
if (millis > 1000 * 60) {
|
||||||
|
num = millis / 1000 / 60;
|
||||||
|
unit = 'min';
|
||||||
|
} else if (millis > 1000) {
|
||||||
|
num = millis / 1000;
|
||||||
|
unit = 's';
|
||||||
|
} else {
|
||||||
|
num = millis;
|
||||||
|
unit = 'ms';
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{Math.round(num * 10) / 10} {unit}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
28
src-web/components/core/SizeTag.tsx
Normal file
28
src-web/components/core/SizeTag.tsx
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
interface Props {
|
||||||
|
contentLength: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function SizeTag({ contentLength }: Props) {
|
||||||
|
let num;
|
||||||
|
let unit;
|
||||||
|
|
||||||
|
if (contentLength > 1000 * 1000 * 1000) {
|
||||||
|
num = contentLength / 1000 / 1000 / 1000;
|
||||||
|
unit = 'GB';
|
||||||
|
} else if (contentLength > 1000 * 1000) {
|
||||||
|
num = contentLength / 1000 / 1000;
|
||||||
|
unit = 'MB';
|
||||||
|
} else if (contentLength > 1000) {
|
||||||
|
num = contentLength / 1000;
|
||||||
|
unit = 'KB';
|
||||||
|
} else {
|
||||||
|
num = contentLength;
|
||||||
|
unit = 'B';
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{Math.round(num * 10) / 10} {unit}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user