-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #382 from shesha-io/fix/containers-in-subforms
fix(ComponentsContainerSubForm): wrapped the components with div
- Loading branch information
Showing
3 changed files
with
126 additions
and
117 deletions.
There are no files selected for viewing
111 changes: 59 additions & 52 deletions
111
shesha-reactjs/src/components/formDesigner/components/subForm/componentsContainerSubForm.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 |
---|---|---|
@@ -1,54 +1,61 @@ | ||
import { IComponentsContainerBaseProps } from "interfaces"; | ||
import { useGlobalState, useSubForm } from "providers"; | ||
import React, { Fragment } from "react"; | ||
import { FC, useCallback } from "react"; | ||
import { executeScriptSync } from "utils/publicUtils"; | ||
import DynamicComponent from "../dynamicView/dynamicComponent"; | ||
|
||
export const ComponentsContainerSubForm: FC<IComponentsContainerBaseProps> = props => { | ||
const { containerId, readOnly } = props; | ||
const { getChildComponents } = useSubForm(); | ||
const components = getChildComponents(containerId); | ||
|
||
//alias added for readability and avoiding names clashes | ||
const { value: subFormData } = useSubForm(); | ||
const { globalState } = useGlobalState(); | ||
|
||
const executeExpression = useCallback( | ||
(expression: string) => { | ||
if (!expression) return true; | ||
const evaluated = executeScriptSync(expression, { data: subFormData, globalState }); | ||
return typeof evaluated === 'boolean' ? evaluated : true; | ||
}, | ||
[subFormData, globalState] | ||
); | ||
|
||
const getReadOnlyState = (isReadOnly: boolean) => (typeof readOnly === 'boolean' ? readOnly : isReadOnly); | ||
|
||
return ( | ||
<Fragment> | ||
{components | ||
?.filter(({ customVisibility }) => { | ||
return executeExpression(customVisibility); | ||
}) | ||
.map(({ customEnabled, disabled: notabled, ...model }) => { | ||
const disabled = !executeExpression(customEnabled) || notabled; | ||
|
||
return ( | ||
<DynamicComponent | ||
model={{ | ||
...model, | ||
isDynamic: true, | ||
readOnly: getReadOnlyState(model?.readOnly), | ||
disabled, | ||
customEnabled: '', | ||
}} | ||
key={model?.id} | ||
/> | ||
); | ||
})} | ||
</Fragment> | ||
); | ||
import { IComponentsContainerBaseProps } from 'interfaces'; | ||
import { useGlobalState, useSubForm } from 'providers'; | ||
import React from 'react'; | ||
import { FC, useCallback } from 'react'; | ||
import { executeScriptSync } from 'utils/publicUtils'; | ||
import DynamicComponent from '../dynamicView/dynamicComponent'; | ||
import { getAlignmentStyle } from 'components/formDesigner/containers/componentsContainerForm'; | ||
import { ICommonContainerProps } from 'designer-components/container/interfaces'; | ||
import { removeUndefinedProperties } from 'utils/array'; | ||
|
||
interface IComponentsContainerSubFormProps extends IComponentsContainerBaseProps, ICommonContainerProps {} | ||
|
||
export const ComponentsContainerSubForm: FC<IComponentsContainerSubFormProps> = (props) => { | ||
const { containerId, readOnly } = props; | ||
const { getChildComponents } = useSubForm(); | ||
const components = getChildComponents(containerId); | ||
|
||
const style = getAlignmentStyle(props); | ||
|
||
//alias added for readability and avoiding names clashes | ||
const { value: subFormData } = useSubForm(); | ||
const { globalState } = useGlobalState(); | ||
|
||
const executeExpression = useCallback( | ||
(expression: string) => { | ||
if (!expression) return true; | ||
const evaluated = executeScriptSync(expression, { data: subFormData, globalState }); | ||
return typeof evaluated === 'boolean' ? evaluated : true; | ||
}, | ||
[subFormData, globalState] | ||
); | ||
|
||
const getReadOnlyState = (isReadOnly: boolean) => (typeof readOnly === 'boolean' ? readOnly : isReadOnly); | ||
|
||
return ( | ||
<div style={removeUndefinedProperties(style)}> | ||
{components | ||
?.filter(({ customVisibility }) => { | ||
return executeExpression(customVisibility); | ||
}) | ||
.map(({ customEnabled, disabled: notabled, ...model }) => { | ||
const disabled = !executeExpression(customEnabled) || notabled; | ||
|
||
return ( | ||
<DynamicComponent | ||
model={{ | ||
...model, | ||
isDynamic: true, | ||
readOnly: getReadOnlyState(model?.readOnly), | ||
disabled, | ||
customEnabled: '', | ||
}} | ||
key={model?.id} | ||
/> | ||
); | ||
})} | ||
</div> | ||
); | ||
}; | ||
|
||
ComponentsContainerSubForm.displayName = "ComponentsContainer(SubForm)"; | ||
ComponentsContainerSubForm.displayName = 'ComponentsContainer(SubForm)'; |
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.