feat: refine configurable header and branding

This commit is contained in:
ajnart committed 2026-08-24 00:35:53 +02:00
1 parent 803d590a16
commit f8d3d5893a
47 files changed
+234 -8634

No files matched your search

+9 -19
View File
@@ -19,7 +19,6 @@ import {
items,
users,
} from "@homarr/db/schema";
import { getServerSettingByKeyAsync } from "@homarr/db/queries";
import {
assistantProviderCanUseOpenRouterServerTools,
assistantProviderIds,
@@ -38,13 +37,6 @@ import { createTRPCRouter, isDemoMode, permissionRequiredProcedure, protectedPro
import { boardRouter, getHomeIdBoardAsync } from "./board";
const adminProcedure = permissionRequiredProcedure.requiresPermission("admin");
const assistantEnabledProcedure = protectedProcedure.use(async ({ ctx, next }) => {
const featureControls = await getServerSettingByKeyAsync(ctx.db, "featureControls");
if (!featureControls.assistantEnabled) {
throw new TRPCError({ code: "NOT_FOUND", message: "Assistant is disabled." });
}
return next({ ctx });
});
const configurationId = "default";
const providerSchema = z.enum(assistantProviderIds);
@@ -461,8 +453,6 @@ const addFeedbackToMessageContent = (serializedContent: string, type: "positive"
export const assistantRouter = createTRPCRouter({
getAvailability: protectedProcedure.query(async ({ ctx }) => {
const featureControls = await getServerSettingByKeyAsync(ctx.db, "featureControls");
if (!featureControls.assistantEnabled) return { enabled: false };
if (isDemoMode) {
return { enabled: true };
}
@@ -475,11 +465,11 @@ export const assistantRouter = createTRPCRouter({
};
}),
getContextEntities: assistantEnabledProcedure.query(async ({ ctx }) => {
getContextEntities: protectedProcedure.query(async ({ ctx }) => {
return await getAssistantContextEntitiesAsync(ctx);
}),
getModelCapabilities: assistantEnabledProcedure
getModelCapabilities: protectedProcedure
.input(z.object({ modelId: z.string().trim().min(1).max(256).optional() }).optional())
.query(async ({ ctx, input }) => {
const configuration = await getConfigurationAsync(ctx.db);
@@ -496,7 +486,7 @@ export const assistantRouter = createTRPCRouter({
};
}),
getRuntimeOptions: assistantEnabledProcedure.query(async ({ ctx }) => {
getRuntimeOptions: protectedProcedure.query(async ({ ctx }) => {
const configuration = await getConfigurationAsync(ctx.db);
if (isDemoMode) {
return {
@@ -694,7 +684,7 @@ export const assistantRouter = createTRPCRouter({
});
}),
createThread: assistantEnabledProcedure
createThread: protectedProcedure
.input(z.object({ localId: z.string().max(128).optional() }).optional())
.mutation(async ({ ctx }) => {
const configuration = await getConfigurationAsync(ctx.db);
@@ -710,7 +700,7 @@ export const assistantRouter = createTRPCRouter({
return { id };
}),
updateThreadModel: assistantEnabledProcedure
updateThreadModel: protectedProcedure
.input(z.object({ threadId: z.string().max(64), modelId: z.string().trim().min(1).max(256) }))
.mutation(async ({ ctx, input }) => {
const [thread, configuration] = await Promise.all([
@@ -755,7 +745,7 @@ export const assistantRouter = createTRPCRouter({
};
}),
getGenerationTelemetry: assistantEnabledProcedure
getGenerationTelemetry: protectedProcedure
.input(
z.object({
threadId: z.string().max(64),
@@ -801,7 +791,7 @@ export const assistantRouter = createTRPCRouter({
};
}),
renameThread: assistantEnabledProcedure
renameThread: protectedProcedure
.input(z.object({ threadId: z.string().max(64), title: z.string().trim().min(1).max(120) }))
.mutation(async ({ ctx, input }) => {
await ownedThreadAsync(ctx.db, input.threadId, ctx.session.user.id);
@@ -818,7 +808,7 @@ export const assistantRouter = createTRPCRouter({
await ctx.db.delete(assistantThreads).where(eq(assistantThreads.id, input.threadId));
}),
appendMessage: assistantEnabledProcedure
appendMessage: protectedProcedure
.input(
z.object({
threadId: z.string().max(64),
@@ -879,7 +869,7 @@ export const assistantRouter = createTRPCRouter({
.where(eq(assistantThreads.id, thread.id));
}),
submitFeedback: assistantEnabledProcedure
submitFeedback: protectedProcedure
.input(
z.object({
threadId: z.string().max(64),
-12
View File
@@ -14,9 +14,7 @@ import {
authBrandingSchema,
brandingServerSettingsSchema,
defaultServerSettingsKeys,
featureControlsServerSettingsSchema,
parseBrandingSettings,
parseFeatureControls,
} from "@homarr/server-settings";
import { createTRPCRouter, permissionRequiredProcedure, publicProcedure } from "../trpc";
@@ -37,8 +35,6 @@ const legacyAuthBrandingUpdateSchema = z.object({
showCustomLogoOnLogin: z.boolean().optional(),
showCustomGreetingOnLogin: z.boolean().optional(),
});
const featureControlsServerSettingsUpdateSchema = featureControlsServerSettingsSchema.partial();
export const serverSettingsRouter = createTRPCRouter({
getCulture: publicProcedure.query(async ({ ctx }) => {
return await getServerSettingByKeyAsync(ctx.db, "culture");
@@ -137,14 +133,6 @@ export const serverSettingsRouter = createTRPCRouter({
await updateServerSettingByKeyAsync(ctx.db, "branding", value);
return;
}
if (input.settingsKey === "featureControls") {
const current = await getServerSettingByKeyAsync(ctx.db, "featureControls");
const parsedInput = featureControlsServerSettingsUpdateSchema.parse(input.value);
const value = parseFeatureControls({ ...current, ...parsedInput });
await updateServerSettingByKeyAsync(ctx.db, "featureControls", value);
return;
}
const current = await getServerSettingByKeyAsync(ctx.db, input.settingsKey);
await updateServerSettingByKeyAsync(ctx.db, input.settingsKey, {
...current,
@@ -1 +1 @@
ALTER TABLE `user` ADD `header_preferences` text DEFAULT ('{"version":3,"visible":true,"searchDisplay":"input","zones":{"left":[{"type":"builtin","id":"logo"}],"center":[{"type":"builtin","id":"search"}],"right":[{"type":"builtin","id":"user"}]}}') NOT NULL;
ALTER TABLE `user` ADD `header_preferences` text DEFAULT ('{"version":3,"visible":true,"searchDisplay":"input","zones":{"left":[{"type":"builtin","id":"logo"}],"center":[{"type":"builtin","id":"search"}],"right":[{"type":"builtin","id":"user"},{"type":"builtin","id":"boardEdit"},{"type":"builtin","id":"boardSettings"}]}}') NOT NULL;
@@ -1,2 +0,0 @@
INSERT IGNORE INTO `serverSetting` (`setting_key`, `value`)
VALUES ('featureControls', '{"json":{"assistantEnabled":true,"boardSwitcherEnabled":true,"widgetContextMenuEnabled":true}}');
@@ -2656,7 +2656,7 @@
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "('{\"version\":3,\"visible\":true,\"searchDisplay\":\"input\",\"zones\":{\"left\":[{\"type\":\"builtin\",\"id\":\"logo\"}],\"center\":[{\"type\":\"builtin\",\"id\":\"search\"}],\"right\":[{\"type\":\"builtin\",\"id\":\"user\"}]}}')"
"default": "('{\"version\":3,\"visible\":true,\"searchDisplay\":\"input\",\"zones\":{\"left\":[{\"type\":\"builtin\",\"id\":\"logo\"}],\"center\":[{\"type\":\"builtin\",\"id\":\"search\"}],\"right\":[{\"type\":\"builtin\",\"id\":\"user\"},{\"type\":\"builtin\",\"id\":\"boardEdit\"},{\"type\":\"builtin\",\"id\":\"boardSettings\"}]}}')"
},
"completed_manage_tour": {
"name": "completed_manage_tour",
@@ -2656,7 +2656,7 @@
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "('{\"version\":3,\"visible\":true,\"searchDisplay\":\"input\",\"zones\":{\"left\":[{\"type\":\"builtin\",\"id\":\"logo\"}],\"center\":[{\"type\":\"builtin\",\"id\":\"search\"}],\"right\":[{\"type\":\"builtin\",\"id\":\"user\"}]}}')"
"default": "('{\"version\":3,\"visible\":true,\"searchDisplay\":\"input\",\"zones\":{\"left\":[{\"type\":\"builtin\",\"id\":\"logo\"}],\"center\":[{\"type\":\"builtin\",\"id\":\"search\"}],\"right\":[{\"type\":\"builtin\",\"id\":\"user\"},{\"type\":\"builtin\",\"id\":\"boardEdit\"},{\"type\":\"builtin\",\"id\":\"boardSettings\"}]}}')"
},
"completed_manage_tour": {
"name": "completed_manage_tour",
File diff suppressed because it is too large. Load diff
@@ -351,13 +351,6 @@
"when": 1787496053718,
"tag": "0049_add_server_branding_settings",
"breakpoints": true
},
{
"idx": 50,
"version": "5",
"when": 1787496060001,
"tag": "0050_add_feature_controls_server_setting",
"breakpoints": true
}
]
}
@@ -1 +1 @@
ALTER TABLE "user" ADD COLUMN "header_preferences" text DEFAULT '{"version":3,"visible":true,"searchDisplay":"input","zones":{"left":[{"type":"builtin","id":"logo"}],"center":[{"type":"builtin","id":"search"}],"right":[{"type":"builtin","id":"user"}]}}' NOT NULL;
ALTER TABLE "user" ADD COLUMN "header_preferences" text DEFAULT '{"version":3,"visible":true,"searchDisplay":"input","zones":{"left":[{"type":"builtin","id":"logo"}],"center":[{"type":"builtin","id":"search"}],"right":[{"type":"builtin","id":"user"},{"type":"builtin","id":"boardEdit"},{"type":"builtin","id":"boardSettings"}]}}' NOT NULL;
@@ -1,3 +0,0 @@
INSERT INTO "serverSetting" ("setting_key", "value")
VALUES ('featureControls', '{"json":{"assistantEnabled":true,"boardSwitcherEnabled":true,"widgetContextMenuEnabled":true}}')
ON CONFLICT ("setting_key") DO NOTHING;
@@ -2521,7 +2521,7 @@
"type": "text",
"primaryKey": false,
"notNull": true,
"default": "'{\"version\":3,\"visible\":true,\"searchDisplay\":\"input\",\"zones\":{\"left\":[{\"type\":\"builtin\",\"id\":\"logo\"}],\"center\":[{\"type\":\"builtin\",\"id\":\"search\"}],\"right\":[{\"type\":\"builtin\",\"id\":\"user\"}]}}'"
"default": "'{\"version\":3,\"visible\":true,\"searchDisplay\":\"input\",\"zones\":{\"left\":[{\"type\":\"builtin\",\"id\":\"logo\"}],\"center\":[{\"type\":\"builtin\",\"id\":\"search\"}],\"right\":[{\"type\":\"builtin\",\"id\":\"user\"},{\"type\":\"builtin\",\"id\":\"boardEdit\"},{\"type\":\"builtin\",\"id\":\"boardSettings\"}]}}'"
},
"completed_manage_tour": {
"name": "completed_manage_tour",
@@ -2521,7 +2521,7 @@
"type": "text",
"primaryKey": false,
"notNull": true,
"default": "'{\"version\":3,\"visible\":true,\"searchDisplay\":\"input\",\"zones\":{\"left\":[{\"type\":\"builtin\",\"id\":\"logo\"}],\"center\":[{\"type\":\"builtin\",\"id\":\"search\"}],\"right\":[{\"type\":\"builtin\",\"id\":\"user\"}]}}'"
"default": "'{\"version\":3,\"visible\":true,\"searchDisplay\":\"input\",\"zones\":{\"left\":[{\"type\":\"builtin\",\"id\":\"logo\"}],\"center\":[{\"type\":\"builtin\",\"id\":\"search\"}],\"right\":[{\"type\":\"builtin\",\"id\":\"user\"},{\"type\":\"builtin\",\"id\":\"boardEdit\"},{\"type\":\"builtin\",\"id\":\"boardSettings\"}]}}'"
},
"completed_manage_tour": {
"name": "completed_manage_tour",
File diff suppressed because it is too large. Load diff
@@ -113,13 +113,6 @@
"when": 1787496053659,
"tag": "0015_add_server_branding_settings",
"breakpoints": true
},
{
"idx": 16,
"version": "7",
"when": 1787496060002,
"tag": "0016_add_feature_controls_server_setting",
"breakpoints": true
}
]
}
@@ -1 +1 @@
ALTER TABLE `user` ADD `header_preferences` text DEFAULT '{"version":3,"visible":true,"searchDisplay":"input","zones":{"left":[{"type":"builtin","id":"logo"}],"center":[{"type":"builtin","id":"search"}],"right":[{"type":"builtin","id":"user"}]}}' NOT NULL;
ALTER TABLE `user` ADD `header_preferences` text DEFAULT '{"version":3,"visible":true,"searchDisplay":"input","zones":{"left":[{"type":"builtin","id":"logo"}],"center":[{"type":"builtin","id":"search"}],"right":[{"type":"builtin","id":"user"},{"type":"builtin","id":"boardEdit"},{"type":"builtin","id":"boardSettings"}]}}' NOT NULL;
@@ -1,3 +0,0 @@
INSERT INTO `serverSetting` (`setting_key`, `value`)
VALUES ('featureControls', '{"json":{"assistantEnabled":true,"boardSwitcherEnabled":true,"widgetContextMenuEnabled":true}}')
ON CONFLICT (`setting_key`) DO NOTHING;
@@ -2551,7 +2551,7 @@
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "'{\"version\":3,\"visible\":true,\"searchDisplay\":\"input\",\"zones\":{\"left\":[{\"type\":\"builtin\",\"id\":\"logo\"}],\"center\":[{\"type\":\"builtin\",\"id\":\"search\"}],\"right\":[{\"type\":\"builtin\",\"id\":\"user\"}]}}'"
"default": "'{\"version\":3,\"visible\":true,\"searchDisplay\":\"input\",\"zones\":{\"left\":[{\"type\":\"builtin\",\"id\":\"logo\"}],\"center\":[{\"type\":\"builtin\",\"id\":\"search\"}],\"right\":[{\"type\":\"builtin\",\"id\":\"user\"},{\"type\":\"builtin\",\"id\":\"boardEdit\"},{\"type\":\"builtin\",\"id\":\"boardSettings\"}]}}'"
},
"completed_manage_tour": {
"name": "completed_manage_tour",
@@ -2551,7 +2551,7 @@
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "'{\"version\":3,\"visible\":true,\"searchDisplay\":\"input\",\"zones\":{\"left\":[{\"type\":\"builtin\",\"id\":\"logo\"}],\"center\":[{\"type\":\"builtin\",\"id\":\"search\"}],\"right\":[{\"type\":\"builtin\",\"id\":\"user\"}]}}'"
"default": "'{\"version\":3,\"visible\":true,\"searchDisplay\":\"input\",\"zones\":{\"left\":[{\"type\":\"builtin\",\"id\":\"logo\"}],\"center\":[{\"type\":\"builtin\",\"id\":\"search\"}],\"right\":[{\"type\":\"builtin\",\"id\":\"user\"},{\"type\":\"builtin\",\"id\":\"boardEdit\"},{\"type\":\"builtin\",\"id\":\"boardSettings\"}]}}'"
},
"completed_manage_tour": {
"name": "completed_manage_tour",
File diff suppressed because it is too large. Load diff
@@ -337,13 +337,6 @@
"when": 1787496053654,
"tag": "0047_add_server_branding_settings",
"breakpoints": true
},
{
"idx": 48,
"version": "6",
"when": 1787496060000,
"tag": "0048_add_feature_controls_server_setting",
"breakpoints": true
}
]
}
+1 -15
View File
@@ -1,12 +1,7 @@
import SuperJSON from "superjson";
import type { ServerSettings } from "@homarr/server-settings";
import {
defaultServerSettings,
defaultServerSettingsKeys,
parseBrandingSettings,
parseFeatureControls,
} from "@homarr/server-settings";
import { defaultServerSettings, defaultServerSettingsKeys, parseBrandingSettings } from "@homarr/server-settings";
import type { Database } from "..";
import { eq } from "..";
@@ -28,11 +23,6 @@ export const getServerSettingsAsync = async (db: Database) => {
acc[settingKey] = parseBrandingSettings(parsedSetting) as never;
return acc;
}
if (settingKey === "featureControls") {
acc[settingKey] = parseFeatureControls(parsedSetting) as never;
return acc;
}
acc[settingKey] = {
...defaultServerSettings[settingKey],
...parsedSetting,
@@ -54,10 +44,6 @@ export const getServerSettingByKeyAsync = async <TKey extends keyof ServerSettin
if (key === "branding") {
return parseBrandingSettings(parsedSetting) as ServerSettings[TKey];
}
if (key === "featureControls") {
return parseFeatureControls(parsedSetting) as ServerSettings[TKey];
}
return {
...defaultServerSettings[key],
...parsedSetting,
@@ -1,6 +1,6 @@
"use client";
import type { FocusEventHandler, KeyboardEventHandler } from "react";
import type { FocusEventHandler, KeyboardEventHandler, ReactNode } from "react";
import { startTransition, useEffect, useMemo, useState } from "react";
import {
ActionIcon,
@@ -48,6 +48,7 @@ interface IconPickerProps {
onFocus?: FocusEventHandler;
onBlur?: FocusEventHandler;
label?: string;
description?: ReactNode;
placeholder?: string;
suggestedSearch?: string | null;
withAsterisk?: boolean;
@@ -63,6 +64,7 @@ export const IconPicker = ({
onBlur,
withAsterisk = true,
label,
description,
placeholder,
suggestedSearch,
}: IconPickerProps) => {
@@ -272,6 +274,7 @@ export const IconPicker = ({
(query.data
? tCommon("iconPicker.header", { countIcons: String(query.data.countIcons) })
: tCommon("iconPicker.headerLoading"));
const inputDescription = description === undefined ? tCommon("iconPicker.description") : description;
return (
<Combobox
@@ -359,7 +362,7 @@ export const IconPicker = ({
withAsterisk={withAsterisk}
error={error}
label={label ?? tCommon("iconPicker.label")}
description={tCommon("iconPicker.description")}
description={inputDescription}
styles={{
description: { color: "var(--mantine-color-text)" },
input: { color: "var(--mantine-color-text)" },
-25
View File
@@ -9,7 +9,6 @@ export const defaultServerSettingsKeys = [
"user",
"appearance",
"branding",
"featureControls",
"culture",
"search",
] as const;
@@ -25,13 +24,6 @@ export const authBrandingSchema = z.object({
showGreeting: z.boolean(),
});
export const featureControlsServerSettingsSchema = z.object({
assistantEnabled: z.boolean(),
boardSwitcherEnabled: z.boolean(),
widgetContextMenuEnabled: z.boolean(),
});
export type FeatureControlsSettings = z.infer<typeof featureControlsServerSettingsSchema>;
const brandingImageUrlSchema = z
.string()
.trim()
@@ -81,12 +73,6 @@ export const defaultBrandingSettings: BrandingSettings = {
defaultRadius: "md",
};
export const defaultFeatureControls: FeatureControlsSettings = {
assistantEnabled: true,
boardSwitcherEnabled: true,
widgetContextMenuEnabled: true,
};
const legacyLoginBrandingSchema = z.object({
showCustomAppNameOnLogin: z.boolean().optional(),
showCustomLogoOnLogin: z.boolean().optional(),
@@ -122,16 +108,6 @@ export const parseBrandingSettings = (value: unknown): BrandingSettings => {
return result.data;
};
export const parseFeatureControls = (value: unknown) => {
const partialValue = z.record(z.string(), z.unknown()).safeParse(value);
if (!partialValue.success) return defaultFeatureControls;
const result = featureControlsServerSettingsSchema.safeParse({ ...defaultFeatureControls, ...partialValue.data });
if (!result.success) return defaultFeatureControls;
return result.data;
};
export const defaultServerSettings = {
analytics: {
enableGeneral: true,
@@ -156,7 +132,6 @@ export const defaultServerSettings = {
defaultColorScheme: "auto" as ColorScheme,
},
branding: defaultBrandingSettings,
featureControls: defaultFeatureControls,
culture: {
defaultLocale: "en" as SupportedLanguage,
},
-3
View File
@@ -24,7 +24,6 @@ export type SettingsContextProps = Omit<
> &
Pick<ServerSettings["user"], "enableGravatar"> & {
branding: ServerSettings["branding"];
featureControls: ServerSettings["featureControls"];
};
export interface PublicServerSettings {
@@ -35,7 +34,6 @@ export interface PublicServerSettings {
>;
user: Pick<ServerSettings["user"], "enableGravatar">;
branding: ServerSettings["branding"];
featureControls: ServerSettings["featureControls"];
}
export type UserSettings = Pick<
@@ -71,5 +69,4 @@ export const createSettings = ({
forceDisableStatus: serverSettings.board.forceDisableStatus,
enableGravatar: serverSettings.user.enableGravatar,
branding: parseBrandingSettings(serverSettings.branding),
featureControls: serverSettings.featureControls,
});
+5 -19
View File
@@ -5689,7 +5689,7 @@
"header": {
"title": "Header studio",
"badge": "Personal",
"description": "Drag each control across the fixed Left, Center, and Right dividers. Click a control to configure it.",
"description": "This is one continuous row. Drag controls anywhere; Left, Center, and Right are fixed dividers and never move.",
"device": {
"desktop": "Desktop",
"mobile": "Mobile"
@@ -5704,7 +5704,7 @@
"show": "Show the header",
"configure": "Move or configure {item}",
"remove": "Remove {item}",
"dropAtEnd": "Drop at the end of the {zone} zone"
"dropIntoZone": "Move into the {zone} section"
},
"preview": {
"board": "Dashboard preview for {name}",
@@ -5713,7 +5713,7 @@
"available": {
"title": "Available controls",
"description": "Add a control, then drag its full button into position above.",
"accountAlways": "Account access always remains available",
"requiredAlways": "This control is required, but you can move it anywhere in the header.",
"allAdded": "Every built-in control is already in your header.",
"add": "Add {item}",
"boardShortcut": "Board shortcut",
@@ -5733,6 +5733,8 @@
"boardSwitcher": "Boards",
"assistant": "Assistant",
"docker": "Docker",
"boardEdit": "Edit board",
"boardSettings": "Board settings",
"settings": "Your settings",
"themeToggle": "Toggle theme",
"user": "Account",
@@ -6011,21 +6013,6 @@
"off": "Off"
}
},
"featureControls": {
"title": "Feature controls",
"assistant": {
"label": "Assistant",
"description": "Show and allow the instance Assistant."
},
"boardSwitcher": {
"label": "Board switcher",
"description": "Allow board switching from the header, account menu, and keyboard shortcut."
},
"widgetContextMenu": {
"label": "Widget context menu",
"description": "Allow widget actions from the context menu."
}
},
"culture": {
"title": "Culture",
"defaultLocale": {
@@ -7625,7 +7612,6 @@
},
"unavailable": {
"checking": "Checking whether the assistant is available…",
"disabledByServer": "An administrator has disabled Assistant for this server.",
"error": "The assistant's availability could not be checked. Try again.",
"notConfigured": "An administrator must configure and enable the assistant first.",
"signIn": "Sign in to use Assistant."
+33 -5
View File
@@ -9,11 +9,15 @@ export const headerBuiltinItemIds = [
"boardSwitcher",
"assistant",
"docker",
"boardEdit",
"boardSettings",
"settings",
"themeToggle",
"user",
] as const;
export const requiredHeaderBuiltinItemIds = ["boardEdit", "boardSettings", "user"] as const;
export const headerPreferenceItemIds = headerBuiltinItemIds;
export const headerItemIds = headerBuiltinItemIds;
@@ -52,6 +56,9 @@ export const createBuiltinHeaderItem = (id: HeaderBuiltinItemId): HeaderBuiltinI
export const createBoardHeaderItem = (boardId: string): HeaderBoardItem => ({ type: "board", boardId });
export const isRequiredHeaderItem = (item: HeaderItem) =>
item.type === "builtin" && requiredHeaderBuiltinItemIds.some((itemId) => itemId === item.id);
export const getHeaderItemKey = (item: HeaderItem): string => {
if (item.type === "board") return `board:${item.boardId}`;
return `builtin:${item.id}`;
@@ -165,6 +172,22 @@ const migrateLegacyHeaderPreferencesV1 = (
const migrateLegacyHeaderPreferencesV2 = (legacy: z.infer<typeof legacyHeaderPreferencesV2Schema>): HeaderPreferences =>
migrateLegacyItems(legacy.visible, legacy.zones);
const includeRequiredHeaderItems = (preferences: HeaderPreferences): HeaderPreferences => {
const itemKeys = new Set(getHeaderItems(preferences.zones).map(getHeaderItemKey));
const missingItems = requiredHeaderBuiltinItemIds
.map(createBuiltinHeaderItem)
.filter((item) => !itemKeys.has(getHeaderItemKey(item)));
if (missingItems.length === 0) return preferences;
return {
...preferences,
zones: {
...preferences.zones,
right: [...preferences.zones.right, ...missingItems],
},
};
};
export const headerPreferencesMutationSchema = z
.discriminatedUnion("version", [
headerPreferencesSchema,
@@ -172,9 +195,9 @@ export const headerPreferencesMutationSchema = z
legacyHeaderPreferencesV2Schema,
])
.transform((preferences): HeaderPreferences => {
if (preferences.version === 1) return migrateLegacyHeaderPreferencesV1(preferences);
if (preferences.version === 2) return migrateLegacyHeaderPreferencesV2(preferences);
return preferences;
if (preferences.version === 1) return includeRequiredHeaderItems(migrateLegacyHeaderPreferencesV1(preferences));
if (preferences.version === 2) return includeRequiredHeaderItems(migrateLegacyHeaderPreferencesV2(preferences));
return includeRequiredHeaderItems(preferences);
});
export const defaultHeaderPreferences = {
@@ -184,7 +207,11 @@ export const defaultHeaderPreferences = {
zones: {
left: [createBuiltinHeaderItem("logo")],
center: [createBuiltinHeaderItem("search")],
right: [createBuiltinHeaderItem("user")],
right: [
createBuiltinHeaderItem("user"),
createBuiltinHeaderItem("boardEdit"),
createBuiltinHeaderItem("boardSettings"),
],
},
} satisfies HeaderPreferences;
@@ -201,4 +228,5 @@ export const parseHeaderPreferences = (value: unknown): HeaderPreferences => {
}
};
export const serializeHeaderPreferences = (value: HeaderPreferences) => JSON.stringify(value);
export const serializeHeaderPreferences = (value: HeaderPreferences) =>
JSON.stringify(includeRequiredHeaderItems(value));
+2
View File
@@ -25,7 +25,9 @@ export {
headerPreferencesVersion,
headerSearchDisplayValues,
headerZoneIds,
isRequiredHeaderItem,
parseHeaderPreferences,
requiredHeaderBuiltinItemIds,
} from "./header-preferences";
export type {
HeaderBoardItem,