@datarailsshared/dr_renderer 1.2.370 → 1.2.371
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.
package/package.json
CHANGED
@@ -9100,7 +9100,7 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
9100
9100
|
|
9101
9101
|
let keysObject;
|
9102
9102
|
if (highchartsRenderer.isSortingOnBackendEnabled) {
|
9103
|
-
keysObject =
|
9103
|
+
keysObject = highchartsRenderer.getAggregatedSortingObjects(row_data);
|
9104
9104
|
}
|
9105
9105
|
|
9106
9106
|
let res = highchartsRenderer.updateSelectedOverrideValues(widget_obj, override_values, row_data);
|
@@ -9700,6 +9700,30 @@ let getHighchartsRenderer = function ($, document, Highcharts, default_colors, h
|
|
9700
9700
|
return res;
|
9701
9701
|
}
|
9702
9702
|
|
9703
|
+
// TODO: move this logic to BE (the problem it is solving that BE returns several sorting objects for more than 1 field in Values)
|
9704
|
+
highchartsRenderer.getAggregatedSortingObjects = function(res) {
|
9705
|
+
let sortingObjectToReturn = null;
|
9706
|
+
|
9707
|
+
lodash.forEach(res, (dataRow) => {
|
9708
|
+
if (!lodash.isNil(dataRow.row_keys) || !lodash.isNil(dataRow.col_keys)) {
|
9709
|
+
if (!sortingObjectToReturn) {
|
9710
|
+
sortingObjectToReturn = Object.assign({}, dataRow);
|
9711
|
+
} else {
|
9712
|
+
sortingObjectToReturn.row_keys = lodash.concat(sortingObjectToReturn.row_keys, dataRow.row_keys || []);
|
9713
|
+
}
|
9714
|
+
dataRow.isSortingObject = true;
|
9715
|
+
}
|
9716
|
+
});
|
9717
|
+
|
9718
|
+
if (sortingObjectToReturn) {
|
9719
|
+
const resWithoutSortObjects = lodash.filter(res, (dataRow) => !dataRow.isSortingObject);
|
9720
|
+
res.length = 0;
|
9721
|
+
Object.assign(res, resWithoutSortObjects);
|
9722
|
+
}
|
9723
|
+
|
9724
|
+
return sortingObjectToReturn;
|
9725
|
+
}
|
9726
|
+
|
9703
9727
|
return highchartsRenderer;
|
9704
9728
|
};
|
9705
9729
|
|
@@ -5577,7 +5577,7 @@ describe('highcharts_renderer', () => {
|
|
5577
5577
|
]
|
5578
5578
|
});
|
5579
5579
|
});
|
5580
|
-
|
5580
|
+
|
5581
5581
|
it('should not replace sorting keys for non-Date fields', () => {
|
5582
5582
|
const keysObject = {
|
5583
5583
|
col_keys: [
|
@@ -5651,4 +5651,62 @@ describe('highcharts_renderer', () => {
|
|
5651
5651
|
highchartsRenderer.replaceSortingKeysWithMappedValues(null, invertedDateStringMap, widget.rows);
|
5652
5652
|
});
|
5653
5653
|
});
|
5654
|
+
|
5655
|
+
|
5656
|
+
describe('Functions getAggregatedSortingObjects', () => {
|
5657
|
+
|
5658
|
+
const simpleRowData = [{ someField1: 'someValue1' }, { someField2: 'someValue2' }];
|
5659
|
+
|
5660
|
+
const generalTestCases = [
|
5661
|
+
{
|
5662
|
+
description: 'should get sort object and remove from data rows (case with all fields)',
|
5663
|
+
expectedObj: { col_keys: ['colKey1', 'colKey2'], row_keys: ['rowKey1', 'rowKey2'], row_keys_by_cols: [['1', '2'], ['2', '1']] },
|
5664
|
+
},
|
5665
|
+
{
|
5666
|
+
description: 'should get sort object and remove from data rows (case with only colkeys)',
|
5667
|
+
expectedObj: { row_keys: [], col_keys: ['colKey1', 'colKey2'] },
|
5668
|
+
},
|
5669
|
+
{
|
5670
|
+
description: 'should get sort object and remove from data rows (case with only rowkeys)',
|
5671
|
+
expectedObj: { row_keys: ['rowKey1', 'rowKey2'], col_keys: [] },
|
5672
|
+
},
|
5673
|
+
{
|
5674
|
+
description: 'should get null sort object and remove from data rows (case with no sorting object)',
|
5675
|
+
expectedObj: null,
|
5676
|
+
}
|
5677
|
+
];
|
5678
|
+
|
5679
|
+
lodash.forEach(generalTestCases, testCase => {
|
5680
|
+
it(testCase.description, () => {
|
5681
|
+
const rowData = lodash.concat(simpleRowData, testCase.expectedObj ? lodash.clone(testCase.expectedObj) : []);
|
5682
|
+
const sortObj = highchartsRenderer.getAggregatedSortingObjects(rowData);
|
5683
|
+
|
5684
|
+
expect(rowData).toEqual(simpleRowData);
|
5685
|
+
expect(sortObj).toEqual(testCase.expectedObj);
|
5686
|
+
});
|
5687
|
+
});
|
5688
|
+
|
5689
|
+
it('should get sort object and remove from data rows (several object encounters - for more than one Values field)', () => {
|
5690
|
+
|
5691
|
+
const expectedObj = { col_keys: ['colKey1', 'colKey2'], row_keys: ['rowKey1', 'rowKey2'] };
|
5692
|
+
const rowData = [
|
5693
|
+
{ someField1: 'someValue1' },
|
5694
|
+
{ col_keys: ['colKey1', 'colKey2'], row_keys: ['rowKey1'] },
|
5695
|
+
{ someField2: 'someValue2' },
|
5696
|
+
{ someField3: 'someValue3' },
|
5697
|
+
{ someField4: 'someValue4' },
|
5698
|
+
{ col_keys: ['colKey1', 'colKey2'], row_keys: ['rowKey2'] },
|
5699
|
+
];
|
5700
|
+
|
5701
|
+
const sortObj = highchartsRenderer.getAggregatedSortingObjects(rowData);
|
5702
|
+
|
5703
|
+
expect(rowData).toEqual([
|
5704
|
+
{ someField1: 'someValue1' },
|
5705
|
+
{ someField2: 'someValue2' },
|
5706
|
+
{ someField3: 'someValue3' },
|
5707
|
+
{ someField4: 'someValue4' },
|
5708
|
+
]);
|
5709
|
+
expect(sortObj).toEqual(expectedObj);
|
5710
|
+
});
|
5711
|
+
});
|
5654
5712
|
});
|