Skip to content

Commit

Permalink
Fix for breaking changes with 24.2
Browse files Browse the repository at this point in the history
  • Loading branch information
tumms2021389 committed Nov 21, 2024
1 parent a160a9a commit 8a19e6c
Show file tree
Hide file tree
Showing 8 changed files with 155 additions and 113 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export const addContainerItem = pConnect => {
const containerManager = pConnect.getContainerManager();
const context = pConnect.getContextName();
containerManager.addContainerItem({
context,
semanticURL: ''
});
};

export const configureBrowserBookmark = pConnect => {
const context = pConnect.getContextName();
const containerName = pConnect.getContainerName();
const navPages = pConnect.getValue('pyPortal.pyPrimaryNavPages');
const defaultViewLabel = Array.isArray(navPages) && navPages[0] ? navPages[0].pyLabel : '';
PCore.configureForBrowserBookmark({
context,
containerName,
acName: containerName,
semanticURL: '',
defaultViewLabel
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { AngularPConnectData, AngularPConnectService } from '../../../../_bridge
import { ProgressSpinnerService } from '../../../../_messages/progress-spinner.service';
import { ReferenceComponent } from '../../reference/reference.component';
import { ComponentMapperComponent } from '../../../../_bridge/component-mapper/component-mapper.component';
import { configureBrowserBookmark } from './helper';

/**
* WARNING: It is not expected that this file should be modified. It is part of infrastructure code that works with
Expand Down Expand Up @@ -96,37 +97,19 @@ export class ViewContainerComponent implements OnInit, OnDestroy {
// And expose less via ui-bootstrap.js
this.state = {
dispatchObject: this.dispatchObject,
// PCore is defined in pxBootstrapShell - eventually will be exported in place of constellationCore

visible: !PCore.checkIfSemanticURL()
};
containerMgr.initializeContainers({
type: mode === CONTAINER_TYPE.MULTIPLE ? CONTAINER_TYPE.MULTIPLE : CONTAINER_TYPE.SINGLE
});

// here, to match Nebula/Constellation, the constructor of ViewContainer is only called once, and thus init/add container is only
// called once. Because of Angular creating and destroy components if the parent changes a lot, this component will be
// created and destroyed more than once. So the sessionStore "hasViewContainer" is set to false in rootContainer and then
// after first round is true here. Subsequent ViewContainer creation will not init/add more containers.

if (sessionStorage.getItem('hasViewContainer') == 'false') {
// unlike Nebula/Constellation, have to initializeContainer after we create a dispatcObject and state, otherwise, when calling
// initializeContainer before, code will get executed that needs state that wasn't defined.

containerMgr.initializeContainers({
type: mode === CONTAINER_TYPE.MULTIPLE ? CONTAINER_TYPE.MULTIPLE : CONTAINER_TYPE.SINGLE
});

if (mode === CONTAINER_TYPE.MULTIPLE && limit) {
/* NOTE: setContainerLimit use is temporary. It is a non-public, unsupported API. */
PCore.getContainerUtils().setContainerLimit(`${APP.APP}/${name}`, limit);
}
if (mode === CONTAINER_TYPE.MULTIPLE && limit) {
/* NOTE: setContainerLimit use is temporary. It is a non-public, unsupported API. */
PCore.getContainerUtils().setContainerLimit(`${APP.APP}/${name}`, limit);
}

if (sessionStorage.getItem('hasViewContainer') == 'false') {
if (this.pConn$.getMetadata().children) {
containerMgr.addContainerItem(this.dispatchObject);
}

sessionStorage.setItem('hasViewContainer', 'true');
}
if (!PCore.checkIfSemanticURL()) containerMgr.addContainerItem(this.pConn$);
if (!this.displayOnlyFA$) configureBrowserBookmark(this.pConn$);

// cannot call checkAndUpdate becasue first time through, will call updateSelf and that is incorrect (causes issues).
// however, need angularPConnect to be initialized with currentProps for future updates, so calling shouldComponentUpdate directly
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,6 @@ export class RootContainerComponent implements OnInit, OnDestroy {
}
});

