Skip to content

Commit 8715cde

Browse files
committed
Fix for breaking changes with 24.2
1 parent 20cf5fe commit 8715cde

File tree

8 files changed

+155
-112
lines changed

8 files changed

+155
-112
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
export const addContainerItem = pConnect => {
2+
const containerManager = pConnect.getContainerManager();
3+
const context = pConnect.getContextName();
4+
containerManager.addContainerItem({
5+
context,
6+
semanticURL: ''
7+
});
8+
};
9+
10+
export const configureBrowserBookmark = pConnect => {
11+
const context = pConnect.getContextName();
12+
const containerName = pConnect.getContainerName();
13+
const navPages = pConnect.getValue('pyPortal.pyPrimaryNavPages');
14+
const defaultViewLabel = Array.isArray(navPages) && navPages[0] ? navPages[0].pyLabel : '';
15+
PCore.configureForBrowserBookmark({
16+
context,
17+
containerName,
18+
acName: containerName,
19+
semanticURL: '',
20+
defaultViewLabel
21+
});
22+
};

packages/angular-sdk-components/src/lib/_components/infra/Containers/view-container/view-container.component.ts

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { AngularPConnectData, AngularPConnectService } from '../../../../_bridge
55
import { ProgressSpinnerService } from '../../../../_messages/progress-spinner.service';
66
import { ReferenceComponent } from '../../reference/reference.component';
77
import { ComponentMapperComponent } from '../../../../_bridge/component-mapper/component-mapper.component';
8+
import { configureBrowserBookmark } from './helper';
89

910
/**
1011
* WARNING: It is not expected that this file should be modified. It is part of infrastructure code that works with
@@ -96,37 +97,19 @@ export class ViewContainerComponent implements OnInit, OnDestroy {
9697
// And expose less via ui-bootstrap.js
9798
this.state = {
9899
dispatchObject: this.dispatchObject,
99-
// PCore is defined in pxBootstrapShell - eventually will be exported in place of constellationCore
100-
101100
visible: !PCore.checkIfSemanticURL()
102101
};
102+
containerMgr.initializeContainers({
103+
type: mode === CONTAINER_TYPE.MULTIPLE ? CONTAINER_TYPE.MULTIPLE : CONTAINER_TYPE.SINGLE
104+
});
103105

104-
// here, to match Nebula/Constellation, the constructor of ViewContainer is only called once, and thus init/add container is only
105-
// called once. Because of Angular creating and destroy components if the parent changes a lot, this component will be
106-
// created and destroyed more than once. So the sessionStore "hasViewContainer" is set to false in rootContainer and then
107-
// after first round is true here. Subsequent ViewContainer creation will not init/add more containers.
108-
109-
if (sessionStorage.getItem('hasViewContainer') == 'false') {
110-
// unlike Nebula/Constellation, have to initializeContainer after we create a dispatcObject and state, otherwise, when calling
111-
// initializeContainer before, code will get executed that needs state that wasn't defined.
112-
113-
containerMgr.initializeContainers({
114-
type: mode === CONTAINER_TYPE.MULTIPLE ? CONTAINER_TYPE.MULTIPLE : CONTAINER_TYPE.SINGLE
115-
});
116-
117-
if (mode === CONTAINER_TYPE.MULTIPLE && limit) {
118-
/* NOTE: setContainerLimit use is temporary. It is a non-public, unsupported API. */
119-
PCore.getContainerUtils().setContainerLimit(`${APP.APP}/${name}`, limit);
120-
}
106+
if (mode === CONTAINER_TYPE.MULTIPLE && limit) {
107+
/* NOTE: setContainerLimit use is temporary. It is a non-public, unsupported API. */
108+
PCore.getContainerUtils().setContainerLimit(`${APP.APP}/${name}`, limit);
121109
}
122110

