Skip to content

Commit dd0b227

Browse files
author
manasa
committed
Added SelfServiceCaseView template to react SDK
1 parent 3173e2e commit dd0b227

File tree

4 files changed

+210
-117
lines changed

4 files changed

+210
-117
lines changed

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

Lines changed: 5 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,22 @@
1-
import type { PropsWithChildren, ReactElement } from 'react';
1+
import type { PropsWithChildren } 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[];
79
}
810

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

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-
// from Constellation DX Components
23-
// get the primary and secondary fields with the raw data (which has the non-resolved property values)
24-
// const regionsRaw = getPConnect().getRawMetadata().children;
25-
// const primaryFieldsRaw = regionsRaw[0].children;
26-
// const secondaryFieldsRaw = regionsRaw[1].children;
27-
28-
// From other SDKs
29-
// may want to move these into useEffect/useState combo
30-
let arPrimaryFields: any[] = [];
31-
let arSecondaryFields: any[] = [];
32-
33-
function prepareComponentInCaseSummary(pConnectMeta, getPConnect) {
34-
const { config, children } = pConnectMeta;
35-
const pConnect = getPConnect();
36-
37-
const caseSummaryComponentObject: any = {};
38-
39-
const { type } = pConnectMeta;
40-
const createdComponent = pConnect.createComponent({
41-
type,
42-
children: children ? [...children] : [],
43-
config: {
44-
...config
45-
}
46-
});
47-
48-
caseSummaryComponentObject.value = createdComponent;
49-
return caseSummaryComponentObject;
50-
}
51-
52-
function prepareCaseSummaryData(summaryFieldChildren) {
53-
const convertChildrenToSummaryData = kid => {
54-
return kid?.map((childItem, index) => {
55-
const childMeta = childItem.getPConnect().meta;
56-
const caseSummaryComponentObject = prepareComponentInCaseSummary(childMeta, childItem.getPConnect);
57-
caseSummaryComponentObject.id = index + 1;
58-
return caseSummaryComponentObject;
59-
});
60-
};
61-
return summaryFieldChildren ? convertChildrenToSummaryData(summaryFieldChildren?.getChildren()) : undefined;
62-
}
63-
64-
for (const child of children as ReactElement[]) {
65-
const childPConn = (child as ReactElement).props.getPConnect();
66-
const childPConnData = childPConn.resolveConfigProps(childPConn.getRawMetadata());
67-
if (childPConnData.name.toLowerCase() === 'primary fields') {
68-
arPrimaryFields = childPConnData.children;
69-
arPrimaryFields.forEach(field => {
70-
if (field.config?.value && typeof field.config?.value === 'string') {
71-
field.config.value = localizedVal(field.config.value, localeCategory);
72-
}
73-
});
74-
} else if (childPConnData.name.toLowerCase() === 'secondary fields') {
75-
const secondarySummaryFields = prepareCaseSummaryData(childPConn);
76-
arSecondaryFields = childPConnData.children;
77-
arSecondaryFields.forEach((field, index) => {
78-
field.config.displayLabel = secondarySummaryFields[index]?.value?.props?.label;
79-
});
80-
}
81-
}
82-
83-
// At this point, should hand off to another component for layout and rendering
84-
// of primary and secondary fields in the Case Summary
85-
86-
// debugging/investigation help
87-
// console.log(`CaseSummary: arPrimaryFields: ${JSON.stringify(arPrimaryFields)}`);
88-
// console.log(`CaseSummary: arSecondaryFields: ${JSON.stringify(arSecondaryFields)}`);
15+
const { arPrimaryFields, arSecondaryFields } = props;
8916

9017
return (
9118
<div id='CaseSummary'>
92-
<CaseSummaryFields status={status} showStatus={showStatus} theFields={arPrimaryFields} />
19+
<CaseSummaryFields theFields={arPrimaryFields} />
9320
<CaseSummaryFields theFields={arSecondaryFields} />
9421
</div>
9522
);

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

