wip(api): add items router
This commit is contained in:
7 files changed
+220
-10
No files matched your search
@@ -1,5 +1,6 @@
|
||||
import { ActionIcon, Avatar, Group, Stack, Text } from "@mantine/core";
|
||||
import { IconBookmark, IconX } from "@tabler/icons-react";
|
||||
import z from "zod";
|
||||
|
||||
import type { RouterOutputs } from "@homarr/api";
|
||||
import { clientApi } from "@homarr/api/client";
|
||||
@@ -56,6 +57,7 @@ export const { definition, componentLoader } = createWidgetDefinition("bookmarks
|
||||
isLoading,
|
||||
};
|
||||
},
|
||||
validate: z.array(z.string()),
|
||||
}),
|
||||
}));
|
||||
},
|
||||
|
||||
@@ -42,7 +42,9 @@ export interface WidgetDefinition {
|
||||
icon: TablerIcon;
|
||||
supportedIntegrations?: IntegrationKind[];
|
||||
integrationsRequired?: boolean;
|
||||
createOptions: (settings: SettingsContextProps) => WidgetOptionsRecord;
|
||||
createOptions: (
|
||||
settings: Pick<SettingsContextProps, "enableStatusByDefault" | "firstDayOfWeek" | "forceDisableStatus">,
|
||||
) => WidgetOptionsRecord;
|
||||
errors?: Partial<
|
||||
Record<
|
||||
DefaultErrorData["code"],
|
||||
|
||||
@@ -115,7 +115,7 @@ export type inferSupportedIntegrationsStrict<TKind extends WidgetKind> = (Widget
|
||||
|
||||
export const reduceWidgetOptionsWithDefaultValues = (
|
||||
kind: WidgetKind,
|
||||
settings: SettingsContextProps,
|
||||
settings: Pick<SettingsContextProps, "enableStatusByDefault" | "firstDayOfWeek" | "forceDisableStatus">,
|
||||
currentValue: Record<string, unknown> = {},
|
||||
) => {
|
||||
const definition = widgetImports[kind].definition;
|
||||
|
||||
@@ -5,6 +5,7 @@ import { z } from "zod/v4";
|
||||
import type { ZodType } from "zod/v4";
|
||||
|
||||
import type { IntegrationKind } from "@homarr/definitions";
|
||||
import { zodEnumFromArray } from "@homarr/validation/enums";
|
||||
|
||||
import type { inferSelectOptionValue, SelectOption } from "./_inputs/widget-select-input";
|
||||
import type { ReleasesRepository } from "./releases/releases-repository";
|
||||
@@ -35,6 +36,7 @@ export interface SortableItemListInput<TItem, TOptionValue extends UniqueIdentif
|
||||
}) => React.ReactNode;
|
||||
uniqueIdentifier: (item: TItem) => TOptionValue;
|
||||
useData: (values: TOptionValue[]) => { data: TItem[] | undefined; isLoading: boolean; error: unknown };
|
||||
validate: z.ZodArray<z.ZodType>;
|
||||
}
|
||||
|
||||
interface SelectInput<TOptions extends readonly SelectOption[]>
|
||||
@@ -64,12 +66,13 @@ const optionsFactory = {
|
||||
type: "switch" as const,
|
||||
defaultValue: input?.defaultValue ?? false,
|
||||
withDescription: input?.withDescription ?? false,
|
||||
validate: z.boolean(),
|
||||
}),
|
||||
text: (input?: TextInput) => ({
|
||||
type: "text" as const,
|
||||
defaultValue: input?.defaultValue ?? "",
|
||||
withDescription: input?.withDescription ?? false,
|
||||
validate: input?.validate,
|
||||
validate: input?.validate ?? z.string(),
|
||||
}),
|
||||
multiSelect: <const TOptions extends SelectOption[]>(input: MultiSelectInput<TOptions>) => ({
|
||||
type: "multiSelect" as const,
|
||||
@@ -77,6 +80,9 @@ const optionsFactory = {
|
||||
options: input.options,
|
||||
searchable: input.searchable ?? false,
|
||||
withDescription: input.withDescription ?? false,
|
||||
validate: z.array(
|
||||
zodEnumFromArray(input.options.map((option) => (typeof option === "string" ? option : option.value))),
|
||||
),
|
||||
}),
|
||||
select: <const TOptions extends SelectOption[]>(input: SelectInput<TOptions>) => ({
|
||||
type: "select" as const,
|
||||
@@ -84,6 +90,7 @@ const optionsFactory = {
|
||||
options: input.options,
|
||||
searchable: input.searchable ?? false,
|
||||
withDescription: input.withDescription ?? false,
|
||||
validate: zodEnumFromArray(input.options.map((option) => (typeof option === "string" ? option : option.value))),
|
||||
}),
|
||||
number: (input: NumberInput) => ({
|
||||
type: "number" as const,
|
||||
@@ -118,19 +125,20 @@ const optionsFactory = {
|
||||
defaultValue: input?.defaultValue ?? [],
|
||||
withDescription: input?.withDescription ?? false,
|
||||
values: [] as string[],
|
||||
validate: input?.validate,
|
||||
validate: input?.validate ?? z.array(z.string()),
|
||||
}),
|
||||
multiReleasesRepositories: (input?: CommonInput<ReleasesRepository[]> & { validate?: ZodType }) => ({
|
||||
multiReleasesRepositories: (input: CommonInput<ReleasesRepository[]> & { validate: ZodType }) => ({
|
||||
type: "multiReleasesRepositories" as const,
|
||||
defaultValue: input?.defaultValue ?? [],
|
||||
withDescription: input?.withDescription ?? false,
|
||||
defaultValue: input.defaultValue ?? [],
|
||||
withDescription: input.withDescription ?? false,
|
||||
values: [] as ReleasesRepository[],
|
||||
validate: input?.validate,
|
||||
validate: input.validate,
|
||||
}),
|
||||
app: () => ({
|
||||
type: "app" as const,
|
||||
defaultValue: "",
|
||||
withDescription: false,
|
||||
validate: z.string(),
|
||||
}),
|
||||
sortableItemList: <const TItem, const TOptionValue extends UniqueIdentifier>(
|
||||
input: SortableItemListInput<TItem, TOptionValue>,
|
||||
@@ -142,6 +150,7 @@ const optionsFactory = {
|
||||
uniqueIdentifier: input.uniqueIdentifier,
|
||||
useData: input.useData,
|
||||
withDescription: false,
|
||||
validate: input.validate,
|
||||
}),
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user