Merge pull request #1035 from Hexastack/1030-issue---block-form-empty-select-for-the-type-of-context-var-capture

fix(frontend): select components defaultValue
This commit is contained in:
Med Marrouchi
2025-05-26 17:59:19 +01:00
committed by GitHub
3 changed files with 8 additions and 11 deletions

View File

@@ -106,7 +106,7 @@ const AutoCompleteEntitySelect = <
return (
<AutoCompleteSelect<Value, Label, Multiple>
{...(options.length && { value })}
value={value}
onChange={onChange}
label={label}
multiple={multiple}

View File

@@ -1,5 +1,5 @@
/*
* Copyright © 2024 Hexastack. All rights reserved.
* Copyright © 2025 Hexastack. All rights reserved.
*
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
@@ -11,6 +11,7 @@ import Autocomplete, {
AutocompleteProps,
AutocompleteValue,
} from "@mui/material/Autocomplete";
import stringify from "fast-json-stable-stringify";
import { forwardRef, useCallback, useMemo } from "react";
import { Input } from "@/app-components/inputs/Input";
@@ -112,7 +113,7 @@ const AutoCompleteSelect = <
{...rest}
ref={ref}
size="small"
key={JSON.stringify(value)}
key={`${stringify(options)}_${stringify(value)}`}
disabled={isDisabled}
defaultValue={selected}
multiple={multiple}

View File

@@ -182,7 +182,7 @@ const ListMessageForm = () => {
}}
defaultValue={content?.fields?.title}
render={({ field }) => {
const { onChange, value, ...rest } = field;
const { onChange, ...rest } = field;
const options = (contentType?.fields || []).filter(
({ type }) => ContentFieldType.TEXT === type,
);
@@ -194,7 +194,6 @@ const ListMessageForm = () => {
labelKey="label"
label={t("label.title")}
multiple={false}
{...(options.length && { value })}
{...rest}
onChange={(_e, selected) => onChange(selected?.name)}
error={!!errors?.options?.["content"]?.fields?.title}
@@ -212,7 +211,7 @@ const ListMessageForm = () => {
control={control}
defaultValue={content?.fields?.subtitle}
render={({ field }) => {
const { onChange, value, ...rest } = field;
const { onChange, ...rest } = field;
const options = (contentType?.fields || []).filter(
({ type }) =>
ContentFieldType.TEXT === type ||
@@ -227,7 +226,6 @@ const ListMessageForm = () => {
label={t("label.subtitle")}
multiple={false}
onChange={(_e, selected) => onChange(selected?.name)}
{...(options.length && { value })}
{...rest}
/>
);
@@ -240,7 +238,7 @@ const ListMessageForm = () => {
control={control}
defaultValue={content?.fields?.image_url}
render={({ field }) => {
const { onChange, value, ...rest } = field;
const { onChange, ...rest } = field;
const options = (contentType?.fields || []).filter(({ type }) =>
[ContentFieldType.FILE].includes(type),
);
@@ -253,7 +251,6 @@ const ListMessageForm = () => {
label={t("label.image_url")}
multiple={false}
onChange={(_e, selected) => onChange(selected?.name)}
{...(options.length && { value })}
{...rest}
/>
);
@@ -266,7 +263,7 @@ const ListMessageForm = () => {
control={control}
defaultValue={content?.fields?.url}
render={({ field }) => {
const { onChange, value, ...rest } = field;
const { onChange, ...rest } = field;
const options = (contentType?.fields || []).filter(({ type }) =>
[ContentFieldType.URL].includes(type),
);
@@ -279,7 +276,6 @@ const ListMessageForm = () => {
label={t("label.url")}
multiple={false}
onChange={(_e, selected) => onChange(selected?.name)}
{...(options.length && { value })}
{...rest}
/>
);