123-
if (sessionStorage.getItem('hasViewContainer') == 'false') {
124-
if (this.pConn$.getMetadata()?.children) {
125-
containerMgr.addContainerItem(this.dispatchObject);
126-
}
127-
128-
sessionStorage.setItem('hasViewContainer', 'true');
129-
}
111+
if (!PCore.checkIfSemanticURL()) containerMgr.addContainerItem(this.pConn$ as any);
112+
if (!this.displayOnlyFA$) configureBrowserBookmark(this.pConn$);
130113

131114
// cannot call checkAndUpdate becasue first time through, will call updateSelf and that is incorrect (causes issues).
132115
// however, need angularPConnect to be initialized with currentProps for future updates, so calling shouldComponentUpdate directly

packages/angular-sdk-components/src/lib/_components/infra/root-container/root-container.component.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,6 @@ export class RootContainerComponent implements OnInit, OnDestroy {
9797
}
9898
});
9999

100-
// clear out hasViewContainer
101-
sessionStorage.setItem('hasViewContainer', 'false');
102-
103100
this.mConn$ = configObjModal.getPConnect();
104101

105102
// First thing in initialization is registering and subscribing to the AngularPConnect service

packages/angular-sdk-components/src/lib/_components/template/app-shell/app-shell.component.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,24 @@ export class AppShellComponent implements OnInit, OnDestroy {
7878
if (this.pages$) {
7979
this.bShowAppShell$ = true;
8080
}
81+
82+
// @ts-ignore - Property 'pyCaseTypesAvailableToCreateDP' does not exist on type pxApplication
83+
const caseTypesAvailableToCreateDP = PCore.getEnvironmentInfo().environmentInfoObject?.pxApplication?.pyCaseTypesAvailableToCreateDP;
84+
if (caseTypesAvailableToCreateDP) {
85+
const portalID = this.pConn$.getValue('.pyOwner');
86+
PCore.getDataPageUtils()
87+
.getPageDataAsync(caseTypesAvailableToCreateDP, this.pConn$.getContextName(), {
88+
PortalName: portalID
89+
})
90+
.then((response: any) => {
91+
if (response?.pyCaseTypesAvailableToCreate) {
92+
this.pConn$.replaceState('.pyCaseTypesAvailableToCreate', response.pyCaseTypesAvailableToCreate, {
93+
skipDirtyValidation: true
94+
});
95+
}
96+
});
97+
}
98+
8199
this.caseTypes$ = this.configProps$.caseTypes;
82100

83101
this.arChildren$ = this.pConn$.getChildren();

packages/angular-sdk-components/src/lib/_components/template/page/page.component.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@ export class PageComponent implements OnInit, OnDestroy {
4242
if (operator && operator != '') {
4343
this.title$ += `, ${operator}`;
4444
}
45-
46-
// when showing a page, similar to updating root, need to cause viewContainer to call "initContainer"
47-
sessionStorage.setItem('hasViewContainer', 'false');
4845
}
4946

5047
ngOnDestroy(): void {

packages/angular-sdk-components/src/lib/_components/widget/todo/todo.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<div class="psdk-todo-header">
33
<div *ngIf="showTodoList$" class="psdk-avatar">{{ this.currentUserInitials$ }}</div>
44
<div id="worklist" class="psdk-todo-text">{{ headerText$ }}</div>
5-
<div *ngIf="showTodoList$" class="psdk-assignment-count">{{ assignmentCount$ }}</div>
5+
<div *ngIf="showTodoList$" class="psdk-assignment-count">{{ count }}</div>
66
</div>
77
<br /><br />
88
<div *ngIf="showTodoList$" class="psdk-display-divider"></div>
@@ -36,7 +36,7 @@
3636
</div>
3737
</div>
3838

39-
<div *ngIf="assignmentCount$ > 3">
39+
<div *ngIf="count > 3">
4040
<div *ngIf="bShowMore$; else showLess" class="psdk-todo-show-more">
4141
<button mat-stroked-button (click)="_showMore()">{{ showMoreLocalizedValue === 'show_more' ? 'Show more' : showMoreLocalizedValue }}</button>
4242
</div>

packages/angular-sdk-components/src/lib/_components/widget/todo/todo.component.ts

Lines changed: 89 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,54 @@
1-
import { Component, OnInit, Input, NgZone, OnDestroy, OnChanges } from '@angular/core';
1+
import { Component, OnInit, Input, OnDestroy } from '@angular/core';
22
import { CommonModule } from '@angular/common';
33
import { MatButtonModule } from '@angular/material/button';
44
import { publicConstants } from '@pega/pcore-pconnect-typedefs/constants';
55
import { ProgressSpinnerService } from '../../../_messages/progress-spinner.service';
66
import { ErrorMessagesService } from '../../../_messages/error-messages.service';
77
import { Utils } from '../../../_helpers/utils';
8+
import { updateWorkList } from '../../../_helpers/createstage-utils';
9+
10+
const fetchMyWorkList = (datapage, fields, numberOfRecords, includeTotalCount, context) => {
11+
return PCore.getDataPageUtils()
12+
.getDataAsync(
13+
datapage,
14+
context,
15+
{},
16+
{
17+
pageNumber: 1,
18+
pageSize: numberOfRecords
19+
},
20+
{
21+
select: Object.keys(fields).map(key => ({ field: PCore.getAnnotationUtils().getPropertyName(fields[key]) })),
22+
sortBy: [
23+
{ field: 'pxUrgencyAssign', type: 'DESC' },
24+
{ field: 'pxDeadlineTime', type: 'ASC' },
25+
{ field: 'pxCreateDateTime', type: 'DESC' }
26+
]
27+
},
28+
{
29+
invalidateCache: true,
30+
additionalApiParams: {
31+
includeTotalCount
32+
}
33+
}
34+
)
35+
.then(response => {
36+
return {
37+
...response,
38+
data: (Array.isArray(response?.data) ? response.data : []).map(row =>
39+
Object.keys(fields).reduce((obj, key) => {
40+
obj[key] = row[PCore.getAnnotationUtils().getPropertyName(fields[key])];
41+
return obj;
42+
}, {})
43+
)
44+
};
45+
});
46+
};
47+
48+
const getMappedValue = value => {
49+
const mappedValue = PCore.getEnvironmentInfo().getKeyMapping(value);
50+
return mappedValue === null ? value : mappedValue;
51+
};
852

953
interface ToDoProps {
1054
// If any, enter additional props that only exist on this component
@@ -23,7 +67,7 @@ interface ToDoProps {
2367
standalone: true,
2468
imports: [CommonModule, MatButtonModule]
2569
})
26-
export class TodoComponent implements OnInit, OnDestroy, OnChanges {
70+
export class TodoComponent implements OnInit, OnDestroy {
2771
@Input() pConn$: typeof PConnect;
2872
@Input() caseInfoID$: string;
2973
@Input() datasource$: any;
@@ -38,7 +82,6 @@ export class TodoComponent implements OnInit, OnDestroy, OnChanges {
3882
configProps$: ToDoProps;
3983
currentUser$: string | undefined;
4084
currentUserInitials$ = '--';
41-
assignmentCount$: number;
4285
bShowMore$ = true;
4386
arAssignments$: any[];
4487
assignmentsSource$: any;
@@ -49,41 +92,21 @@ export class TodoComponent implements OnInit, OnDestroy, OnChanges {
4992
showlessLocalizedValue = this.localizedVal('show_less', 'CosmosFields');
5093
showMoreLocalizedValue = this.localizedVal('show_more', 'CosmosFields');
5194
canPerform: boolean;
95+
count: number;
5296

5397
constructor(
5498
private psService: ProgressSpinnerService,
5599
private erService: ErrorMessagesService,
56-
private ngZone: NgZone,
57100
private utils: Utils
58101
) {}
59102

60103
ngOnInit() {
61104
this.CONSTS = PCore.getConstants();
62105
const { CREATE_STAGE_SAVED, CREATE_STAGE_DELETED } = PCore.getEvents().getCaseEvent();
63106

64-
PCore.getPubSubUtils().subscribe(
65-
PCore.getConstants().PUB_SUB_EVENTS.EVENT_CANCEL,
66-
() => {
67-
this.updateToDo();
68-
},
69-
'updateToDo'
70-
);
71-
72-
PCore.getPubSubUtils().subscribe(
73-
CREATE_STAGE_SAVED,
74-
() => {
75-
this.updateList();
76-
},
77-
CREATE_STAGE_SAVED
78-
);
79-
80-
PCore.getPubSubUtils().subscribe(
81-
CREATE_STAGE_DELETED,
82-
() => {
83-
this.updateList();
84-
},
85-
CREATE_STAGE_DELETED
86-
);
107+
PCore.getPubSubUtils().subscribe(PCore.getConstants().PUB_SUB_EVENTS.EVENT_CANCEL, () => this.updateToDo(), 'updateToDo');
108+
PCore.getPubSubUtils().subscribe(CREATE_STAGE_SAVED, () => this.updateList(), CREATE_STAGE_SAVED);
109+
PCore.getPubSubUtils().subscribe(CREATE_STAGE_DELETED, () => this.updateList(), CREATE_STAGE_DELETED);
87110

88111
this.updateToDo();
89112
}
@@ -92,55 +115,39 @@ export class TodoComponent implements OnInit, OnDestroy, OnChanges {
92115
const { CREATE_STAGE_SAVED, CREATE_STAGE_DELETED } = PCore.getEvents().getCaseEvent();
93116

94117
PCore.getPubSubUtils().unsubscribe(PCore.getConstants().PUB_SUB_EVENTS.EVENT_CANCEL, 'updateToDo');
95-
96118
PCore.getPubSubUtils().unsubscribe(CREATE_STAGE_SAVED, CREATE_STAGE_SAVED);
97-
98119
PCore.getPubSubUtils().unsubscribe(CREATE_STAGE_DELETED, CREATE_STAGE_DELETED);
99120
}
100121

101-
ngOnChanges() {
102-
// don't update until we'va had an init
103-
if (PCore) {
104-
this.updateToDo();
105-
}
106-
}
107-
108-
updateWorkList(key) {
109-
PCore.getDataApiUtils()
110-
.getData(key)
111-
.then(responseData => {
112-
const dataObject = {};
113-
dataObject[key] = {
114-
pxResults: responseData.data.data
115-
};
116-
117-
this.pConn$.updateState(dataObject);
118-
this.updateToDo();
119-
})
120-
.catch(err => {
121-
console.error(err?.stack);
122-
});
123-
}
124-
125122
updateList() {
126-
this.updateWorkList('D_pyMyWorkList');
123+
const {
124+
WORK_BASKET: {
125+
DATA_PAGES: { D__PY_MY_WORK_LIST }
126+
}
127+
} = PCore.getConstants();
128+
updateWorkList(getPConnect, getMappedValue(D__PY_MY_WORK_LIST));
127129
}
128130

129131
updateToDo() {
130132
this.configProps$ = this.pConn$.resolveConfigProps(this.pConn$.getConfigProps()) as ToDoProps;
131133

132-
if (this.headerText$ == undefined) {
133-
this.headerText$ = this.configProps$.headerText;
134-
}
135-
136-
this.datasource$ = this.configProps$.datasource ? this.configProps$.datasource : this.datasource$;
137-
this.myWorkList$ = this.configProps$.myWorkList ? this.configProps$.myWorkList : this.myWorkList$;
134+
this.headerText$ = this.headerText$ || this.configProps$.headerText;
135+
this.datasource$ = this.datasource$ || this.configProps$.datasource;
136+
this.myWorkList$ = this.myWorkList$ || this.configProps$.myWorkList;
138137

139138
this.assignmentsSource$ = this.datasource$?.source || this.myWorkList$?.source;
140139

141140
if (this.showTodoList$) {
142-
this.assignmentCount$ = this.assignmentsSource$ != null ? this.assignmentsSource$.length : 0;
143-
this.arAssignments$ = this.topThreeAssignments(this.assignmentsSource$);
141+
if (this.assignmentsSource$) {
142+
this.count = this.assignmentsSource$ ? this.assignmentsSource$.length : 0;
143+
this.arAssignments$ = this.topThreeAssignments(this.assignmentsSource$);
144+
} else if (this.myWorkList$.datapage) {
145+
fetchMyWorkList(this.myWorkList$.datapage, this.pConn$.getComponentConfig()?.myWorkList.fields, 3, true, this.context$).then(responseData => {
146+
this.deferLoadWorklistItems(responseData);
147+
});
148+
} else {
149+
this.arAssignments$ = [];
150+
}
144151
} else {
145152
// get caseInfoId assignment.
146153
// eslint-disable-next-line no-lonely-if
@@ -155,6 +162,11 @@ export class TodoComponent implements OnInit, OnDestroy, OnChanges {
155162
this.currentUserInitials$ = this.utils.getInitials(this.currentUser$ ?? '');
156163
}
157164

165+
deferLoadWorklistItems(responseData) {
166+
this.count = responseData.totalCount;
167+
this.arAssignments$ = responseData.data;
168+
}
169+
158170
getID(assignment: any) {
159171
if (assignment.value) {
160172
const refKey = assignment.value;
@@ -181,15 +193,6 @@ export class TodoComponent implements OnInit, OnDestroy, OnChanges {
181193
return this.type$ === this.CONSTS.TODO ? assignment.name : assignment.stepName;
182194
}
183195

184-
initAssignments(): any[] {
185-
if (this.assignmentsSource$) {
186-
this.assignmentCount$ = this.assignmentsSource$.length;
187-
return this.topThreeAssignments(this.assignmentsSource$);
188-
}
189-
// turn off todolist
190-
return [];
191-
}
192-
193196
getCaseInfoAssignment(assignmentsSource: any[], caseInfoID: string) {
194197
const result: any[] = [];
195198
for (const source of assignmentsSource) {
@@ -206,18 +209,26 @@ export class TodoComponent implements OnInit, OnDestroy, OnChanges {
206209
}
207210

208211
_showMore() {
209-
this.ngZone.run(() => {
210-
this.bShowMore$ = false;
212+
this.bShowMore$ = false;
213+
214+
const { WORKLIST } = PCore.getConstants();
215+
216+
if (this.type$ === WORKLIST && this.count && this.count > this.arAssignments$.length && !this.assignmentsSource$) {
217+
fetchMyWorkList(this.myWorkList$.datapage, this.pConn$.getComponentConfig()?.myWorkList.fields, this.count, false, this.context$).then(
218+
response => {
219+
this.arAssignments$ = response.data;
220+
}
221+
);
222+
} else {
211223
this.arAssignments$ = this.assignmentsSource$;
212-
});
224+
}
213225
}
214226

215227
_showLess() {
216-
this.ngZone.run(() => {
217-
this.bShowMore$ = true;
228+
this.bShowMore$ = true;
229+
const { WORKLIST } = PCore.getConstants();
218230

219-
this.arAssignments$ = this.topThreeAssignments(this.assignmentsSource$);
220-
});
231+
this.arAssignments$ = this.type$ === WORKLIST ? this.arAssignments$.slice(0, 3) : this.topThreeAssignments(this.assignmentsSource$);
221232
}
222233

223234
isChildCase(assignment) {

0 commit comments

Comments
 (0)