Lines changed: 62 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ 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';
1213

1314
interface CaseViewProps extends PConnProps {
1415
// If any, enter additional props that only exist on this component
@@ -18,6 +19,15 @@ interface CaseViewProps extends PConnProps {
1819
showIconInHeader: boolean;
1920
caseInfo: any;
2021
lastUpdateCaseTime: any;
22+
bShowUtilitiesRegion: any;
23+
bShowCaseActions: any;
24+
bShowCaseLifecycle: any;
25+
bShowPromotedActions: any;
26+
bShowPulseRegion: any;
27+
bShowSummaryRegion: any;
28+
selfServiceCaseView?: boolean;
29+
utilitysRegionEmpty?: boolean;
30+
summaryData?: any;
2131
}
2232

2333
const useStyles = makeStyles(theme => ({
@@ -52,19 +62,23 @@ export default function CaseView(props: PropsWithChildren<CaseViewProps>) {
5262
const CaseViewActionsMenu = getComponentFromMap('CaseViewActionsMenu');
5363
const VerticalTabs = getComponentFromMap('VerticalTabs');
5464
const DeferLoad = getComponentFromMap('DeferLoad');
65+
const CaseSummary = getComponentFromMap('CaseSummary');
5566

5667
const {
5768
getPConnect,
5869
icon = '',
5970
header,
6071
subheader,
6172
children = [],
62-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
63-
showIconInHeader = true,
73+
bShowCaseLifecycle,
74+
bShowSummaryRegion,
75+
bShowUtilitiesRegion,
76+
selfServiceCaseView,
77+
utilitysRegionEmpty,
6478
caseInfo: { availableActions = [], availableProcesses = [], hasNewAttachments, caseTypeID = '', caseTypeName = '' }
6579
} = props;
6680
const { lastUpdateCaseTime = getPConnect().getValue('caseInfo.lastUpdateTime') } = props;
67-
81+
let { summaryData: { primarySummaryFields = [], secondarySummaryFields = [] } = {} } = props;
6882
const currentCaseID = props.caseInfo.ID;
6983
let isComponentMounted = true;
7084
const { displayOnlyFA } = useContext<any>(StoreContext);
@@ -84,9 +98,8 @@ export default function CaseView(props: PropsWithChildren<CaseViewProps>) {
8498
*/
8599
function getChildRegionByName(inName: string): any {
86100
for (const child of children as ReactElement[]) {
87-
const theMetadataType: string = (child as ReactElement).props.getPConnect().getRawMetadata().type.toLowerCase();
88-
const theMetadataName: string = (child as ReactElement).props.getPConnect().getRawMetadata().name.toLowerCase();
89-
101+
const theMetadataType: string = (child as ReactElement).props.getPConnect().getRawMetadata().type?.toLowerCase();
102+
const theMetadataName: string = (child as ReactElement).props.getPConnect().getRawMetadata().name?.toLowerCase();
90103
if (theMetadataType === 'region' && theMetadataName === inName) {
91104
return child;
92105
}
@@ -95,7 +108,14 @@ export default function CaseView(props: PropsWithChildren<CaseViewProps>) {
95108
return null;
96109
}
97110

98-
const theSummaryRegion = getChildRegionByName('summary');
111+
const theSummaryRegion = children && children[0];
112+
113+
if (!selfServiceCaseView) {
114+
const data = prepareCaseSummaryData(theSummaryRegion);
115+
primarySummaryFields = data.primarySummaryFields;
116+
secondarySummaryFields = data.secondarySummaryFields;
117+
}
118+
99119
const theStagesRegion = getChildRegionByName('stages');
100120
const theTodoRegion = getChildRegionByName('todo');
101121
const theUtilitiesRegion = getChildRegionByName('utilities');
@@ -109,7 +129,7 @@ export default function CaseView(props: PropsWithChildren<CaseViewProps>) {
109129
// const tmpLoadData2 = { config: { label: "Case History", name: "CaseHistory" }, type: "DeferLoad" };
110130

111131
// Extract the tabs we need to display from theTabsRegion (one tab per entry in theTabsRegionChildren)
112-
const theTabsRegionChildren = theTabsRegion.props.getPConnect().getChildren();
132+
const theTabsRegionChildren = theTabsRegion?.props.getPConnect().getChildren();
113133

114134
// vertTabInfo is sent to VerticalTabs component
115135
const vertTabInfo: object[] = [];
@@ -208,45 +228,49 @@ export default function CaseView(props: PropsWithChildren<CaseViewProps>) {
208228
return (
209229
<Grid2 container>
210230
<Grid2 size={{ xs: 3 }}>
211-
<div hidden={true} id='current-caseID'>
212-
{currentCaseID}
213-
</div>
214-
<Card className={classes.root}>
215-
<CardHeader
216-
className={classes.caseViewHeader}
217-
title={
218-
<Typography variant='h6' component='div' id='case-name'>
219-
{PCore.getLocaleUtils().getLocaleValue(header, '', localeKey)}
220-
</Typography>
221-
}
222-
subheader={
223-
<Typography variant='body1' component='div' id='caseId'>
224-
{subheader}
225-
</Typography>
226-
}
227-
avatar={
228-
<Avatar className={classes.caseViewIconBox} variant='square'>
229-
<img src={svgCase} className={classes.caseViewIconImage} />
230-
</Avatar>
231-
}
232-
/>
233-
{getActionButtonsHtml()}
234-
<Divider />
235-
{theSummaryRegion}
236-
<Divider />
237-
{vertTabInfo.length > 1 && <VerticalTabs tabconfig={vertTabInfo} />}
238-
</Card>
231+
{(selfServiceCaseView ? bShowSummaryRegion && (primarySummaryFields.length > 0 || secondarySummaryFields.length > 0) : true) && (
232+
<div>
233+
<div hidden={true} id='current-caseID'>
234+
{currentCaseID}
235+
</div>
236+
<Card className={classes.root}>
237+
<CardHeader
238+
className={classes.caseViewHeader}
239+
title={
240+
<Typography variant='h6' component='div' id='case-name'>
241+
{PCore.getLocaleUtils().getLocaleValue(header, '', localeKey)}
242+
</Typography>
243+
}
244+
subheader={
245+
<Typography variant='body1' component='div' id='caseId'>
246+
{subheader}
247+
</Typography>
248+
}
249+
avatar={
250+
<Avatar className={classes.caseViewIconBox} variant='square'>
251+
<img src={svgCase} className={classes.caseViewIconImage} />
252+
</Avatar>
253+
}
254+
/>
255+
{!selfServiceCaseView && getActionButtonsHtml()}
256+
<Divider />
257+
<CaseSummary arPrimaryFields={primarySummaryFields} arSecondaryFields={secondarySummaryFields}></CaseSummary>
258+
<Divider />
259+
{vertTabInfo.length > 1 && <VerticalTabs tabconfig={vertTabInfo} />}
260+
</Card>
261+
</div>
262+
)}
239263
</Grid2>
240264

241265
<Grid2 size={{ xs: 6 }}>
242-
{theStagesRegion}
266+
{bShowCaseLifecycle && theStagesRegion}
243267
{theTodoRegion}
244268
{deferLoadInfo.length > 0 && (
245269
<DeferLoad getPConnect={getPConnect} name={deferLoadInfo[activeVertTab].config.name} isTab lastUpdateCaseTime={lastUpdateCaseTime} />
246270
)}
247271
</Grid2>
248272

249-
<Grid2 size={{ xs: 3 }}>{theUtilitiesRegion}</Grid2>
273+
{(selfServiceCaseView ? bShowUtilitiesRegion && utilitysRegionEmpty : true) && <Grid2 size={{ xs: 3 }}>{theUtilitiesRegion}</Grid2>}
250274
</Grid2>
251275
);
252276
}
Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,87 @@
1+
import { getComponentFromMap } from '../../../bridge/helpers/sdk_component_map';
2+
import { prepareCaseSummaryData, filterUtilities } from '../utils';
3+
14
export default function SelfServiceCaseView(props) {
2-
console.log('SelfServiceCaseView props:', props);
5+
const CaseViewActionsMenu = getComponentFromMap('CaseViewActionsMenu');
6+
const CaseView = getComponentFromMap('CaseView');
7+
const {
8+
getPConnect,
9+
header,
10+
showCaseLifecycle = true,
11+
showPulseRegion = true,
12+
showSummaryRegion = true,
13+
showUtilitiesRegion = true,
14+
showCaseActions = true,
15+
showPromotedActions = true,
16+
children,
17+
caseClass,
18+
caseInfo: { availableActions = [], availableProcesses = [], caseTypeID = '', caseTypeName = '' }
19+
} = props;
20+
const pConnect = getPConnect();
21+
const [bShowCaseLifecycle, bShowPulseRegion, bShowSummaryRegion, bShowUtilitiesRegion, bShowCaseActions, bShowPromotedActions] = [
22+
showCaseLifecycle,
23+
showPulseRegion,
24+
showSummaryRegion,
25+
showUtilitiesRegion,
26+
showCaseActions,
27+
showPromotedActions
28+
].map((prop: boolean | string) => prop === true || prop === 'true');
29+
const isObjectType: boolean = (PCore.getCaseUtils() as any).isObjectCaseType(caseClass);
30+
const localeKey = pConnect?.getCaseLocaleReference();
31+
32+
const renderedRegions: any = isObjectType
33+
? {
34+
caseSummary: children[0],
35+
utilities: filterUtilities(children[2])
36+
}
37+
: {
38+
caseSummary: children[0],
39+
stages: children[1],
40+
todo: children[2],
41+
utilities: filterUtilities(children[4])
42+
};
43+
const { primarySummaryFields, secondarySummaryFields } = prepareCaseSummaryData(
44+
renderedRegions.caseSummary,
45+
(config: any) => config?.availableInChannel?.selfService === true
46+
);
47+
48+
const isUtilitiesRegionNotEmpty: () => boolean = () => {
49+
const utilitiesElement = renderedRegions.utilities;
50+
if (utilitiesElement?.props?.getPConnect()?.getChildren()?.length > 0) {
51+
return utilitiesElement.props
52+
.getPConnect()
53+
.getChildren()
54+
.some((prop: { getPConnect: () => any }) => prop.getPConnect().getConfigProps().visibility !== false);
55+
}
56+
return false;
57+
};
58+
59+
return (
60+
<div>
61+
<div style={{ display: 'flex', justifyContent: 'space-around', alignItems: 'center', margin: '10px' }}>
62+
<div>{PCore.getLocaleUtils().getLocaleValue(header, '', localeKey)}</div>
63+
{bShowCaseActions && (
64+
<CaseViewActionsMenu
65+
getPConnect={getPConnect}
66+
availableActions={availableActions}
67+
availableProcesses={availableProcesses}
68+
caseTypeName={caseTypeName}
69+
caseTypeID={caseTypeID}
70+
/>
71+
)}
72+
</div>
73+
<CaseView
74+
{...props}
75+
summaryData={{ primarySummaryFields, secondarySummaryFields }}
76+
selfServiceCaseView={true}
77+
bShowCaseLifecycle={bShowCaseLifecycle}
78+
bShowPulseRegion={bShowPulseRegion}
79+
bShowSummaryRegion={bShowSummaryRegion}
80+
bShowUtilitiesRegion={bShowUtilitiesRegion}
81+
bShowCaseActions={bShowCaseActions}
82+
bShowPromotedActions={bShowPromotedActions}
83+
utilitysRegionNotEmpty={isUtilitiesRegionNotEmpty()}
84+
/>
85+
</div>
86+
);
387
}

0 commit comments

Comments
 (0)