// clear out hasViewContainer
sessionStorage.setItem('hasViewContainer', 'false');

this.mConn$ = configObjModal.getPConnect();

// First thing in initialization is registering and subscribing to the AngularPConnect service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,24 @@ export class AppShellComponent implements OnInit, OnDestroy {
if (this.pages$) {
this.bShowAppShell$ = true;
}

// @ts-ignore - Property 'pyCaseTypesAvailableToCreateDP' does not exist on type pxApplication
const caseTypesAvailableToCreateDP = PCore.getEnvironmentInfo().environmentInfoObject?.pxApplication?.pyCaseTypesAvailableToCreateDP;
if (caseTypesAvailableToCreateDP) {
const portalID = this.pConn$.getValue('.pyOwner');
PCore.getDataPageUtils()
.getPageDataAsync(caseTypesAvailableToCreateDP, this.pConn$.getContextName(), {
PortalName: portalID
})
.then((response: any) => {
if (response?.pyCaseTypesAvailableToCreate) {
this.pConn$.replaceState('.pyCaseTypesAvailableToCreate', response.pyCaseTypesAvailableToCreate, {
skipDirtyValidation: true
});
}
});
}

this.caseTypes$ = this.configProps$.caseTypes;

this.arChildren$ = this.pConn$.getChildren() as any[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ export class PageComponent implements OnInit, OnDestroy {
if (operator && operator != '') {
this.title$ += `, ${operator}`;
}

// when showing a page, similar to updating root, need to cause viewContainer to call "initContainer"
sessionStorage.setItem('hasViewContainer', 'false');
}

ngOnDestroy(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="psdk-todo-header">
<div *ngIf="showTodoList$" class="psdk-avatar">{{ this.currentUserInitials$ }}</div>
<div id="worklist" class="psdk-todo-text">{{ headerText$ }}</div>
<div *ngIf="showTodoList$" class="psdk-assignment-count">{{ assignmentCount$ }}</div>
<div *ngIf="showTodoList$" class="psdk-assignment-count">{{ count }}</div>
</div>
<br /><br />
<div *ngIf="showTodoList$" class="psdk-display-divider"></div>
Expand Down Expand Up @@ -36,7 +36,7 @@
</div>
</div>

<div *ngIf="assignmentCount$ > 3">
<div *ngIf="count > 3">
<div *ngIf="bShowMore$; else showLess" class="psdk-todo-show-more">
<button mat-stroked-button (click)="_showMore()">{{ showMoreLocalizedValue === 'show_more' ? 'Show more' : showMoreLocalizedValue }}</button>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,54 @@
import { Component, OnInit, Input, NgZone, OnDestroy, OnChanges } from '@angular/core';
import { Component, OnInit, Input, OnDestroy } from '@angular/core';
import { CommonModule } from '@angular/common';
import { MatButtonModule } from '@angular/material/button';
import { publicConstants } from '@pega/pcore-pconnect-typedefs/constants';
import { ProgressSpinnerService } from '../../../_messages/progress-spinner.service';
import { ErrorMessagesService } from '../../../_messages/error-messages.service';
import { Utils } from '../../../_helpers/utils';
import { updateWorkList } from '../../../_helpers/createstage-utils';

const fetchMyWorkList = (datapage, fields, numberOfRecords, includeTotalCount, context) => {
return PCore.getDataPageUtils()
.getDataAsync(
datapage,
context,
{},
{
pageNumber: 1,
pageSize: numberOfRecords
},
{
select: Object.keys(fields).map(key => ({ field: PCore.getAnnotationUtils().getPropertyName(fields[key]) })),
sortBy: [
{ field: 'pxUrgencyAssign', type: 'DESC' },
{ field: 'pxDeadlineTime', type: 'ASC' },
{ field: 'pxCreateDateTime', type: 'DESC' }
]
},
{
invalidateCache: true,
additionalApiParams: {
includeTotalCount
}
}
)
.then(response => {
return {
...response,
data: (Array.isArray(response?.data) ? response.data : []).map(row =>
Object.keys(fields).reduce((obj, key) => {
obj[key] = row[PCore.getAnnotationUtils().getPropertyName(fields[key])];
return obj;
}, {})
)
};
});
};

const getMappedValue = value => {
const mappedValue = PCore.getEnvironmentInfo().getKeyMapping(value);
return mappedValue === null ? value : mappedValue;
};

interface ToDoProps {
// If any, enter additional props that only exist on this component
Expand All @@ -23,7 +67,7 @@ interface ToDoProps {
standalone: true,
imports: [CommonModule, MatButtonModule]
})
export class TodoComponent implements OnInit, OnDestroy, OnChanges {
export class TodoComponent implements OnInit, OnDestroy {
@Input() pConn$: typeof PConnect;
@Input() caseInfoID$: string;
@Input() datasource$: any;
Expand All @@ -38,7 +82,6 @@ export class TodoComponent implements OnInit, OnDestroy, OnChanges {
configProps$: ToDoProps;
currentUser$: string;
currentUserInitials$ = '--';
assignmentCount$: number;
bShowMore$ = true;
arAssignments$: any[];
assignmentsSource$: any;
Expand All @@ -49,41 +92,21 @@ export class TodoComponent implements OnInit, OnDestroy, OnChanges {
showlessLocalizedValue = this.localizedVal('show_less', 'CosmosFields');
showMoreLocalizedValue = this.localizedVal('show_more', 'CosmosFields');
canPerform: boolean;
count: number;

constructor(
private psService: ProgressSpinnerService,
private erService: ErrorMessagesService,
private ngZone: NgZone,
private utils: Utils
) {}

ngOnInit() {
this.CONSTS = PCore.getConstants();
const { CREATE_STAGE_SAVED, CREATE_STAGE_DELETED }: any = PCore.getEvents().getCaseEvent();

PCore.getPubSubUtils().subscribe(
PCore.getConstants().PUB_SUB_EVENTS.EVENT_CANCEL,
() => {
this.updateToDo();
},
'updateToDo'
);

PCore.getPubSubUtils().subscribe(
CREATE_STAGE_SAVED,
() => {
this.updateList();
},
CREATE_STAGE_SAVED
);

PCore.getPubSubUtils().subscribe(
CREATE_STAGE_DELETED,
() => {
this.updateList();
},
CREATE_STAGE_DELETED
);
PCore.getPubSubUtils().subscribe(PCore.getConstants().PUB_SUB_EVENTS.EVENT_CANCEL, () => this.updateToDo(), 'updateToDo');
PCore.getPubSubUtils().subscribe(CREATE_STAGE_SAVED, () => this.updateList(), CREATE_STAGE_SAVED);
PCore.getPubSubUtils().subscribe(CREATE_STAGE_DELETED, () => this.updateList(), CREATE_STAGE_DELETED);

this.updateToDo();
}
Expand All @@ -92,56 +115,39 @@ export class TodoComponent implements OnInit, OnDestroy, OnChanges {
const { CREATE_STAGE_SAVED, CREATE_STAGE_DELETED }: any = PCore.getEvents().getCaseEvent();

PCore.getPubSubUtils().unsubscribe(PCore.getConstants().PUB_SUB_EVENTS.EVENT_CANCEL, 'updateToDo');

PCore.getPubSubUtils().unsubscribe(CREATE_STAGE_SAVED, CREATE_STAGE_SAVED);

PCore.getPubSubUtils().unsubscribe(CREATE_STAGE_DELETED, CREATE_STAGE_DELETED);
}

ngOnChanges() {
// don't update until we'va had an init
if (PCore) {
this.updateToDo();
}
}

updateWorkList(key) {
PCore.getDataApiUtils()
// @ts-ignore - 2nd parameter "payload" and 3rd parameter "context" should be optional in getData method
.getData(key)
.then(responseData => {
const dataObject = {};
dataObject[key] = {
pxResults: responseData.data.data
};

this.pConn$.updateState(dataObject);
this.updateToDo();
})
.catch(err => {
console.error(err?.stack);
});
}

updateList() {
this.updateWorkList('D_pyMyWorkList');
const {
WORK_BASKET: {
DATA_PAGES: { D__PY_MY_WORK_LIST }
}
} = PCore.getConstants();
updateWorkList(getPConnect, getMappedValue(D__PY_MY_WORK_LIST));
}

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

if (this.headerText$ == undefined) {
this.headerText$ = this.configProps$.headerText;
}

this.datasource$ = this.configProps$.datasource ? this.configProps$.datasource : this.datasource$;
this.myWorkList$ = this.configProps$.myWorkList ? this.configProps$.myWorkList : this.myWorkList$;
this.headerText$ = this.headerText$ || this.configProps$.headerText;
this.datasource$ = this.datasource$ || this.configProps$.datasource;
this.myWorkList$ = this.myWorkList$ || this.configProps$.myWorkList;

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

if (this.showTodoList$) {
this.assignmentCount$ = this.assignmentsSource$ != null ? this.assignmentsSource$.length : 0;
this.arAssignments$ = this.topThreeAssignments(this.assignmentsSource$);
if (this.assignmentsSource$) {
this.count = this.assignmentsSource$ ? this.assignmentsSource$.length : 0;
this.arAssignments$ = this.topThreeAssignments(this.assignmentsSource$);
} else if (this.myWorkList$.datapage) {
fetchMyWorkList(this.myWorkList$.datapage, this.pConn$.getComponentConfig()?.myWorkList.fields, 3, true, this.context$).then(responseData => {
this.deferLoadWorklistItems(responseData);
});
} else {
this.arAssignments$ = [];
}
} else {
// get caseInfoId assignment.
// eslint-disable-next-line no-lonely-if
Expand All @@ -156,6 +162,11 @@ export class TodoComponent implements OnInit, OnDestroy, OnChanges {
this.currentUserInitials$ = this.utils.getInitials(this.currentUser$);
}

deferLoadWorklistItems(responseData) {
this.count = responseData.totalCount;
this.arAssignments$ = responseData.data;
}

getID(assignment: any) {
if (assignment.value) {
const refKey = assignment.value;
Expand All @@ -182,15 +193,6 @@ export class TodoComponent implements OnInit, OnDestroy, OnChanges {
return this.type$ === this.CONSTS.TODO ? assignment.name : assignment.stepName;
}

initAssignments(): any[] {
if (this.assignmentsSource$) {
this.assignmentCount$ = this.assignmentsSource$.length;
return this.topThreeAssignments(this.assignmentsSource$);
}
// turn off todolist
return [];
}

getCaseInfoAssignment(assignmentsSource: any[], caseInfoID: string) {
const result: any[] = [];
for (const source of assignmentsSource) {
Expand All @@ -207,18 +209,26 @@ export class TodoComponent implements OnInit, OnDestroy, OnChanges {
}

_showMore() {
this.ngZone.run(() => {
this.bShowMore$ = false;
this.bShowMore$ = false;

const { WORKLIST } = PCore.getConstants();

if (this.type$ === WORKLIST && this.count && this.count > this.arAssignments$.length && !this.assignmentsSource$) {
fetchMyWorkList(this.myWorkList$.datapage, this.pConn$.getComponentConfig()?.myWorkList.fields, this.count, false, this.context$).then(
response => {
this.arAssignments$ = response.data;
}
);
} else {
this.arAssignments$ = this.assignmentsSource$;
});
}
}

_showLess() {
this.ngZone.run(() => {
this.bShowMore$ = true;
this.bShowMore$ = true;
const { WORKLIST } = PCore.getConstants();

this.arAssignments$ = this.topThreeAssignments(this.assignmentsSource$);
});
this.arAssignments$ = this.type$ === WORKLIST ? this.arAssignments$.slice(0, 3) : this.topThreeAssignments(this.assignmentsSource$);
}

isChildCase(assignment) {
Expand Down
Loading

0 comments on commit 8a19e6c

Please sign in to comment.