-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(1314737): Multiple input in the Boost form is not working correctly
- Loading branch information
1 parent
274f2b7
commit cb36a7c
Showing
6 changed files
with
89 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 0 additions & 82 deletions
82
packages/components/src/components/stateful/FieldGuesser/EditableModelConfig.tsx
This file was deleted.
Oops, something went wrong.
67 changes: 67 additions & 0 deletions
67
packages/components/src/components/stateful/FieldGuesser/MultipleInput.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import React, { SyntheticEvent, useMemo } from 'react' | ||
import { | ||
DataContentType, | ||
IFieldGuesserProps, | ||
IInputDependencies, | ||
valueInitializer, | ||
} from '@elastic-suite/gally-admin-shared' | ||
import FieldGuesser from './FieldGuesser' | ||
|
||
interface IProps extends Omit<IFieldGuesserProps, 'onChange' | 'value'> { | ||
value?: string | ||
onChange?: (val: string, event?: SyntheticEvent<Element, Event>) => void | ||
} | ||
|
||
function MultipleInput(props: IProps): JSX.Element { | ||
const { | ||
multipleInputConfiguration: { inputDependencies }, | ||
onChange, | ||
...otherProps | ||
} = props | ||
|
||
const fields: IInputDependencies[] = useMemo(() => { | ||
return ( | ||
Array.isArray(inputDependencies) ? inputDependencies : [inputDependencies] | ||
).filter( | ||
(inputDependencie) => | ||
inputDependencie.value === otherProps.data[inputDependencie.field] | ||
) | ||
}, [inputDependencies, otherProps.data]) | ||
|
||
return ( | ||
<> | ||
{fields.map((field) => { | ||
const value = otherProps.value | ||
? JSON.parse(otherProps.value as string)?.[field.jsonKeyValue] ?? | ||
valueInitializer(field.input) | ||
: valueInitializer(field.input) | ||
|
||
function handleChange( | ||
_name: string, | ||
value: unknown, | ||
event?: React.SyntheticEvent<Element, Event> | ||
): void { | ||
const newValue: Record<string, unknown> = otherProps.value | ||
? JSON.parse(otherProps.value as string) | ||
: {} | ||
newValue[field?.jsonKeyValue] = value | ||
onChange(JSON.stringify(newValue), event) | ||
} | ||
|
||
return ( | ||
<FieldGuesser | ||
key={field.jsonKeyValue} | ||
{...otherProps} | ||
input={field.input as DataContentType} | ||
editable | ||
id={field.input} | ||
value={value} | ||
onChange={handleChange} | ||
/> | ||
) | ||
})} | ||
</> | ||
) | ||
} | ||
|
||
export default MultipleInput |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters