@sap-ux/fe-fpm-writer 0.36.1 → 0.37.1

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 choices = transformChoices((0, xml_1.getXPathStringsForXmlFile)((0, path_1.join)(appPath, viewOrFragmentPath), fs), false);
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]) => ({ name: 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): Record<string, string>;
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
- const pageMacroDefinition = macrosNamespace ? `${macrosNamespace}:Page` : 'macros:Page';
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.36.1",
4
+ "version": "0.37.1",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/SAP/open-ux-tools.git",
@@ -30,8 +30,8 @@
30
30
  "semver": "7.5.4",
31
31
  "xml-formatter": "2.6.1",
32
32
  "xpath": "0.0.33",
33
- "@sap-ux/fiori-annotation-api": "0.6.13",
34
- "@sap-ux/project-access": "1.30.10"
33
+ "@sap-ux/fiori-annotation-api": "0.6.14",
34
+ "@sap-ux/project-access": "1.30.11"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@types/inquirer": "8.2.6",
@@ -40,8 +40,8 @@
40
40
  "@types/mem-fs-editor": "7.0.1",
41
41
  "@types/semver": "7.5.2",
42
42
  "@types/vinyl": "2.0.7",
43
- "@sap-ux/i18n": "0.3.2",
44
- "@sap-ux/ui-prompting": "0.3.37"
43
+ "@sap-ux/i18n": "0.3.3",
44
+ "@sap-ux/ui-prompting": "0.4.0"
45
45
  },
46
46
  "engines": {
47
47
  "node": ">=20.x"