Skip to content

Commit ef35796

Browse files
4manasamanasa
andauthored
Hiding the EmbedListUUID column in embeddedData table and default labels not displaying in embedded data issue fixed (#476)
Co-authored-by: manasa <[email protected]>
1 parent 56e8ca2 commit ef35796

File tree

2 files changed

+143
-20
lines changed

2 files changed

+143
-20
lines changed

packages/react-sdk-components/src/components/helpers/simpleTableHelpers.ts

Lines changed: 116 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,51 @@ export const getApiContext = (processedData, pConnect, reorderCB) => {
8989
};
9090
};
9191

92+
const PRIMARY_FIELDS = 'pyPrimaryFields';
93+
const SUPPORTED_FIELD_TYPES = [
94+
'Address',
95+
'TextArea',
96+
'TextInput',
97+
'Phone',
98+
'Email',
99+
'Time',
100+
'URL',
101+
'Percentage',
102+
'Integer',
103+
'Decimal',
104+
'Date',
105+
'DateTime',
106+
'Currency',
107+
'Checkbox',
108+
'Dropdown',
109+
'AutoComplete',
110+
'UserReference',
111+
'RichText'
112+
];
113+
114+
export const getConfigFields = (rawFields, contextClass, primaryFieldsViewIndex) => {
115+
let primaryFields: any = [];
116+
let configFields: any = [];
117+
118+
if (primaryFieldsViewIndex > -1) {
119+
let primaryFieldVMD: any = PCore.getMetadataUtils().resolveView(PRIMARY_FIELDS);
120+
if (Array.isArray(primaryFieldVMD)) {
121+
primaryFieldVMD = primaryFieldVMD.find(primaryFieldView => primaryFieldView.classID === contextClass);
122+
primaryFields = primaryFieldVMD?.children?.[0]?.children || [];
123+
} else if (primaryFieldVMD?.classID === contextClass) {
124+
primaryFields = primaryFieldVMD?.children?.[0]?.children || [];
125+
}
126+
127+
if (primaryFields.length) {
128+
primaryFields = primaryFields.filter(primaryField => SUPPORTED_FIELD_TYPES.includes(primaryField.type));
129+
}
130+
}
131+
132+
configFields = [...rawFields.slice(0, primaryFieldsViewIndex), ...primaryFields, ...rawFields.slice(primaryFieldsViewIndex + 1)];
133+
// filter duplicate fields after combining raw fields and primary fields
134+
return configFields.filter((field, index) => configFields.findIndex(_field => field.config?.value === _field.config?.value) === index);
135+
};
136+
92137
export const buildMetaForListView = (fieldMetadata, fields, type, ruleClass, name, propertyLabel, isDataObject, parameters) => {
93138
return {
94139
name,
@@ -126,11 +171,80 @@ export const buildMetaForListView = (fieldMetadata, fields, type, ruleClass, nam
126171
};
127172
};
128173

129-
export const buildFieldsForTable = (configFields, fields, showDeleteButton) => {
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/react-sdk-components/src/components/template/SimpleTable/SimpleTableManual/SimpleTableManual.tsx

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ export default function SimpleTableManual(props: PropsWithChildren<SimpleTableMa
163163
const menuIconOverride$ = Utils.getImageSrc('trash', Utils.getSDKStaticConentUrl());
164164

165165
const resolvedFields = children?.[0]?.children || presets?.[0].children?.[0].children;
166+
const primaryFieldsViewIndex = resolvedFields.findIndex(field => field.config.value === 'pyPrimaryFields');
166167
// NOTE: props has each child.config with datasource and value undefined
167168
// but getRawMetadata() has each child.config with datasource and value showing their unresolved values (ex: "@P thePropName")
168169
// We need to use the prop name as the "glue" to tie the table dataSource, displayColumns and data together.
@@ -208,7 +209,10 @@ export default function SimpleTableManual(props: PropsWithChildren<SimpleTableMa
208209
// Constellation DX Components do). It will also have the "label", and "meta" contains the original,
209210
// unchanged config info. For now, much of the info here is carried over from
210211
// Constellation DX Components.
211-
const fieldDefs = buildFieldsForTable(rawFields, resolvedFields, showDeleteButton);
212+
const fieldDefs = buildFieldsForTable(rawFields, getPConnect(), showDeleteButton, {
213+
primaryFieldsViewIndex,
214+
fields: resolvedFields
215+
});
212216

213217
useLayoutEffect(() => {
214218
if (allowEditingInModal) {
@@ -360,23 +364,25 @@ export default function SimpleTableManual(props: PropsWithChildren<SimpleTableMa
360364
const data: any = [];
361365
rawFields.forEach(item => {
362366
// removing label field from config to hide title in the table cell
363-
item = { ...item, config: { ...item.config, label: '', displayMode: readOnlyMode || allowEditingInModal ? 'DISPLAY_ONLY' : undefined } };
364-
const referenceListData = getReferenceList(pConn);
365-
const isDatapage = referenceListData.startsWith('D_');
366-
const pageReferenceValue = isDatapage
367-
? `${referenceListData}[${index}]`
368-
: `${pConn.getPageReference()}${referenceListData.substring(referenceListData.lastIndexOf('.'))}[${index}]`;
369-
const config = {
370-
meta: item,
371-
options: {
372-
context,
373-
pageReference: pageReferenceValue,
374-
referenceList: referenceListData,
375-
hasForm: true
376-
}
377-
};
378-
const view = PCore.createPConnect(config);
379-
data.push(createElement(createPConnectComponent(), view));
367+
if (!item.config.hide) {
368+
item = { ...item, config: { ...item.config, label: '', displayMode: readOnlyMode || allowEditingInModal ? 'DISPLAY_ONLY' : undefined } };
369+
const referenceListData = getReferenceList(pConn);
370+
const isDatapage = referenceListData.startsWith('D_');
371+
const pageReferenceValue = isDatapage
372+
? `${referenceListData}[${index}]`
373+
: `${pConn.getPageReference()}${referenceListData.substring(referenceListData.lastIndexOf('.'))}[${index}]`;
374+
const config = {
375+
meta: item,
376+
options: {
377+
context,
378+
pageReference: pageReferenceValue,
379+
referenceList: referenceListData,
380+
hasForm: true
381+
}
382+
};
383+
const view = PCore.createPConnect(config);
384+
data.push(createElement(createPConnectComponent(), view));
385+
}
380386
});
381387
eleData.push(data);
382388
});
@@ -608,6 +614,9 @@ export default function SimpleTableManual(props: PropsWithChildren<SimpleTableMa
608614
<TableHead className={classes.header}>
609615
<TableRow>
610616
{fieldDefs.map((field: any, index) => {
617+
if (field?.meta?.config?.hide) {
618+
return null; // Skip rendering if hide = true
619+
}
611620
return (
612621
<TableCell key={`head-${displayedColumns[index]}`} className={classes.tableCell}>
613622
{(readOnlyMode || allowEditingInModal) && field.cellRenderer !== 'DeleteIcon' ? (

0 commit comments

Comments
 (0)