fix: finish widget modernization audit
This commit is contained in:
1 parent
bbcfc505bc
commit
747ccdfa9e
27 files changed
+340
-115
No files matched your search
@@ -9,6 +9,7 @@ import type { UmamiVisitorStats } from "@homarr/integrations/types";
|
||||
import { useCurrentIntlLocale, useScopedI18n } from "@homarr/translation/client";
|
||||
|
||||
import { UmamiEventsContent } from "./umami-events-content";
|
||||
import { getUmamiLayout } from "./umami-layout";
|
||||
import { UmamiTopPagesContent, UmamiTopReferrersContent } from "./umami-top-list";
|
||||
import { formatTimeFrameLabel, formatXLabel, umamiQueryOptions } from "./umami-utils";
|
||||
import type { TimeFrame } from "./umami-utils";
|
||||
@@ -96,11 +97,11 @@ export function UmamiContent({
|
||||
|
||||
const isOverlay = chartStyle === "overlay" && hasEventSeries;
|
||||
const overlayBarSize = 16;
|
||||
const isAdvanced = displayMode === "advanced";
|
||||
const isDense = !isAdvanced && height < 120;
|
||||
const showXAxis = isAdvanced || height >= 140;
|
||||
const showSecondaryStats = isAdvanced || height >= 96;
|
||||
const showDetailedStats = isAdvanced || (width >= 260 && height >= 150);
|
||||
const { isDense, showXAxis, showSecondaryStats, showDetailedStats, stackAdvancedContent } = getUmamiLayout({
|
||||
width,
|
||||
height,
|
||||
displayMode,
|
||||
});
|
||||
|
||||
const selectedView =
|
||||
viewMode === "events" ? (
|
||||
@@ -181,22 +182,21 @@ export function UmamiContent({
|
||||
</SimpleGrid>
|
||||
);
|
||||
|
||||
const advancedContent =
|
||||
width < 900 ? (
|
||||
<ScrollArea h="100%">
|
||||
<Stack gap="md">
|
||||
<Box h={Math.max(280, Math.min(420, height - 160))}>{selectedView}</Box>
|
||||
{advancedLists}
|
||||
</Stack>
|
||||
</ScrollArea>
|
||||
) : (
|
||||
<SimpleGrid cols={2} spacing="md" h="100%" style={{ gridTemplateRows: "minmax(0, 1fr)" }}>
|
||||
<Box h="100%" mih={260}>
|
||||
{selectedView}
|
||||
</Box>
|
||||
<ScrollArea h="100%">{advancedLists}</ScrollArea>
|
||||
</SimpleGrid>
|
||||
);
|
||||
const advancedContent = stackAdvancedContent ? (
|
||||
<ScrollArea h="100%">
|
||||
<Stack gap="md">
|
||||
<Box h={Math.max(280, Math.min(420, height - 160))}>{selectedView}</Box>
|
||||
{advancedLists}
|
||||
</Stack>
|
||||
</ScrollArea>
|
||||
) : (
|
||||
<SimpleGrid cols={2} spacing="md" h="100%" style={{ gridTemplateRows: "minmax(0, 1fr)" }}>
|
||||
<Box h="100%" mih={260}>
|
||||
{selectedView}
|
||||
</Box>
|
||||
<ScrollArea h="100%">{advancedLists}</ScrollArea>
|
||||
</SimpleGrid>
|
||||
);
|
||||
|
||||
return (
|
||||
<Stack gap={isDense ? 2 : 4} p={isDense ? 4 : "xs"} h="100%" pos="relative">
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
import { describe, expect, test } from "vitest";
|
||||
|
||||
import { getUmamiLayout } from "./umami-layout";
|
||||
|
||||
describe("Umami layout", () => {
|
||||
test.each([
|
||||
{ width: 260, height: 119, property: "isDense" as const, expected: true },
|
||||
{ width: 260, height: 120, property: "isDense" as const, expected: false },
|
||||
{ width: 260, height: 139, property: "showXAxis" as const, expected: false },
|
||||
{ width: 260, height: 140, property: "showXAxis" as const, expected: true },
|
||||
{ width: 260, height: 95, property: "showSecondaryStats" as const, expected: false },
|
||||
{ width: 260, height: 96, property: "showSecondaryStats" as const, expected: true },
|
||||
{ width: 259, height: 150, property: "showDetailedStats" as const, expected: false },
|
||||
{ width: 260, height: 149, property: "showDetailedStats" as const, expected: false },
|
||||
{ width: 260, height: 150, property: "showDetailedStats" as const, expected: true },
|
||||
])("sets $property to $expected at $width x $height", ({ width, height, property, expected }) => {
|
||||
expect(getUmamiLayout({ width, height, displayMode: "compact" })[property]).toBe(expected);
|
||||
});
|
||||
|
||||
test("keeps advanced details visible and changes columns at 900px", () => {
|
||||
expect(getUmamiLayout({ width: 899, height: 80, displayMode: "advanced" })).toEqual({
|
||||
isDense: false,
|
||||
showXAxis: true,
|
||||
showSecondaryStats: true,
|
||||
showDetailedStats: true,
|
||||
stackAdvancedContent: true,
|
||||
});
|
||||
expect(getUmamiLayout({ width: 900, height: 80, displayMode: "advanced" }).stackAdvancedContent).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,16 @@
|
||||
interface UmamiLayoutInput {
|
||||
width: number;
|
||||
height: number;
|
||||
displayMode: "compact" | "advanced";
|
||||
}
|
||||
|
||||
export const getUmamiLayout = ({ width, height, displayMode }: UmamiLayoutInput) => {
|
||||
const isAdvanced = displayMode === "advanced";
|
||||
return {
|
||||
isDense: !isAdvanced && height < 120,
|
||||
showXAxis: isAdvanced || height >= 140,
|
||||
showSecondaryStats: isAdvanced || height >= 96,
|
||||
showDetailedStats: isAdvanced || (width >= 260 && height >= 150),
|
||||
stackAdvancedContent: isAdvanced && width < 900,
|
||||
};
|
||||
};
|
||||
Reference in new issue
Block a user