Skip to content

Commit 560f3d9

Browse files
committed
Basis for Upstreams UI
1 parent 7ea64c4 commit 560f3d9

File tree

13 files changed

+411
-0
lines changed

13 files changed

+411
-0
lines changed

frontend/src/Router.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const NginxTemplates = lazy(() => import("pages/NginxTemplates"));
1818
const Login = lazy(() => import("pages/Login"));
1919
const GeneralSettings = lazy(() => import("pages/Settings"));
2020
const Setup = lazy(() => import("pages/Setup"));
21+
const Upstreams = lazy(() => import("pages/Upstreams"));
2122
const Users = lazy(() => import("pages/Users"));
2223

2324
function Router() {
@@ -56,6 +57,7 @@ function Router() {
5657
<Suspense fallback={Spinner}>
5758
<Routes>
5859
<Route path="/hosts" element={<Hosts />} />
60+
<Route path="/upstreams" element={<Upstreams />} />
5961
<Route path="/ssl/certificates" element={<Certificates />} />
6062
<Route
6163
path="/ssl/authorities"

frontend/src/api/npm/getUpstreams.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import * as api from "./base";
2+
import { UpstreamsResponse } from "./responseTypes";
3+
4+
export async function getUpstreams(
5+
offset = 0,
6+
limit = 10,
7+
sort?: string,
8+
filters?: { [key: string]: string },
9+
abortController?: AbortController,
10+
): Promise<UpstreamsResponse> {
11+
const { result } = await api.get(
12+
{
13+
url: "upstreams",
14+
params: { limit, offset, sort, expand: "user", ...filters },
15+
},
16+
abortController,
17+
);
18+
return result;
19+
}

frontend/src/api/npm/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export * from "./getHosts";
1212
export * from "./getNginxTemplates";
1313
export * from "./getSettings";
1414
export * from "./getToken";
15+
export * from "./getUpstreams";
1516
export * from "./getUser";
1617
export * from "./getUsers";
1718
export * from "./helpers";

frontend/src/api/npm/models.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,28 @@ export interface NginxTemplate {
120120
type: string;
121121
template: string;
122122
}
123+
124+
export interface Upstream {
125+
// todo
126+
id: number;
127+
createdOn: number;
128+
modifiedOn: number;
129+
userId: number;
130+
type: string;
131+
nginxTemplateId: number;
132+
listenInterface: number;
133+
domainNames: string[];
134+
upstreamId: number;
135+
certificateId: number;
136+
accessListId: number;
137+
sslForced: boolean;
138+
cachingEnabled: boolean;
139+
blockExploits: boolean;
140+
allowWebsocketUpgrade: boolean;
141+
http2Support: boolean;
142+
hstsEnabled: boolean;
143+
hstsSubdomains: boolean;
144+
paths: string;
145+
advancedConfig: string;
146+
isDisabled: boolean;
147+
}

frontend/src/api/npm/responseTypes.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
Setting,
88
Sort,
99
User,
10+
Upstream,
1011
} from "./models";
1112

1213
export interface BaseResponse {
@@ -56,3 +57,7 @@ export interface HostsResponse extends BaseResponse {
5657
export interface NginxTemplatesResponse extends BaseResponse {
5758
items: NginxTemplate[];
5859
}
60+
61+
export interface UpstreamsResponse extends BaseResponse {
62+
items: Upstream[];
63+
}

frontend/src/components/Table/Formatters.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,30 @@ function HostStatusFormatter() {
185185
return formatCell;
186186
}
187187

188+
function UpstreamStatusFormatter() {
189+
const formatCell = ({ value, row }: any) => {
190+
if (value === "ready") {
191+
return (
192+
<Badge color="cyan.500">{intl.formatMessage({ id: "ready" })}</Badge>
193+
);
194+
}
195+
if (value === "ok") {
196+
return (
197+
<Badge color="green.500">{intl.formatMessage({ id: "ok" })}</Badge>
198+
);
199+
}
200+
if (value === "error") {
201+
return (
202+
<Tooltip label={row.original.errorMessage}>
203+
<Badge color="red.500">{intl.formatMessage({ id: "error" })}</Badge>
204+
</Tooltip>
205+
);
206+
}
207+
};
208+
209+
return formatCell;
210+
}
211+
188212
function HostTypeFormatter() {
189213
const formatCell = ({ value }: any) => {
190214
return intl.formatMessage({ id: `host-type.${value}` });
@@ -222,4 +246,5 @@ export {
222246
HostTypeFormatter,
223247
IDFormatter,
224248
SecondsFormatter,
249+
UpstreamStatusFormatter,
225250
};

frontend/src/hooks/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ export * from "./useHealth";
88
export * from "./useHosts";
99
export * from "./useNginxTemplates";
1010
export * from "./useSettings";
11+
export * from "./useUpstreams";
1112
export * from "./useUser";
1213
export * from "./useUsers";

frontend/src/hooks/useUpstreams.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import {
2+
getUpstreams,
3+
HostsResponse,
4+
tableSortToAPI,
5+
tableFiltersToAPI,
6+
} from "api/npm";
7+
import { useQuery } from "react-query";
8+
9+
const fetchUpstreams = (
10+
offset = 0,
11+
limit = 10,
12+
sortBy?: any,
13+
filters?: any,
14+
) => {
15+
return getUpstreams(
16+
offset,
17+
limit,
18+
tableSortToAPI(sortBy),
19+
tableFiltersToAPI(filters),
20+
);
21+
};
22+
23+
const useUpstreams = (
24+
offset = 0,
25+
limit = 10,
26+
sortBy?: any,
27+
filters?: any,
28+
options = {},
29+
) => {
30+
return useQuery<HostsResponse, Error>(
31+
["upstreams", { offset, limit, sortBy, filters }],
32+
() => fetchUpstreams(offset, limit, sortBy, filters),
33+
{
34+
keepPreviousData: true,
35+
staleTime: 15 * 1000, // 15 seconds
36+
...options,
37+
},
38+
);
39+
};
40+
41+
export { fetchUpstreams, useUpstreams };

frontend/src/locale/src/de.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@
8080
"column.name": {
8181
"defaultMessage": "Name"
8282
},
83+
"column.servers": {
84+
"defaultMessage": "Servers"
85+
},
8386
"column.status": {
8487
"defaultMessage": "Status"
8588
},
@@ -116,6 +119,12 @@
116119
"create-host-title": {
117120
"defaultMessage": "Es gibt keine Proxy-Hosts"
118121
},
122+
"create-upstream": {
123+
"defaultMessage": "Create Upstream"
124+
},
125+
"create-upstream-title": {
126+
"defaultMessage": "There are no Upstreams"
127+
},
119128
"dashboard.title": {
120129
"defaultMessage": "Armaturenbrett"
121130
},
@@ -257,6 +266,9 @@
257266
"no-access": {
258267
"defaultMessage": "Kein Zugang"
259268
},
269+
"ok": {
270+
"defaultMessage": "OK"
271+
},
260272
"password.confirm": {
261273
"defaultMessage": "Bestätige neues Passwort"
262274
},

frontend/src/locale/src/en.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,9 @@
254254
"column.name": {
255255
"defaultMessage": "Name"
256256
},
257+
"column.servers": {
258+
"defaultMessage": "Servers"
259+
},
257260
"column.status": {
258261
"defaultMessage": "Status"
259262
},
@@ -290,6 +293,12 @@
290293
"create-host-title": {
291294
"defaultMessage": "There are no Proxy Hosts"
292295
},
296+
"create-upstream": {
297+
"defaultMessage": "Create Upstream"
298+
},
299+
"create-upstream-title": {
300+
"defaultMessage": "There are no Upstreams"
301+
},
293302
"dashboard.title": {
294303
"defaultMessage": "Dashboard"
295304
},
@@ -446,6 +455,9 @@
446455
"no-access": {
447456
"defaultMessage": "No Access"
448457
},
458+
"ok": {
459+
"defaultMessage": "OK"
460+
},
449461
"password.confirm": {
450462
"defaultMessage": "Confirm New Password"
451463
},

0 commit comments

Comments
 (0)