@@ -126,11 +126,125 @@ export const buildMetaForListView = (fieldMetadata, fields, type, ruleClass, nam
126126 } ;
127127} ;
128128
129- export const buildFieldsForTable = ( configFields , fields , showDeleteButton ) => {
129+ const PRIMARY_FIELDS = 'pyPrimaryFields' ;
130+ const SUPPORTED_FIELD_TYPES = [
131+ 'Address' ,
132+ 'TextArea' ,
133+ 'TextInput' ,
134+ 'Phone' ,
135+ 'Email' ,
136+ 'Time' ,
137+ 'URL' ,
138+ 'Percentage' ,
139+ 'Integer' ,
140+ 'Decimal' ,
141+ 'Date' ,
142+ 'DateTime' ,
143+ 'Currency' ,
144+ 'Checkbox' ,
145+ 'Dropdown' ,
146+ 'AutoComplete' ,
147+ 'UserReference' ,
148+ 'RichText'
149+ ] ;
150+
151+ export const getConfigFields = ( rawFields , contextClass , primaryFieldsViewIndex ) => {
152+ let primaryFields : any = [ ] ;
153+ let configFields : any = [ ] ;
154+
155+ if ( primaryFieldsViewIndex > - 1 ) {
156+ let primaryFieldVMD : any = PCore . getMetadataUtils ( ) . resolveView ( PRIMARY_FIELDS ) ;
157+ if ( Array . isArray ( primaryFieldVMD ) ) {
158+ primaryFieldVMD = primaryFieldVMD . find ( primaryFieldView => primaryFieldView . classID === contextClass ) ;
159+ primaryFields = primaryFieldVMD ?. children ?. [ 0 ] ?. children || [ ] ;
160+ } else if ( primaryFieldVMD ?. classID === contextClass ) {
161+ primaryFields = primaryFieldVMD ?. children ?. [ 0 ] ?. children || [ ] ;
162+ }
163+
164+ if ( primaryFields . length ) {
165+ primaryFields = primaryFields . filter ( primaryField => SUPPORTED_FIELD_TYPES . includes ( primaryField . type ) ) ;
166+ }
167+ }
168+
169+ configFields = [ ...rawFields . slice ( 0 , primaryFieldsViewIndex ) , ...primaryFields , ...rawFields . slice ( primaryFieldsViewIndex + 1 ) ] ;
170+ // filter duplicate fields after combining raw fields and primary fields
171+ return configFields . filter ( ( field , index ) => configFields . findIndex ( _field => field . config ?. value === _field . config ?. value ) === index ) ;
172+ } ;
173+
174+ export function isFLProperty ( label ) {
175+ return label ?. startsWith ( '@FL' ) ;
176+ }
177+
178+ /**
179+ * [getFieldLabel]
180+ * Description - A utility that returns resolved field label for "@FL" annotation i.e from data model.
181+ * @param {Object } fieldConfig
182+ * @returns {string } resolved label string
183+ *
184+ * example:
185+ * fieldConfig = {label: "@FL .pyID", classID: "TestCase-Work"};
186+ * return "Case ID"
187+ */
188+ export function getFieldLabel ( fieldConfig ) {
189+ const { label, classID, caption } = fieldConfig ;
190+ let fieldLabel = ( label ?? caption ) ?. substring ( 4 ) ;
191+ const labelSplit = fieldLabel ?. split ( '.' ) ;
192+ const propertyName = labelSplit ?. pop ( ) ;
193+ const fieldMetaData : any = PCore . getMetadataUtils ( ) . getPropertyMetadata ( propertyName , classID ) ?? { } ;
194+ fieldLabel = fieldMetaData . label ?? fieldMetaData . caption ?? propertyName ;
195+ return fieldLabel ;
196+ }
197+
198+ export const updateFieldLabels = ( fields , configFields , primaryFieldsViewIndex , pConnect , options ) => {
199+ const labelsOfFields : any = [ ] ;
200+ const { columnsRawConfig = [ ] } = options ;
201+ fields . forEach ( ( field , idx ) => {
202+ const rawColumnConfig = columnsRawConfig [ idx ] ?. config ;
203+ if ( field . config . value === PRIMARY_FIELDS ) {
204+ labelsOfFields . push ( '' ) ;
205+ } else if ( isFLProperty ( rawColumnConfig ?. label ?? rawColumnConfig ?. caption ) ) {
206+ labelsOfFields . push ( getFieldLabel ( rawColumnConfig ) || field . config . label || field . config . caption ) ;
207+ } else {
208+ labelsOfFields . push ( field . config . label || field . config . caption ) ;
209+ }
210+ } ) ;
211+
212+ if ( primaryFieldsViewIndex > - 1 ) {
213+ const totalPrimaryFieldsColumns = configFields . length - fields . length + 1 ;
214+ if ( totalPrimaryFieldsColumns ) {
215+ const primaryFieldLabels : any = [ ] ;
216+ for ( let i = primaryFieldsViewIndex ; i < primaryFieldsViewIndex + totalPrimaryFieldsColumns ; i += 1 ) {
217+ let label = configFields [ i ] . config ?. label ;
218+ if ( isFLProperty ( label ) ) {
219+ label = getFieldLabel ( configFields [ i ] . config ) ;
220+ } else if ( label . startsWith ( '@' ) ) {
221+ label = label . substring ( 3 ) ;
222+ }
223+ if ( pConnect ) {
224+ label = pConnect . getLocalizedValue ( label ) ;
225+ }
226+ primaryFieldLabels . push ( label ) ;
227+ }
228+ labelsOfFields . splice ( primaryFieldsViewIndex , 1 , ...primaryFieldLabels ) ;
229+ } else {
230+ labelsOfFields . splice ( primaryFieldsViewIndex , 1 ) ;
231+ }
232+ }
233+ return labelsOfFields ;
234+ } ;
235+
236+ export const buildFieldsForTable = ( configFields , pConnect , showDeleteButton , options ) => {
237+ const { primaryFieldsViewIndex, fields } = options ;
238+
239+ // get resolved field labels for primary fields raw config included in configFields
240+ const fieldsLabels = updateFieldLabels ( fields , configFields , primaryFieldsViewIndex , pConnect , {
241+ columnsRawConfig : pConnect . getRawConfigProps ( ) ?. children . find ( item => item ?. name === 'Columns' ) ?. children
242+ } ) ;
243+
130244 const fieldDefs = configFields ?. map ( ( field , index ) => {
131245 return {
132246 type : 'text' ,
133- label : fields [ index ] . config . label || fields [ index ] . config . caption ,
247+ label : fieldsLabels [ index ] ,
134248 fillAvailableSpace : ! ! field . config . fillAvailableSpace ,
135249 id : `${ index } ` ,
136250 name : field . config . value . substr ( 4 ) ,
0 commit comments