Skip to content

Commit

Permalink
Fix mdx query for expanding hierarchy items (T566817, T620434) (#3512)
Browse files Browse the repository at this point in the history
* Fix mdx query for expanding hirarchy items

* Add unit test

* fix test name
  • Loading branch information
roman-simionov authored Apr 3, 2018
1 parent 3c08666 commit 28e5d97
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 62 deletions.
24 changes: 15 additions & 9 deletions js/ui/pivot_grid/xmla_store/xmla_store.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@ exports.XmlaStore = Class.inherit((function() {
}

function mdxDescendants(level, levelMember, nextLevel) {
levelMember = levelMember ? "." + levelMember : "";
return "Descendants({" + level + levelMember + "}, " + nextLevel + ", SELF_AND_BEFORE)";
var memberExpression = levelMember ? levelMember : level;

return "Descendants({" + memberExpression + "}, " + nextLevel + ", SELF_AND_BEFORE)";
}

function getAllMember(dimension) {
Expand Down Expand Up @@ -141,7 +142,7 @@ exports.XmlaStore = Class.inherit((function() {

if(i < path.length) {
if(isLastDimensionInGroup) {
arg = "(" + dataField + "." + preparePathValue(path[i]) + ")";
arg = "(" + dataField + "." + preparePathValue(path[i], dataField) + ")";
}
} else if(i <= expandAllIndex) {
if(i === 0 && expandAllCount === 0) {
Expand Down Expand Up @@ -267,7 +268,7 @@ exports.XmlaStore = Class.inherit((function() {
}

each(filterValues, function(_, filterValue) {
var filterMdx = dataField + "." + preparePathValue(Array.isArray(filterValue) ? filterValue[filterValue.length - 1] : filterValue);
var filterMdx = dataField + "." + preparePathValue(Array.isArray(filterValue) ? filterValue[filterValue.length - 1] : filterValue, dataField);
if(field.filterType === "exclude") {
filterExpression.push(filterMdx + ".parent");
filterMdx = "Descendants(" + filterMdx + ")";
Expand Down Expand Up @@ -341,7 +342,7 @@ exports.XmlaStore = Class.inherit((function() {
each(options.path, function(index, value) {
var dimension = options[options.headerName][index];
if(!dimension.hierarchyName || dimension.hierarchyName !== options[options.headerName][index + 1].hierarchyName) {
slice.push(dimension.dataField + "." + preparePathValue(value));
slice.push(dimension.dataField + "." + preparePathValue(value, dimension.dataField));
}
});
}
Expand All @@ -363,7 +364,7 @@ exports.XmlaStore = Class.inherit((function() {
if(field.hierarchyName && (fields[index + 1] || {}).hierarchyName === field.hierarchyName) {
return;
}
slice.push(field.dataField + "." + preparePathValue(value));
slice.push(field.dataField + "." + preparePathValue(value, field.dataField));
});
}

Expand Down Expand Up @@ -525,10 +526,15 @@ exports.XmlaStore = Class.inherit((function() {
return cells;
}

function preparePathValue(pathValue) {
function preparePathValue(pathValue, dataField) {
if(pathValue) {
return (typeUtils.isString(pathValue) && pathValue.indexOf("&[") !== -1) ? pathValue : "[" + pathValue + "]";
pathValue = typeUtils.isString(pathValue) && pathValue.indexOf("&[") !== -1 ? pathValue : "[" + pathValue + "]";

if(dataField && pathValue.indexOf(dataField + ".") === 0) {
pathValue = pathValue.slice(dataField.length + 1, pathValue.length);
}
}
return pathValue;
}

function getItem(hash, name, member, index) {
Expand All @@ -542,7 +548,7 @@ exports.XmlaStore = Class.inherit((function() {
if(!item.value && member) {
item.text = member.caption;
item.value = member.value;
item.key = name ? name.slice(name.indexOf('&[')) : '';
item.key = name ? name : '';
item.levelName = member.levelName;
item.hierarchyName = member.hierarchyName;
item.parentName = member.parentName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3914,15 +3914,15 @@ if(window.INTRANET) {
dataSource.on("changed", function() {

assert.deepEqual(prepareLoadedData(dataSource.getData().columns), [
{ key: "&[4]", value: "Accessories", index: 1 },
{ key: "&[1]", value: "Bikes", index: 2 },
{ key: "&[3]", value: "Clothing", index: 3 }
{ key: "[Product].[Category].&[4]", value: "Accessories", index: 1 },
{ key: "[Product].[Category].&[1]", value: "Bikes", index: 2 },
{ key: "[Product].[Category].&[3]", value: "Clothing", index: 3 }
]);
assert.deepEqual(prepareLoadedData(dataSource.getData().rows), [
{ key: "&[2001]", value: 2001, index: 1 },
{ key: "&[2002]", value: 2002, index: 2 },
{ key: "&[2003]", value: 2003, index: 3 },
{ key: "&[2004]", value: 2004, index: 4 }
{ key: "[Ship Date].[Calendar Year].&[2001]", value: 2001, index: 1 },
{ key: "[Ship Date].[Calendar Year].&[2002]", value: 2002, index: 2 },
{ key: "[Ship Date].[Calendar Year].&[2003]", value: 2003, index: 3 },
{ key: "[Ship Date].[Calendar Year].&[2004]", value: 2004, index: 4 }
]);
assert.strictEqual(dataSource.getData().grandTotalColumnIndex, 0);
assert.strictEqual(dataSource.getData().grandTotalRowIndex, 0);
Expand Down Expand Up @@ -3959,21 +3959,21 @@ if(window.INTRANET) {

dataSource.on("changed", function() {
assert.deepEqual(prepareLoadedData(dataSource.getData().columns), [
{ key: "&[4]", value: "Accessories", index: 1 },
{ key: "&[1]", value: "Bikes", index: 2 },
{ key: "&[3]", value: "Clothing", index: 3 }
{ key: "[Product].[Category].&[4]", value: "Accessories", index: 1 },
{ key: "[Product].[Category].&[1]", value: "Bikes", index: 2 },
{ key: "[Product].[Category].&[3]", value: "Clothing", index: 3 }
]);

assert.deepEqual(dataSource.getData().rows.length, 12, "month count");
assert.deepEqual(dataSource.getData().rows[0], {
index: 1,
key: "&[1]",
key: "[Ship Date].[Month of Year].&[1]",
text: "January",
value: 1
}, "month 1");
assert.deepEqual(dataSource.getData().rows[11], {
index: 12,
key: "&[12]",
key: "[Ship Date].[Month of Year].&[12]",
text: "December",
value: 12
}, "month 12");
Expand Down
Loading

0 comments on commit 28e5d97

Please sign in to comment.