mirror of
https://github.com/ajnart/homarr.git
synced 2026-01-30 03:09:19 +01:00
* chore: add parent_section_id and change position to x and y_offset for sqlite section table * chore: rename existing positions to x_offset and y_offset * chore: add related mysql migration * chore: add missing height and width to section table * fix: missing width and height in migration copy script * fix: typecheck issues * fix: test not working caused by unsimilar schemas * wip: add dynamic section * refactor: improve structure of gridstack sections * feat: add rendering of dynamic sections * feat: add saving of moved sections * wip: add static row count, restrict min-width and height * chore: address pull request feedback * fix: format issues * fix: size calculation within dynamic sections * fix: on resize not called when min width or height is reached * fix: size of items while dragging is to big * chore: temporarly remove migration files * chore: readd migrations * fix: format and deepsource issues * chore: remove db_dev.sqlite file * chore: add *.sqlite to .gitignore * chore: address pull request feedback * feat: add dynamic section actions for adding and removing them
72 lines
1.9 KiB
TypeScript
72 lines
1.9 KiB
TypeScript
import { z } from "zod";
|
|
|
|
import { integrationKinds, widgetKinds } from "@homarr/definitions";
|
|
|
|
import { zodEnumFromArray } from "./enums";
|
|
|
|
export const integrationSchema = z.object({
|
|
id: z.string(),
|
|
kind: zodEnumFromArray(integrationKinds),
|
|
name: z.string(),
|
|
url: z.string(),
|
|
});
|
|
|
|
export type BoardItemIntegration = z.infer<typeof integrationSchema>;
|
|
|
|
export const itemAdvancedOptionsSchema = z.object({
|
|
customCssClasses: z.array(z.string()).default([]),
|
|
});
|
|
|
|
export type BoardItemAdvancedOptions = z.infer<typeof itemAdvancedOptionsSchema>;
|
|
|
|
export const sharedItemSchema = z.object({
|
|
id: z.string(),
|
|
xOffset: z.number(),
|
|
yOffset: z.number(),
|
|
height: z.number(),
|
|
width: z.number(),
|
|
integrationIds: z.array(z.string()),
|
|
advancedOptions: itemAdvancedOptionsSchema,
|
|
});
|
|
|
|
export const commonItemSchema = z
|
|
.object({
|
|
kind: zodEnumFromArray(widgetKinds),
|
|
options: z.record(z.unknown()),
|
|
})
|
|
.and(sharedItemSchema);
|
|
|
|
const createCategorySchema = <TItemSchema extends z.ZodTypeAny>(itemSchema: TItemSchema) =>
|
|
z.object({
|
|
id: z.string(),
|
|
name: z.string(),
|
|
kind: z.literal("category"),
|
|
yOffset: z.number(),
|
|
xOffset: z.number(),
|
|
items: z.array(itemSchema),
|
|
});
|
|
|
|
const createEmptySchema = <TItemSchema extends z.ZodTypeAny>(itemSchema: TItemSchema) =>
|
|
z.object({
|
|
id: z.string(),
|
|
kind: z.literal("empty"),
|
|
yOffset: z.number(),
|
|
xOffset: z.number(),
|
|
items: z.array(itemSchema),
|
|
});
|
|
|
|
const createDynamicSchema = <TItemSchema extends z.ZodTypeAny>(itemSchema: TItemSchema) =>
|
|
z.object({
|
|
id: z.string(),
|
|
kind: z.literal("dynamic"),
|
|
yOffset: z.number(),
|
|
xOffset: z.number(),
|
|
width: z.number(),
|
|
height: z.number(),
|
|
items: z.array(itemSchema),
|
|
parentSectionId: z.string(),
|
|
});
|
|
|
|
export const createSectionSchema = <TItemSchema extends z.ZodTypeAny>(itemSchema: TItemSchema) =>
|
|
z.union([createCategorySchema(itemSchema), createEmptySchema(itemSchema), createDynamicSchema(itemSchema)]);
|