Skip to content

Commit e021e81

Browse files
author
Sharma
committed
Fixed CaseSummary fields not getting rendered in Details template
1 parent 726b650 commit e021e81

File tree

2 files changed

+66
-14
lines changed

2 files changed

+66
-14
lines changed

packages/react-sdk-components/src/components/template/CaseSummary/CaseSummary.tsx

Lines changed: 64 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,81 @@
1-
import type { PropsWithChildren } from 'react';
1+
import type { PropsWithChildren, ReactElement } from 'react';
22
import { getComponentFromMap } from '../../../bridge/helpers/sdk_component_map';
33
import type { PConnProps } from '../../../types/PConnProps';
44

55
interface CaseSummaryProps extends PConnProps {
66
// If any, enter additional props that only exist on this component
7-
arPrimaryFields: any[];
8-
arSecondaryFields: any[];
97
}
108

119
export default function CaseSummary(props: PropsWithChildren<CaseSummaryProps>) {
1210
// Get emitted components from map (so we can get any override that may exist)
1311
const CaseSummaryFields = getComponentFromMap('CaseSummaryFields');
1412

15-
const { arPrimaryFields, arSecondaryFields } = props;
13+
const { getPConnect, children } = props;
14+
15+
const thePConn = getPConnect();
16+
const theConfigProps: any = thePConn.getConfigProps();
17+
// const { status, showStatus } = theConfigProps;
18+
const status = theConfigProps.status;
19+
const showStatus = theConfigProps.showStatus;
20+
const localizedVal = PCore.getLocaleUtils().getLocaleValue;
21+
const localeCategory = 'ModalContainer';
22+
23+
let arPrimaryFields: any[] = [];
24+
let arSecondaryFields: any[] = [];
25+
26+
function prepareComponentInCaseSummary(pConnectMeta, getPConnect) {
27+
const { config, children } = pConnectMeta;
28+
const pConnect = getPConnect();
29+
30+
const caseSummaryComponentObject: any = {};
31+
32+
const { type } = pConnectMeta;
33+
const createdComponent = pConnect.createComponent({
34+
type,
35+
children: children ? [...children] : [],
36+
config: {
37+
...config
38+
}
39+
});
40+
41+
caseSummaryComponentObject.value = createdComponent;
42+
return caseSummaryComponentObject;
43+
}
44+
45+
function prepareCaseSummaryData(summaryFieldChildren) {
46+
const convertChildrenToSummaryData = kid => {
47+
return kid?.map((childItem, index) => {
48+
const childMeta = childItem.getPConnect().meta;
49+
const caseSummaryComponentObject = prepareComponentInCaseSummary(childMeta, childItem.getPConnect);
50+
caseSummaryComponentObject.id = index + 1;
51+
return caseSummaryComponentObject;
52+
});
53+
};
54+
return summaryFieldChildren ? convertChildrenToSummaryData(summaryFieldChildren?.getChildren()) : undefined;
55+
}
56+
57+
for (const child of children as ReactElement[]) {
58+
const childPConn = (child as ReactElement).props.getPConnect();
59+
const childPConnData = childPConn.resolveConfigProps(childPConn.getRawMetadata());
60+
if (childPConnData.name.toLowerCase() === 'primary fields') {
61+
arPrimaryFields = childPConnData.children;
62+
arPrimaryFields.forEach(field => {
63+
if (field.config?.value && typeof field.config?.value === 'string') {
64+
field.config.value = localizedVal(field.config.value, localeCategory);
65+
}
66+
});
67+
} else if (childPConnData.name.toLowerCase() === 'secondary fields') {
68+
const secondarySummaryFields = prepareCaseSummaryData(childPConn);
69+
arSecondaryFields = childPConnData.children;
70+
arSecondaryFields.forEach((field, index) => {
71+
field.config.displayLabel = secondarySummaryFields[index]?.value?.props?.label;
72+
});
73+
}
74+
}
1675

1776
return (
1877
<div id='CaseSummary'>
19-
<CaseSummaryFields theFields={arPrimaryFields} />
78+
<CaseSummaryFields status={status} showStatus={showStatus} theFields={arPrimaryFields} />
2079
<CaseSummaryFields theFields={arSecondaryFields} />
2180
</div>
2281
);

packages/react-sdk-components/src/components/template/CaseView/CaseView.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { Utils } from '../../helpers/utils';
99
import StoreContext from '../../../bridge/Context/StoreContext';
1010
import { getComponentFromMap } from '../../../bridge/helpers/sdk_component_map';
1111
import type { PConnProps } from '../../../types/PConnProps';
12-
import { prepareCaseSummaryData } from '../utils';
1312

1413
interface CaseViewProps extends PConnProps {
1514
// If any, enter additional props that only exist on this component
@@ -50,7 +49,6 @@ export default function CaseView(props: PropsWithChildren<CaseViewProps>) {
5049
const CaseViewActionsMenu = getComponentFromMap('CaseViewActionsMenu');
5150
const VerticalTabs = getComponentFromMap('VerticalTabs');
5251
const DeferLoad = getComponentFromMap('DeferLoad');
53-
const CaseSummary = getComponentFromMap('CaseSummary');
5452

5553
const {
5654
getPConnect,
@@ -90,16 +88,11 @@ export default function CaseView(props: PropsWithChildren<CaseViewProps>) {
9088
return null;
9189
}
9290

93-
const theSummaryRegion = children && children[0];
94-
95-
const data = prepareCaseSummaryData(theSummaryRegion);
96-
const primarySummaryFields = data.primarySummaryFields;
97-
const secondarySummaryFields = data.secondarySummaryFields;
98-
9991
const theStagesRegion = getChildRegionByName('stages');
10092
const theTodoRegion = getChildRegionByName('todo');
10193
const theUtilitiesRegion = getChildRegionByName('utilities');
10294
const theTabsRegion = getChildRegionByName('tabs');
95+
const theSummaryRegion = getChildRegionByName('summary');
10396

10497
let iconForCaseType = caseTypeIcon ? caseTypeIcon.replace('pi pi-', '') : icon;
10598

@@ -237,7 +230,7 @@ export default function CaseView(props: PropsWithChildren<CaseViewProps>) {
237230
/>
238231
{getActionButtonsHtml()}
239232
<Divider />
240-
<CaseSummary arPrimaryFields={primarySummaryFields} arSecondaryFields={secondarySummaryFields}></CaseSummary>
233+
{theSummaryRegion}
241234
<Divider />
242235
{vertTabInfo.length > 1 && <VerticalTabs tabconfig={vertTabInfo} />}
243236
</Card>

0 commit comments

Comments
 (0)