feat: reduce disruptive UI confirmations (#6688)
* feat: reduce disruptive UI confirmations * fix: keep destructive confirmations red
This commit is contained in:
1 parent
9c441571bc
commit
a002b91add
86 files changed
+3201
-2277
No files matched your search
@@ -4,5 +4,4 @@ import { createFormContext } from "@homarr/form";
|
||||
|
||||
import type { WidgetEditModalState } from "../modals/widget-edit-modal";
|
||||
|
||||
export const [FormProvider, useFormContext, useForm] =
|
||||
createFormContext<Omit<WidgetEditModalState, "advancedOptions">>();
|
||||
export const [FormProvider, useFormContext, useForm] = createFormContext<WidgetEditModalState>();
|
||||
@@ -1,5 +1,7 @@
|
||||
// @vitest-environment jsdom
|
||||
|
||||
/* eslint-disable unicorn/consistent-function-scoping -- Component mocks are intentionally colocated with their module factory. */
|
||||
|
||||
import { act } from "react";
|
||||
import type { ReactNode } from "react";
|
||||
import { createRoot } from "react-dom/client";
|
||||
@@ -30,6 +32,7 @@ vi.mock("@mantine/core", () => {
|
||||
|
||||
return {
|
||||
Button: Container,
|
||||
Collapse: Container,
|
||||
Fieldset: Container,
|
||||
Group: Container,
|
||||
NumberInput: Input,
|
||||
@@ -39,11 +42,6 @@ vi.mock("@mantine/core", () => {
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("@homarr/modals", () => ({
|
||||
createModal: () => ({ withOptions: () => null }),
|
||||
useModalAction: () => ({ openModal: vi.fn() }),
|
||||
}));
|
||||
|
||||
vi.mock("@homarr/translation/client", () => ({
|
||||
useCurrentIntlLocale: () => "en",
|
||||
useI18n: () => (key: string) => key,
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
"use client";
|
||||
|
||||
import { useCallback, useEffect, useRef } from "react";
|
||||
import { useCallback, useEffect, useRef, useState } from "react";
|
||||
import {
|
||||
ActionIcon,
|
||||
Alert,
|
||||
Anchor,
|
||||
Button,
|
||||
Collapse,
|
||||
Fieldset,
|
||||
Group,
|
||||
Loader,
|
||||
NumberInput,
|
||||
Paper,
|
||||
Stack,
|
||||
Table,
|
||||
Text,
|
||||
TextInput,
|
||||
Tooltip,
|
||||
@@ -20,7 +21,6 @@ import { IconClick, IconListSearch } from "@tabler/icons-react";
|
||||
|
||||
import type { RouterOutputs } from "@homarr/api";
|
||||
import { clientApi } from "@homarr/api/client";
|
||||
import { createModal, useModalAction } from "@homarr/modals";
|
||||
import { useCurrentIntlLocale, useI18n } from "@homarr/translation/client";
|
||||
|
||||
import { formatLocalizedCompactNumber } from "../common/locale";
|
||||
@@ -33,7 +33,7 @@ export const WidgetLocationInput = ({ property, kind, options }: CommonWidgetInp
|
||||
const t = useWidgetInputTranslation(kind, property);
|
||||
const tLocation = useI18n("widget.common.location");
|
||||
const form = useFormContext();
|
||||
const { openModal } = useModalAction(LocationSearchModal);
|
||||
const [searchQuery, setSearchQuery] = useState<string | null>(null);
|
||||
const fieldPath = `options.${property}`;
|
||||
const inputProps = form.getInputProps(fieldPath);
|
||||
const value = isOptionLocation(inputProps.value) ? inputProps.value : options.defaultValue;
|
||||
@@ -58,26 +58,23 @@ export const WidgetLocationInput = ({ property, kind, options }: CommonWidgetInp
|
||||
handleChange(location);
|
||||
form.clearFieldError(`options.${property}.latitude`);
|
||||
form.clearFieldError(`options.${property}.longitude`);
|
||||
setSearchQuery(null);
|
||||
},
|
||||
[form, handleChange, property],
|
||||
);
|
||||
|
||||
const onSearch = useCallback(() => {
|
||||
if (!selectionEnabled) return;
|
||||
setSearchQuery(value.name);
|
||||
}, [selectionEnabled, value.name]);
|
||||
|
||||
openModal({
|
||||
query: value.name,
|
||||
onLocationSelect,
|
||||
});
|
||||
}, [selectionEnabled, value.name, onLocationSelect, openModal]);
|
||||
|
||||
form.watch(`options.${property}.latitude`, ({ value }) => {
|
||||
if (typeof value !== "number") return;
|
||||
form.watch(`options.${property}.latitude`, ({ value: nextValue }) => {
|
||||
if (typeof nextValue !== "number") return;
|
||||
form.setFieldValue(`options.${property}.name`, unknownLocation);
|
||||
});
|
||||
|
||||
form.watch(`options.${property}.longitude`, ({ value }) => {
|
||||
if (typeof value !== "number") return;
|
||||
form.watch(`options.${property}.longitude`, ({ value: nextValue }) => {
|
||||
if (typeof nextValue !== "number") return;
|
||||
form.setFieldValue(`options.${property}.name`, unknownLocation);
|
||||
});
|
||||
|
||||
@@ -121,6 +118,16 @@ export const WidgetLocationInput = ({ property, kind, options }: CommonWidgetInp
|
||||
value={longitudeInputProps.value ?? value.longitude}
|
||||
/>
|
||||
</Group>
|
||||
|
||||
<Collapse expanded={searchQuery !== null}>
|
||||
{searchQuery && (
|
||||
<LocationSearchResults
|
||||
query={searchQuery}
|
||||
onLocationSelect={onLocationSelect}
|
||||
onClose={() => setSearchQuery(null)}
|
||||
/>
|
||||
)}
|
||||
</Collapse>
|
||||
</Stack>
|
||||
</Fieldset>
|
||||
);
|
||||
@@ -143,124 +150,123 @@ type LocationOnChange = (
|
||||
},
|
||||
) => void;
|
||||
|
||||
interface LocationSearchInnerProps {
|
||||
interface LocationSearchResultsProps {
|
||||
query: string;
|
||||
onLocationSelect: (location: OptionLocation) => void;
|
||||
onClose: () => void;
|
||||
}
|
||||
|
||||
const LocationSearchModal = createModal<LocationSearchInnerProps>(({ actions, innerProps }) => {
|
||||
const t = useI18n("widget.common.location.table");
|
||||
const LocationSearchResults = ({ query, onLocationSelect, onClose }: LocationSearchResultsProps) => {
|
||||
const tLocation = useI18n("widget.common.location");
|
||||
const tCommon = useI18n("common");
|
||||
const { data, isPending, error } = clientApi.location.searchCity.useQuery({
|
||||
query: innerProps.query,
|
||||
});
|
||||
const { data, isPending, error, refetch } = clientApi.location.searchCity.useQuery({ query });
|
||||
|
||||
if (error) {
|
||||
return (
|
||||
<Alert title={tCommon("error")} color="red">
|
||||
{tCommon("action.tryAgain")}
|
||||
</Alert>
|
||||
<Stack gap="xs">
|
||||
<Alert title={tCommon("error")} color="red">
|
||||
<Button variant="light" color="red" size="compact-sm" onClick={() => void refetch()}>
|
||||
{tCommon("action.tryAgain")}
|
||||
</Button>
|
||||
</Alert>
|
||||
<Group justify="right">
|
||||
<Button variant="default" size="compact-sm" onClick={onClose}>
|
||||
{tCommon("action.close")}
|
||||
</Button>
|
||||
</Group>
|
||||
</Stack>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Stack>
|
||||
<Table striped>
|
||||
<Table.Thead>
|
||||
<Table.Tr>
|
||||
<Table.Th style={{ width: "70%" }}>{t("header.city")}</Table.Th>
|
||||
<Table.Th style={{ width: "50%" }}>{t("header.country")}</Table.Th>
|
||||
<Table.Th>{t("header.coordinates")}</Table.Th>
|
||||
<Table.Th>{t("header.population")}</Table.Th>
|
||||
<Table.Th style={{ width: 40 }} />
|
||||
</Table.Tr>
|
||||
</Table.Thead>
|
||||
<Table.Tbody>
|
||||
{isPending && (
|
||||
<Table.Tr>
|
||||
<Table.Td colSpan={5}>
|
||||
<Group justify="center">
|
||||
<Loader />
|
||||
</Group>
|
||||
</Table.Td>
|
||||
</Table.Tr>
|
||||
)}
|
||||
{data?.results.map((city) => (
|
||||
<LocationSelectTableRow
|
||||
key={city.id}
|
||||
city={city}
|
||||
onLocationSelect={innerProps.onLocationSelect}
|
||||
closeModal={actions.closeModal}
|
||||
/>
|
||||
))}
|
||||
</Table.Tbody>
|
||||
</Table>
|
||||
<Stack component="section" aria-label={tLocation("search")} gap="xs">
|
||||
<Stack gap={4} mah={320} style={{ overflow: "hidden auto" }}>
|
||||
{isPending && (
|
||||
<Group justify="center" py="md">
|
||||
<Loader />
|
||||
</Group>
|
||||
)}
|
||||
{!isPending && data?.results.length === 0 && (
|
||||
<Text ta="center" c="dimmed" py="md">
|
||||
{tCommon("noResults")}
|
||||
</Text>
|
||||
)}
|
||||
{data?.results.map((city) => (
|
||||
<LocationSelectResult key={city.id} city={city} onLocationSelect={onLocationSelect} />
|
||||
))}
|
||||
</Stack>
|
||||
<Group justify="right">
|
||||
<Button variant="light" onClick={actions.closeModal}>
|
||||
{tCommon("action.cancel")}
|
||||
<Button variant="default" size="compact-sm" onClick={onClose}>
|
||||
{tCommon("action.close")}
|
||||
</Button>
|
||||
</Group>
|
||||
</Stack>
|
||||
);
|
||||
}).withOptions({
|
||||
defaultTitle(t) {
|
||||
return t("widget.common.location.search");
|
||||
},
|
||||
size: "xl",
|
||||
});
|
||||
};
|
||||
|
||||
interface LocationSearchTableRowProps {
|
||||
interface LocationSelectResultProps {
|
||||
city: RouterOutputs["location"]["searchCity"]["results"][number];
|
||||
onLocationSelect: (location: OptionLocation) => void;
|
||||
closeModal: () => void;
|
||||
}
|
||||
|
||||
const LocationSelectTableRow = ({ city, onLocationSelect, closeModal }: LocationSearchTableRowProps) => {
|
||||
const LocationSelectResult = ({ city, onLocationSelect }: LocationSelectResultProps) => {
|
||||
const t = useI18n("widget.common.location.table");
|
||||
const locale = useCurrentIntlLocale();
|
||||
let populationLabel = t("population.fallback");
|
||||
if (city.population) {
|
||||
populationLabel = `${t("header.population")}: ${formatLocalizedCompactNumber(city.population, locale)}`;
|
||||
}
|
||||
const onSelect = useCallback(() => {
|
||||
onLocationSelect({
|
||||
name: city.name,
|
||||
latitude: city.latitude,
|
||||
longitude: city.longitude,
|
||||
});
|
||||
closeModal();
|
||||
}, [city, onLocationSelect, closeModal]);
|
||||
}, [city, onLocationSelect]);
|
||||
|
||||
return (
|
||||
<Table.Tr>
|
||||
<Table.Td>
|
||||
<Text style={{ whiteSpace: "nowrap" }}>{city.name}</Text>
|
||||
</Table.Td>
|
||||
<Table.Td>
|
||||
<Text style={{ whiteSpace: "nowrap" }}>{city.country}</Text>
|
||||
</Table.Td>
|
||||
<Table.Td>
|
||||
<Anchor target="_blank" href={`https://www.google.com/maps/place/${city.latitude},${city.longitude}`}>
|
||||
<Text style={{ whiteSpace: "nowrap" }}>
|
||||
{city.latitude}, {city.longitude}
|
||||
<Paper withBorder p="xs">
|
||||
<Group justify="space-between" align="flex-start" wrap="nowrap">
|
||||
<Stack gap={2} miw={0}>
|
||||
<Text fw={500} style={{ overflowWrap: "anywhere" }}>
|
||||
{city.name}
|
||||
</Text>
|
||||
</Anchor>
|
||||
</Table.Td>
|
||||
<Table.Td>
|
||||
{city.population ? (
|
||||
<Text style={{ whiteSpace: "nowrap" }}>{formatLocalizedCompactNumber(city.population, locale)}</Text>
|
||||
) : (
|
||||
<Text c="gray"> {t("population.fallback")}</Text>
|
||||
)}
|
||||
</Table.Td>
|
||||
<Table.Td>
|
||||
<Text size="xs" c="dimmed" style={{ overflowWrap: "anywhere" }}>
|
||||
{city.country}
|
||||
</Text>
|
||||
<Group gap="xs" wrap="wrap">
|
||||
<Anchor
|
||||
size="xs"
|
||||
target="_blank"
|
||||
href={`https://www.google.com/maps/place/${city.latitude},${city.longitude}`}
|
||||
>
|
||||
{city.latitude}, {city.longitude}
|
||||
</Anchor>
|
||||
<Text size="xs" c="dimmed">
|
||||
{populationLabel}
|
||||
</Text>
|
||||
</Group>
|
||||
</Stack>
|
||||
<Tooltip
|
||||
label={t("action.select", {
|
||||
city: city.name,
|
||||
countryCode: city.country_code ?? "??",
|
||||
})}
|
||||
>
|
||||
<ActionIcon color="red" variant="subtle" onClick={onSelect}>
|
||||
<ActionIcon
|
||||
flex="0 0 auto"
|
||||
color="red"
|
||||
variant="subtle"
|
||||
onClick={onSelect}
|
||||
aria-label={t("action.select", {
|
||||
city: city.name,
|
||||
countryCode: city.country_code ?? "??",
|
||||
})}
|
||||
>
|
||||
<IconClick size="var(--mantine-font-size-md)" />
|
||||
</ActionIcon>
|
||||
</Tooltip>
|
||||
</Table.Td>
|
||||
</Table.Tr>
|
||||
</Group>
|
||||
</Paper>
|
||||
);
|
||||
};
|
||||
@@ -1,106 +0,0 @@
|
||||
import { useRef, useState } from "react";
|
||||
import type { NumberInputHandlers } from "@mantine/core";
|
||||
import { ActionIcon, Button, Flex, Group, Modal, NumberInput, rem, Stack, Text } from "@mantine/core";
|
||||
import { IconClockPause } from "@tabler/icons-react";
|
||||
|
||||
import { useI18n } from "@homarr/translation/client";
|
||||
|
||||
interface TimerModalProps {
|
||||
opened: boolean;
|
||||
close: () => void;
|
||||
selectedIntegrationIds: string[];
|
||||
disableDns: (data: { duration: number; integrationId: string }) => void;
|
||||
}
|
||||
|
||||
const TimerModal = ({ opened, close, selectedIntegrationIds, disableDns }: TimerModalProps) => {
|
||||
const t = useI18n("widget.dnsHoleControls");
|
||||
const tCommon = useI18n("common");
|
||||
const [hours, setHours] = useState(0);
|
||||
const [minutes, setMinutes] = useState(0);
|
||||
const hoursHandlers = useRef<NumberInputHandlers>(null);
|
||||
const minutesHandlers = useRef<NumberInputHandlers>(null);
|
||||
|
||||
const handleSetTimer = () => {
|
||||
const duration = hours * 3600 + minutes * 60;
|
||||
selectedIntegrationIds.forEach((integrationId) => {
|
||||
disableDns({ duration, integrationId });
|
||||
});
|
||||
setHours(0);
|
||||
setMinutes(0);
|
||||
close();
|
||||
};
|
||||
|
||||
return (
|
||||
<Modal
|
||||
withinPortal
|
||||
radius="lg"
|
||||
shadow="sm"
|
||||
size="sm"
|
||||
opened={opened}
|
||||
onClose={() => {
|
||||
close();
|
||||
setHours(0);
|
||||
setMinutes(0);
|
||||
}}
|
||||
title={t("controls.setTimer")}
|
||||
>
|
||||
<Flex direction="column" align="center" justify="center">
|
||||
<Stack align="flex-end">
|
||||
<Group>
|
||||
<Text>{tCommon("information.hours")}</Text>
|
||||
<ActionIcon size={35} variant="default" onClick={() => hoursHandlers.current?.decrement()}>
|
||||
–
|
||||
</ActionIcon>
|
||||
<NumberInput
|
||||
hideControls
|
||||
value={hours}
|
||||
onChange={(val) => setHours(Number(val))}
|
||||
handlersRef={hoursHandlers}
|
||||
max={999}
|
||||
min={0}
|
||||
step={1}
|
||||
styles={{ input: { width: rem(54), textAlign: "center" } }}
|
||||
/>
|
||||
<ActionIcon size={35} variant="default" onClick={() => hoursHandlers.current?.increment()}>
|
||||
+
|
||||
</ActionIcon>
|
||||
</Group>
|
||||
<Group>
|
||||
<Text>{tCommon("information.minutes")}</Text>
|
||||
<ActionIcon size={35} variant="default" onClick={() => minutesHandlers.current?.decrement()}>
|
||||
–
|
||||
</ActionIcon>
|
||||
<NumberInput
|
||||
hideControls
|
||||
value={minutes}
|
||||
onChange={(val) => setMinutes(Number(val))}
|
||||
handlersRef={minutesHandlers}
|
||||
max={59}
|
||||
min={0}
|
||||
step={1}
|
||||
styles={{ input: { width: rem(54), textAlign: "center" } }}
|
||||
/>
|
||||
<ActionIcon size={35} variant="default" onClick={() => minutesHandlers.current?.increment()}>
|
||||
+
|
||||
</ActionIcon>
|
||||
</Group>
|
||||
</Stack>
|
||||
<Text ta="center" c="dimmed" my={5}>
|
||||
{t("controls.unlimited")}
|
||||
</Text>
|
||||
<Button
|
||||
variant="light"
|
||||
color="red"
|
||||
leftSection={<IconClockPause size="var(--mantine-font-size-xl)" />}
|
||||
h="2rem"
|
||||
w="12rem"
|
||||
onClick={handleSetTimer}
|
||||
>
|
||||
{t("controls.set")}
|
||||
</Button>
|
||||
</Flex>
|
||||
</Modal>
|
||||
);
|
||||
};
|
||||
|
||||
export default TimerModal;
|
||||
@@ -1,5 +1,8 @@
|
||||
"use client";
|
||||
|
||||
/* eslint-disable react/no-unstable-nested-components -- TimerPopover uses render props to wire controlled targets. */
|
||||
/* eslint-disable import/no-unassigned-import -- The shared widget stylesheet is loaded for its side effects. */
|
||||
|
||||
import "../../widgets-common.css";
|
||||
|
||||
import { useState } from "react";
|
||||
@@ -18,7 +21,6 @@ import {
|
||||
Tooltip,
|
||||
UnstyledButton,
|
||||
} from "@mantine/core";
|
||||
import { useDisclosure } from "@mantine/hooks";
|
||||
import { IconCircleFilled, IconClockPause, IconPlayerPlay, IconPlayerStop } from "@tabler/icons-react";
|
||||
import combineClasses from "clsx";
|
||||
|
||||
@@ -38,7 +40,7 @@ import { getUsableWidgetQueryData, isInitialWidgetQueryPending } from "../../com
|
||||
import { WidgetQueryLoadingState } from "../../common/query-state-indicator";
|
||||
import actionTargetClasses from "../../common/action-target.module.css";
|
||||
import classes from "./component.module.css";
|
||||
import TimerModal from "./TimerModal";
|
||||
import TimerPopover from "./timer-popover";
|
||||
|
||||
const dnsLightStatus = (enabled: boolean | undefined) =>
|
||||
`var(--mantine-color-${typeof enabled === "undefined" ? "blue" : enabled ? "green" : "red"}-6`;
|
||||
@@ -123,11 +125,8 @@ export default function DnsHoleControlsWidget({
|
||||
|
||||
const t = useI18n("widget.dnsHoleControls");
|
||||
|
||||
// Timer modal setup
|
||||
const [selectedIntegrationIds, setSelectedIntegrationIds] = useState<string[]>([]);
|
||||
const [bulkPending, setBulkPending] = useState(false);
|
||||
const [bulkFailureCount, setBulkFailureCount] = useState(0);
|
||||
const [opened, { close, open }] = useDisclosure(false);
|
||||
|
||||
const controlAllButtonsVisible = options.showToggleAllButtons && integrationsWithInteractions.length > 0;
|
||||
const actionsPending = bulkPending || isEnabling || isDisabling;
|
||||
@@ -177,26 +176,29 @@ export default function DnsHoleControlsWidget({
|
||||
</Button>
|
||||
</Tooltip>
|
||||
|
||||
<Tooltip label={t("controls.setTimer")}>
|
||||
<Button
|
||||
aria-label={t("controls.setTimer")}
|
||||
size="xs"
|
||||
p={0}
|
||||
className="dns-hole-controls-timer-all-button"
|
||||
onClick={() => {
|
||||
setSelectedIntegrationIds(integrationsSummaries.enabled);
|
||||
open();
|
||||
}}
|
||||
disabled={integrationsSummaries.enabled.length === 0 || actionsPending}
|
||||
variant="light"
|
||||
color="yellow"
|
||||
bd={0}
|
||||
radius={board.itemRadius}
|
||||
flex={1}
|
||||
>
|
||||
<IconClockPause className="dns-hole-controls-timer-all-icon" size="var(--mantine-font-size-md)" />
|
||||
</Button>
|
||||
</Tooltip>
|
||||
<TimerPopover
|
||||
target={(onClick) => (
|
||||
<Tooltip label={t("controls.setTimer")}>
|
||||
<Button
|
||||
aria-label={t("controls.setTimer")}
|
||||
size="xs"
|
||||
p={0}
|
||||
className="dns-hole-controls-timer-all-button"
|
||||
disabled={integrationsSummaries.enabled.length === 0 || actionsPending}
|
||||
variant="light"
|
||||
color="yellow"
|
||||
bd={0}
|
||||
radius={board.itemRadius}
|
||||
flex={1}
|
||||
onClick={onClick}
|
||||
>
|
||||
<IconClockPause className="dns-hole-controls-timer-all-icon" size="var(--mantine-font-size-md)" />
|
||||
</Button>
|
||||
</Tooltip>
|
||||
)}
|
||||
selectedIntegrationIds={integrationsSummaries.enabled}
|
||||
disableDns={(input) => void disableDns(input).catch(() => undefined)}
|
||||
/>
|
||||
|
||||
<Tooltip label={t("controls.disableAll")}>
|
||||
<Button
|
||||
@@ -230,9 +232,8 @@ export default function DnsHoleControlsWidget({
|
||||
key={summary.integration.id}
|
||||
integrationsWithInteractions={integrationsWithInteractions}
|
||||
toggleDns={toggleDns}
|
||||
disableDns={(input) => void disableDns(input).catch(() => undefined)}
|
||||
data={summary}
|
||||
setSelectedIntegrationIds={setSelectedIntegrationIds}
|
||||
open={open}
|
||||
t={t}
|
||||
hasIconColor={board.iconColor !== null}
|
||||
rootWidth={width}
|
||||
@@ -255,13 +256,6 @@ export default function DnsHoleControlsWidget({
|
||||
</Text>
|
||||
</Tooltip>
|
||||
)}
|
||||
|
||||
<TimerModal
|
||||
opened={opened}
|
||||
close={close}
|
||||
selectedIntegrationIds={selectedIntegrationIds}
|
||||
disableDns={(input) => void disableDns(input).catch(() => undefined)}
|
||||
/>
|
||||
</Stack>
|
||||
);
|
||||
}
|
||||
@@ -269,9 +263,8 @@ export default function DnsHoleControlsWidget({
|
||||
interface ControlsCardProps {
|
||||
integrationsWithInteractions: string[];
|
||||
toggleDns: (integrationId: string) => Promise<void>;
|
||||
disableDns: (data: { duration: number; integrationId: string }) => void;
|
||||
data: AvailableDnsSummaryResult;
|
||||
setSelectedIntegrationIds: (integrationId: string[]) => void;
|
||||
open: () => void;
|
||||
t: ReturnType<typeof useI18n<"widget.dnsHoleControls">>;
|
||||
hasIconColor: boolean;
|
||||
rootWidth: number;
|
||||
@@ -282,9 +275,8 @@ interface ControlsCardProps {
|
||||
const ControlsCard: React.FC<ControlsCardProps> = ({
|
||||
integrationsWithInteractions,
|
||||
toggleDns,
|
||||
disableDns,
|
||||
data,
|
||||
setSelectedIntegrationIds,
|
||||
open,
|
||||
t,
|
||||
hasIconColor,
|
||||
rootWidth,
|
||||
@@ -382,21 +374,24 @@ const ControlsCard: React.FC<ControlsCardProps> = ({
|
||||
<IconPlayerStop size="var(--mantine-font-size-xs)" />
|
||||
</ActionIcon>
|
||||
)}
|
||||
<ActionIcon
|
||||
className={actionTargetClasses.root}
|
||||
aria-label={`${t("controls.setTimer")}: ${data.integration.name}`}
|
||||
onClick={() => {
|
||||
setSelectedIntegrationIds([data.integration.id]);
|
||||
open();
|
||||
}}
|
||||
size="sm"
|
||||
color="yellow"
|
||||
variant="light"
|
||||
display={isInteractPermitted ? undefined : "none"}
|
||||
disabled={!controlEnabled || !isEnabled}
|
||||
>
|
||||
<IconClockPause size="var(--mantine-font-size-xs)" />
|
||||
</ActionIcon>
|
||||
<TimerPopover
|
||||
target={(onClick) => (
|
||||
<ActionIcon
|
||||
className={actionTargetClasses.root}
|
||||
aria-label={`${t("controls.setTimer")}: ${data.integration.name}`}
|
||||
size="sm"
|
||||
color="yellow"
|
||||
variant="light"
|
||||
display={isInteractPermitted ? undefined : "none"}
|
||||
disabled={!controlEnabled || !isEnabled}
|
||||
onClick={onClick}
|
||||
>
|
||||
<IconClockPause size="var(--mantine-font-size-xs)" />
|
||||
</ActionIcon>
|
||||
)}
|
||||
selectedIntegrationIds={[data.integration.id]}
|
||||
disableDns={disableDns}
|
||||
/>
|
||||
</Group>
|
||||
)}
|
||||
{layout === "md" && (
|
||||
@@ -445,24 +440,27 @@ const ControlsCard: React.FC<ControlsCardProps> = ({
|
||||
</Flex>
|
||||
</Flex>
|
||||
{layout === "md" && (
|
||||
<ActionIcon
|
||||
aria-label={`${t("controls.setTimer")}: ${data.integration.name}`}
|
||||
className={combineClasses("dns-hole-controls-item-timer-button", actionTargetClasses.root)}
|
||||
display={isInteractPermitted ? undefined : "none"}
|
||||
disabled={!controlEnabled || !isEnabled}
|
||||
color="yellow"
|
||||
size={30}
|
||||
radius={board.itemRadius}
|
||||
bd={0}
|
||||
ms={"auto"}
|
||||
variant="subtle"
|
||||
onClick={() => {
|
||||
setSelectedIntegrationIds([data.integration.id]);
|
||||
open();
|
||||
}}
|
||||
>
|
||||
<IconClockPause className="dns-hole-controls-item-timer-icon" size="var(--mantine-font-size-xl)" />
|
||||
</ActionIcon>
|
||||
<TimerPopover
|
||||
target={(onClick) => (
|
||||
<ActionIcon
|
||||
aria-label={`${t("controls.setTimer")}: ${data.integration.name}`}
|
||||
className={combineClasses("dns-hole-controls-item-timer-button", actionTargetClasses.root)}
|
||||
display={isInteractPermitted ? undefined : "none"}
|
||||
disabled={!controlEnabled || !isEnabled}
|
||||
color="yellow"
|
||||
size={30}
|
||||
radius={board.itemRadius}
|
||||
bd={0}
|
||||
ms={"auto"}
|
||||
variant="subtle"
|
||||
onClick={onClick}
|
||||
>
|
||||
<IconClockPause className="dns-hole-controls-item-timer-icon" size="var(--mantine-font-size-xl)" />
|
||||
</ActionIcon>
|
||||
)}
|
||||
selectedIntegrationIds={[data.integration.id]}
|
||||
disableDns={disableDns}
|
||||
/>
|
||||
)}
|
||||
</Flex>
|
||||
</Card>
|
||||
|
||||
@@ -0,0 +1,146 @@
|
||||
import type { ReactNode } from "react";
|
||||
import { useRef, useState } from "react";
|
||||
import type { NumberInputHandlers } from "@mantine/core";
|
||||
import { ActionIcon, Button, Flex, Group, NumberInput, Popover, rem, Stack, Text } from "@mantine/core";
|
||||
import { IconClockPause } from "@tabler/icons-react";
|
||||
import { useDisclosure } from "@mantine/hooks";
|
||||
|
||||
import { useI18n } from "@homarr/translation/client";
|
||||
|
||||
interface TimerPopoverProps {
|
||||
target: (onClick: () => void) => ReactNode;
|
||||
selectedIntegrationIds: string[];
|
||||
disableDns: (data: { duration: number; integrationId: string }) => void;
|
||||
}
|
||||
|
||||
const TimerPopover = ({ target, selectedIntegrationIds, disableDns }: TimerPopoverProps) => {
|
||||
const t = useI18n("widget.dnsHoleControls");
|
||||
const tCommon = useI18n("common");
|
||||
const [opened, { close, open }] = useDisclosure(false);
|
||||
const [hours, setHours] = useState(0);
|
||||
const [minutes, setMinutes] = useState(0);
|
||||
const hoursHandlers = useRef<NumberInputHandlers>(null);
|
||||
const minutesHandlers = useRef<NumberInputHandlers>(null);
|
||||
|
||||
const handleSetTimer = () => {
|
||||
const duration = hours * 3600 + minutes * 60;
|
||||
selectedIntegrationIds.forEach((integrationId) => {
|
||||
disableDns({ duration, integrationId });
|
||||
});
|
||||
setHours(0);
|
||||
setMinutes(0);
|
||||
close();
|
||||
};
|
||||
|
||||
const reset = () => {
|
||||
close();
|
||||
setHours(0);
|
||||
setMinutes(0);
|
||||
};
|
||||
|
||||
const handleToggle = () => {
|
||||
if (opened) {
|
||||
reset();
|
||||
return;
|
||||
}
|
||||
open();
|
||||
};
|
||||
|
||||
return (
|
||||
<Popover
|
||||
opened={opened}
|
||||
onChange={(nextOpened) => {
|
||||
if (nextOpened) open();
|
||||
if (!nextOpened) reset();
|
||||
}}
|
||||
position="bottom"
|
||||
shadow="sm"
|
||||
>
|
||||
<Popover.Target>{target(handleToggle)}</Popover.Target>
|
||||
<Popover.Dropdown>
|
||||
<Stack gap="sm" maw={280}>
|
||||
<Text fw={500}>{t("controls.setTimer")}</Text>
|
||||
<Flex direction="column" align="center" justify="center">
|
||||
<Stack align="flex-end">
|
||||
<Group>
|
||||
<Text>{tCommon("information.hours")}</Text>
|
||||
<ActionIcon
|
||||
size={35}
|
||||
variant="default"
|
||||
onClick={() => hoursHandlers.current?.decrement()}
|
||||
aria-label={`− ${tCommon("information.hours")}`}
|
||||
>
|
||||
–
|
||||
</ActionIcon>
|
||||
<NumberInput
|
||||
hideControls
|
||||
value={hours}
|
||||
onChange={(val) => setHours(Number(val))}
|
||||
handlersRef={hoursHandlers}
|
||||
aria-label={tCommon("information.hours")}
|
||||
max={999}
|
||||
min={0}
|
||||
step={1}
|
||||
styles={{ input: { width: rem(54), textAlign: "center" } }}
|
||||
/>
|
||||
<ActionIcon
|
||||
size={35}
|
||||
variant="default"
|
||||
onClick={() => hoursHandlers.current?.increment()}
|
||||
aria-label={`+ ${tCommon("information.hours")}`}
|
||||
>
|
||||
+
|
||||
</ActionIcon>
|
||||
</Group>
|
||||
<Group>
|
||||
<Text>{tCommon("information.minutes")}</Text>
|
||||
<ActionIcon
|
||||
size={35}
|
||||
variant="default"
|
||||
onClick={() => minutesHandlers.current?.decrement()}
|
||||
aria-label={`− ${tCommon("information.minutes")}`}
|
||||
>
|
||||
–
|
||||
</ActionIcon>
|
||||
<NumberInput
|
||||
hideControls
|
||||
value={minutes}
|
||||
onChange={(val) => setMinutes(Number(val))}
|
||||
handlersRef={minutesHandlers}
|
||||
aria-label={tCommon("information.minutes")}
|
||||
max={59}
|
||||
min={0}
|
||||
step={1}
|
||||
styles={{ input: { width: rem(54), textAlign: "center" } }}
|
||||
/>
|
||||
<ActionIcon
|
||||
size={35}
|
||||
variant="default"
|
||||
onClick={() => minutesHandlers.current?.increment()}
|
||||
aria-label={`+ ${tCommon("information.minutes")}`}
|
||||
>
|
||||
+
|
||||
</ActionIcon>
|
||||
</Group>
|
||||
</Stack>
|
||||
<Text ta="center" c="dimmed" my={5}>
|
||||
{t("controls.unlimited")}
|
||||
</Text>
|
||||
<Button
|
||||
variant="light"
|
||||
color="red"
|
||||
leftSection={<IconClockPause size="var(--mantine-font-size-xl)" />}
|
||||
h="2rem"
|
||||
w="12rem"
|
||||
onClick={handleSetTimer}
|
||||
>
|
||||
{t("controls.set")}
|
||||
</Button>
|
||||
</Flex>
|
||||
</Stack>
|
||||
</Popover.Dropdown>
|
||||
</Popover>
|
||||
);
|
||||
};
|
||||
|
||||
export default TimerPopover;
|
||||
@@ -1,66 +0,0 @@
|
||||
"use client";
|
||||
|
||||
import { CloseButton, ColorInput, Input, Stack, TextInput, useMantineTheme } from "@mantine/core";
|
||||
|
||||
import { useForm } from "@homarr/form";
|
||||
import { createModal, ModalFormFooter, modalSizeForm } from "@homarr/modals";
|
||||
import { useI18n } from "@homarr/translation/client";
|
||||
import { TextMultiSelect } from "@homarr/ui";
|
||||
import type { BoardItemAdvancedOptions } from "@homarr/validation/shared";
|
||||
|
||||
interface InnerProps {
|
||||
advancedOptions: BoardItemAdvancedOptions;
|
||||
onSuccess: (options: BoardItemAdvancedOptions) => void;
|
||||
}
|
||||
|
||||
export const WidgetAdvancedOptionsModal = createModal<InnerProps>(({ actions, innerProps }) => {
|
||||
const t = useI18n("item.edit");
|
||||
const theme = useMantineTheme();
|
||||
const form = useForm({
|
||||
initialValues: innerProps.advancedOptions,
|
||||
});
|
||||
const handleSubmit = (values: BoardItemAdvancedOptions) => {
|
||||
innerProps.onSuccess({
|
||||
...values,
|
||||
// we want to fallback to null if the title is empty
|
||||
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
|
||||
title: values.title?.trim() || null,
|
||||
});
|
||||
actions.closeModal();
|
||||
};
|
||||
|
||||
return (
|
||||
<form onSubmit={form.onSubmit(handleSubmit)}>
|
||||
<Stack>
|
||||
<TextInput
|
||||
label={t("field.title.label")}
|
||||
data-autofocus
|
||||
{...form.getInputProps("title")}
|
||||
rightSection={<Input.ClearButton onClick={() => form.setFieldValue("title", "")} />}
|
||||
/>
|
||||
<TextMultiSelect label={t("field.customCssClasses.label")} {...form.getInputProps("customCssClasses")} />
|
||||
<ColorInput
|
||||
label={t("field.borderColor.label")}
|
||||
format="hex"
|
||||
swatches={Object.values(theme.colors).map((color) => color[6])}
|
||||
rightSection={
|
||||
<CloseButton
|
||||
onClick={() => form.setFieldValue("borderColor", "")}
|
||||
style={{ display: form.getInputProps("borderColor").value ? undefined : "none" }}
|
||||
/>
|
||||
}
|
||||
{...form.getInputProps("borderColor")}
|
||||
/>
|
||||
<ModalFormFooter onCancel={actions.closeModal} />
|
||||
</Stack>
|
||||
</form>
|
||||
);
|
||||
}).withOptions({
|
||||
defaultTitle(t) {
|
||||
return t("item.edit.advancedOptions.title");
|
||||
},
|
||||
size: modalSizeForm,
|
||||
transitionProps: {
|
||||
duration: 0,
|
||||
},
|
||||
});
|
||||
@@ -5,19 +5,25 @@
|
||||
import { useEffect, useId, useRef, useState } from "react";
|
||||
import type { ComponentType, FormEvent, PropsWithChildren } from "react";
|
||||
import {
|
||||
Accordion,
|
||||
Alert,
|
||||
Badge,
|
||||
Box,
|
||||
Button,
|
||||
Center,
|
||||
CloseButton,
|
||||
ColorInput,
|
||||
Divider,
|
||||
Group,
|
||||
Input as MantineInput,
|
||||
NumberInput,
|
||||
SimpleGrid,
|
||||
Stack,
|
||||
Tabs,
|
||||
Text,
|
||||
TextInput,
|
||||
Tooltip,
|
||||
useMantineTheme,
|
||||
} from "@mantine/core";
|
||||
import { schemaResolver } from "@mantine/form";
|
||||
import { useElementSize } from "@mantine/hooks";
|
||||
@@ -30,11 +36,11 @@ import { objectEntries } from "@homarr/common";
|
||||
import { IntegrationProvider, useSession } from "@homarr/auth/client";
|
||||
import { useOptionalBoard } from "@homarr/boards/context";
|
||||
import type { WidgetKind } from "@homarr/definitions";
|
||||
import { createModal, modalSizeForm, useModalAction } from "@homarr/modals";
|
||||
import { createModal, modalSizeForm } from "@homarr/modals";
|
||||
import type { SettingsContextProps } from "@homarr/settings/creator";
|
||||
import { SpotlightProvider } from "@homarr/spotlight";
|
||||
import { useI18n } from "@homarr/translation/client";
|
||||
import { IntegrationAvatar } from "@homarr/ui";
|
||||
import { IntegrationAvatar, TextMultiSelect } from "@homarr/ui";
|
||||
import { zodErrorMap } from "@homarr/validation/form/i18n";
|
||||
|
||||
import { getInputForType } from "../_inputs";
|
||||
@@ -47,7 +53,6 @@ import { OPTIONS_SUPER_REFINE } from "../options";
|
||||
import type { IntegrationSelectOption } from "../widget-integration-select";
|
||||
import { WidgetIntegrationSelect } from "../widget-integration-select";
|
||||
import { WidgetCardShell, WidgetTitleBadge } from "../widget-card-shell";
|
||||
import { WidgetAdvancedOptionsModal } from "./widget-advanced-options-modal";
|
||||
import type { EmbeddedAppEditFormHandle } from "./embedded-app-edit-form";
|
||||
import { EmbeddedAppEditForm } from "./embedded-app-edit-form";
|
||||
import classes from "./widget-edit-modal.module.css";
|
||||
@@ -314,7 +319,7 @@ export const WidgetEditModal = createModal<WidgetEditModalProps<WidgetKind>>(({
|
||||
const tCommon = useI18n("common");
|
||||
const board = useOptionalBoard();
|
||||
const { data: session } = useSession();
|
||||
const [advancedOptions, setAdvancedOptions] = useState<BoardItemAdvancedOptions>(innerProps.value.advancedOptions);
|
||||
const theme = useMantineTheme();
|
||||
const appEditRef = useRef<EmbeddedAppEditFormHandle>(null);
|
||||
const integrationEditHandles = useRef(new Map<string, EmbeddedIntegrationEditFormHandle>());
|
||||
const integrationEditRefCallbacks = useRef(
|
||||
@@ -368,6 +373,7 @@ export const WidgetEditModal = createModal<WidgetEditModalProps<WidgetKind>>(({
|
||||
options: optionsSchema,
|
||||
integrationIds: integrationIdsSchema,
|
||||
advancedOptions: z.object({
|
||||
title: z.string().max(64).nullable(),
|
||||
customCssClasses: z.array(z.string()),
|
||||
borderColor: z.string(),
|
||||
}),
|
||||
@@ -377,7 +383,6 @@ export const WidgetEditModal = createModal<WidgetEditModalProps<WidgetKind>>(({
|
||||
validateInputOnBlur: true,
|
||||
validateInputOnChange: true,
|
||||
});
|
||||
const { openModal } = useModalAction(WidgetAdvancedOptionsModal);
|
||||
|
||||
const canModifyApps = session?.user.permissions.includes("app-modify-all") ?? false;
|
||||
const canConfigureWidget = innerProps.kind !== "customApi" || (session?.user.permissions.includes("admin") ?? false);
|
||||
@@ -457,7 +462,10 @@ export const WidgetEditModal = createModal<WidgetEditModalProps<WidgetKind>>(({
|
||||
innerProps.onSuccessfulEdit(
|
||||
{
|
||||
...values,
|
||||
advancedOptions,
|
||||
advancedOptions: {
|
||||
...values.advancedOptions,
|
||||
title: values.advancedOptions.title?.trim() || null,
|
||||
},
|
||||
},
|
||||
previewSize ?? undefined,
|
||||
);
|
||||
@@ -519,14 +527,14 @@ export const WidgetEditModal = createModal<WidgetEditModalProps<WidgetKind>>(({
|
||||
<Box
|
||||
className={classes.workspace}
|
||||
data-with-preview={innerProps.previewComponent ? true : undefined}
|
||||
data-with-settings={hasWidgetSettings ? true : undefined}
|
||||
data-with-settings
|
||||
>
|
||||
{innerProps.previewComponent && (
|
||||
<WidgetEditPreview
|
||||
kind={innerProps.kind}
|
||||
Component={innerProps.previewComponent}
|
||||
definition={definition}
|
||||
state={{ ...form.values, advancedOptions }}
|
||||
state={form.values}
|
||||
itemId={innerProps.itemId}
|
||||
boardId={innerProps.boardId ?? board?.id}
|
||||
dimensions={previewDimensions}
|
||||
@@ -536,107 +544,131 @@ export const WidgetEditModal = createModal<WidgetEditModalProps<WidgetKind>>(({
|
||||
PreviewWrapper={innerProps.previewWrapper}
|
||||
/>
|
||||
)}
|
||||
{innerProps.previewComponent && hasWidgetSettings && (
|
||||
<Divider orientation="vertical" className={classes.previewDivider} />
|
||||
)}
|
||||
<form id={widgetFormId} className={classes.settingsForm} onSubmit={onFormSubmit} hidden={!hasWidgetSettings}>
|
||||
{hasWidgetSettings && (
|
||||
<Stack className={classes.settingsPanel} gap="sm">
|
||||
<Group gap="xs" wrap="nowrap">
|
||||
<IconSettings size={16} />
|
||||
<Text fw={600} size="sm">
|
||||
{tItem("settings.label")}
|
||||
</Text>
|
||||
</Group>
|
||||
{canConfigureWidget && innerProps.integrationSupport && (
|
||||
<Box className={classes.fullWidthField}>
|
||||
<WidgetIntegrationSelect
|
||||
label={tItem("field.integrations.label")}
|
||||
data={innerProps.integrationData}
|
||||
canSelectMultiple={maxIntegrations > 1}
|
||||
withAsterisk={integrationsRequired}
|
||||
onOpenNewIntegration={canCreateIntegration ? handleOpenNewIntegration : undefined}
|
||||
{...form.getInputProps("integrationIds")}
|
||||
/>
|
||||
</Box>
|
||||
)}
|
||||
{canConfigureWidget && (
|
||||
<Stack gap="sm">
|
||||
{switchOptions.length > 0 && (
|
||||
<SimpleGrid cols={{ base: 1, sm: 2 }} spacing="sm" verticalSpacing="sm">
|
||||
{switchOptions.map(([key, value]) => {
|
||||
const Input = getInputForType(value.type);
|
||||
if (!Input) {
|
||||
return null;
|
||||
}
|
||||
{innerProps.previewComponent && <Divider orientation="vertical" className={classes.previewDivider} />}
|
||||
<form id={widgetFormId} className={classes.settingsForm} onSubmit={onFormSubmit}>
|
||||
<Stack className={classes.settingsPanel} gap="sm">
|
||||
{hasWidgetSettings && (
|
||||
<>
|
||||
<Group gap="xs" wrap="nowrap">
|
||||
<IconSettings size={16} />
|
||||
<Text fw={600} size="sm">
|
||||
{tItem("settings.label")}
|
||||
</Text>
|
||||
</Group>
|
||||
{canConfigureWidget && innerProps.integrationSupport && (
|
||||
<Box className={classes.fullWidthField}>
|
||||
<WidgetIntegrationSelect
|
||||
label={tItem("field.integrations.label")}
|
||||
data={innerProps.integrationData}
|
||||
canSelectMultiple={maxIntegrations > 1}
|
||||
withAsterisk={integrationsRequired}
|
||||
onOpenNewIntegration={canCreateIntegration ? handleOpenNewIntegration : undefined}
|
||||
{...form.getInputProps("integrationIds")}
|
||||
/>
|
||||
</Box>
|
||||
)}
|
||||
{canConfigureWidget && (
|
||||
<Stack gap="sm">
|
||||
{switchOptions.length > 0 && (
|
||||
<SimpleGrid cols={{ base: 1, sm: 2 }} spacing="sm" verticalSpacing="sm">
|
||||
{switchOptions.map(([key, value]) => {
|
||||
const Input = getInputForType(value.type);
|
||||
if (!Input) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<Box
|
||||
key={key}
|
||||
className={classes.switchOption}
|
||||
data-option-type={value.type}
|
||||
onClick={(event) => {
|
||||
const target = event.target;
|
||||
if (target instanceof Element && target.closest("label, input")) return;
|
||||
const input = event.currentTarget.querySelector<HTMLInputElement>("input[type=checkbox]");
|
||||
if (!input?.disabled) input?.click();
|
||||
}}
|
||||
>
|
||||
<Input
|
||||
kind={innerProps.kind}
|
||||
property={key}
|
||||
options={value as never}
|
||||
initialOptions={innerProps.value.options}
|
||||
itemId={innerProps.itemId}
|
||||
boardId={innerProps.boardId ?? board?.id}
|
||||
/>
|
||||
</Box>
|
||||
);
|
||||
})}
|
||||
</SimpleGrid>
|
||||
)}
|
||||
{otherOptions.map(([key, value]) => {
|
||||
const Input = getInputForType(value.type);
|
||||
if (!Input) {
|
||||
return null;
|
||||
}
|
||||
return (
|
||||
<Box
|
||||
key={key}
|
||||
className={classes.switchOption}
|
||||
data-option-type={value.type}
|
||||
onClick={(event) => {
|
||||
const target = event.target;
|
||||
if (target instanceof Element && target.closest("label, input")) return;
|
||||
const input = event.currentTarget.querySelector<HTMLInputElement>("input[type=checkbox]");
|
||||
if (!input?.disabled) input?.click();
|
||||
}}
|
||||
>
|
||||
<Input
|
||||
kind={innerProps.kind}
|
||||
property={key}
|
||||
options={value as never}
|
||||
initialOptions={innerProps.value.options}
|
||||
itemId={innerProps.itemId}
|
||||
boardId={innerProps.boardId ?? board?.id}
|
||||
/>
|
||||
</Box>
|
||||
);
|
||||
})}
|
||||
</SimpleGrid>
|
||||
)}
|
||||
{otherOptions.map(([key, value]) => {
|
||||
const Input = getInputForType(value.type);
|
||||
if (!Input) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<Box key={key} data-option-type={value.type}>
|
||||
<Input
|
||||
kind={innerProps.kind}
|
||||
property={key}
|
||||
options={value as never}
|
||||
initialOptions={innerProps.value.options}
|
||||
itemId={innerProps.itemId}
|
||||
boardId={innerProps.boardId ?? board?.id}
|
||||
return (
|
||||
<Box key={key} data-option-type={value.type}>
|
||||
<Input
|
||||
kind={innerProps.kind}
|
||||
property={key}
|
||||
options={value as never}
|
||||
initialOptions={innerProps.value.options}
|
||||
itemId={innerProps.itemId}
|
||||
boardId={innerProps.boardId ?? board?.id}
|
||||
/>
|
||||
</Box>
|
||||
);
|
||||
})}
|
||||
</Stack>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
<Accordion variant="contained">
|
||||
<Accordion.Item value="advanced-options">
|
||||
<Accordion.Control>{tItem("advancedOptions.label")}</Accordion.Control>
|
||||
<Accordion.Panel>
|
||||
<Stack gap="sm">
|
||||
<TextInput
|
||||
label={tItem("field.title.label")}
|
||||
rightSection={
|
||||
<MantineInput.ClearButton
|
||||
onClick={() => form.setFieldValue("advancedOptions.title", "")}
|
||||
disabled={!form.values.advancedOptions.title}
|
||||
/>
|
||||
</Box>
|
||||
);
|
||||
})}
|
||||
</Stack>
|
||||
)}
|
||||
</Stack>
|
||||
)}
|
||||
}
|
||||
{...form.getInputProps("advancedOptions.title")}
|
||||
/>
|
||||
<TextMultiSelect
|
||||
label={tItem("field.customCssClasses.label")}
|
||||
{...form.getInputProps("advancedOptions.customCssClasses")}
|
||||
/>
|
||||
<ColorInput
|
||||
label={tItem("field.borderColor.label")}
|
||||
format="hex"
|
||||
swatches={Object.values(theme.colors).map((color) => color[6])}
|
||||
rightSection={
|
||||
<CloseButton
|
||||
aria-label={tCommon("action.remove")}
|
||||
onClick={() => form.setFieldValue("advancedOptions.borderColor", "")}
|
||||
style={{ display: form.values.advancedOptions.borderColor ? undefined : "none" }}
|
||||
/>
|
||||
}
|
||||
{...form.getInputProps("advancedOptions.borderColor")}
|
||||
/>
|
||||
</Stack>
|
||||
</Accordion.Panel>
|
||||
</Accordion.Item>
|
||||
</Accordion>
|
||||
</Stack>
|
||||
</form>
|
||||
</Box>
|
||||
);
|
||||
|
||||
const footer = (
|
||||
<Box className={classes.footer}>
|
||||
<Group justify="space-between" wrap="nowrap">
|
||||
<Button
|
||||
variant="subtle"
|
||||
type="button"
|
||||
onClick={() =>
|
||||
openModal({
|
||||
advancedOptions,
|
||||
onSuccess: setAdvancedOptions,
|
||||
})
|
||||
}
|
||||
>
|
||||
{tItem("advancedOptions.label")}
|
||||
</Button>
|
||||
<Group justify="end" wrap="nowrap">
|
||||
<Group gap="xs" wrap="nowrap">
|
||||
<Button onClick={actions.closeModal} variant="subtle" color="gray">
|
||||
{tCommon("action.cancel")}
|
||||
|
||||
@@ -66,6 +66,7 @@ import { useForm } from "@homarr/form";
|
||||
import type { TranslationObject } from "@homarr/translation";
|
||||
import { useI18n } from "@homarr/translation/client";
|
||||
import type { TablerIcon } from "@homarr/ui";
|
||||
import { InlineConfirmActionIcon } from "@homarr/ui";
|
||||
|
||||
import type { WidgetComponentProps } from "../definition";
|
||||
import actionTargetClasses from "../common/action-target.module.css";
|
||||
@@ -80,7 +81,6 @@ import { useSession } from "@homarr/auth/client";
|
||||
import { constructBoardPermissions } from "@homarr/auth/shared";
|
||||
import { useRequiredBoard } from "@homarr/boards/context";
|
||||
import { hotkeys } from "@homarr/definitions";
|
||||
import { useConfirmModal } from "@homarr/modals";
|
||||
|
||||
const iconProps = {
|
||||
size: 30,
|
||||
@@ -285,21 +285,10 @@ export function Notebook({
|
||||
return false;
|
||||
}, [editor]);
|
||||
|
||||
const { openConfirmModal } = useConfirmModal();
|
||||
const handleEditCancel = useCallback(() => {
|
||||
if (savingRef.current) return;
|
||||
openConfirmModal({
|
||||
title: t("dismiss.title"),
|
||||
children: t("dismiss.message"),
|
||||
labels: {
|
||||
confirm: t("dismiss.action.discard"),
|
||||
cancel: t("dismiss.action.keepEditing"),
|
||||
},
|
||||
onConfirm: () => {
|
||||
setIsEditing(handleEditCancelCallback);
|
||||
},
|
||||
});
|
||||
}, [setIsEditing, handleEditCancelCallback, openConfirmModal, t]);
|
||||
setIsEditing(handleEditCancelCallback);
|
||||
}, [setIsEditing, handleEditCancelCallback]);
|
||||
|
||||
const handleEditToggle = useCallback(async () => {
|
||||
if (!editor || savingRef.current) return;
|
||||
@@ -369,8 +358,7 @@ export function Notebook({
|
||||
},
|
||||
toolbar: {
|
||||
backgroundColor: "transparent",
|
||||
borderColor:
|
||||
"rgb(from var(--mantine-color-default-border) r g b / calc(var(--opacity, 1) * 0.45))",
|
||||
borderColor: "rgb(from var(--mantine-color-default-border) r g b / calc(var(--opacity, 1) * 0.45))",
|
||||
padding: "0.5rem",
|
||||
},
|
||||
content: {
|
||||
@@ -554,19 +542,22 @@ export function Notebook({
|
||||
{isEditing ? <IconDeviceFloppy {...iconProps} /> : <IconEdit {...iconProps} />}
|
||||
</ActionIcon>
|
||||
{isEditing && (
|
||||
<ActionIcon
|
||||
<InlineConfirmActionIcon
|
||||
className={`homarr-notebook-action ${actionTargetClasses.root}`}
|
||||
data-visible
|
||||
title={tCommon("action.cancel")}
|
||||
aria-label={tCommon("action.cancel")}
|
||||
confirmLabel={t("dismiss.message")}
|
||||
confirmationAriaLabel={t("dismiss.action.discard")}
|
||||
confirmationChildren={<IconCheck {...iconProps} />}
|
||||
onConfirm={handleEditCancel}
|
||||
color={primaryColor}
|
||||
variant="light"
|
||||
size={30}
|
||||
disabled={isSaving}
|
||||
onClick={handleEditCancel}
|
||||
>
|
||||
<IconX {...iconProps} />
|
||||
</ActionIcon>
|
||||
</InlineConfirmActionIcon>
|
||||
)}
|
||||
</Stack>
|
||||
)}
|
||||
|
||||
Reference in new issue
Block a user