Skip to content

Commit f943ba6

Browse files
TASK-1828883: cleaning template-utils.js
1 parent a97118d commit f943ba6

File tree

1 file changed

+39
-82
lines changed

1 file changed

+39
-82
lines changed
Lines changed: 39 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
export const TABLE_CELL = 'SdkRenderer';
21
const PRIMARY_FIELDS = 'pyPrimaryFields';
32

43
export function getReferenceList(pConn) {
@@ -16,35 +15,63 @@ export function getReferenceList(pConn) {
1615

1716
export const buildFieldsForTable = (configFields, pConnect, options) => {
1817
const { primaryFieldsViewIndex, fields } = options;
19-
2018
// get resolved field labels for primary fields raw config included in configFields
2119
const fieldsLabels = updateFieldLabels(fields, configFields, primaryFieldsViewIndex, pConnect, {
2220
columnsRawConfig: pConnect.getRawConfigProps()?.children?.find(item => item?.name === 'Columns')?.children
2321
});
2422

25-
const fieldDefs = configFields?.map((field, index) => {
23+
return configFields?.map((field, index) => {
2624
return {
2725
type: 'text',
2826
label: fieldsLabels[index],
2927
fillAvailableSpace: !!field.config.fillAvailableSpace,
3028
id: `${index}`,
3129
name: field.config.value.substr(4),
32-
cellRenderer: TABLE_CELL,
3330
sort: false,
3431
noContextMenu: true,
3532
showMenu: false,
3633
meta: {
3734
...field
38-
},
39-
// BUG-615253: Workaround for autosize in table with lazy loading components
40-
width: getFieldWidth(field, fields[index].config.label)
35+
}
4136
};
4237
});
43-
44-
return fieldDefs;
4538
};
4639

47-
export const updateFieldLabels = (fields, configFields, primaryFieldsViewIndex, pConnect, options) => {
40+
/**
41+
* This method evaluates whether a row action is allowed based on the provided conditions.
42+
* @param {string|boolean|undefined} rawExpression - The condition for allowing row action.
43+
* @param {object} rowData - The data of the row being evaluated.
44+
* @returns {boolean} - Returns true if the row action is allowed, false otherwise.
45+
*/
46+
export function evaluateAllowRowAction(rawExpression, rowData) {
47+
if (rawExpression === undefined || rawExpression === true) return true;
48+
if (rawExpression.startsWith?.("@E ")) {
49+
const expression = rawExpression.replace("@E ", "");
50+
return PCore.getExpressionEngine().evaluate(expression, rowData);
51+
}
52+
return false;
53+
}
54+
55+
export function getContext(thePConn) {
56+
const contextName = thePConn.getContextName();
57+
const pageReference = thePConn.getPageReference();
58+
const {
59+
readonlyContextList,
60+
referenceList = readonlyContextList
61+
} = thePConn.getStateProps()?.config || thePConn.getStateProps();
62+
63+
const pageReferenceForRows = referenceList.startsWith('.') ? `${pageReference}.${referenceList.substring(1)}` : referenceList;
64+
const viewName = thePConn.viewName;
65+
66+
return {
67+
contextName,
68+
referenceListStr: referenceList,
69+
pageReferenceForRows,
70+
viewName
71+
};
72+
}
73+
74+
function updateFieldLabels (fields, configFields, primaryFieldsViewIndex, pConnect, options) {
4875
const labelsOfFields = [];
4976
const { columnsRawConfig = [] } = options;
5077
fields.forEach((field, idx) => {
@@ -82,46 +109,10 @@ export const updateFieldLabels = (fields, configFields, primaryFieldsViewIndex,
82109
return labelsOfFields;
83110
};
84111

85-
export function isFLProperty(label) {
112+
function isFLProperty(label) {
86113
return label?.startsWith('@FL');
87114
}
88115

89-
function getFieldWidth(field, label) {
90-
let width;
91-
switch (field.type) {
92-
case 'Time':
93-
width = 150;
94-
break;
95-
case 'Date':
96-
width = 160;
97-
break;
98-
case 'DateTime':
99-
width = 205;
100-
break;
101-
case 'AutoComplete':
102-
case 'TextArea':
103-
width = 190;
104-
break;
105-
case 'Currency':
106-
case 'TextInput':
107-
width = 182;
108-
break;
109-
case 'Checkbox':
110-
// eslint-disable-next-line no-case-declarations
111-
const text = document.createElement('span');
112-
document.body.appendChild(text);
113-
text.style.fontSize = '13px';
114-
text.style.position = 'absolute';
115-
text.innerHTML = label;
116-
width = Math.ceil(text.clientWidth) + 30;
117-
document.body.removeChild(text);
118-
break;
119-
default:
120-
width = 180;
121-
}
122-
return width;
123-
}
124-
125116
/**
126117
* [getFieldLabel]
127118
* Description - A utility that returns resolved field label for "@FL" annotation i.e from data model.
@@ -132,7 +123,7 @@ function getFieldWidth(field, label) {
132123
* fieldConfig = {label: "@FL .pyID", classID: "TestCase-Work"};
133124
* return "Case ID"
134125
*/
135-
export function getFieldLabel(fieldConfig) {
126+
function getFieldLabel(fieldConfig) {
136127
const { label, classID, caption } = fieldConfig;
137128
let fieldLabel = (label ?? caption)?.substring(4);
138129
const labelSplit = fieldLabel?.split('.');
@@ -141,37 +132,3 @@ export function getFieldLabel(fieldConfig) {
141132
fieldLabel = fieldMetaData.label ?? fieldMetaData.caption ?? propertyName;
142133
return fieldLabel;
143134
}
144-
145-
/**
146-
* This method evaluates whether a row action is allowed based on the provided conditions.
147-
* @param {string|boolean|undefined} rawExpression - The condition for allowing row action.
148-
* @param {object} rowData - The data of the row being evaluated.
149-
* @returns {boolean} - Returns true if the row action is allowed, false otherwise.
150-
*/
151-
export function evaluateAllowRowAction(rawExpression, rowData) {
152-
if (rawExpression === undefined || rawExpression === true) return true;
153-
if (rawExpression.startsWith?.("@E ")) {
154-
const expression = rawExpression.replace("@E ", "");
155-
return PCore.getExpressionEngine().evaluate(expression, rowData);
156-
}
157-
return false;
158-
}
159-
160-
export function getContext(thePConn) {
161-
const contextName = thePConn.getContextName();
162-
const pageReference = thePConn.getPageReference();
163-
const {
164-
readonlyContextList,
165-
referenceList = readonlyContextList
166-
} = thePConn.getStateProps()?.config || thePConn.getStateProps();
167-
168-
const pageReferenceForRows = referenceList.startsWith('.') ? `${pageReference}.${referenceList.substring(1)}` : referenceList;
169-
const viewName = thePConn.viewName;
170-
171-
return {
172-
contextName,
173-
referenceListStr: referenceList,
174-
pageReferenceForRows,
175-
viewName
176-
};
177-
}

0 commit comments

Comments
 (0)