Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ensure repeatRenderManager passes down props correctly #1033

Merged
merged 1 commit into from
Feb 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -79,36 +79,19 @@ export class RepeatRenderManager {

return (
<>
{displayValues.map((value, index) => {
const elementProps = useMemo(() => ({
...restProps,
indexes: { ...(indexes || {}), [ repeaterField.id ]: index }
}), [ index ]);

const localExpressionContextInfo = useMemo(() => ({
data: parentExpressionContextInfo.data,
this: value,
parent: buildExpressionContext(parentExpressionContextInfo),
i: [ ...parentExpressionContextInfo.i , index + 1 ]
}), [ index, value ]);

return !showRemove ?
<LocalExpressionContext.Provider value={ localExpressionContextInfo }>
<RowsRenderer { ...elementProps } />
</LocalExpressionContext.Provider> :
<div class="fjs-repeat-row-container">
<div class="fjs-repeat-row-rows">
<LocalExpressionContext.Provider value={ localExpressionContextInfo }>
<RowsRenderer { ...elementProps } />
</LocalExpressionContext.Provider>
</div>
<button class="fjs-repeat-row-remove" type="button" aria-label={ `Remove list item ${index + 1}` } onClick={ () => onDeleteItem(index) }>
<div class="fjs-repeat-row-remove-icon-container">
<DeleteSvg />
</div>
</button>
</div>;
})}
{displayValues.map((value, index) =>
<RepetitionScaffold
key={ index }
index={ index }
value={ value }
parentExpressionContextInfo={ parentExpressionContextInfo }
repeaterField={ repeaterField }
RowsRenderer={ RowsRenderer }
indexes={ indexes }
onDeleteItem={ onDeleteItem }
showRemove={ showRemove }
{ ...restProps } />
)}
</>
);
}
Expand Down Expand Up @@ -196,4 +179,63 @@ export class RepeatRenderManager {

}

/**
* Individual repetition of a repeated field and context scaffolding.
*
* @param {Object} props
* @param {number} props.index
* @param {Object} props.value
* @param {Object} props.parentExpressionContextInfo
* @param {Object} props.repeaterField
* @param {Function} props.RowsRenderer
* @param {Object} props.indexes
* @param {Function} props.onDeleteItem
* @param {boolean} props.showRemove
*/

const RepetitionScaffold = (props) => {

const {
index,
value,
parentExpressionContextInfo,
repeaterField,
RowsRenderer,
indexes,
onDeleteItem,
showRemove,
...restProps
} = props;

const elementProps = useMemo(() => ({
...restProps,
indexes: { ...(indexes || {}), [ repeaterField.id ]: index }
}), [ index, indexes, repeaterField.id, restProps ]);

const localExpressionContextInfo = useMemo(() => ({
data: parentExpressionContextInfo.data,
this: value,
parent: buildExpressionContext(parentExpressionContextInfo),
i: [ ...parentExpressionContextInfo.i , index + 1 ]
}), [ index, parentExpressionContextInfo, value ]);

return !showRemove ?
<LocalExpressionContext.Provider value={ localExpressionContextInfo }>
<RowsRenderer { ...elementProps } />
</LocalExpressionContext.Provider> :
<div class="fjs-repeat-row-container">
<div class="fjs-repeat-row-rows">
<LocalExpressionContext.Provider value={ localExpressionContextInfo }>
<RowsRenderer { ...elementProps } />
</LocalExpressionContext.Provider>
</div>
<button class="fjs-repeat-row-remove" type="button" aria-label={ `Remove list item ${index + 1}` } onClick={ () => onDeleteItem(index) }>
<div class="fjs-repeat-row-remove-icon-container">
<DeleteSvg />
</div>
</button>
</div>;

};

RepeatRenderManager.$inject = [ 'form', 'formFields', 'formFieldRegistry', 'pathRegistry' ];
Loading