Skip to content

Commit 0f71857

Browse files
committed
Use status components for true/false things
1 parent fac5f2c commit 0f71857

File tree

12 files changed

+60
-53
lines changed

12 files changed

+60
-53
lines changed

frontend/src/components/Table/Formatter/CertificateInUseFormatter.tsx

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import OverlayTrigger from "react-bootstrap/OverlayTrigger";
22
import Popover from "react-bootstrap/Popover";
33
import type { DeadHost, ProxyHost, RedirectionHost, Stream } from "src/api/backend";
4+
import { TrueFalseFormatter } from "src/components";
45
import { T } from "src/locale";
56

67
const getSection = (title: string, items: ProxyHost[] | RedirectionHost[] | DeadHost[]) => {
@@ -52,11 +53,7 @@ interface Props {
5253
export function CertificateInUseFormatter({ proxyHosts, redirectionHosts, deadHosts, streams }: Props) {
5354
const totalCount = proxyHosts?.length + redirectionHosts?.length + deadHosts?.length + streams?.length;
5455
if (totalCount === 0) {
55-
return (
56-
<span className="badge bg-red-lt">
57-
<T id="certificate.not-in-use" />
58-
</span>
59-
);
56+
return <TrueFalseFormatter value={false} falseLabel="certificate.not-in-use" />;
6057
}
6158

6259
proxyHosts.sort();
@@ -76,10 +73,10 @@ export function CertificateInUseFormatter({ proxyHosts, redirectionHosts, deadHo
7673
);
7774

7875
return (
79-
<OverlayTrigger trigger="hover" placement="bottom" overlay={popover}>
80-
<span className="badge bg-lime-lt">
81-
<T id="certificate.in-use" />
82-
</span>
76+
<OverlayTrigger trigger={["hover", "click", "focus"]} placement="bottom" overlay={popover}>
77+
<div>
78+
<TrueFalseFormatter value trueLabel="certificate.in-use" />
79+
</div>
8380
</OverlayTrigger>
8481
);
8582
}

frontend/src/components/Table/Formatter/DomainsFormatter.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import cn from "classnames";
12
import type { ReactNode } from "react";
23
import { DateTimeFormat, T } from "src/locale";
34

@@ -6,9 +7,10 @@ interface Props {
67
createdOn?: string;
78
niceName?: string;
89
provider?: string;
10+
color?: string;
911
}
1012

11-
const DomainLink = ({ domain }: { domain: string }) => {
13+
const DomainLink = ({ domain, color }: { domain: string; color?: string }) => {
1214
// when domain contains a wildcard, make the link go nowhere.
1315
let onClick: ((e: React.MouseEvent) => void) | undefined;
1416
if (domain.includes("*")) {
@@ -20,15 +22,14 @@ const DomainLink = ({ domain }: { domain: string }) => {
2022
href={`http://${domain}`}
2123
target="_blank"
2224
onClick={onClick}
23-
className="badge bg-yellow-lt domain-name me-2"
25+
className={cn("badge", color ? `bg-${color}-lt` : null, "domain-name", "me-2")}
2426
>
2527
{domain}
2628
</a>
2729
);
2830
};
2931

30-
export function DomainsFormatter({ domains, createdOn, niceName, provider }: Props) {
31-
console.log("PROVIDER:", provider);
32+
export function DomainsFormatter({ domains, createdOn, niceName, provider, color }: Props) {
3233
const elms: ReactNode[] = [];
3334
if (domains.length === 0 && !niceName) {
3435
elms.push(
@@ -45,7 +46,7 @@ export function DomainsFormatter({ domains, createdOn, niceName, provider }: Pro
4546
);
4647
}
4748

48-
domains.map((domain: string) => elms.push(<DomainLink key={domain} domain={domain} />));
49+
domains.map((domain: string) => elms.push(<DomainLink key={domain} domain={domain} color={color} />));
4950

5051
return (
5152
<div className="flex-fill">

frontend/src/components/Table/Formatter/EnabledFormatter.tsx

Lines changed: 0 additions & 13 deletions
This file was deleted.

frontend/src/components/Table/Formatter/StatusFormatter.tsx

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import cn from "classnames";
2+
import { T } from "src/locale";
3+
4+
interface Props {
5+
value: boolean;
6+
trueLabel?: string;
7+
trueColor?: string;
8+
falseLabel?: string;
9+
falseColor?: string;
10+
}
11+
export function TrueFalseFormatter({
12+
value,
13+
trueLabel = "enabled",
14+
trueColor = "lime",
15+
falseLabel = "disabled",
16+
falseColor = "red",
17+
}: Props) {
18+
return (
19+
<span className={cn("status", `status-${value ? trueColor : falseColor}`)}>
20+
<span className="status-dot status-dot-animated" />
21+
<T id={value ? trueLabel : falseLabel} />
22+
</span>
23+
);
24+
}

frontend/src/components/Table/Formatter/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ export * from "./CertificateInUseFormatter";
44
export * from "./DateFormatter";
55
export * from "./DomainsFormatter";
66
export * from "./EmailFormatter";
7-
export * from "./EnabledFormatter";
87
export * from "./EventFormatter";
98
export * from "./GravatarFormatter";
109
export * from "./RolesFormatter";
11-
export * from "./StatusFormatter";
10+
export * from "./TrueFalseFormatter";
1211
export * from "./ValueWithDateFormatter";

frontend/src/pages/Dashboard/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ const Dashboard = () => {
116116
<code>{`Todo:
117117
118118
- check mobile
119+
- use statuses for table formatters where applicable: https://docs.tabler.io/ui/components/statuses
119120
- add help docs for host types
120121
- REDO SCREENSHOTS in docs folder
121122
- search codebase for "TODO"
@@ -125,7 +126,6 @@ const Dashboard = () => {
125126
126127
More for api, then implement here:
127128
- Add error message_18n for all backend errors
128-
- minor: certificates expand with hosts needs to omit 'is_deleted'
129129
- properly wrap all logger.debug called in isDebug check
130130
- add new api endpoint changes to swagger docs
131131

frontend/src/pages/Nginx/DeadHosts/Table.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@ import { IconDotsVertical, IconEdit, IconPower, IconTrash } from "@tabler/icons-
22
import { createColumnHelper, getCoreRowModel, useReactTable } from "@tanstack/react-table";
33
import { useMemo } from "react";
44
import type { DeadHost } from "src/api/backend";
5-
import { CertificateFormatter, DomainsFormatter, EmptyData, GravatarFormatter, StatusFormatter } from "src/components";
5+
import {
6+
CertificateFormatter,
7+
DomainsFormatter,
8+
EmptyData,
9+
GravatarFormatter,
10+
TrueFalseFormatter,
11+
} from "src/components";
612
import { TableLayout } from "src/components/Table/TableLayout";
713
import { intl, T } from "src/locale";
814

@@ -48,7 +54,7 @@ export default function Table({ data, isFetching, onEdit, onDelete, onDisableTog
4854
id: "enabled",
4955
header: intl.formatMessage({ id: "column.status" }),
5056
cell: (info: any) => {
51-
return <StatusFormatter enabled={info.getValue()} />;
57+
return <TrueFalseFormatter value={info.getValue()} trueLabel="online" falseLabel="offline" />;
5258
},
5359
}),
5460
columnHelper.display({

frontend/src/pages/Nginx/ProxyHosts/Table.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
DomainsFormatter,
99
EmptyData,
1010
GravatarFormatter,
11-
StatusFormatter,
11+
TrueFalseFormatter,
1212
} from "src/components";
1313
import { TableLayout } from "src/components/Table/TableLayout";
1414
import { intl, T } from "src/locale";
@@ -70,7 +70,7 @@ export default function Table({ data, isFetching, onEdit, onDelete, onDisableTog
7070
id: "enabled",
7171
header: intl.formatMessage({ id: "column.status" }),
7272
cell: (info: any) => {
73-
return <StatusFormatter enabled={info.getValue()} />;
73+
return <TrueFalseFormatter value={info.getValue()} trueLabel="online" falseLabel="offline" />;
7474
},
7575
}),
7676
columnHelper.display({

frontend/src/pages/Nginx/RedirectionHosts/Table.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@ import { IconDotsVertical, IconEdit, IconPower, IconTrash } from "@tabler/icons-
22
import { createColumnHelper, getCoreRowModel, useReactTable } from "@tanstack/react-table";
33
import { useMemo } from "react";
44
import type { RedirectionHost } from "src/api/backend";
5-
import { CertificateFormatter, DomainsFormatter, EmptyData, GravatarFormatter, StatusFormatter } from "src/components";
5+
import {
6+
CertificateFormatter,
7+
DomainsFormatter,
8+
EmptyData,
9+
GravatarFormatter,
10+
TrueFalseFormatter,
11+
} from "src/components";
612
import { TableLayout } from "src/components/Table/TableLayout";
713
import { intl, T } from "src/locale";
814

@@ -69,7 +75,7 @@ export default function Table({ data, isFetching, onEdit, onDelete, onDisableTog
6975
id: "enabled",
7076
header: intl.formatMessage({ id: "column.status" }),
7177
cell: (info: any) => {
72-
return <StatusFormatter enabled={info.getValue()} />;
78+
return <TrueFalseFormatter value={info.getValue()} trueLabel="online" falseLabel="offline" />;
7379
},
7480
}),
7581
columnHelper.display({

0 commit comments

Comments
 (0)