Skip to content

Commit

Permalink
Allow formData to be accessed on summary page of array builder (#32240)
Browse files Browse the repository at this point in the history
  • Loading branch information
rhasselle-oddball authored Oct 4, 2024
1 parent d9ac9e2 commit e26ffd1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ export default function ArrayBuilderSummaryPage({
// alert
setShowUpdatedAlert(false);

setRemovedItemText(getText('alertItemDeleted', item));
setRemovedItemText(getText('alertItemDeleted', item, props.data));
setRemovedItemIndex(index);
setShowRemovedAlert(true);
requestAnimationFrame(() => {
Expand Down Expand Up @@ -302,7 +302,7 @@ export default function ArrayBuilderSummaryPage({
className="vads-u-color--gray-dark vads-u-margin-top--0"
data-title-for-noun-singular={nounSingular}
>
{getText(textType, updatedItemData)}
{getText(textType, updatedItemData, props.data)}
</Heading>
);

Expand All @@ -314,7 +314,7 @@ export default function ArrayBuilderSummaryPage({
onDismiss={onDismissUpdatedAlert}
nounSingular={nounSingular}
index={updateItemIndex}
text={getText('alertItemUpdated', updatedItemData)}
text={getText('alertItemUpdated', updatedItemData, props.data)}
/>
) : null}
</div>
Expand Down Expand Up @@ -362,7 +362,11 @@ export default function ArrayBuilderSummaryPage({
<UpdatedAlert show={showUpdatedAlert} />
<ReviewErrorAlert show={showReviewErrorAlert} />
<ArrayBuilderCards
cardDescription={getText('cardDescription', updatedItemData)}
cardDescription={getText(
'cardDescription',
updatedItemData,
props.data,
)}
arrayPath={arrayPath}
nounSingular={nounSingular}
nounPlural={nounPlural}
Expand Down Expand Up @@ -390,12 +394,14 @@ export default function ArrayBuilderSummaryPage({
className="form-review-panel-page-header vads-u-font-size--h5"
data-title-for-noun-singular={`${nounSingular}`}
>
{getText('summaryTitle', updatedItemData)}
{getText('summaryTitle', updatedItemData, props.data)}
</h4>
</div>
<dl className="review">
<div className="review-row">
<dt>{getText('yesNoBlankReviewQuestion')}</dt>
<dt>
{getText('yesNoBlankReviewQuestion', null, props.data)}
</dt>
<dd>
<span
className="dd-privacy-hidden"
Expand All @@ -408,17 +414,21 @@ export default function ArrayBuilderSummaryPage({
</dl>
</>
)}
{getText('summaryDescription') && (
{getText('summaryDescription', null, props.data) && (
<span className="vads-u-font-family--sans vads-u-font-weight--normal vads-u-display--block">
{getText('summaryDescription')}
{getText('summaryDescription', null, props.data)}
</span>
)}
<Cards />
{!isMaxItemsReached && (
<div className="vads-u-margin-top--2">
<va-button
data-action="add"
text={getText('reviewAddButtonText', updatedItemData)}
text={getText(
'reviewAddButtonText',
updatedItemData,
props.data,
)}
onClick={addAnotherItemButtonClick}
name={`${nounPlural}AddButton`}
primary
Expand All @@ -434,14 +444,14 @@ export default function ArrayBuilderSummaryPage({
uiSchema['ui:title'] = (
<>
<Title textType="summaryTitle" />
{getText('summaryDescription') && (
{getText('summaryDescription', null, props.data) && (
<span className="vads-u-font-family--sans vads-u-font-weight--normal vads-u-display--block">
{getText('summaryDescription')}
{getText('summaryDescription', null, props.data)}
</span>
)}
{isMaxItemsReached && (
<MaxItemsAlert>
{getText('alertMaxItems', updatedItemData)}
{getText('alertMaxItems', updatedItemData, props.data)}
</MaxItemsAlert>
)}
</>
Expand All @@ -451,7 +461,8 @@ export default function ArrayBuilderSummaryPage({
} else {
uiSchema['ui:title'] = <Title textType="summaryTitleWithoutItems" />;
uiSchema['ui:description'] =
getText('summaryDescriptionWithoutItems') || undefined;
getText('summaryDescriptionWithoutItems', null, props.data) ||
undefined;
}

if (schema?.properties && maxItems && arrayData?.length >= maxItems) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ export function initGetText({
/**
* @param {ArrayBuilderTextKey} key
* @param {any} itemData
* @param {any} [formData]
* @returns {string}
*/
return (key, itemData) => {
return (key, itemData, formData) => {
const keyVal = getTextValues?.[key];
if (key === 'getItemName' || key === 'cardDescription') {
return typeof keyVal === 'function' ? keyVal(itemData) : keyVal;
Expand All @@ -47,6 +48,7 @@ export function initGetText({
? getTextValues?.[key]({
...getTextProps,
itemData,
formData,
})
: keyVal;
};
Expand Down

0 comments on commit e26ffd1

Please sign in to comment.