Skip to content

Commit 1a77603

Browse files
committed
[INTERNAL] DemoKit: visualisation of structured parameters
Parameters of constructors/methods/events, which are of typeDefs are now visualized in DemoKit in expandable Rows of Table: when row is expanded the properties of the typedef are shown in additional rows of the same Table. JIRA: BGSOFUIPIRIN-6935 Change-Id: I65f9d7b781a2fe2579fa9748e3e23c2a29d9434f
1 parent 2b4c7b2 commit 1a77603

File tree

6 files changed

+507
-69
lines changed

6 files changed

+507
-69
lines changed

lib/jsdoc/transformApiJson.js

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,10 @@ function transformer(sInputFile, sOutputFile, sLibraryFile, vDependencyAPIFiles,
156156
* UI5Types: ["sap.ui.core.Control"] // skip template if its value is "${0}" (default value)
157157
* }
158158
* @param {string} sComplexType
159+
* @param {Object<string,object>} oAllDependentAPIs Map of entity names to their symbol
159160
* @returns {{template=: string, UI5Types=: string[]}}
160161
*/
161-
function parseUI5Types(sComplexType) {
162+
function parseUI5Types(sComplexType, oAllDependentAPIs) {
162163
let oParsed;
163164
try {
164165
oParsed = typeParser.parseSimpleTypes(sComplexType, isUI5Type);
@@ -176,6 +177,14 @@ function transformer(sInputFile, sOutputFile, sLibraryFile, vDependencyAPIFiles,
176177

177178
if (oParsed.simpleTypes?.length) { // it can be empty if none of the included simple types satisfied the filter function
178179
result.UI5Types = oParsed.simpleTypes;
180+
181+
// check whether the type refers to a typedef and set a marker
182+
if (result.template == null && result.UI5Types.length === 1) {
183+
const symbol = oAllDependentAPIs[result.UI5Types[0]];
184+
if (symbol?.kind === "typedef" && Array.isArray(symbol.properties)) {
185+
result.refersToTypedef = true;
186+
}
187+
}
179188
}
180189

181190
return result;
@@ -266,6 +275,8 @@ function transformer(sInputFile, sOutputFile, sLibraryFile, vDependencyAPIFiles,
266275
* @param {object} oChainObject chain object
267276
*/
268277
const transformApiJson = function (oChainObject) {
278+
const {oAllDependentAPIs} = oChainObject;
279+
269280
// Function is a copy from: LibraryInfo.js => LibraryInfo.prototype._getActualComponent => "match" inline method
270281
function matchComponent(sModuleName, sPattern) {
271282
sModuleName = sModuleName.toLowerCase();
@@ -435,7 +446,7 @@ function transformer(sInputFile, sOutputFile, sLibraryFile, vDependencyAPIFiles,
435446
// Types
436447
oParameter.types = [];
437448
if (oParameter.type) {
438-
oParameter.typeInfo = parseUI5Types(oParameter.type);
449+
oParameter.typeInfo = parseUI5Types(oParameter.type, oAllDependentAPIs);
439450
// Keep file size in check
440451
delete oParameter.type;
441452
}
@@ -520,7 +531,7 @@ function transformer(sInputFile, sOutputFile, sLibraryFile, vDependencyAPIFiles,
520531
// Type
521532
if (oSymbol.kind !== "enum") { // enum properties don't have an own type
522533
if (oProperty.type) {
523-
oProperty.typeInfo = parseUI5Types(oProperty.type);
534+
oProperty.typeInfo = parseUI5Types(oProperty.type, oAllDependentAPIs);
524535
// Keep file size in check
525536
delete oProperty.type;
526537
}
@@ -560,7 +571,7 @@ function transformer(sInputFile, sOutputFile, sLibraryFile, vDependencyAPIFiles,
560571

561572
// Type
562573
if (oProperty.type) {
563-
oProperty.typeInfo = parseUI5Types(oProperty.type);
574+
oProperty.typeInfo = parseUI5Types(oProperty.type, oAllDependentAPIs);
564575
// Keep file size in check
565576
delete oProperty.type;
566577
}
@@ -687,7 +698,7 @@ function transformer(sInputFile, sOutputFile, sLibraryFile, vDependencyAPIFiles,
687698

688699
// Link Enabled
689700
if (oSetting.type) {
690-
oSetting.typeInfo = parseUI5Types(oSetting.type);
701+
oSetting.typeInfo = parseUI5Types(oSetting.type, oAllDependentAPIs);
691702
delete oSetting.type; // Keep file size in check
692703
}
693704

@@ -756,7 +767,7 @@ function transformer(sInputFile, sOutputFile, sLibraryFile, vDependencyAPIFiles,
756767
oEvent.parameters.forEach((oParameter) => {
757768

758769
if (oParameter.type) {
759-
oParameter.typeInfo = parseUI5Types(oParameter.type);
770+
oParameter.typeInfo = parseUI5Types(oParameter.type, oAllDependentAPIs);
760771
delete oParameter.type; // Keep file size in check
761772
}
762773

@@ -789,7 +800,7 @@ function transformer(sInputFile, sOutputFile, sLibraryFile, vDependencyAPIFiles,
789800
if (oSymbol.methods) {
790801

791802
// Pre-process methods
792-
methods.buildMethodsModel(oSymbol.methods);
803+
methods.buildMethodsModel(oSymbol.methods, oAllDependentAPIs);
793804

794805
oSymbol.methods.forEach((oMethod) => {
795806

@@ -950,6 +961,14 @@ function transformer(sInputFile, sOutputFile, sLibraryFile, vDependencyAPIFiles,
950961
}
951962

952963
function loadDependencyLibraryFiles (oChainObject) {
964+
const oAllDependentAPIs = oChainObject.oAllDependentAPIs = Object.create(null);
965+
// add symbols from current library
966+
if (oChainObject.fileData.symbols) {
967+
for (const oSymbol of oChainObject.fileData.symbols) {
968+
oAllDependentAPIs[oSymbol.name] = oSymbol;
969+
}
970+
}
971+
953972
if (!oChainObject.aDependentLibraryFiles) {
954973
return oChainObject;
955974
}
@@ -978,6 +997,12 @@ function transformer(sInputFile, sOutputFile, sLibraryFile, vDependencyAPIFiles,
978997
// In this case we don't add it to the dependency list to skip double iteration.
979998
if (oData && oChainObject.fileData.library !== oData.library) {
980999
oDependentAPIs[oData.library] = oData.symbols;
1000+
1001+
if (Array.isArray(oData.symbols)) {
1002+
for (const oSymbol of oData.symbols) {
1003+
oAllDependentAPIs[oSymbol.name] = oSymbol;
1004+
}
1005+
}
9811006
}
9821007
});
9831008

@@ -2196,7 +2221,7 @@ function transformer(sInputFile, sOutputFile, sLibraryFile, vDependencyAPIFiles,
21962221
* Adjusts methods info so that it can be easily displayed in a table
21972222
* @param aMethods - the methods array initially coming from the server
21982223
*/
2199-
buildMethodsModel: function (aMethods) {
2224+
buildMethodsModel: function (aMethods, oAllDependentAPIs) {
22002225
var fnExtractParameterProperties = function (oParameter, aParameters, iDepth, aPhoneName) {
22012226
if (oParameter.parameterProperties) {
22022227
Object.keys(oParameter.parameterProperties).forEach(function (sProperty) {
@@ -2206,7 +2231,7 @@ function transformer(sInputFile, sOutputFile, sLibraryFile, vDependencyAPIFiles,
22062231

22072232
// Handle types
22082233
if (oProperty.type) {
2209-
oProperty.typeInfo = parseUI5Types(oProperty.type);
2234+
oProperty.typeInfo = parseUI5Types(oProperty.type, oAllDependentAPIs);
22102235
// Keep file size in check
22112236
delete oProperty.type;
22122237
}
@@ -2238,7 +2263,7 @@ function transformer(sInputFile, sOutputFile, sLibraryFile, vDependencyAPIFiles,
22382263
if (oMethod.parameters) {
22392264
oMethod.parameters.forEach(function (oParameter) {
22402265
if (oParameter.type) {
2241-
oParameter.typeInfo = parseUI5Types(oParameter.type);
2266+
oParameter.typeInfo = parseUI5Types(oParameter.type, oAllDependentAPIs);
22422267
// Keep file size in check
22432268
delete oParameter.type;
22442269
}
@@ -2259,7 +2284,7 @@ function transformer(sInputFile, sOutputFile, sLibraryFile, vDependencyAPIFiles,
22592284
// Handle return values
22602285
if (oMethod.returnValue && oMethod.returnValue.type) {
22612286
// Handle types
2262-
oMethod.returnValue.typeInfo = parseUI5Types(oMethod.returnValue.type);
2287+
oMethod.returnValue.typeInfo = parseUI5Types(oMethod.returnValue.type, oAllDependentAPIs);
22632288
}
22642289

22652290
});

src/sap.ui.documentation/src/sap/ui/documentation/LightTable.js

Lines changed: 20 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -35,68 +35,42 @@ sap.ui.define(['sap/ui/core/Control'],
3535
}
3636
},
3737
renderer: {
38-
apiVersion: 2,
38+
apiVersion: 2,
3939

40-
render: function(oRm, oControl) {
41-
var aRows = oControl.getRows(),
42-
aControls,
40+
render: function(oRm, oControl) {
41+
var aRows = oControl.getRows(),
4342
aColumnTitles = oControl.getColumnTitles(),
44-
aLen,
45-
a,
4643
iLen,
4744
i;
4845

49-
oRm.openStart("div", oControl);
50-
oRm.class("sapUiDocLightTable");
51-
oRm.class("columns-" + oControl.getColumnCount());
52-
oRm.openEnd();
46+
oRm.openStart("div", oControl);
47+
oRm.class("sapUiDocLightTable");
48+
oRm.class("columns-" + oControl.getColumnCount());
49+
oRm.openEnd();
5350

54-
// Column titles
55-
oRm.openStart("div")
56-
.class("head")
57-
.openEnd();
58-
59-
for (i = 0, iLen = aColumnTitles.length; i < iLen; i++) {
60-
oRm.openStart("div")
61-
.class("cell")
62-
.openEnd();
63-
64-
oRm.text(aColumnTitles[i])
65-
.close("div");
66-
}
67-
68-
oRm.close("div");
69-
70-
// Rows
71-
for (i = 0, iLen = aRows.length; i < iLen; i++) {
51+
// Column titles
7252
oRm.openStart("div")
73-
.class("row")
53+
.class("head")
7454
.openEnd();
7555

76-
aControls = aRows[i].getContent();
77-
for (a = 0, aLen = aControls.length; a < aLen; a++) {
56+
for (i = 0, iLen = aColumnTitles.length; i < iLen; i++) {
7857
oRm.openStart("div")
7958
.class("cell")
8059
.openEnd();
8160

82-
// Handle inline title
83-
if (a > 0) {
84-
oRm.openStart("div")
85-
.class("inTitle")
86-
.openEnd()
87-
.text(aColumnTitles[a] + ":")
88-
.close("div");
89-
}
61+
oRm.text(aColumnTitles[i])
62+
.close("div");
63+
}
64+
65+
oRm.close("div");
9066

91-
oRm.renderControl(aControls[a]);
92-
oRm.close("div");
67+
// Render rows (each row handles its own rendering including subRows)
68+
for (i = 0, iLen = aRows.length; i < iLen; i++) {
69+
oRm.renderControl(aRows[i]);
9370
}
9471

9572
oRm.close("div");
9673
}
97-
98-
oRm.close("div");
9974
}
100-
}});
101-
102-
});
75+
});
76+
});

0 commit comments

Comments
 (0)