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:
@@ -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/);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user