Skip to content

Commit 046a608

Browse files
committed
feat: add Overview dashboard (Services, Backups & Domains tabs)
1 parent 1183c7c commit 046a608

17 files changed

Lines changed: 2770 additions & 9 deletions

File tree

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
import {
2+
getBackupOverviewIcon,
3+
getServiceOverviewIcon,
4+
} from "@dokploy/server/services/overview";
5+
import { describe, expect, test } from "vitest";
6+
7+
describe("getServiceOverviewIcon", () => {
8+
test("returns a db icon for every known DB engine type", () => {
9+
for (const type of [
10+
"postgres",
11+
"mariadb",
12+
"mysql",
13+
"mongo",
14+
"redis",
15+
"libsql",
16+
] as const) {
17+
expect(getServiceOverviewIcon({ type, icon: null })).toEqual({
18+
kind: "db",
19+
engine: type,
20+
});
21+
}
22+
});
23+
24+
test("returns a custom icon for application/compose with a service icon set", () => {
25+
expect(
26+
getServiceOverviewIcon({
27+
type: "application",
28+
icon: "data:image/png;base64,x",
29+
}),
30+
).toEqual({ kind: "custom", url: "data:image/png;base64,x" });
31+
expect(
32+
getServiceOverviewIcon({
33+
type: "compose",
34+
icon: "data:image/png;base64,y",
35+
}),
36+
).toEqual({ kind: "custom", url: "data:image/png;base64,y" });
37+
});
38+
39+
test("falls back to a generic icon for application/compose without a service icon", () => {
40+
expect(getServiceOverviewIcon({ type: "application", icon: null })).toEqual(
41+
{
42+
kind: "generic",
43+
type: "application",
44+
},
45+
);
46+
expect(getServiceOverviewIcon({ type: "compose", icon: null })).toEqual({
47+
kind: "generic",
48+
type: "compose",
49+
});
50+
});
51+
});
52+
53+
describe("getBackupOverviewIcon", () => {
54+
test("returns a db icon for a database backup with a known databaseType", () => {
55+
expect(
56+
getBackupOverviewIcon({
57+
databaseType: "postgres",
58+
serviceType: null,
59+
serviceOwnerType: "postgres",
60+
}),
61+
).toEqual({ kind: "db", engine: "postgres" });
62+
});
63+
64+
test("returns a webServer icon for a web-server database backup", () => {
65+
expect(
66+
getBackupOverviewIcon({
67+
databaseType: "web-server",
68+
serviceType: null,
69+
serviceOwnerType: "web-server",
70+
}),
71+
).toEqual({ kind: "webServer" });
72+
});
73+
74+
test("returns a db icon for a compose-type backup dumping a known DB engine", () => {
75+
expect(
76+
getBackupOverviewIcon({
77+
databaseType: "mysql",
78+
serviceType: null,
79+
serviceOwnerType: "compose",
80+
}),
81+
).toEqual({ kind: "db", engine: "mysql" });
82+
});
83+
84+
test("returns a db icon for a volume backup of a known DB engine service", () => {
85+
expect(
86+
getBackupOverviewIcon({
87+
databaseType: null,
88+
serviceType: "mongo",
89+
serviceOwnerType: "mongo",
90+
}),
91+
).toEqual({ kind: "db", engine: "mongo" });
92+
});
93+
94+
test("returns a generic application icon for a volume backup of an application", () => {
95+
expect(
96+
getBackupOverviewIcon({
97+
databaseType: null,
98+
serviceType: "application",
99+
serviceOwnerType: "application",
100+
}),
101+
).toEqual({ kind: "generic", type: "application" });
102+
});
103+
104+
test("returns a generic compose icon for a volume backup of a compose service", () => {
105+
expect(
106+
getBackupOverviewIcon({
107+
databaseType: null,
108+
serviceType: "compose",
109+
serviceOwnerType: "compose",
110+
}),
111+
).toEqual({ kind: "generic", type: "compose" });
112+
});
113+
});
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import type { OverviewDomain } from "@dokploy/server/services/overview";
2+
import { sortOverviewDomains } from "@dokploy/server/services/overview";
3+
import { describe, expect, test } from "vitest";
4+
5+
const makeDomain = (overrides: Partial<OverviewDomain>): OverviewDomain => ({
6+
domainId: "id",
7+
host: "example.com",
8+
path: "/",
9+
port: 3000,
10+
customEntrypoint: null,
11+
https: true,
12+
certificateType: "letsencrypt",
13+
createdAt: "2024-01-01T00:00:00.000Z",
14+
enabled: true,
15+
domainType: "application",
16+
serviceOwnerId: "app",
17+
serviceOwnerType: "application",
18+
serviceName: "App",
19+
projectId: "project",
20+
projectName: "Project",
21+
environmentId: "environment",
22+
environmentName: "Environment",
23+
...overrides,
24+
});
25+
26+
describe("sortOverviewDomains", () => {
27+
test("sorts by createdAt asc/desc", () => {
28+
const domains = [
29+
makeDomain({ domainId: "old", createdAt: "2023-01-01T00:00:00.000Z" }),
30+
makeDomain({ domainId: "new", createdAt: "2024-06-01T00:00:00.000Z" }),
31+
makeDomain({ domainId: "mid", createdAt: "2023-12-01T00:00:00.000Z" }),
32+
];
33+
34+
expect(
35+
sortOverviewDomains(domains, "createdAt-asc").map((d) => d.domainId),
36+
).toEqual(["old", "mid", "new"]);
37+
expect(
38+
sortOverviewDomains(domains, "createdAt-desc").map((d) => d.domainId),
39+
).toEqual(["new", "mid", "old"]);
40+
});
41+
42+
test("sorts by port asc/desc, with portless domains always last", () => {
43+
const domains = [
44+
makeDomain({ domainId: "none", port: null }),
45+
makeDomain({ domainId: "low", port: 80 }),
46+
makeDomain({ domainId: "high", port: 8080 }),
47+
];
48+
49+
expect(
50+
sortOverviewDomains(domains, "port-asc").map((d) => d.domainId),
51+
).toEqual(["low", "high", "none"]);
52+
expect(
53+
sortOverviewDomains(domains, "port-desc").map((d) => d.domainId),
54+
).toEqual(["high", "low", "none"]);
55+
});
56+
57+
test("port sort with all domains portless is a no-op", () => {
58+
const domains = [
59+
makeDomain({ domainId: "a", port: null }),
60+
makeDomain({ domainId: "b", port: null }),
61+
];
62+
63+
expect(
64+
sortOverviewDomains(domains, "port-desc").map((d) => d.domainId),
65+
).toEqual(["a", "b"]);
66+
});
67+
68+
test("does not mutate the input array", () => {
69+
const domains = [
70+
makeDomain({ domainId: "b", port: 8080 }),
71+
makeDomain({ domainId: "a", port: 80 }),
72+
];
73+
const original = [...domains];
74+
75+
sortOverviewDomains(domains, "port-asc");
76+
77+
expect(domains).toEqual(original);
78+
});
79+
});
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
import type { OverviewService } from "@dokploy/server/services/overview";
2+
import { sortOverviewServices } from "@dokploy/server/services/overview";
3+
import { describe, expect, test } from "vitest";
4+
5+
const makeService = (overrides: Partial<OverviewService>): OverviewService => ({
6+
id: "id",
7+
type: "application",
8+
name: "name",
9+
appName: "app-name",
10+
status: "running",
11+
createdAt: "2024-01-01T00:00:00.000Z",
12+
serverId: null,
13+
serverName: null,
14+
icon: null,
15+
projectId: "project",
16+
projectName: "Project",
17+
environmentId: "environment",
18+
environmentName: "Environment",
19+
lastDeployAt: null,
20+
...overrides,
21+
});
22+
23+
describe("sortOverviewServices", () => {
24+
test("sorts by name asc/desc", () => {
25+
const services = [
26+
makeService({ id: "b", name: "Bravo" }),
27+
makeService({ id: "a", name: "Alpha" }),
28+
makeService({ id: "c", name: "Charlie" }),
29+
];
30+
31+
expect(sortOverviewServices(services, "name-asc").map((s) => s.id)).toEqual(
32+
["a", "b", "c"],
33+
);
34+
expect(
35+
sortOverviewServices(services, "name-desc").map((s) => s.id),
36+
).toEqual(["c", "b", "a"]);
37+
});
38+
39+
test("sorts by type asc/desc", () => {
40+
const services = [
41+
makeService({ id: "app", type: "application" }),
42+
makeService({ id: "pg", type: "postgres" }),
43+
makeService({ id: "comp", type: "compose" }),
44+
];
45+
46+
expect(sortOverviewServices(services, "type-asc").map((s) => s.id)).toEqual(
47+
["app", "comp", "pg"],
48+
);
49+
expect(
50+
sortOverviewServices(services, "type-desc").map((s) => s.id),
51+
).toEqual(["pg", "comp", "app"]);
52+
});
53+
54+
test("sorts by createdAt asc/desc", () => {
55+
const services = [
56+
makeService({ id: "old", createdAt: "2023-01-01T00:00:00.000Z" }),
57+
makeService({ id: "new", createdAt: "2024-06-01T00:00:00.000Z" }),
58+
makeService({ id: "mid", createdAt: "2023-12-01T00:00:00.000Z" }),
59+
];
60+
61+
expect(
62+
sortOverviewServices(services, "createdAt-asc").map((s) => s.id),
63+
).toEqual(["old", "mid", "new"]);
64+
expect(
65+
sortOverviewServices(services, "createdAt-desc").map((s) => s.id),
66+
).toEqual(["new", "mid", "old"]);
67+
});
68+
69+
test("sorts by lastDeploy asc/desc, with never-deployed services always last", () => {
70+
const services = [
71+
makeService({ id: "never", lastDeployAt: null }),
72+
makeService({ id: "old", lastDeployAt: "2023-01-01T00:00:00.000Z" }),
73+
makeService({ id: "new", lastDeployAt: "2024-06-01T00:00:00.000Z" }),
74+
];
75+
76+
expect(
77+
sortOverviewServices(services, "lastDeploy-desc").map((s) => s.id),
78+
).toEqual(["new", "old", "never"]);
79+
expect(
80+
sortOverviewServices(services, "lastDeploy-asc").map((s) => s.id),
81+
).toEqual(["old", "new", "never"]);
82+
});
83+
84+
test("lastDeploy sort with all services never deployed is a no-op", () => {
85+
const services = [
86+
makeService({ id: "a", lastDeployAt: null }),
87+
makeService({ id: "b", lastDeployAt: null }),
88+
];
89+
90+
expect(
91+
sortOverviewServices(services, "lastDeploy-desc").map((s) => s.id),
92+
).toEqual(["a", "b"]);
93+
});
94+
95+
test("does not mutate the input array", () => {
96+
const services = [
97+
makeService({ id: "b", name: "Bravo" }),
98+
makeService({ id: "a", name: "Alpha" }),
99+
];
100+
const original = [...services];
101+
102+
sortOverviewServices(services, "name-asc");
103+
104+
expect(services).toEqual(original);
105+
});
106+
});

