@@ -5,6 +5,7 @@ import { PConnFieldProps } from '../../../_types/PConnProps.interface';
55import { generateColumns , getDataRelationshipContextFromKey } from './utils' ;
66import { ComponentMapperComponent } from '../../../_bridge/component-mapper/component-mapper.component' ;
77import { CommonModule } from '@angular/common' ;
8+ import { ComponentMetadataConfig } from '@pega/pcore-pconnect-typedefs/interpreter/types' ;
89
910interface ObjectReferenceProps extends PConnFieldProps {
1011 showPromotedFilters : boolean ;
@@ -35,7 +36,7 @@ export class ObjectReferenceComponent implements OnInit, OnDestroy {
3536 canBeChangedInReviewMode : boolean ;
3637 newComponentName : string ;
3738 newPconn : typeof PConnect ;
38- parentProps : { } ;
39+ rawViewMetadata : ComponentMetadataConfig | undefined ;
3940
4041 constructor ( private angularPConnect : AngularPConnectService ) { }
4142
@@ -72,28 +73,30 @@ export class ObjectReferenceComponent implements OnInit, OnDestroy {
7273 const inline = this . configProps . inline ;
7374 const showPromotedFilters = this . configProps . showPromotedFilters ;
7475 const referenceType : string = targetObjectType === 'case' ? 'Case' : 'Data' ;
75- const rawViewMetadata = this . pConn$ . getRawMetadata ( ) ;
76- const refFieldMetadata = this . pConn$ . getFieldMetadata ( rawViewMetadata ?. config ?. value ?. split ( '.' , 2 ) [ 1 ] ) ;
76+ this . rawViewMetadata = this . pConn$ . getRawMetadata ( ) ;
77+ const refFieldMetadata = this . pConn$ . getFieldMetadata ( this . rawViewMetadata ?. config ?. value ?. split ( '.' , 2 ) [ 1 ] ) ;
7778
7879 // Destructured properties
7980 const propsToUse = { ...this . pConn$ . getInheritedProps ( ) , ...this . configProps } ;
8081
8182 // Computed variables
8283 this . isDisplayModeEnabled = displayMode === 'DISPLAY_ONLY' ;
83- this . canBeChangedInReviewMode = editableInReview && [ 'Autocomplete' , 'Dropdown' ] . includes ( ( rawViewMetadata ?. config as any ) ?. componentType ) ;
84+ this . canBeChangedInReviewMode = editableInReview && [ 'Autocomplete' , 'Dropdown' ] . includes ( ( this . rawViewMetadata ?. config as any ) ?. componentType ) ;
8485 // componentType is not defined in ComponentMetadataConfig type so using any
85- this . type = ( rawViewMetadata ?. config as any ) ?. componentType ;
86+ this . type = ( this . rawViewMetadata ?. config as any ) ?. componentType ;
8687
8788 if ( this . type === 'SemanticLink' && ! this . canBeChangedInReviewMode ) {
8889 const config : any = {
89- ...rawViewMetadata ?. config ,
90- primaryField : ( rawViewMetadata ?. config as any ) . displayField
90+ ...this . rawViewMetadata ?. config ,
91+ primaryField : ( this . rawViewMetadata ?. config as any ) . displayField
9192 } ;
92- config . caseClass = ( rawViewMetadata ?. config as any ) . targetObjectClass ;
93+ config . caseClass = ( this . rawViewMetadata ?. config as any ) . targetObjectClass ;
9394 config . text = config . primaryField ;
9495 config . caseID = config . value ;
9596 config . contextPage = `@P .${
96- ( rawViewMetadata ?. config as any ) ?. displayField ? getDataRelationshipContextFromKey ( ( rawViewMetadata ?. config as any ) . displayField ) : null
97+ ( this . rawViewMetadata ?. config as any ) ?. displayField
98+ ? getDataRelationshipContextFromKey ( ( this . rawViewMetadata ?. config as any ) . displayField )
99+ : null
97100 } `;
98101 config . resourceParams = {
99102 workID : config . value
@@ -110,8 +113,8 @@ export class ObjectReferenceComponent implements OnInit, OnDestroy {
110113 displayMode,
111114 referenceType,
112115 hideLabel,
113- dataRelationshipContext : ( rawViewMetadata ?. config as any ) ?. displayField
114- ? getDataRelationshipContextFromKey ( ( rawViewMetadata ?. config as any ) . displayField )
116+ dataRelationshipContext : ( this . rawViewMetadata ?. config as any ) ?. displayField
117+ ? getDataRelationshipContextFromKey ( ( this . rawViewMetadata ?. config as any ) . displayField )
115118 : null
116119 }
117120 } ,
@@ -124,7 +127,7 @@ export class ObjectReferenceComponent implements OnInit, OnDestroy {
124127
125128 if ( this . type !== 'SemanticLink' && ! this . isDisplayModeEnabled ) {
126129 // 1) Set datasource
127- const config : any = { ...rawViewMetadata ?. config } ;
130+ const config : any = { ...this . rawViewMetadata ?. config } ;
128131 generateColumns ( config , this . pConn$ , referenceType ) ;
129132 config . deferDatasource = true ;
130133 config . listType = 'datapage' ;
@@ -190,16 +193,64 @@ export class ObjectReferenceComponent implements OnInit, OnDestroy {
190193 ) ;
191194 this . newComponentName = component ?. getPConnect ( ) . getComponentName ( ) ;
192195 this . newPconn = component ?. getPConnect ( ) ;
193- if ( rawViewMetadata ?. config ) {
194- rawViewMetadata . config = config ? { ...config } : rawViewMetadata . config ;
196+ if ( this . rawViewMetadata ?. config ) {
197+ this . rawViewMetadata . config = config ? { ...config } : this . rawViewMetadata . config ;
195198 }
196- this . parentProps = {
197- parentPconn : this . pConn$ ,
198- rawViewMetadata,
199- canBeChangedInReviewMode : this . canBeChangedInReviewMode ,
200- isDisplayModeEnabled : this . isDisplayModeEnabled ,
201- mode
202- } ;
199+ }
200+ }
201+
202+ onRecordChange ( value ) {
203+ const caseKey = this . pConn$ . getCaseInfo ( ) . getKey ( ) ?? '' ;
204+ const refreshOptions = { autoDetectRefresh : true , propertyName : '' } ;
205+ refreshOptions . propertyName = this . rawViewMetadata ?. config ?. value ;
206+
207+ if ( ! this . canBeChangedInReviewMode || ! this . pConn$ . getValue ( '__currentPageTabViewName' ) ) {
208+ const pgRef = this . pConn$ . getPageReference ( ) . replace ( 'caseInfo.content' , '' ) ?? '' ;
209+ const viewName = this . rawViewMetadata ?. name ;
210+ if ( viewName && viewName . length > 0 ) {
211+ getPConnect ( ) . getActionsApi ( ) . refreshCaseView ( caseKey , viewName , pgRef , refreshOptions ) ;
212+ }
213+ }
214+
215+ const propValue = value ;
216+ const propName =
217+ this . rawViewMetadata ?. type === 'SimpleTableSelect' && this . configProps . mode === 'multi'
218+ ? PCore . getAnnotationUtils ( ) . getPropertyName ( this . rawViewMetadata ?. config ?. selectionList )
219+ : PCore . getAnnotationUtils ( ) . getPropertyName ( this . rawViewMetadata ?. config ?. value ) ;
220+
221+ if ( propValue && this . canBeChangedInReviewMode && this . isDisplayModeEnabled ) {
222+ PCore . getCaseUtils ( )
223+ . getCaseEditLock ( caseKey , '' )
224+ . then ( caseResponse => {
225+ const pageTokens = this . pConn$ . getPageReference ( ) . replace ( 'caseInfo.content' , '' ) . split ( '.' ) ;
226+ let curr = { } ;
227+ const commitData = curr ;
228+
229+ pageTokens ?. forEach ( el => {
230+ if ( el !== '' ) {
231+ curr [ el ] = { } ;
232+ curr = curr [ el ] ;
233+ }
234+ } ) ;
235+
236+ // expecting format like {Customer: {pyID:"C-100"}}
237+ const propArr = propName . split ( '.' ) ;
238+ propArr . forEach ( ( element , idx ) => {
239+ if ( idx + 1 === propArr . length ) {
240+ curr [ element ] = propValue ;
241+ } else {
242+ curr [ element ] = { } ;
243+ curr = curr [ element ] ;
244+ }
245+ } ) ;
246+
247+ PCore . getCaseUtils ( )
248+ . updateCaseEditFieldsData ( caseKey , { [ caseKey ] : commitData } , caseResponse . headers . etag , this . pConn$ ?. getContextName ( ) ?? '' )
249+ . then ( response => {
250+ PCore . getContainerUtils ( ) . updateParentLastUpdateTime ( this . pConn$ . getContextName ( ) ?? '' , response . data . data . caseInfo . lastUpdateTime ) ;
251+ PCore . getContainerUtils ( ) . updateRelatedContextEtag ( this . pConn$ . getContextName ( ) ?? '' , response . headers . etag ) ;
252+ } ) ;
253+ } ) ;
203254 }
204255 }
205256}
0 commit comments