style: auto-fix lint and format
This commit is contained in:
1 parent
83b93e17da
commit
bf26f17fcd
3 files changed
+21
-62
No files matched your search
@@ -2,12 +2,7 @@
|
|||||||
|
|
||||||
import { useCallback, useMemo } from "react";
|
import { useCallback, useMemo } from "react";
|
||||||
import { Menu } from "@mantine/core";
|
import { Menu } from "@mantine/core";
|
||||||
import {
|
import { IconCopy, IconLayoutKanban, IconPencil, IconTrash } from "@tabler/icons-react";
|
||||||
IconCopy,
|
|
||||||
IconLayoutKanban,
|
|
||||||
IconPencil,
|
|
||||||
IconTrash,
|
|
||||||
} from "@tabler/icons-react";
|
|
||||||
|
|
||||||
import { clientApi } from "@homarr/api/client";
|
import { clientApi } from "@homarr/api/client";
|
||||||
import { useRequiredBoard } from "@homarr/boards/context";
|
import { useRequiredBoard } from "@homarr/boards/context";
|
||||||
@@ -17,10 +12,7 @@ import { useSettings } from "@homarr/settings";
|
|||||||
import { translateIfNecessary } from "@homarr/translation";
|
import { translateIfNecessary } from "@homarr/translation";
|
||||||
import { useI18n, useScopedI18n } from "@homarr/translation/client";
|
import { useI18n, useScopedI18n } from "@homarr/translation/client";
|
||||||
import type { WidgetContextMenuAction } from "@homarr/widgets";
|
import type { WidgetContextMenuAction } from "@homarr/widgets";
|
||||||
import {
|
import { reduceWidgetOptionsWithDefaultValues, widgetImports } from "@homarr/widgets";
|
||||||
reduceWidgetOptionsWithDefaultValues,
|
|
||||||
widgetImports,
|
|
||||||
} from "@homarr/widgets";
|
|
||||||
import { WidgetEditModal } from "@homarr/widgets/modals";
|
import { WidgetEditModal } from "@homarr/widgets/modals";
|
||||||
|
|
||||||
import type { SectionItem } from "~/app/[locale]/boards/_types";
|
import type { SectionItem } from "~/app/[locale]/boards/_types";
|
||||||
@@ -34,11 +26,7 @@ interface WidgetContextMenuProps {
|
|||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const WidgetContextMenu = ({
|
export const WidgetContextMenu = ({ item, widgetStateRef, children }: WidgetContextMenuProps) => {
|
||||||
item,
|
|
||||||
widgetStateRef,
|
|
||||||
children,
|
|
||||||
}: WidgetContextMenuProps) => {
|
|
||||||
const [isEditMode] = useEditMode();
|
const [isEditMode] = useEditMode();
|
||||||
const board = useRequiredBoard();
|
const board = useRequiredBoard();
|
||||||
const tItem = useScopedI18n("item");
|
const tItem = useScopedI18n("item");
|
||||||
@@ -47,36 +35,20 @@ export const WidgetContextMenu = ({
|
|||||||
const { openModal } = useModalAction(WidgetEditModal);
|
const { openModal } = useModalAction(WidgetEditModal);
|
||||||
const { openModal: openMoveModal } = useModalAction(ItemMoveModal);
|
const { openModal: openMoveModal } = useModalAction(ItemMoveModal);
|
||||||
const { openConfirmModal } = useConfirmModal();
|
const { openConfirmModal } = useConfirmModal();
|
||||||
const {
|
const { updateItemOptions, updateItemAdvancedOptions, updateItemIntegrations, duplicateItem, removeItem } =
|
||||||
updateItemOptions,
|
useItemActions();
|
||||||
updateItemAdvancedOptions,
|
const { data: integrationData, isPending } = clientApi.integration.all.useQuery();
|
||||||
updateItemIntegrations,
|
const currentDefinition = useMemo(() => widgetImports[item.kind].definition, [item.kind]);
|
||||||
duplicateItem,
|
|
||||||
removeItem,
|
|
||||||
} = useItemActions();
|
|
||||||
const { data: integrationData, isPending } =
|
|
||||||
clientApi.integration.all.useQuery();
|
|
||||||
const currentDefinition = useMemo(
|
|
||||||
() => widgetImports[item.kind].definition,
|
|
||||||
[item.kind],
|
|
||||||
);
|
|
||||||
const { gridstack } = useSectionContext().refs;
|
const { gridstack } = useSectionContext().refs;
|
||||||
|
|
||||||
const options = useMemo(
|
const options = useMemo(
|
||||||
() =>
|
() => reduceWidgetOptionsWithDefaultValues(item.kind, settings, item.options) as Record<string, unknown>,
|
||||||
reduceWidgetOptionsWithDefaultValues(
|
|
||||||
item.kind,
|
|
||||||
settings,
|
|
||||||
item.options,
|
|
||||||
) as Record<string, unknown>,
|
|
||||||
[item.kind, settings, item.options],
|
[item.kind, settings, item.options],
|
||||||
);
|
);
|
||||||
|
|
||||||
type OptionDef = { type: string; skipContextMenu?: boolean };
|
type OptionDef = { type: string; skipContextMenu?: boolean };
|
||||||
const autoToggleActions = useMemo(() => {
|
const autoToggleActions = useMemo(() => {
|
||||||
const rawOptions = currentDefinition.createOptions(
|
const rawOptions = currentDefinition.createOptions(settings) as unknown as Record<string, OptionDef>;
|
||||||
settings,
|
|
||||||
) as unknown as Record<string, OptionDef>;
|
|
||||||
return Object.entries(rawOptions)
|
return Object.entries(rawOptions)
|
||||||
.filter(([, def]) => def.type === "switch" && !def.skipContextMenu)
|
.filter(([, def]) => def.type === "switch" && !def.skipContextMenu)
|
||||||
.map<WidgetContextMenuAction>(([key]) => ({
|
.map<WidgetContextMenuAction>(([key]) => ({
|
||||||
@@ -114,14 +86,7 @@ export const WidgetContextMenu = ({
|
|||||||
widgetStateRef,
|
widgetStateRef,
|
||||||
});
|
});
|
||||||
return (Array.isArray(actions) ? actions : []) as WidgetContextMenuAction[];
|
return (Array.isArray(actions) ? actions : []) as WidgetContextMenuAction[];
|
||||||
}, [
|
}, [currentDefinition, options, item, updateItemOptions, isEditMode, widgetStateRef]);
|
||||||
currentDefinition,
|
|
||||||
options,
|
|
||||||
item,
|
|
||||||
updateItemOptions,
|
|
||||||
isEditMode,
|
|
||||||
widgetStateRef,
|
|
||||||
]);
|
|
||||||
|
|
||||||
const openEditModal = useCallback(() => {
|
const openEditModal = useCallback(() => {
|
||||||
openModal(
|
openModal(
|
||||||
@@ -149,17 +114,11 @@ export const WidgetContextMenu = ({
|
|||||||
integrationData: (integrationData ?? []).filter(
|
integrationData: (integrationData ?? []).filter(
|
||||||
(integration) =>
|
(integration) =>
|
||||||
"supportedIntegrations" in currentDefinition &&
|
"supportedIntegrations" in currentDefinition &&
|
||||||
(currentDefinition.supportedIntegrations as string[]).some(
|
(currentDefinition.supportedIntegrations as string[]).some((kind) => kind === integration.kind),
|
||||||
(kind) => kind === integration.kind,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
integrationSupport:
|
integrationSupport: "supportedIntegrations" in currentDefinition,
|
||||||
"supportedIntegrations" in currentDefinition,
|
|
||||||
settings,
|
settings,
|
||||||
appId:
|
appId: item.kind === "app" ? (item.options.appId as string | undefined) : undefined,
|
||||||
item.kind === "app"
|
|
||||||
? (item.options.appId as string | undefined)
|
|
||||||
: undefined,
|
|
||||||
},
|
},
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
{ title: (translateFn: any) => `${translateFn("item.edit.title")} - ${translateFn(`widget.${item.kind}.name`)}` },
|
{ title: (translateFn: any) => `${translateFn("item.edit.title")} - ${translateFn(`widget.${item.kind}.name`)}` },
|
||||||
@@ -216,10 +175,7 @@ export const WidgetContextMenu = ({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const widgetActions: WidgetContextMenuAction[] = [
|
const widgetActions: WidgetContextMenuAction[] = [...autoToggleActions, ...widgetContextActions];
|
||||||
...autoToggleActions,
|
|
||||||
...widgetContextActions,
|
|
||||||
];
|
|
||||||
actions.push(...widgetActions);
|
actions.push(...widgetActions);
|
||||||
|
|
||||||
if (isEditMode) {
|
if (isEditMode) {
|
||||||
|
|||||||
@@ -85,9 +85,7 @@ export interface WidgetDefinition {
|
|||||||
}
|
}
|
||||||
>
|
>
|
||||||
>;
|
>;
|
||||||
contextActions?: (
|
contextActions?: (props: Omit<WidgetContextActionProps<WidgetKind>, "kind">) => WidgetContextMenuAction[];
|
||||||
props: Omit<WidgetContextActionProps<WidgetKind>, "kind">,
|
|
||||||
) => WidgetContextMenuAction[];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface WidgetProps<TKind extends WidgetKind> {
|
export interface WidgetProps<TKind extends WidgetKind> {
|
||||||
|
|||||||
@@ -61,7 +61,12 @@ import * as video from "./video";
|
|||||||
import * as weather from "./weather";
|
import * as weather from "./weather";
|
||||||
import * as customApi from "./custom-api";
|
import * as customApi from "./custom-api";
|
||||||
|
|
||||||
export type { WidgetDefinition, WidgetContextMenuAction, WidgetContextActionProps, WidgetOptionsSettings } from "./definition";
|
export type {
|
||||||
|
WidgetDefinition,
|
||||||
|
WidgetContextMenuAction,
|
||||||
|
WidgetContextActionProps,
|
||||||
|
WidgetOptionsSettings,
|
||||||
|
} from "./definition";
|
||||||
export type { WidgetComponentProps };
|
export type { WidgetComponentProps };
|
||||||
export type { WidgetOptionDefinition, WidgetOptionType } from "./options";
|
export type { WidgetOptionDefinition, WidgetOptionType } from "./options";
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user