‎apps/dokploy/components/dashboard/application/volume-backups/restore-volume-backups.tsx‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ interface Props {
5050
id: string;
5151
type: "application" | "compose";
5252
serverId?: string;
53+
trigger?: React.ReactNode;
5354
}
5455

5556
const RestoreBackupSchema = z.object({
@@ -64,7 +65,12 @@ const RestoreBackupSchema = z.object({
6465
}),
6566
});
6667

67-
export const RestoreVolumeBackups = ({ id, type, serverId }: Props) => {
68+
export const RestoreVolumeBackups = ({
69+
id,
70+
type,
71+
serverId,
72+
trigger,
73+
}: Props) => {
6874
const [isOpen, setIsOpen] = useState(false);
6975
const [search, setSearch] = useState("");
7076
const [debouncedSearchTerm, setDebouncedSearchTerm] = useState("");
@@ -144,10 +150,12 @@ export const RestoreVolumeBackups = ({ id, type, serverId }: Props) => {
144150
return (
145151
<Dialog open={isOpen} onOpenChange={setIsOpen}>
146152
<DialogTrigger asChild>
147-
<Button variant="outline">
148-
<RotateCcw className="mr-2 size-4" />
149-
Restore Volume Backup
150-
</Button>
153+
{trigger ?? (
154+
<Button variant="outline">
155+
<RotateCcw className="mr-2 size-4" />
156+
Restore Volume Backup
157+
</Button>
158+
)}
151159
</DialogTrigger>
152160
<DialogContent className="sm:max-w-lg">
153161
<DialogHeader>

‎apps/dokploy/components/dashboard/database/backups/restore-backup.tsx‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ interface Props {
7474
databaseType?: DatabaseType;
7575
serverId?: string | null;
7676
backupType?: "database" | "compose";
77+
trigger?: React.ReactNode;
7778
}
7879

7980
const RestoreBackupSchema = z
@@ -200,6 +201,7 @@ export const RestoreBackup = ({
200201
databaseType,
201202
serverId,
202203
backupType = "database",
204+
trigger,
203205
}: Props) => {
204206
const [isOpen, setIsOpen] = useState(false);
205207
const [search, setSearch] = useState("");
@@ -311,10 +313,12 @@ export const RestoreBackup = ({
311313
return (
312314
<Dialog open={isOpen} onOpenChange={setIsOpen}>
313315
<DialogTrigger asChild>
314-
<Button variant="outline">
315-
<RotateCcw className="mr-2 size-4" />
316-
Restore Backup
317-
</Button>
316+
{trigger ?? (
317+
<Button variant="outline">
318+
<RotateCcw className="mr-2 size-4" />
319+
Restore Backup
320+
</Button>
321+
)}
318322
</DialogTrigger>
319323
<DialogContent className="sm:max-w-2xl">
320324
<DialogHeader>

0 commit comments

Comments
 (0)