Skip to content

Commit c7f9910

Browse files
4manasamashmtumms2021389
authored
Semantic URL changes (#401)
* semanticURL changes --------- Co-authored-by: mashm <[email protected]> Co-authored-by: Siva Rama Krishna <[email protected]>
1 parent 508131c commit c7f9910

File tree

4 files changed

+54
-9
lines changed

4 files changed

+54
-9
lines changed

packages/react-sdk-components/src/components/infra/View/View.tsx

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { PropsWithChildren } from 'react';
1+
import { PropsWithChildren, useEffect } from 'react';
22

33
import { getComponentFromMap } from '../../../bridge/helpers/sdk_component_map';
44
import { getAllFields } from '../../helpers/template-utils';
@@ -18,6 +18,7 @@ interface ViewProps extends PConnProps {
1818
visibility?: boolean;
1919
name?: string;
2020
bInForm?: boolean;
21+
type?: any;
2122
}
2223

2324
//
@@ -41,21 +42,53 @@ const NO_HEADER_TEMPLATES = [
4142
];
4243

4344
export default function View(props: PropsWithChildren<ViewProps>) {
44-
const { children, template, getPConnect, mode, visibility, name: pageName } = props;
45+
const { children, template, getPConnect, mode, visibility, name: pageName, type, title } = props;
4546
let { label = '', showLabel = false } = props;
47+
const { PAGE_TYPES: { PAGE, LANDINGPAGE, LISTPAGE } = {}, MODAL } = PCore.getConstants();
4648

4749
// Get the inherited props from the parent to determine label settings. For 8.6, this is only for embedded data form views
4850
// Putting this logic here instead of copy/paste in every Form template index.js
4951

5052
const inheritedProps: any = getPConnect().getInheritedProps(); // try to remove any when getInheritedProps typedefs are fixed
5153
label = inheritedProps.label || label;
5254
showLabel = inheritedProps.showLabel || showLabel;
55+
const localeUtils = PCore.getLocaleUtils();
5356

5457
const isEmbeddedDataView = mode === 'editable'; // would be better to check the reference child for `context` attribute if possible
5558
if (isEmbeddedDataView && showLabel === undefined) {
5659
showLabel = true;
5760
}
5861

62+
useEffect(() => {
63+
// Get the localized application label
64+
let applicationLabel = PCore.getEnvironmentInfo().getApplicationLabel();
65+
applicationLabel = localeUtils.getLocaleValue(`${applicationLabel}`, '', '');
66+
const caseInfo = getPConnect().getCaseInfo();
67+
const isAssignmentInCreateStage = caseInfo && caseInfo.isAssignmentInCreateStage();
68+
const isRenderingInModal = getPConnect().getContainerName().includes(MODAL);
69+
const isRenderingInPreviewPanel = getPConnect().getContainerName().includes('preview');
70+
71+
/* If assignment is in create stage and rendering in modal don't update the title.
72+
Title will be updated on completion of create stage and when the assignment is rendered inline to the page.
73+
*/
74+
const canUpdateTitle =
75+
!isRenderingInPreviewPanel &&
76+
(type === PAGE || type === LANDINGPAGE || type === LISTPAGE) &&
77+
!(isRenderingInModal && isAssignmentInCreateStage) &&
78+
PCore.getEnvironmentInfo().getRenderingMode() === 'FULL_PORTAL';
79+
// Incase of home route title is same as applicationLabel so setting to empty to just show applicationLabel
80+
let titleVar = title === applicationLabel ? '' : title;
81+
82+
if (canUpdateTitle) {
83+
if (caseInfo) {
84+
const name = caseInfo.getName();
85+
const id = caseInfo.getBusinessID();
86+
titleVar = name && id ? `${name} (${id})` : titleVar;
87+
}
88+
document.title = titleVar ? `${titleVar} - ${applicationLabel}` : applicationLabel;
89+
}
90+
}, [type, title, getPConnect, PAGE, LANDINGPAGE, LISTPAGE]);
91+
5992
const key = `${getPConnect().getContextName()}_${getPConnect().getPageReference()}_${pageName}`;
6093
// As long as the template is defined in the dependencies of the view
6194
// it will be loaded, otherwise fall back to single column

packages/react-sdk-components/src/samples/AppSelector/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const AppSelector = () => {
2323
<Route path={`${baseURL}embedded.html`} element={<EmbeddedTopLevel />} />
2424
<Route path={`${baseURL}portal`} element={<FullPortal />} />
2525
<Route path={`${baseURL}portal.html`} element={<FullPortal />} />
26+
<Route path={`${baseURL}prweb/*`} element={<FullPortal />} />
2627
<Route path='*' element={<EmbeddedTopLevel />} />
2728
</Routes>
2829
</div>

packages/react-sdk-components/src/samples/FullPortal/index.tsx

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable no-console */
12
import { useEffect, useMemo, useState } from 'react';
23
import ReactDOM from 'react-dom';
34
import { useLocation, useNavigate } from 'react-router-dom';
@@ -118,7 +119,6 @@ export default function FullPortal() {
118119
// Initialize the SdkComponentMap (local and pega-provided)
119120
// eslint-disable-next-line @typescript-eslint/no-unused-vars
120121
getSdkComponentMap(localSdkComponentMap).then((theComponentMap: any) => {
121-
// eslint-disable-next-line no-console
122122
console.log(`SdkComponentMap initialized`);
123123

124124
// Don't call initialRender until SdkComponentMap is fully initialized
@@ -137,15 +137,12 @@ export default function FullPortal() {
137137
if (queryPortal) {
138138
myLoadPortal('pega-root', queryPortal, []);
139139
} else if (thePortal) {
140-
// eslint-disable-next-line no-console
141140
console.log(`Loading specified appPortal: ${thePortal}`);
142141
myLoadPortal('pega-root', thePortal, []);
143142
} else if (myLoadDefaultPortal && defaultPortal && !excludePortals.includes(defaultPortal)) {
144-
// eslint-disable-next-line no-console
145143
console.log(`Loading default portal`);
146144
myLoadDefaultPortal('pega-root', []);
147145
} else {
148-
// eslint-disable-next-line no-console
149146
console.log('Loading portal selection screen');
150147
setPortalSelectionScreen(true);
151148
setDefaultPortalName(defaultPortal);
@@ -162,31 +159,42 @@ export default function FullPortal() {
162159
}
163160

164161
function doRedirectDone() {
165-
navigate(window.location.pathname);
162+
const redirectUrl: any = sessionStorage.getItem('url');
163+
navigate(redirectUrl);
164+
sessionStorage.removeItem('url');
166165
let localeOverride: any = sessionStorage.getItem('rsdk_locale');
167166
if (!localeOverride) {
168167
localeOverride = undefined;
169168
}
170169
// appName and mainRedirect params have to be same as earlier invocation
171-
loginIfNecessary({ appName: 'portal', mainRedirect: true, locale: localeOverride });
170+
loginIfNecessary({ appName: 'portal', mainRedirect: true, locale: localeOverride, enableSemanticUrls: true });
172171
}
173172

174173
// One time (initialization)
175174
useEffect(() => {
176175
document.addEventListener('SdkConstellationReady', () => {
177176
// start the portal
177+
sessionStorage.setItem('isLoggedIn', 'true');
178178
startPortal();
179179
});
180180
let localeOverride: any = sessionStorage.getItem('rsdk_locale');
181181
if (!localeOverride) {
182182
localeOverride = undefined;
183183
}
184+
const isLoggedIn = sessionStorage.getItem('isLoggedIn');
185+
const redirected = sessionStorage.getItem('redirected');
186+
if (isLoggedIn !== 'true' && redirected !== 'true') {
187+
sessionStorage.setItem('url', window.location.pathname);
188+
navigate('/portal');
189+
}
190+
sessionStorage.setItem('redirected', 'true');
184191
// Login if needed, doing an initial main window redirect
185192
loginIfNecessary({
186193
appName: 'portal',
187194
mainRedirect: true,
188195
redirectDoneCB: doRedirectDone,
189-
locale: localeOverride
196+
locale: localeOverride,
197+
enableSemanticUrls: true
190198
});
191199
}, []);
192200

packages/react-sdk-components/src/samples/TopLevelApp/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ document.addEventListener('SdkLoggedOut', () => {
1818
theLogoutMsgDiv.innerHTML = `You are logged out. Refresh the page to log in again.`;
1919
thePegaRoot.appendChild(theLogoutMsgDiv);
2020
}
21+
sessionStorage.removeItem('isLoggedIn');
22+
sessionStorage.removeItem('redirected');
2123
sessionStorage.removeItem('rsdk_portalName');
24+
window.location.href = `${window.location.origin}/portal`;
2225
});
2326

2427
export default TopLevelApp;

0 commit comments

Comments
 (0)