@@ -64,138 +64,56 @@ export class ObjectReferenceComponent implements OnInit, OnDestroy {
6464
6565 updateSelf ( ) {
6666 this . configProps = this . pConn$ . resolveConfigProps ( this . pConn$ . getConfigProps ( ) ) as ObjectReferenceProps ;
67- const displayMode = this . configProps . displayMode ;
68- const editableInReview = this . configProps . allowAndPersistChangesInReviewMode ?? false ;
69- const targetObjectType = this . configProps . targetObjectType ;
70- const mode = this . configProps . mode ;
71- const parameters = this . configProps . parameters ;
72- const hideLabel = this . configProps . hideLabel ;
73- const inline = this . configProps . inline ;
74- const showPromotedFilters = this . configProps . showPromotedFilters ;
67+ const {
68+ displayMode,
69+ allowAndPersistChangesInReviewMode : editableInReview = false ,
70+ targetObjectType,
71+ mode,
72+ parameters,
73+ hideLabel,
74+ inline,
75+ showPromotedFilters
76+ } = this . configProps ;
77+
7578 const referenceType : string = targetObjectType === 'case' ? 'Case' : 'Data' ;
7679 this . rawViewMetadata = this . pConn$ . getRawMetadata ( ) ;
7780 const refFieldMetadata = this . pConn$ . getFieldMetadata ( this . rawViewMetadata ?. config ?. value ?. split ( '.' , 2 ) [ 1 ] ?? '' ) ;
78-
79- // Destructured properties
8081 const propsToUse = { ...this . pConn$ . getInheritedProps ( ) , ...this . configProps } ;
8182
82- // Computed variables
8383 this . isDisplayModeEnabled = displayMode === 'DISPLAY_ONLY' ;
84- this . canBeChangedInReviewMode = editableInReview && [ 'Autocomplete' , 'Dropdown' ] . includes ( ( this . rawViewMetadata ?. config as any ) ?. componentType ) ;
85- // componentType is not defined in ComponentMetadataConfig type so using any
86- this . type = ( this . rawViewMetadata ?. config as any ) ?. componentType ;
84+ this . type = this . getComponentType ( ) ;
85+ this . canBeChangedInReviewMode = editableInReview && [ 'Autocomplete' , 'Dropdown' ] . includes ( this . type ) ;
8786
8887 if ( this . type === 'SemanticLink' && ! this . canBeChangedInReviewMode ) {
8988 const config : any = {
9089 ...this . rawViewMetadata ?. config ,
91- primaryField : ( this . rawViewMetadata ?. config as any ) . displayField
90+ primaryField : ( this . rawViewMetadata ?. config as any ) . displayField ,
91+ caseClass : ( this . rawViewMetadata ?. config as any ) . targetObjectClass ,
92+ text : ( this . rawViewMetadata ?. config as any ) . displayField ,
93+ caseID : ( this . rawViewMetadata ?. config as any ) . value ,
94+ contextPage : `@P .${ ( this . rawViewMetadata ?. config as any ) . displayField ? getDataRelationshipContextFromKey ( ( this . rawViewMetadata ?. config as any ) . displayField ) : null } ` ,
95+ resourceParams : { workID : ( this . rawViewMetadata ?. config as any ) . value } ,
96+ resourcePayload : { caseClassName : ( this . rawViewMetadata ?. config as any ) . targetObjectClass }
9297 } ;
93- config . caseClass = ( this . rawViewMetadata ?. config as any ) . targetObjectClass ;
94- config . text = config . primaryField ;
95- config . caseID = config . value ;
96- config . contextPage = `@P .${
97- ( this . rawViewMetadata ?. config as any ) ?. displayField
98- ? getDataRelationshipContextFromKey ( ( this . rawViewMetadata ?. config as any ) . displayField )
99- : null
100- } `;
101- config . resourceParams = {
102- workID : config . value
103- } ;
104- config . resourcePayload = {
105- caseClassName : config . caseClass
106- } ;
107-
108- const component = this . pConn$ . createComponent (
109- {
110- type : 'SemanticLink' ,
111- config : {
112- ...config ,
113- displayMode,
114- referenceType,
115- hideLabel,
116- dataRelationshipContext : ( this . rawViewMetadata ?. config as any ) ?. displayField
117- ? getDataRelationshipContextFromKey ( ( this . rawViewMetadata ?. config as any ) . displayField )
118- : null
119- }
120- } ,
121- '' ,
122- 0 ,
123- { }
124- ) ;
125- this . newPconn = component ?. getPConnect ( ) ;
98+ this . createSemanticLinkPConnect ( config , displayMode ?? '' , referenceType , hideLabel ) ;
99+ return ;
126100 }
127101
128102 if ( this . type !== 'SemanticLink' && ! this . isDisplayModeEnabled ) {
129- // 1) Set datasource
130103 const config : any = { ...this . rawViewMetadata ?. config } ;
131104 generateColumns ( config , this . pConn$ , referenceType ) ;
132105 config . deferDatasource = true ;
133106 config . listType = 'datapage' ;
134107 if ( [ 'Dropdown' , 'AutoComplete' ] . includes ( this . type ) && ! config . placeholder ) {
135108 config . placeholder = '@L Select...' ;
136109 }
137-
138- // 2) Pass through configs
139110 config . showPromotedFilters = showPromotedFilters ;
140-
141111 if ( ! this . canBeChangedInReviewMode ) {
142112 config . displayMode = displayMode ;
143113 }
114+ config . parameters = parameters ;
144115
145- // 3) Define field meta
146-
147- const fieldMetaData = {
148- datasourceMetadata : {
149- datasource : {
150- parameters : { } ,
151- propertyForDisplayText : false ,
152- propertyForValue : false ,
153- name : ''
154- }
155- }
156- } ;
157- if ( config ?. parameters ) {
158- fieldMetaData . datasourceMetadata . datasource . parameters = parameters ;
159- }
160- fieldMetaData . datasourceMetadata . datasource . propertyForDisplayText = config ?. datasource ?. fields ?. text ?. startsWith ( '@P' )
161- ? config ?. datasource ?. fields ?. text ?. substring ( 3 )
162- : config ?. datasource ?. fields ?. text ;
163- fieldMetaData . datasourceMetadata . datasource . propertyForValue = config ?. datasource ?. fields ?. value ?. startsWith ( '@P' )
164- ? config ?. datasource ?. fields ?. value ?. substring ( 3 )
165- : config ?. datasource ?. fields ?. value ;
166- fieldMetaData . datasourceMetadata . datasource . name = config ?. referenceList ?? '' ;
167-
168- const component = this . pConn$ . createComponent (
169- {
170- type : this . type ,
171- config : {
172- ...config ,
173- descriptors : mode === 'single' ? refFieldMetadata ?. descriptors : null ,
174- datasourceMetadata : fieldMetaData ?. datasourceMetadata ,
175- required : propsToUse . required ,
176- visibility : propsToUse . visibility ,
177- disabled : propsToUse . disabled ,
178- label : propsToUse . label ,
179- parameters : config . parameters ,
180- readOnly : false ,
181- localeReference : config . localeReference ,
182- ...( mode === 'single' ? { referenceType } : '' ) ,
183- contextClass : config . targetObjectClass ,
184- primaryField : config ?. displayField ,
185- dataRelationshipContext : config ?. displayField ? getDataRelationshipContextFromKey ( config . displayField ) : null ,
186- hideLabel,
187- inline
188- }
189- } ,
190- '' ,
191- 0 ,
192- { }
193- ) ;
194- this . newComponentName = component ?. getPConnect ( ) . getComponentName ( ) ;
195- this . newPconn = component ?. getPConnect ( ) ;
196- if ( this . rawViewMetadata ?. config ) {
197- this . rawViewMetadata . config = config ? { ...config } : this . rawViewMetadata . config ;
198- }
116+ this . createOtherComponentPConnect ( config , propsToUse , mode , refFieldMetadata , referenceType , hideLabel , inline ) ;
199117 }
200118 }
201119
@@ -253,4 +171,67 @@ export class ObjectReferenceComponent implements OnInit, OnDestroy {
253171 } ) ;
254172 }
255173 }
174+
175+ private getComponentType ( ) : string {
176+ // componentType is not defined in ComponentMetadataConfig type so using any
177+ return ( this . rawViewMetadata ?. config as any ) ?. componentType ;
178+ }
179+
180+ private createSemanticLinkPConnect ( config : any , displayMode : string , referenceType : string , hideLabel : boolean ) {
181+ const semanticLinkConfig = {
182+ ...config ,
183+ displayMode,
184+ referenceType,
185+ hideLabel,
186+ dataRelationshipContext : config . displayField ? getDataRelationshipContextFromKey ( config . displayField ) : null
187+ } ;
188+
189+ const component = this . pConn$ . createComponent ( { type : 'SemanticLink' , config : semanticLinkConfig } , '' , 0 , { } ) ;
190+ this . newPconn = component ?. getPConnect ( ) ;
191+ }
192+
193+ private createOtherComponentPConnect (
194+ config : any ,
195+ propsToUse : any ,
196+ mode : string ,
197+ refFieldMetadata : any ,
198+ referenceType : string ,
199+ hideLabel : boolean ,
200+ inline : boolean
201+ ) {
202+ const fieldMetaData = {
203+ datasourceMetadata : {
204+ datasource : {
205+ parameters : config . parameters ?? { } ,
206+ propertyForDisplayText : config . datasource ?. fields ?. text ?. substring ( 3 ) ?? config . datasource ?. fields ?. text ,
207+ propertyForValue : config . datasource ?. fields ?. value ?. substring ( 3 ) ?? config . datasource ?. fields ?. value ,
208+ name : config . referenceList ?? ''
209+ }
210+ }
211+ } ;
212+
213+ const componentConfig = {
214+ ...config ,
215+ descriptors : mode === 'single' ? refFieldMetadata ?. descriptors : null ,
216+ datasourceMetadata : fieldMetaData . datasourceMetadata ,
217+ required : propsToUse . required ,
218+ visibility : propsToUse . visibility ,
219+ disabled : propsToUse . disabled ,
220+ label : propsToUse . label ,
221+ readOnly : false ,
222+ ...( mode === 'single' && { referenceType } ) ,
223+ contextClass : config . targetObjectClass ,
224+ primaryField : config . displayField ,
225+ dataRelationshipContext : config . displayField ? getDataRelationshipContextFromKey ( config . displayField ) : null ,
226+ hideLabel,
227+ inline
228+ } ;
229+
230+ const component = this . pConn$ . createComponent ( { type : this . type , config : componentConfig } , '' , 0 , { } ) ;
231+ this . newComponentName = component ?. getPConnect ( ) . getComponentName ( ) ;
232+ this . newPconn = component ?. getPConnect ( ) ;
233+ if ( this . rawViewMetadata ?. config ) {
234+ this . rawViewMetadata . config = { ...config } ;
235+ }
236+ }
256237}
0 commit comments