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
@@ -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")}
|
||||
|
||||
Reference in new issue
Block a user