Skip to content

Commit ba3cd83

Browse files
author
manasa
committed
Hiding the EmbedListUUID column in embeddedData table
1 parent 0b29c93 commit ba3cd83

File tree

2 files changed

+144
-22
lines changed

2 files changed

+144
-22
lines changed

packages/angular-sdk-components/src/lib/_components/template/simple-table-manual/helpers.ts

Lines changed: 116 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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),

packages/angular-sdk-components/src/lib/_components/template/simple-table-manual/simple-table-manual.component.ts

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ export class SimpleTableManualComponent implements OnInit, OnDestroy {
306306
this.defaultView = editModeConfig ? editModeConfig.defaultView : viewForAddAndEditModal;
307307
this.bUseSeparateViewForEdit = editModeConfig ? editModeConfig.useSeparateViewForEdit : useSeparateViewForEdit;
308308
this.editView = editModeConfig ? editModeConfig.editView : viewForEditModal;
309+
const primaryFieldsViewIndex = resolvedFields.findIndex(field => field.config.value === 'pyPrimaryFields');
309310
// const showDeleteButton = !this.readOnlyMode && !hideDeleteRow;
310311

311312
// Nebula has other handling for isReadOnlyMode but has Cosmos-specific code
@@ -316,8 +317,11 @@ export class SimpleTableManualComponent implements OnInit, OnDestroy {
316317
// Nebula does). It will also have the "label", and "meta" contains the original,
317318
// unchanged config info. For now, much of the info here is carried over from
318319
// Nebula and we may not end up using it all.
319-
this.fieldDefs = buildFieldsForTable(rawFields, resolvedFields, showDeleteButton);
320-
320+
this.fieldDefs = buildFieldsForTable(rawFields, this.pConn$, showDeleteButton, {
321+
primaryFieldsViewIndex,
322+
fields: resolvedFields
323+
});
324+
this.fieldDefs = this.fieldDefs?.filter(field => !(field.meta?.config?.hide === true));
321325
this.initializeDefaultPageInstructions();
322326

323327
// end of from Nebula
@@ -992,24 +996,28 @@ export class SimpleTableManualComponent implements OnInit, OnDestroy {
992996
this.referenceList.forEach((element, index) => {
993997
const data: any = [];
994998
this.rawFields?.forEach(item => {
995-
item = {
996-
...item,
997-
config: { ...item.config, label: '', displayMode: this.readOnlyMode || this.allowEditingInModal ? 'DISPLAY_ONLY' : undefined }
998-
};
999-
const referenceListData = getReferenceList(this.pConn$);
1000-
const isDatapage = referenceListData.startsWith('D_');
1001-
const pageReferenceValue = isDatapage ? `${referenceListData}[${index}]` : `${this.pConn$.getPageReference()}${referenceListData}[${index}]`;
1002-
const config = {
1003-
meta: item,
1004-
options: {
1005-
context,
1006-
pageReference: pageReferenceValue,
1007-
referenceList: referenceListData,
1008-
hasForm: true
1009-
}
1010-
};
1011-
const view = PCore.createPConnect(config);
1012-
data.push(view);
999+
if (!item?.config?.hide) {
1000+
item = {
1001+
...item,
1002+
config: { ...item.config, label: '', displayMode: this.readOnlyMode || this.allowEditingInModal ? 'DISPLAY_ONLY' : undefined }
1003+
};
1004+
const referenceListData = getReferenceList(this.pConn$);
1005+
const isDatapage = referenceListData.startsWith('D_');
1006+
const pageReferenceValue = isDatapage
1007+
? `${referenceListData}[${index}]`
1008+
: `${this.pConn$.getPageReference()}${referenceListData}[${index}]`;
1009+
const config = {
1010+
meta: item,
1011+
options: {
1012+
context,
1013+
pageReference: pageReferenceValue,
1014+
referenceList: referenceListData,
1015+
hasForm: true
1016+
}
1017+
};
1018+
const view = PCore.createPConnect(config);
1019+
data.push(view);
1020+
}
10131021
});
10141022
eleData.push(data);
10151023
});

0 commit comments

Comments
 (0)