|
1 | | -import type { PropsWithChildren } from 'react'; |
| 1 | +import type { PropsWithChildren, ReactElement } from 'react'; |
2 | 2 | import { getComponentFromMap } from '../../../bridge/helpers/sdk_component_map'; |
3 | 3 | import type { PConnProps } from '../../../types/PConnProps'; |
4 | 4 |
|
5 | 5 | interface CaseSummaryProps extends PConnProps { |
6 | | - // If any, enter additional props that only exist on this component |
7 | 6 | arPrimaryFields: any[]; |
8 | 7 | arSecondaryFields: any[]; |
| 8 | + // If any, enter additional props that only exist on this component |
9 | 9 | } |
10 | 10 |
|
11 | 11 | export default function CaseSummary(props: PropsWithChildren<CaseSummaryProps>) { |
12 | 12 | // Get emitted components from map (so we can get any override that may exist) |
13 | 13 | const CaseSummaryFields = getComponentFromMap('CaseSummaryFields'); |
14 | 14 |
|
15 | | - const { arPrimaryFields, arSecondaryFields } = props; |
| 15 | + const { getPConnect, children } = props; |
| 16 | + let { arPrimaryFields = [], arSecondaryFields = [] } = props; |
| 17 | + |
| 18 | + const thePConn = getPConnect && getPConnect(); |
| 19 | + const theConfigProps: any = thePConn?.getConfigProps(); |
| 20 | + |
| 21 | + const status = theConfigProps?.status; |
| 22 | + const showStatus = theConfigProps?.showStatus; |
| 23 | + const localizedVal = PCore.getLocaleUtils().getLocaleValue; |
| 24 | + const localeCategory = 'ModalContainer'; |
| 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 | + if (arPrimaryFields.length === 0 && arSecondaryFields.length === 0) { |
| 58 | + for (const child of children as ReactElement[]) { |
| 59 | + const childPConn = (child as ReactElement).props.getPConnect(); |
| 60 | + const childPConnData = childPConn.resolveConfigProps(childPConn.getRawMetadata()); |
| 61 | + if (childPConnData.name.toLowerCase() === 'primary fields') { |
| 62 | + arPrimaryFields = childPConnData.children; |
| 63 | + arPrimaryFields.forEach(field => { |
| 64 | + if (field.config?.value && typeof field.config?.value === 'string') { |
| 65 | + field.config.value = localizedVal(field.config.value, localeCategory); |
| 66 | + } |
| 67 | + }); |
| 68 | + } else if (childPConnData.name.toLowerCase() === 'secondary fields') { |
| 69 | + const secondarySummaryFields = prepareCaseSummaryData(childPConn); |
| 70 | + arSecondaryFields = childPConnData.children; |
| 71 | + arSecondaryFields.forEach((field, index) => { |
| 72 | + field.config.displayLabel = secondarySummaryFields[index]?.value?.props?.label; |
| 73 | + }); |
| 74 | + } |
| 75 | + } |
| 76 | + } |
16 | 77 |
|
17 | 78 | return ( |
18 | 79 | <div id='CaseSummary'> |
19 | | - <CaseSummaryFields theFields={arPrimaryFields} /> |
| 80 | + <CaseSummaryFields status={status} showStatus={showStatus} theFields={arPrimaryFields} /> |
20 | 81 | <CaseSummaryFields theFields={arSecondaryFields} /> |
21 | 82 | </div> |
22 | 83 | ); |
|
0 commit comments