From f8368b030cd9bd9bb70b4b0ed99772cf65164958 Mon Sep 17 00:00:00 2001 From: Darin Kelkhoff Date: Tue, 3 Dec 2024 15:55:18 -0600 Subject: [PATCH] CE-1955 make PreviewRecordUsingTableLayout a private component - try to make it re-render the associated child grids when switching records --- .../components/processes/ValidationReview.tsx | 164 ++++++++++-------- 1 file changed, 91 insertions(+), 73 deletions(-) diff --git a/src/qqq/components/processes/ValidationReview.tsx b/src/qqq/components/processes/ValidationReview.tsx index 015c3d5..7aa1902 100644 --- a/src/qqq/components/processes/ValidationReview.tsx +++ b/src/qqq/components/processes/ValidationReview.tsx @@ -266,76 +266,6 @@ function ValidationReview({ ); - /*************************************************************************** - ** - ***************************************************************************/ - function previewRecordUsingTableLayout(record: QRecord) - { - if (!previewTableMetaData) - { - return (Loading...); - } - - const renderedSections: JSX.Element[] = []; - const tableSections = TableUtils.getSectionsForRecordSidebar(previewTableMetaData); - const previewRecord = previewRecords[previewRecordIndex]; - - for (let i = 0; i < tableSections.length; i++) - { - const section = tableSections[i]; - if (section.isHidden) - { - continue; - } - - if (section.fieldNames) - { - renderedSections.push( -

{section.label}

- - {renderSectionOfFields(section.name, section.fieldNames, previewTableMetaData, false, previewRecord, undefined, {label: {fontWeight: "500"}})} - -
); - } - else if (section.widgetName) - { - const widget = qInstance.widgets.get(section.widgetName); - if (widget) - { - let data: ChildRecordListData = null; - if (associationPreviewsByWidgetName[section.widgetName]) - { - const associationPreview = associationPreviewsByWidgetName[section.widgetName]; - const associationRecords = previewRecord.associatedRecords.get(associationPreview.associationName) ?? []; - data = { - canAddChildRecord: false, - childTableMetaData: childTableMetaData[associationPreview.tableName], - defaultValuesForNewChildRecords: {}, - disabledFieldsForNewChildRecords: {}, - queryOutput: {records: associationRecords}, - totalRows: associationRecords.length, - tablePath: "", - title: "", - viewAllLink: "", - }; - - renderedSections.push( - { - data && -

{section.label}

- - - -
- } -
); - } - } - } - } - - return renderedSections; - } const recordPreviewWidget = step.recordListFields && ( @@ -370,11 +300,11 @@ function ValidationReview({ { processValues.validationSummary ? ( <> - It appears as though this process does not contain any valid records. + It appears as though this process does not contain any valid records. ) : ( <> - If you choose to Perform Validation, and there are any valid records, then you will see a preview here. + If you choose to Perform Validation, and there are any valid records, then you will see a preview here. ) } @@ -405,7 +335,15 @@ function ValidationReview({ )) } { - previewRecords && processValues.formatPreviewRecordUsingTableLayout && previewRecords[previewRecordIndex] && previewRecordUsingTableLayout(previewRecords[previewRecordIndex]) + previewRecords && processValues.formatPreviewRecordUsingTableLayout && previewRecords[previewRecordIndex] && + } @@ -441,4 +379,84 @@ function ValidationReview({ ); } + + +interface PreviewRecordUsingTableLayoutProps +{ + index: number + record: QRecord, + tableMetaData: QTableMetaData, + qInstance: QInstance, + associationPreviewsByWidgetName: { [widgetName: string]: AssociationPreview }, + childTableMetaData: { [name: string]: QTableMetaData }, +} + +function PreviewRecordUsingTableLayout({record, tableMetaData, qInstance, associationPreviewsByWidgetName, childTableMetaData, index}: PreviewRecordUsingTableLayoutProps): JSX.Element +{ + if (!tableMetaData) + { + return (Loading...); + } + + const renderedSections: JSX.Element[] = []; + const tableSections = TableUtils.getSectionsForRecordSidebar(tableMetaData); + + for (let i = 0; i < tableSections.length; i++) + { + const section = tableSections[i]; + if (section.isHidden) + { + continue; + } + + if (section.fieldNames) + { + renderedSections.push( +

{section.label}

+ + {renderSectionOfFields(section.name, section.fieldNames, tableMetaData, false, record, undefined, {label: {fontWeight: "500"}})} + +
); + } + else if (section.widgetName) + { + const widget = qInstance.widgets.get(section.widgetName); + if (widget) + { + let data: ChildRecordListData = null; + if (associationPreviewsByWidgetName[section.widgetName]) + { + const associationPreview = associationPreviewsByWidgetName[section.widgetName]; + const associationRecords = record.associatedRecords.get(associationPreview.associationName) ?? []; + data = { + canAddChildRecord: false, + childTableMetaData: childTableMetaData[associationPreview.tableName], + defaultValuesForNewChildRecords: {}, + disabledFieldsForNewChildRecords: {}, + queryOutput: {records: associationRecords}, + totalRows: associationRecords.length, + tablePath: "", + title: "", + viewAllLink: "", + }; + + renderedSections.push( + { + data && +

{section.label}

+ + + +
+ } +
); + } + } + } + } + + return <>{renderedSections}; +} + + export default ValidationReview;