mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-12-04 03:07:08 +03:00
compact converted 0.18 grid layouts in render order
0.18 stored every new grid tile at y 0 and left gaps behind removed cameras, relying on the grid's vertical compaction at render to stack tiles in render order (Birdseye, then camera order). The current grid renders without compaction and conversion only rescaled the coordinates, so upgraded groups with more than three tiles showed tiles on top of each other, often covering Birdseye, and gaps that 0.18 never displayed. Conversion now sorts tiles by render order and compacts them once, so each layout opens as 0.18 showed it.
This commit is contained in:
@@ -13,7 +13,8 @@
|
|||||||
* Tiles measured in separate round-trips can straddle that reflow and disagree
|
* Tiles measured in separate round-trips can straddle that reflow and disagree
|
||||||
* on scale, so cameraBoxes() takes every measurement in one evaluate.
|
* on scale, so cameraBoxes() takes every measurement in one evaluate.
|
||||||
*
|
*
|
||||||
* Used by live-grid-aspect-modes.spec.ts and masonry-live-grid.spec.ts.
|
* Used by live-grid-aspect-modes.spec.ts, live-grid-legacy-layouts.spec.ts and
|
||||||
|
* masonry-live-grid.spec.ts.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { expect, type Page } from "@playwright/test";
|
import { expect, type Page } from "@playwright/test";
|
||||||
|
|||||||
@@ -45,6 +45,11 @@ export class LivePage extends BasePage {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Birdseye tile on the draggable grid, the one without a camera card. */
|
||||||
|
get birdseyeTile(): Locator {
|
||||||
|
return this.page.locator(".react-grid-item:not(:has([data-camera]))");
|
||||||
|
}
|
||||||
|
|
||||||
/** Edit-layout toggle on the draggable grid (desktop, custom groups). */
|
/** Edit-layout toggle on the draggable grid (desktop, custom groups). */
|
||||||
get editLayoutButton(): Locator {
|
get editLayoutButton(): Locator {
|
||||||
return this.page.getByTestId("toggle-edit-layout");
|
return this.page.getByTestId("toggle-edit-layout");
|
||||||
|
|||||||
@@ -89,8 +89,8 @@ test.describe("Live grid aspect modes @critical", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// 0.17/0.18 shape: bare array on a 12-column grid, 4x4 standard tiles.
|
// 0.17/0.18 shape: bare array on a 12-column grid, 4x4 standard tiles.
|
||||||
// backyard was manually resized to 8x8 and sits beside front_door's column,
|
// backyard was manually resized to 8x8 and sits beside front_door's column.
|
||||||
// front_door is a standard tile on the row below.
|
// front_door is stored on the row below, but 0.18 compacted it to the top.
|
||||||
const key = await persistedLayoutKey(frigateApp.page, GROUP);
|
const key = await persistedLayoutKey(frigateApp.page, GROUP);
|
||||||
await seedLayout(frigateApp.page, key, [
|
await seedLayout(frigateApp.page, key, [
|
||||||
{ i: "backyard", x: 4, y: 0, w: 8, h: 8, moved: false, static: false },
|
{ i: "backyard", x: 4, y: 0, w: 8, h: 8, moved: false, static: false },
|
||||||
@@ -127,21 +127,21 @@ test.describe("Live grid aspect modes @critical", () => {
|
|||||||
stored.layout.find((i: LayoutItem) => i.i === "front_door"),
|
stored.layout.find((i: LayoutItem) => i.i === "front_door"),
|
||||||
).toMatchObject({
|
).toMatchObject({
|
||||||
x: 0,
|
x: 0,
|
||||||
y: 144,
|
y: 0,
|
||||||
w: 32,
|
w: 32,
|
||||||
h: 72,
|
h: 72,
|
||||||
});
|
});
|
||||||
|
|
||||||
// arrangement on screen: backyard indented, front_door below it
|
// arrangement on screen: front_door top-left, backyard beside it
|
||||||
const { backyard, front_door: frontDoor } = await cameraBoxes(
|
const { backyard, front_door: frontDoor } = await cameraBoxes(
|
||||||
frigateApp.page,
|
frigateApp.page,
|
||||||
["backyard", "front_door"] as const,
|
["backyard", "front_door"] as const,
|
||||||
);
|
);
|
||||||
expect(backyard.x).toBeGreaterThan(frontDoor.x + frontDoor.w / 2);
|
expect(backyard.x).toBeGreaterThan(frontDoor.x + frontDoor.w / 2);
|
||||||
expect(frontDoor.y).toBeGreaterThan(backyard.y + backyard.h / 2);
|
expect(Math.abs(frontDoor.y - backyard.y)).toBeLessThan(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("conversion is a pure scale, so odd sizes and positions survive", async ({
|
test("conversion scales odd sizes and keeps tiles adjacent", async ({
|
||||||
frigateApp,
|
frigateApp,
|
||||||
}) => {
|
}) => {
|
||||||
await frigateApp.goto(`/?group=${GROUP}`);
|
await frigateApp.goto(`/?group=${GROUP}`);
|
||||||
@@ -175,8 +175,9 @@ test.describe("Live grid aspect modes @critical", () => {
|
|||||||
)!;
|
)!;
|
||||||
const backyard = stored.layout.find((i: LayoutItem) => i.i === "backyard")!;
|
const backyard = stored.layout.find((i: LayoutItem) => i.i === "backyard")!;
|
||||||
|
|
||||||
expect(frontDoor).toMatchObject({ x: 0, y: 54, w: 40, h: 90 });
|
// the empty rows above both tiles compact away, as they did in 0.18
|
||||||
expect(backyard).toMatchObject({ x: 40, y: 54, w: 56, h: 90 });
|
expect(frontDoor).toMatchObject({ x: 0, y: 0, w: 40, h: 90 });
|
||||||
|
expect(backyard).toMatchObject({ x: 40, y: 0, w: 56, h: 90 });
|
||||||
|
|
||||||
// still adjacent, still inside the grid, still not overlapping
|
// still adjacent, still inside the grid, still not overlapping
|
||||||
expect(frontDoor.x + frontDoor.w).toBe(backyard.x);
|
expect(frontDoor.x + frontDoor.w).toBe(backyard.x);
|
||||||
|
|||||||
@@ -0,0 +1,157 @@
|
|||||||
|
/**
|
||||||
|
* Live grid layouts saved by 0.18.
|
||||||
|
*
|
||||||
|
* 0.18 stored every new tile at y 0 and let the grid compact the tiles at
|
||||||
|
* render, in render order (Birdseye, then camera order). Its stored layouts
|
||||||
|
* can share cells and hold gaps that never showed. Conversion compacts the same
|
||||||
|
* way, so each layout opens exactly as 0.18 displayed it.
|
||||||
|
*
|
||||||
|
* Each stored layout below was captured from 0.18's IndexedDB, and each
|
||||||
|
* expected cell is where 0.18 rendered that tile.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { test, expect } from "../fixtures/frigate-test";
|
||||||
|
import { BASE_CONFIG } from "../fixtures/mock-data/config";
|
||||||
|
import { LivePage } from "../pages/live.page";
|
||||||
|
import {
|
||||||
|
persistedLayoutKey,
|
||||||
|
readLayout,
|
||||||
|
seedLayout,
|
||||||
|
type LayoutItem,
|
||||||
|
} from "../helpers/grid-layout";
|
||||||
|
|
||||||
|
// one 0.18 cell is 32 columns by 72 rows on the current grid
|
||||||
|
const CELL_W = 32;
|
||||||
|
const CELL_H = 72;
|
||||||
|
|
||||||
|
const tile = (i: string, x: number, y: number) => ({ i, x, y, w: 4, h: 4 });
|
||||||
|
|
||||||
|
type Scenario = {
|
||||||
|
name: string;
|
||||||
|
cameras: string[];
|
||||||
|
stored: LayoutItem[];
|
||||||
|
rendered: Record<string, [number, number]>;
|
||||||
|
};
|
||||||
|
|
||||||
|
const SCENARIOS: Scenario[] = [
|
||||||
|
{
|
||||||
|
name: "a group created with Birdseye",
|
||||||
|
cameras: ["birdseye", "front_door", "backyard", "garage"],
|
||||||
|
stored: [
|
||||||
|
tile("birdseye", 0, 0),
|
||||||
|
tile("front_door", 4, 0),
|
||||||
|
tile("backyard", 8, 0),
|
||||||
|
tile("garage", 0, 0),
|
||||||
|
],
|
||||||
|
rendered: {
|
||||||
|
birdseye: [0, 0],
|
||||||
|
front_door: [1, 0],
|
||||||
|
backyard: [2, 0],
|
||||||
|
garage: [0, 1],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Birdseye and a camera added after a drag",
|
||||||
|
cameras: [
|
||||||
|
"front_door",
|
||||||
|
"backyard",
|
||||||
|
"garage",
|
||||||
|
"porch",
|
||||||
|
"driveway",
|
||||||
|
"birdseye",
|
||||||
|
],
|
||||||
|
stored: [
|
||||||
|
tile("front_door", 0, 4),
|
||||||
|
tile("backyard", 4, 0),
|
||||||
|
tile("garage", 8, 0),
|
||||||
|
tile("porch", 0, 0),
|
||||||
|
tile("driveway", 4, 0),
|
||||||
|
tile("birdseye", 0, 0),
|
||||||
|
],
|
||||||
|
rendered: {
|
||||||
|
birdseye: [0, 0],
|
||||||
|
backyard: [1, 0],
|
||||||
|
garage: [2, 0],
|
||||||
|
porch: [0, 1],
|
||||||
|
driveway: [1, 1],
|
||||||
|
front_door: [0, 2],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "a camera added ahead of the others in camera order",
|
||||||
|
cameras: ["backyard", "garage", "porch", "driveway", "front_door"],
|
||||||
|
stored: [
|
||||||
|
tile("backyard", 0, 0),
|
||||||
|
tile("garage", 4, 0),
|
||||||
|
tile("porch", 8, 0),
|
||||||
|
tile("driveway", 0, 0),
|
||||||
|
tile("front_door", 0, 0),
|
||||||
|
],
|
||||||
|
rendered: {
|
||||||
|
front_door: [0, 0],
|
||||||
|
garage: [1, 0],
|
||||||
|
porch: [2, 0],
|
||||||
|
backyard: [0, 1],
|
||||||
|
driveway: [0, 2],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "a camera removed after a drag",
|
||||||
|
cameras: ["front_door", "backyard", "garage"],
|
||||||
|
stored: [
|
||||||
|
tile("front_door", 0, 4),
|
||||||
|
tile("backyard", 4, 0),
|
||||||
|
tile("garage", 8, 0),
|
||||||
|
],
|
||||||
|
rendered: {
|
||||||
|
front_door: [0, 0],
|
||||||
|
backyard: [1, 0],
|
||||||
|
garage: [2, 0],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const frontDoor = BASE_CONFIG.cameras.front_door;
|
||||||
|
|
||||||
|
test.describe("Live grid 0.18 layouts @critical", () => {
|
||||||
|
test.skip(
|
||||||
|
({ frigateApp }) => frigateApp.isMobile,
|
||||||
|
"Draggable grid is desktop-only",
|
||||||
|
);
|
||||||
|
|
||||||
|
SCENARIOS.forEach(({ name, cameras, stored, rendered }, index) => {
|
||||||
|
test(`opens ${name} as 0.18 showed it`, async ({ frigateApp }) => {
|
||||||
|
const group = `legacy${index}`;
|
||||||
|
await frigateApp.installDefaults({
|
||||||
|
config: {
|
||||||
|
cameras: {
|
||||||
|
porch: { ...frontDoor, name: "porch" },
|
||||||
|
driveway: { ...frontDoor, name: "driveway" },
|
||||||
|
},
|
||||||
|
camera_groups: { [group]: { cameras, icon: "LuCar", order: 1 } },
|
||||||
|
},
|
||||||
|
});
|
||||||
|
await frigateApp.goto(`/?group=${group}`);
|
||||||
|
const key = await persistedLayoutKey(frigateApp.page, group);
|
||||||
|
await seedLayout(frigateApp.page, key, stored);
|
||||||
|
await frigateApp.page.reload();
|
||||||
|
|
||||||
|
await expect
|
||||||
|
.poll(async () => (await readLayout(frigateApp.page, key))?.version, {
|
||||||
|
timeout: 10_000,
|
||||||
|
})
|
||||||
|
.toBe(2);
|
||||||
|
|
||||||
|
const layout = (await readLayout(frigateApp.page, key))!.layout;
|
||||||
|
const cells = Object.fromEntries(
|
||||||
|
layout.map((item) => [item.i, [item.x / CELL_W, item.y / CELL_H]]),
|
||||||
|
);
|
||||||
|
expect(cells).toEqual(rendered);
|
||||||
|
|
||||||
|
if (cameras.includes("birdseye")) {
|
||||||
|
await new LivePage(frigateApp.page, true).birdseyeTile.click();
|
||||||
|
await expect(frigateApp.page).toHaveURL(/#birdseye/);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -18,7 +18,11 @@ import {
|
|||||||
LayoutItem,
|
LayoutItem,
|
||||||
ResponsiveGridLayout as Responsive,
|
ResponsiveGridLayout as Responsive,
|
||||||
} from "react-grid-layout";
|
} from "react-grid-layout";
|
||||||
import { aspectRatio, getCompactor } from "react-grid-layout/core";
|
import {
|
||||||
|
aspectRatio,
|
||||||
|
getCompactor,
|
||||||
|
verticalCompactor,
|
||||||
|
} from "react-grid-layout/core";
|
||||||
import "react-grid-layout/css/styles.css";
|
import "react-grid-layout/css/styles.css";
|
||||||
import "react-resizable/css/styles.css";
|
import "react-resizable/css/styles.css";
|
||||||
import {
|
import {
|
||||||
@@ -311,10 +315,17 @@ export default function DraggableGridLayout({
|
|||||||
[layoutAspects],
|
[layoutAspects],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const cameraNames = useMemo(
|
||||||
|
() =>
|
||||||
|
includeBirdseye && birdseyeConfig?.enabled
|
||||||
|
? ["birdseye", ...cameras.map((camera) => camera?.name || "")]
|
||||||
|
: cameras.map((camera) => camera?.name || ""),
|
||||||
|
[cameras, includeBirdseye, birdseyeConfig],
|
||||||
|
);
|
||||||
|
|
||||||
// Rescale a pre-masonry layout onto the current grid. Both axes scale by a
|
// Rescale a pre-masonry layout onto the current grid. Both axes scale by a
|
||||||
// constant, so tiles the user resized keep their size and their arrangement
|
// constant, so tiles the user resized keep their size. Only meaningful in
|
||||||
// stays intact. Only meaningful in bucketed mode, where a tile still has the
|
// bucketed mode, where a tile still has the shape those coordinates assumed.
|
||||||
// shape those coordinates assumed.
|
|
||||||
const convertLegacyLayout = useCallback(
|
const convertLegacyLayout = useCallback(
|
||||||
(stored: unknown): Layout | undefined => {
|
(stored: unknown): Layout | undefined => {
|
||||||
if (naturalAspectLayout || !Array.isArray(stored) || !stored.length) {
|
if (naturalAspectLayout || !Array.isArray(stored) || !stored.length) {
|
||||||
@@ -349,9 +360,17 @@ export default function DraggableGridLayout({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return converted;
|
// 0.18 stored new tiles at y 0 and compacted the grid at render, in
|
||||||
|
// render order. Compacting the same way reproduces what 0.18 showed.
|
||||||
|
|
||||||
|
return verticalCompactor.compact(
|
||||||
|
converted
|
||||||
|
.filter((item) => cameraNames.includes(item.i))
|
||||||
|
.sort((a, b) => cameraNames.indexOf(a.i) - cameraNames.indexOf(b.i)),
|
||||||
|
GRID_COLS,
|
||||||
|
);
|
||||||
},
|
},
|
||||||
[naturalAspectLayout],
|
[naturalAspectLayout, cameraNames],
|
||||||
);
|
);
|
||||||
|
|
||||||
const generateLayout = useCallback(
|
const generateLayout = useCallback(
|
||||||
@@ -360,11 +379,6 @@ export default function DraggableGridLayout({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const cameraNames =
|
|
||||||
includeBirdseye && birdseyeConfig?.enabled
|
|
||||||
? ["birdseye", ...cameras.map((camera) => camera?.name || "")]
|
|
||||||
: cameras.map((camera) => camera?.name || "");
|
|
||||||
|
|
||||||
const existing: LayoutItem[] = baseLayout
|
const existing: LayoutItem[] = baseLayout
|
||||||
? baseLayout.filter((layout) => cameraNames.includes(layout.i))
|
? baseLayout.filter((layout) => cameraNames.includes(layout.i))
|
||||||
: [];
|
: [];
|
||||||
@@ -426,7 +440,7 @@ export default function DraggableGridLayout({
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
[cameras, isGridLayoutLoaded, includeBirdseye, birdseyeConfig, dimsFor],
|
[cameraNames, isGridLayoutLoaded, dimsFor],
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user