-
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.
SHIBUI-2539: Fixed bug with property values changing on deletion
- Loading branch information
Showing
37 changed files
with
400 additions
and
292 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
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,57 @@ | ||
| import React, { Fragment } from 'react'; | ||
| import FloatingLabel from 'react-bootstrap/FloatingLabel'; | ||
| import Form from 'react-bootstrap/Form'; | ||
| import { useValidator } from '../../core/hooks/useValidator'; | ||
| import { useTranslator } from '../../i18n/hooks'; | ||
|
|
||
| export function PropertyInput({ property, onChange }) { | ||
|
|
||
| const translate = useTranslator(); | ||
|
|
||
| const value = React.useMemo(() => { | ||
| const { propertyValue, displayType } = property; | ||
| switch (displayType) { | ||
| case 'number': | ||
| return parseInt(propertyValue); | ||
| case 'boolean': | ||
| return propertyValue ? Boolean(propertyValue) : false; | ||
| default: | ||
| return propertyValue || ''; | ||
| } | ||
| }, [property]); | ||
|
|
||
| const { errors } = useValidator({ value }, { | ||
| value: { | ||
| custom: { | ||
| isValid: (value) => !value || value?.length <= 255, | ||
| message: translate(`message.must-be-unique`), | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| return ( | ||
| <Fragment> | ||
| {property.displayType !== 'boolean' ? | ||
| <FloatingLabel | ||
| controlId={`valueInput-${property.propertyName}`} | ||
| label={translate('label.configuration-value')}> | ||
| <Form.Control | ||
| type={property.displayType === 'number' ? 'number' : 'text'} | ||
| placeholder="value" | ||
| name={`properties.${property.resourceId}.propertyValue`} | ||
| value={ value } | ||
| onChange={ (evt) => onChange({ id: property.resourceId, propertyValue: evt.target.value }) } | ||
| maxLength={255} | ||
| isInvalid={ errors.value } /> | ||
| </FloatingLabel> | ||
| : | ||
| <Form.Check type="switch" | ||
| label={ value?.toString() === 'true' ? translate('value.true') : translate('value.false') } | ||
| reverse={'true'} | ||
| checked={ value } | ||
| onChange={ (evt) => onChange({ id: property.resourceId, propertyValue: evt.target.checked }) } | ||
| className="my-3" /> | ||
| } | ||
| </Fragment> | ||
| ); | ||
| } |
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
Oops, something went wrong.