Merge pull request #1104 from Hexastack/1103-issue---refactor-to-use-spreading-props

refactor(frontend): prioritize speading props
This commit is contained in:
Med Marrouchi 2025-06-09 09:32:11 +01:00 committed by GitHub
commit 9aea582915
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 13 additions and 47 deletions

View File

@ -52,15 +52,9 @@ const AutoCompleteEntitySelect = <
Multiple extends boolean | undefined = true, Multiple extends boolean | undefined = true,
>( >(
{ {
label,
value,
entity, entity,
format, format,
searchFields, searchFields,
multiple,
onChange,
error,
helperText,
preprocess, preprocess,
idKey = "id", idKey = "id",
labelKey, labelKey,
@ -106,17 +100,11 @@ const AutoCompleteEntitySelect = <
return ( return (
<AutoCompleteSelect<Value, Label, Multiple> <AutoCompleteSelect<Value, Label, Multiple>
value={value}
onChange={onChange}
label={label}
multiple={multiple}
ref={ref} ref={ref}
idKey={idKey} idKey={idKey}
labelKey={labelKey} labelKey={labelKey}
options={options || []} options={options || []}
onSearch={onSearch} onSearch={onSearch}
error={error}
helperText={helperText}
loading={isFetching} loading={isFetching}
{...rest} {...rest}
/> />

View File

@ -52,15 +52,12 @@ const AutoCompleteSelect = <
FreeSolo extends boolean | undefined = false, FreeSolo extends boolean | undefined = false,
>( >(
{ {
label,
value, value,
options = [], options = [],
idKey = "id", idKey = "id",
labelKey, labelKey,
multiple, multiple,
onSearch, onSearch,
error,
helperText,
isOptionEqualToValue = (option, value) => isOptionEqualToValue = (option, value) =>
option?.[idKey] === value?.[idKey], option?.[idKey] === value?.[idKey],
getOptionLabel = (option) => option?.[String(labelKey)] || option?.[idKey], getOptionLabel = (option) => option?.[String(labelKey)] || option?.[idKey],
@ -157,10 +154,7 @@ const AutoCompleteSelect = <
renderInput={(props) => ( renderInput={(props) => (
<Input <Input
{...props} {...props}
label={label}
onChange={(e) => handleSearch(e.target.value)} onChange={(e) => handleSearch(e.target.value)}
error={error}
helperText={helperText}
InputProps={{ InputProps={{
...props.InputProps, ...props.InputProps,
endAdornment: ( endAdornment: (

View File

@ -14,7 +14,7 @@ import { forwardRef, useState } from "react";
import { Input } from "./Input"; import { Input } from "./Input";
export const PasswordInput = forwardRef<any, TextFieldProps>( export const PasswordInput = forwardRef<any, TextFieldProps>(
({ onChange, InputProps, ...rest }, ref) => { ({ InputProps, ...rest }, ref) => {
const [showPassword, setShowPassword] = useState(false); const [showPassword, setShowPassword] = useState(false);
const handleTogglePasswordVisibility = () => { const handleTogglePasswordVisibility = () => {
setShowPassword(!showPassword); setShowPassword(!showPassword);
@ -25,7 +25,6 @@ export const PasswordInput = forwardRef<any, TextFieldProps>(
ref={ref} ref={ref}
type={showPassword ? "text" : "password"} type={showPassword ? "text" : "password"}
{...rest} {...rest}
onChange={onChange}
InputProps={{ InputProps={{
...InputProps, ...InputProps,
endAdornment: ( endAdornment: (

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: * 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. * 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
@ -63,17 +63,9 @@ const ButtonsMessageForm = () => {
name="message.buttons" name="message.buttons"
control={control} control={control}
defaultValue={block?.message.buttons || []} defaultValue={block?.message.buttons || []}
render={({ field }) => { render={({ field }) => (
const { value, onChange } = field; <ButtonsInput {...field} fieldPath="message.buttons" />
)}
return (
<ButtonsInput
fieldPath="message.buttons"
value={value}
onChange={onChange}
/>
);
}}
/> />
</ContentItem> </ContentItem>
</> </>

View File

@ -295,21 +295,14 @@ const ListMessageForm = () => {
name="options.content.buttons" name="options.content.buttons"
control={control} control={control}
defaultValue={content?.buttons || []} defaultValue={content?.buttons || []}
render={({ field }) => { render={({ field }) => (
const { value, onChange } = field;
return (
<ButtonsInput <ButtonsInput
{...field}
fieldPath="options.content.buttons" fieldPath="options.content.buttons"
value={value}
onChange={(buttons) => {
onChange(buttons);
}}
disablePayload={true} disablePayload={true}
maxInput={displayMode === "list" ? 1 : 2} maxInput={displayMode === "list" ? 1 : 2}
/> />
); )}
}}
/> />
</ContentItem> </ContentItem>
</Grid> </Grid>