-
Notifications
You must be signed in to change notification settings - Fork 6
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 #128 from formio/FIO-8731
FIO-8731: Update fix to nested hidden components
- Loading branch information
1 parent
5dc3bf3
commit 0272ce5
Showing
6 changed files
with
69 additions
and
5 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,56 @@ | ||
import { set } from 'lodash'; | ||
import { | ||
ProcessorScope, | ||
ProcessorContext, | ||
ProcessorInfo, | ||
ProcessorFnSync, | ||
ConditionsScope, | ||
Component, | ||
ProcessorFn, | ||
} from "types"; | ||
import { componentInfo, eachComponentData, getComponentPath } from 'utils/formUtil'; | ||
|
||
/** | ||
* This processor function checks components for the `hidden` property and, if children are present, sets them to hidden as well. | ||
*/ | ||
export const hideChildrenProcessor: ProcessorFnSync<ConditionsScope> = (context) => { | ||
const { component, path, row, scope } = context; | ||
// Check if there's a conditional set for the component and if it's marked as conditionally hidden | ||
const isConditionallyHidden = scope.conditionals?.find((cond) => { | ||
return path.includes(cond.path) && cond.conditionallyHidden; | ||
}); | ||
if (component.hidden && isConditionallyHidden) { | ||
const info = componentInfo(component); | ||
if (info.hasColumns || info.hasComps || info.hasRows) { | ||
// If this is a container component, we need to make the mutation to all the child components as well. | ||
eachComponentData([component], row, (comp: Component, data: any, compRow: any, compPath: string) => { | ||
if (comp !== component) { | ||
// the path set here is not the absolute path, but the path relative to the parent component | ||
(scope as ConditionsScope).conditionals?.push({ path: getComponentPath(comp, compPath), conditionallyHidden: true }); | ||
set(comp, 'hidden', true); | ||
} | ||
}); | ||
} | ||
} else if (component.hidden) { | ||
const info = componentInfo(component); | ||
if (info.hasColumns || info.hasComps || info.hasRows) { | ||
// If this is a container component, we need to make the mutation to all the child components as well. | ||
eachComponentData([component], row, (comp: Component, data: any, compRow: any, compPath: string) => { | ||
if (comp !== component) { | ||
set(comp, 'hidden', true); | ||
} | ||
}); | ||
} | ||
} | ||
} | ||
|
||
export const hideChildrenProcessorAsync: ProcessorFn<ProcessorScope> = async (context) => { | ||
return hideChildrenProcessor(context); | ||
}; | ||
|
||
export const hideChildrenProcessorInfo: ProcessorInfo<ProcessorContext<ProcessorScope>, void> = { | ||
name: 'hideChildren', | ||
shouldProcess: () => true, | ||
processSync: hideChildrenProcessor, | ||
process: hideChildrenProcessorAsync, | ||
} |
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