fix: address release v2 reviews

This commit is contained in:
ajnart committed 2026-08-14 02:18:46 +02:00
1 parent 4905ea6738
commit 32732680e5
55 files changed
+925 -294

No files matched your search

@@ -46,7 +46,7 @@ describe("getAssistantWidgetConfiguration", () => {
boardName: "Home",
kind: "audioStats",
summary: "Show audio statistics",
integrationIds: ["navidrome-1", "audiobookshelf-1", "plex-1"],
integrationIds: ["navidrome-private", "navidrome-1", "audiobookshelf-1", "plex-1"],
},
settings,
[
@@ -66,7 +66,10 @@ export const BoardSetupChecklist = () => {
</ActionIcon>
</Tooltip>
</Group>
<Progress value={(progress.completedCount / progress.totalCount) * 100} aria-label={t("progress")} />
<Progress
value={progress.totalCount === 0 ? 0 : (progress.completedCount / progress.totalCount) * 100}
aria-label={t("progress")}
/>
<ChecklistStep
complete={progress.steps.content}
label={t("step.content.label")}
@@ -86,6 +86,7 @@ const createItemLayouts = (
? currentSection.layouts.find((layout) => layout.layoutId === layoutId)
: undefined;
const lane = currentSection.kind === "empty" ? getRootSectionLane(currentSection.xOffset) : "main";
if (currentSection.kind === "container" && !containerLayout) return [];
const columnCount = containerLayout?.width ?? (boardLayout ? getBoardLaneColumnCount(boardLayout, lane) : 0);
if (columnCount === 0) return [];
const size = {
@@ -169,6 +169,27 @@ describe("item actions create-item", () => {
]);
});
test("omits layouts where the requested container has no layout entry", () => {
const board = new BoardMockBuilder()
.addLayout({ id: "mobile", name: "Mobile", role: "mobile", columnCount: 3, breakpoint: 0 })
.addEmptySection({ id: "canvas" })
.addSection(
new ContainerSectionMockBuilder({ id: "media" })
.addLayout({ layoutId: "base", parentSectionId: "canvas", width: 4, height: 3 })
.build(),
)
.build();
const baseLayout = board.layouts.find((layout) => layout.role === "base");
if (!baseLayout) throw new Error("Expected a base layout");
baseLayout.id = "base";
const result = createItemCallback({ id: "calendar", kind: "clock", targetSectionId: "media" })(board);
expect(result.items.find((item) => item.id === "calendar")?.layouts).toEqual([
expect.objectContaining({ layoutId: "base", sectionId: "media" }),
]);
});
test("sizes a new item for its requested rail and omits layouts where that rail is hidden", () => {
const board = new BoardMockBuilder()
.addLayout({ id: "mobile", name: "Mobile", role: "mobile", columnCount: 3, breakpoint: 0 })
@@ -15,11 +15,12 @@ describe("getBoardRecipeRecommendations", () => {
preferredIntegrationKind: "jellyfin",
});
expect(recommendations).toHaveLength(3);
expect(recommendations.slice(0, 2).every(({ isNewlyAvailable }) => isNewlyAvailable)).toBe(true);
expect(recommendations.at(2)).toEqual(
expect.objectContaining({ integrationKind: "piHole", isNewlyAvailable: false }),
);
const firstFallbackIndex = recommendations.findIndex(({ isNewlyAvailable }) => !isNewlyAvailable);
expect(recommendations.some(({ isNewlyAvailable }) => isNewlyAvailable)).toBe(true);
if (firstFallbackIndex !== -1) {
expect(recommendations.slice(0, firstFallbackIndex).every(({ isNewlyAvailable }) => isNewlyAvailable)).toBe(true);
expect(recommendations.slice(firstFallbackIndex).every(({ isNewlyAvailable }) => !isNewlyAvailable)).toBe(true);
}
});
test("does not recommend widget kinds already present on the board", () => {
@@ -29,7 +30,8 @@ describe("getBoardRecipeRecommendations", () => {
preferredIntegrationKind: "piHole",
});
expect(recommendations.map(({ widgetKind }) => widgetKind)).toEqual(["dnsHoleControls"]);
expect(recommendations.every(({ widgetKind }) => widgetKind !== "dnsHoleSummary")).toBe(true);
expect(recommendations.every(({ integrationKind }) => integrationKind === "piHole")).toBe(true);
});
test("deduplicates configured kinds and emitted widget capabilities", () => {
@@ -39,7 +41,9 @@ describe("getBoardRecipeRecommendations", () => {
limit: 10,
});
expect(recommendations.map(({ widgetKind }) => widgetKind)).toEqual(["dnsHoleControls", "dnsHoleSummary"]);
const widgetKinds = recommendations.map(({ widgetKind }) => widgetKind);
expect(new Set(widgetKinds).size).toBe(widgetKinds.length);
expect(recommendations.every(({ integrationKind }) => integrationKind === "piHole")).toBe(true);
});
test("falls back to other configured integrations when the new service has no missing widgets", () => {
@@ -1,4 +1,4 @@
import { useMemo, useRef, useState } from "react";
import { useEffect, useMemo, useRef, useState } from "react";
import { Avatar, Badge, Box, Button, Center, Divider, Group, Image, Select, Stack, Text, Tooltip } from "@mantine/core";
import { notifications } from "@mantine/notifications";
import { IconApi } from "@tabler/icons-react";
@@ -94,10 +94,16 @@ const ItemSelectModalContent = ({
],
[board.sections, currentLayout, mainCanvasSection, t],
);
const [targetSectionId, setTargetSectionId] = useState<string | null>(mainCanvasSection?.id ?? null);
const [targetSectionId, setTargetSectionId] = useState<string | null>(placementOptions[0]?.value ?? null);
const [loadingSelection, setLoadingSelection] = useState<string | null>(null);
const selectionLock = useRef(false);
const { createItem, removeItem } = useItemActions();
useEffect(() => {
if (placementOptions.some(({ value }) => value === targetSectionId)) return;
setTargetSectionId(placementOptions[0]?.value ?? null);
}, [placementOptions, targetSectionId]);
const { openModal: openEditModal } = useModalAction(LazyWidgetEditModal);
const { openModal: openIntegrationModal } = useModalAction(IntegrationSelectModal);
const settings = useSettings();
@@ -155,14 +161,32 @@ const ItemSelectModalContent = ({
});
};
const notifyCreated = (itemId: string, name: string) => {
const notifyCreated = (updatedBoard: ReturnType<typeof createItem>, itemId: string, name: string) => {
const createdItem = updatedBoard?.items.find((item) => item.id === itemId);
if (!createdItem) {
showErrorNotification({
title: t("item.create.notification.error.title"),
message: t("item.create.notification.error.message"),
});
return false;
}
const actualSectionId =
createdItem.layouts.find(({ layoutId }) => layoutId === currentLayoutId)?.sectionId ??
createdItem.layouts[0]?.sectionId;
const actualDestination = placementOptions.find(({ value }) => value === actualSectionId)?.label;
const wasRelocated = targetSectionId !== null && actualSectionId !== targetSectionId && actualDestination;
const notificationId = `board-item-created:${itemId}`;
showSuccessNotification({
id: notificationId,
title: t("item.create.notification.success.title"),
message: (
<Group justify="space-between" wrap="nowrap">
<Text size="sm">{t("item.create.notification.success.message", { name })}</Text>
<Text size="sm">
{wasRelocated
? t("item.create.notification.success.relocatedMessage", { name, destination: actualDestination })
: t("item.create.notification.success.message", { name })}
</Text>
<Button
variant="subtle"
size="compact-xs"
@@ -177,6 +201,7 @@ const ItemSelectModalContent = ({
),
autoClose: 10_000,
});
return true;
};
const handleAddCustomWidget = async (customWidgetDefinition: NonNullable<typeof customWidgetDefs>[number]) => {
@@ -204,7 +229,7 @@ const ItemSelectModalContent = ({
integrationIds: [],
},
onSuccessfulEdit: ({ options: configuredOptions, advancedOptions }) => {
createItem({
const updatedBoard = createItem({
id: itemId,
kind: "customApi",
integrationIds: [],
@@ -212,7 +237,7 @@ const ItemSelectModalContent = ({
targetSectionId: targetSectionId ?? undefined,
advancedOptions,
});
notifyCreated(itemId, customWidgetDefinition.name);
notifyCreated(updatedBoard, itemId, customWidgetDefinition.name);
},
integrationData: [],
integrationSupport: false,
@@ -247,8 +272,8 @@ const ItemSelectModalContent = ({
ensureDataAsync: ensureIntegrationDataAsync,
});
const maxIntegrations = (definition as { maxIntegrations?: number }).maxIntegrations ?? Infinity;
const integrationIds = matchingIntegrations.slice(0, maxIntegrations).map((i) => i.id);
const maxIntegrations = "maxIntegrations" in definition ? (definition.maxIntegrations ?? Infinity) : Infinity;
const matchingIntegrationCount = Math.min(matchingIntegrations.length, maxIntegrations);
const itemId = createId();
const defaultOptions = reduceWidgetOptionsWithDefinition(definition, settings);
const openEditor = (
@@ -267,7 +292,7 @@ const ItemSelectModalContent = ({
integrationIds: selectedIntegrationIds,
},
onSuccessfulEdit: ({ options, integrationIds: newIntegrationIds, advancedOptions }) => {
createItem({
const updatedBoard = createItem({
id: itemId,
kind,
options,
@@ -275,7 +300,7 @@ const ItemSelectModalContent = ({
targetSectionId: targetSectionId ?? undefined,
advancedOptions,
});
notifyCreated(itemId, t(`widget.${kind}.name`));
if (!notifyCreated(updatedBoard, itemId, t(`widget.${kind}.name`))) return;
trackSetup("widget-completed", {
entryPoint: "board",
intent: kind,
@@ -295,7 +320,7 @@ const ItemSelectModalContent = ({
const integrationsRequired =
hasIntegrationSupport && (!("integrationsRequired" in definition) || definition.integrationsRequired !== false);
if (integrationsRequired && integrationIds.length === 0) {
if (integrationsRequired && matchingIntegrationCount === 0) {
trackSetup("dependency-blocked", {
entryPoint: "board",
intent: kind,
@@ -12,7 +12,15 @@ describe("SetupMetricProperties", () => {
"hasBoardContext",
"canResolveInline",
] satisfies (keyof SetupMetricProperties)[];
type ExpectedKey = (typeof allowedKeys)[number];
type ActualKey = keyof SetupMetricProperties;
const exactContract: [ActualKey] extends [ExpectedKey]
? [ExpectedKey] extends [ActualKey]
? true
: false
: false = true;
expect(exactContract).toBe(true);
expect(allowedKeys).not.toContain("url");
expect(allowedKeys).not.toContain("query");
expect(allowedKeys).not.toContain("recordId");
@@ -3,6 +3,8 @@
import { useCallback } from "react";
import { clientApi } from "@homarr/api/client";
import { showErrorNotification } from "@homarr/notifications";
import { useI18n } from "@homarr/translation/client";
export type SetupMetricEvent =
| "surface-opened"
@@ -30,7 +32,15 @@ export interface SetupMetricProperties {
* Never pass record IDs, names, URLs, search text, credentials, or provider responses here.
*/
export const useSetupAnalytics = () => {
const { mutate } = clientApi.analytics.trackFeature.useMutation();
const t = useI18n();
const { mutate } = clientApi.analytics.trackFeature.useMutation({
onError() {
showErrorNotification({
title: t("common.error"),
message: t("universalCreate.analyticsError"),
});
},
});
return useCallback(
(event: SetupMetricEvent, properties: SetupMetricProperties) => {
@@ -173,6 +173,6 @@ export const UniversalCreateModal = createModal<UniversalCreateModalProps>(({ ac
</Stack>
);
}).withOptions({
defaultTitle: "universalCreate.title",
defaultTitle: (t) => t("universalCreate.title"),
size: "lg",
});