@sap-ux/fe-fpm-writer 0.36.1 → 0.37.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -63,9 +63,10 @@ export declare function getAggregationPathPrompt(context: PromptContext, propert
|
|
|
63
63
|
*
|
|
64
64
|
* @param obj - object to be converted to choices
|
|
65
65
|
* @param sort - apply alphabetical sort(default is "true")
|
|
66
|
+
* @param defaultKey - default key to be checked in choices
|
|
66
67
|
* @returns the list of choices.
|
|
67
68
|
*/
|
|
68
|
-
export declare function transformChoices(obj: Record<string, string> | string[], sort?: boolean): PromptListChoices;
|
|
69
|
+
export declare function transformChoices(obj: Record<string, string> | string[], sort?: boolean, defaultKey?: string): PromptListChoices;
|
|
69
70
|
/**
|
|
70
71
|
* Returns a Prompt for selecting existing filter bar ID or entering a new one.
|
|
71
72
|
*
|
|
@@ -200,7 +200,9 @@ function getAggregationPathPrompt(context, properties = {}) {
|
|
|
200
200
|
? (answers) => {
|
|
201
201
|
const { viewOrFragmentPath } = answers;
|
|
202
202
|
if (viewOrFragmentPath) {
|
|
203
|
-
const
|
|
203
|
+
const { inputChoices, pageMacroDefinition } = (0, xml_1.getXPathStringsForXmlFile)((0, path_1.join)(appPath, viewOrFragmentPath), fs);
|
|
204
|
+
const key = Object.keys(inputChoices).find((k) => k.endsWith(`/${pageMacroDefinition}`));
|
|
205
|
+
const choices = transformChoices(inputChoices, false, key);
|
|
204
206
|
if (!choices.length) {
|
|
205
207
|
throw new Error('Failed while fetching the aggregation path.');
|
|
206
208
|
}
|
|
@@ -221,12 +223,19 @@ function getAggregationPathPrompt(context, properties = {}) {
|
|
|
221
223
|
*
|
|
222
224
|
* @param obj - object to be converted to choices
|
|
223
225
|
* @param sort - apply alphabetical sort(default is "true")
|
|
226
|
+
* @param defaultKey - default key to be checked in choices
|
|
224
227
|
* @returns the list of choices.
|
|
225
228
|
*/
|
|
226
|
-
function transformChoices(obj, sort = true) {
|
|
229
|
+
function transformChoices(obj, sort = true, defaultKey) {
|
|
227
230
|
let choices = [];
|
|
228
231
|
if (!Array.isArray(obj)) {
|
|
229
|
-
choices = Object.entries(obj).map(([key, value]) =>
|
|
232
|
+
choices = Object.entries(obj).map(([key, value]) => {
|
|
233
|
+
// Add checked if value matches defaultKey example: `/mvc:View/macro:Page/`
|
|
234
|
+
if (key === defaultKey) {
|
|
235
|
+
return { name: key, value, checked: true };
|
|
236
|
+
}
|
|
237
|
+
return { name: key, value };
|
|
238
|
+
});
|
|
230
239
|
if (sort) {
|
|
231
240
|
choices = choices.sort((a, b) => a.name.localeCompare(b.name));
|
|
232
241
|
}
|
|
@@ -13,9 +13,12 @@ export declare function isElementIdAvailable(fs: Editor, viewOrFragmentPath: str
|
|
|
13
13
|
*
|
|
14
14
|
* @param xmlFilePath - the xml file path
|
|
15
15
|
* @param fs - the file system object for reading files
|
|
16
|
-
* @returns the list of xpath strings.
|
|
16
|
+
* @returns the list of xpath strings & page macro definition if page macro has been added by user.
|
|
17
17
|
*/
|
|
18
|
-
export declare function getXPathStringsForXmlFile(xmlFilePath: string, fs: Editor):
|
|
18
|
+
export declare function getXPathStringsForXmlFile(xmlFilePath: string, fs: Editor): {
|
|
19
|
+
inputChoices: Record<string, string>;
|
|
20
|
+
pageMacroDefinition?: string;
|
|
21
|
+
};
|
|
19
22
|
/**
|
|
20
23
|
* Method returns ids of specific macro element found in passed xml file.
|
|
21
24
|
*
|
|
@@ -37,10 +37,11 @@ const augmentXpathWithLocalNames = (path) => {
|
|
|
37
37
|
*
|
|
38
38
|
* @param xmlFilePath - the xml file path
|
|
39
39
|
* @param fs - the file system object for reading files
|
|
40
|
-
* @returns the list of xpath strings.
|
|
40
|
+
* @returns the list of xpath strings & page macro definition if page macro has been added by user.
|
|
41
41
|
*/
|
|
42
42
|
function getXPathStringsForXmlFile(xmlFilePath, fs) {
|
|
43
43
|
const result = {};
|
|
44
|
+
let pageMacroDefinition;
|
|
44
45
|
try {
|
|
45
46
|
const xmlContent = fs.read(xmlFilePath);
|
|
46
47
|
const errorHandler = (level, message) => {
|
|
@@ -50,7 +51,7 @@ function getXPathStringsForXmlFile(xmlFilePath, fs) {
|
|
|
50
51
|
const nodes = [{ parentNode: '', node: xmlDocument.firstChild }];
|
|
51
52
|
// check macros namespace and page macro definition
|
|
52
53
|
const macrosNamespace = getOrAddMacrosNamespace(xmlDocument);
|
|
53
|
-
|
|
54
|
+
pageMacroDefinition = macrosNamespace ? `${macrosNamespace}:Page` : 'macros:Page';
|
|
54
55
|
let hasPageMacroChild = false;
|
|
55
56
|
while (nodes && nodes.length > 0) {
|
|
56
57
|
const { parentNode, node } = nodes.shift();
|
|
@@ -79,7 +80,7 @@ function getXPathStringsForXmlFile(xmlFilePath, fs) {
|
|
|
79
80
|
catch (error) {
|
|
80
81
|
throw new Error(`An error occurred while parsing the view or fragment xml. Details: ${getErrorMessage(error)}`);
|
|
81
82
|
}
|
|
82
|
-
return result;
|
|
83
|
+
return { inputChoices: result, pageMacroDefinition };
|
|
83
84
|
}
|
|
84
85
|
/**
|
|
85
86
|
* Returns the message property if the error is an instance of `Error` else a string representation of the error.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sap-ux/fe-fpm-writer",
|
|
3
3
|
"description": "SAP Fiori elements flexible programming model writer",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.37.0",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "https://github.com/SAP/open-ux-tools.git",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"@types/semver": "7.5.2",
|
|
42
42
|
"@types/vinyl": "2.0.7",
|
|
43
43
|
"@sap-ux/i18n": "0.3.2",
|
|
44
|
-
"@sap-ux/ui-prompting": "0.
|
|
44
|
+
"@sap-ux/ui-prompting": "0.4.0"
|
|
45
45
|
},
|
|
46
46
|
"engines": {
|
|
47
47
|
"node": ">=20.x"
|