diff --git a/web/src/components/config-form/theme/templates/FieldTemplate.tsx b/web/src/components/config-form/theme/templates/FieldTemplate.tsx index 39915457d..d16b05a38 100644 --- a/web/src/components/config-form/theme/templates/FieldTemplate.tsx +++ b/web/src/components/config-form/theme/templates/FieldTemplate.tsx @@ -378,6 +378,190 @@ export function FieldTemplate(props: FieldTemplateProps) { uiOptions, ); + const shouldRenderStandardLabel = + displayLabel && + finalLabel && + !isBoolean && + !useSplitLayout && + !isMultiSchemaWrapper && + !isObjectField && + !isAdditionalProperty; + + const shouldRenderSplitLabel = + displayLabel && + finalLabel && + !isMultiSchemaWrapper && + !isObjectField && + !isAdditionalProperty; + + const shouldRenderBooleanLabel = displayLabel && finalLabel; + + const renderDocsLink = (className?: string) => { + if (!fieldDocsUrl || !shouldShowDescription) { + return null; + } + + return ( +
+ + {t("readTheDocumentation", { ns: "common" })} + + +
+ ); + }; + + const renderDescription = (className?: string) => { + if (!finalDescription || !shouldShowDescription) { + return null; + } + + return ( +

+ {finalDescription} +

+ ); + }; + + const renderStandardLabel = () => { + if (!shouldRenderStandardLabel) { + return null; + } + + return ( + + ); + }; + + const renderBooleanLabel = () => { + if (!shouldRenderBooleanLabel) { + return null; + } + + return ( + + ); + }; + + const renderSplitLabel = () => { + if (!shouldRenderSplitLabel) { + return null; + } + + return ( + + ); + }; + + const renderBooleanSplitLayout = () => ( + <> +
+
+ {renderBooleanLabel()} +
{children}
+
+ {renderDescription()} + {renderDocsLink()} +
+ +
+
+ {renderBooleanLabel()} + {renderDescription()} + {renderDocsLink()} +
+
+
{children}
+
+
+ + ); + + const renderBooleanInlineLayout = () => ( +
+
+ {renderBooleanLabel()} + {renderDescription()} + {renderDocsLink()} +
+
{children}
+
+ ); + + const renderSplitValueLayout = () => ( +
+
+ {renderSplitLabel()} + {renderDescription("hidden md:block")} + {renderDocsLink("hidden md:flex")} +
+ +
+ {children} + {renderDescription("md:hidden")} + {renderDocsLink("md:hidden")} +
+
+ ); + + const renderDefaultValueLayout = () => ( + <> + {children} + {renderDescription()} + {renderDocsLink()} + + ); + + const renderFieldLayout = () => { + if (isBoolean) { + return useSplitBooleanLayout + ? renderBooleanSplitLayout() + : renderBooleanInlineLayout(); + } + + if (useSplitLayout) { + return renderSplitValueLayout(); + } + + return renderDefaultValueLayout(); + }; + return ( {beforeContent}
- {displayLabel && - finalLabel && - !isBoolean && - !useSplitLayout && - !isMultiSchemaWrapper && - !isObjectField && - !isAdditionalProperty && ( - - )} - - {isBoolean ? ( - useSplitBooleanLayout ? ( - <> -
-
- {displayLabel && finalLabel && ( - - )} -
{children}
-
- {finalDescription && shouldShowDescription && ( -

- {finalDescription} -

- )} - {fieldDocsUrl && shouldShowDescription && ( -
- - {t("readTheDocumentation", { ns: "common" })} - - -
- )} -
- -
-
- {displayLabel && finalLabel && ( - - )} - {finalDescription && shouldShowDescription && ( -

- {finalDescription} -

- )} - {fieldDocsUrl && shouldShowDescription && ( -
- - {t("readTheDocumentation", { ns: "common" })} - - -
- )} -
-
-
{children}
-
-
- - ) : ( -
-
- {displayLabel && finalLabel && ( - - )} - {finalDescription && shouldShowDescription && ( -

- {finalDescription} -

- )} - {fieldDocsUrl && shouldShowDescription && ( -
- - {t("readTheDocumentation", { ns: "common" })} - - -
- )} -
-
{children}
-
- ) - ) : useSplitLayout ? ( -
-
- {displayLabel && - finalLabel && - !isMultiSchemaWrapper && - !isObjectField && - !isAdditionalProperty && ( - - )} - - {finalDescription && shouldShowDescription && ( -

- {finalDescription} -

- )} - {fieldDocsUrl && shouldShowDescription && ( -
- - {t("readTheDocumentation", { ns: "common" })} - - -
- )} -
- -
- {children} - - {finalDescription && shouldShowDescription && ( -

- {finalDescription} -

- )} - {fieldDocsUrl && shouldShowDescription && ( -
- - {t("readTheDocumentation", { ns: "common" })} - - -
- )} -
-
- ) : ( - <> - {children} - - {finalDescription && shouldShowDescription && ( -

- {finalDescription} -

- )} - {fieldDocsUrl && shouldShowDescription && ( -
- - {t("readTheDocumentation", { ns: "common" })} - - -
- )} - - )} + {renderStandardLabel()} + {renderFieldLayout()} {errors} {help} diff --git a/web/src/components/config-form/theme/widgets/TimezoneSelectWidget.tsx b/web/src/components/config-form/theme/widgets/TimezoneSelectWidget.tsx index 3e5253270..eef8570ac 100644 --- a/web/src/components/config-form/theme/widgets/TimezoneSelectWidget.tsx +++ b/web/src/components/config-form/theme/widgets/TimezoneSelectWidget.tsx @@ -8,6 +8,7 @@ import { SelectValue, } from "@/components/ui/select"; import { useTranslation } from "react-i18next"; +import { getSizedFieldClassName } from "../utils"; const DEFAULT_TIMEZONE_VALUE = "__browser__"; @@ -27,11 +28,12 @@ function getTimezoneList(): string[] { } export function TimezoneSelectWidget(props: WidgetProps) { - const { id, value, disabled, readonly, onChange, schema } = props; + const { id, value, disabled, readonly, onChange, schema, options } = props; const { t } = useTranslation(["views/settings", "common"]); const timezones = useMemo(() => getTimezoneList(), []); const selectedValue = value ? String(value) : DEFAULT_TIMEZONE_VALUE; + const fieldClassName = getSizedFieldClassName(options, "sm"); const defaultLabel = t("configForm.timezone.defaultOption", { ns: "views/settings", }); @@ -44,7 +46,7 @@ export function TimezoneSelectWidget(props: WidgetProps) { } disabled={disabled || readonly} > - +