feat!: release v2 (#6545)

Co-authored-by: Artur <145776561+arturict@users.noreply.github.com>
Co-authored-by: arturict <arturict@users.noreply.github.com>
Co-authored-by: Thomas <thomas@ajnart.fr>
Co-authored-by: Afonso Jorge Ramos <afonsojorgeramos@gmail.com>
Co-authored-by: Danura30082 <danura30082+github@gmail.com>
Co-authored-by: Kushie <122986913+kushiemoon-dev@users.noreply.github.com>
Co-authored-by: ajnart <thomas@ajnart.fr>
Co-authored-by: ajnart <thomas@ajnart.dev>
Co-authored-by: chenjun <chenjun@foxmail.com>
Co-authored-by: Wikibear <wikibear@users.noreply.github.com>
Co-authored-by: Bergasha <bergasha@gmail.com>
Co-authored-by: leafyelin <43306196+leafyelin@users.noreply.github.com>
Co-authored-by: Lucas Araujo <lucas.lra@gmail.com>
Co-authored-by: GreenMonito <86085570+GreenMonito@users.noreply.github.com>
Co-authored-by: Nerdy-Technician <roffo@nerdy-technician.social>
Co-authored-by: Jun <34545896+jcstrong@users.noreply.github.com>
Co-authored-by: Edmond Abraham <54119952+gitedmond@users.noreply.github.com>
Co-authored-by: thrawnx <tight.bulb9384@fastmail.com>
Co-authored-by: Chris <58918656+nordada@users.noreply.github.com>
Co-authored-by: yi111 <153097222+Yi-111-a@users.noreply.github.com>
Co-authored-by: Yanis <naamaneyanis@gmail.com>
Co-authored-by: Wikibear <me@sej.de>
Co-authored-by: alessiottavo <93441886+alessiottavo@users.noreply.github.com>
This commit is contained in:
3286 files changed
+284386 -139176

No files matched your search

@@ -3,35 +3,44 @@ import { z } from "zod/v4";
import type { RouterOutputs } from "@homarr/api";
import { clientApi } from "@homarr/api/client";
import { buildDockerServiceUrlCandidates } from "@homarr/definitions";
import { useZodForm } from "@homarr/form";
import { createModal } from "@homarr/modals";
import { showErrorNotification, showSuccessNotification } from "@homarr/notifications";
import { useI18n } from "@homarr/translation/client";
import { appHrefSchema } from "@homarr/validation/app";
interface AddDockerAppToHomarrProps {
selectedContainers: RouterOutputs["docker"]["getContainers"]["containers"];
initialUrls?: (string | null)[];
}
const formSchema = z.object({
containerUrls: z.array(appHrefSchema),
});
export const AddDockerAppToHomarrModal = createModal<AddDockerAppToHomarrProps>(({ actions, innerProps }) => {
const t = useI18n();
const form = useZodForm(
z.object({
containerUrls: z.array(z.string().url().nullable()),
}),
{
initialValues: {
containerUrls: innerProps.selectedContainers.map((container) => {
if (Array.isArray(container.ports) && container.ports[0]) {
return `http://${container.ports[0].IP}:${container.ports[0].PublicPort}`;
}
const utils = clientApi.useUtils();
const form = useZodForm(formSchema, {
initialValues: {
containerUrls: innerProps.selectedContainers.map((container, index) => {
const initialUrl = innerProps.initialUrls?.[index];
if (initialUrl !== undefined) return initialUrl;
return null;
}),
},
const candidates = buildDockerServiceUrlCandidates({
containerName: container.name,
endpointHost: container.host,
ports: container.ports,
}).filter(({ url }) => url.length > 0);
return candidates.find(({ scopes }) => scopes.includes("browser"))?.url ?? candidates[0]?.url ?? null;
}),
},
);
});
const { mutate, isPending } = clientApi.app.createMany.useMutation({
onSuccess() {
void utils.app.invalidate();
actions.closeModal();
showSuccessNotification({
title: t("docker.action.addToHomarr.notification.success.title"),
@@ -45,13 +54,13 @@ export const AddDockerAppToHomarrModal = createModal<AddDockerAppToHomarrProps>(
});
},
});
const handleSubmit = () => {
const handleSubmit = ({ containerUrls }: z.infer<typeof formSchema>) => {
mutate(
innerProps.selectedContainers.map((container, index) => ({
name: container.name,
iconUrl: container.iconUrl,
description: null,
href: form.values.containerUrls[index] ?? null,
href: containerUrls[index] || null,
pingUrl: null,
})),
);
@@ -61,28 +70,31 @@ export const AddDockerAppToHomarrModal = createModal<AddDockerAppToHomarrProps>(
<LoadingOverlay visible={isPending} />
<Stack>
<List spacing={"xs"}>
{innerProps.selectedContainers.map((container, index) => (
<List.Item
styles={{ itemWrapper: { width: "100%" }, itemLabel: { flex: 1 } }}
icon={
<Avatar
variant="outline"
radius={container.iconUrl ? "sm" : "md"}
size={30}
styles={{ image: { objectFit: "contain" } }}
src={container.iconUrl}
>
{container.name.at(0)?.toUpperCase()}
</Avatar>
}
key={container.id}
>
<Group justify="space-between" wrap={"nowrap"}>
<Text lineClamp={1}>{container.name}</Text>
<TextInput {...form.getInputProps(`containerUrls.${index}`)} />
</Group>
</List.Item>
))}
{innerProps.selectedContainers.map((container, index) => {
const inputProps = form.getInputProps(`containerUrls.${index}`);
return (
<List.Item
styles={{ itemWrapper: { width: "100%" }, itemLabel: { flex: 1 } }}
icon={
<Avatar
variant="outline"
radius={container.iconUrl ? "sm" : "md"}
size={30}
styles={{ image: { objectFit: "contain" } }}
src={container.iconUrl}
>
{container.name.at(0)?.toUpperCase()}
</Avatar>
}
key={container.id}
>
<Group justify="space-between" wrap={"nowrap"}>
<Text lineClamp={1}>{container.name}</Text>
<TextInput {...inputProps} value={inputProps.value ?? ""} />
</Group>
</List.Item>
);
})}
</List>
<Group justify="end">
<Button onClick={actions.closeModal} variant="light" px={"xl"}>
@@ -0,0 +1,25 @@
import { describe, expect, test, vi } from "vitest";
import { createDockerRemovalConfirmation } from "./confirm-docker-container-removal";
describe("createDockerRemovalConfirmation", () => {
test("does not remove containers before explicit confirmation", () => {
const remove = vi.fn();
const t = vi.fn((key: string, values?: Record<string, string>) => `${key}:${JSON.stringify(values)}`);
const confirmation = createDockerRemovalConfirmation(
[{ name: "sonarr" }, { name: "radarr" }],
t as never,
"Remove",
remove,
);
expect(remove).not.toHaveBeenCalled();
expect(confirmation.title).toContain('"count":"2"');
expect(confirmation.children).toContain('"names":"sonarr, radarr"');
expect(confirmation.confirmProps.children).toBe("Remove");
confirmation.onConfirm();
expect(remove).toHaveBeenCalledOnce();
});
});
@@ -0,0 +1,38 @@
"use client";
import { useCallback } from "react";
import { useConfirmModal } from "@homarr/modals";
import { useI18n } from "@homarr/translation/client";
interface DockerContainerName {
name: string;
}
export const createDockerRemovalConfirmation = (
containers: DockerContainerName[],
t: ReturnType<typeof useI18n<"docker.action.remove">>,
confirmLabel: string,
onConfirm: () => void | Promise<void>,
) => ({
title: t("confirmation.title", { count: String(containers.length) }),
children: t("confirmation.message", {
count: String(containers.length),
names: containers.map(({ name }) => name).join(", "),
}),
confirmProps: { children: confirmLabel, color: "red.9" },
onConfirm,
});
export const useDockerContainerRemovalConfirmation = () => {
const t = useI18n("docker.action.remove");
const commonT = useI18n("common.action");
const { openConfirmModal } = useConfirmModal();
return useCallback(
(containers: DockerContainerName[], onConfirm: () => void | Promise<void>) => {
openConfirmModal(createDockerRemovalConfirmation(containers, t, commonT("remove"), onConfirm));
},
[commonT, openConfirmModal, t],
);
};
@@ -1 +1,5 @@
export { AddDockerAppToHomarrModal as AddDockerAppToHomarr } from "./add-docker-app-to-homarr";
export {
createDockerRemovalConfirmation,
useDockerContainerRemovalConfirmation,
} from "./confirm-docker-container-removal";