Skip to content

Commit

Permalink
Merge pull request #635 from ivan-nejezchleb/ONE-3417
Browse files Browse the repository at this point in the history
RELATED: ONE-3417 Create default Treemap sorting on Uri component

Reviewed-by: Petr Benes <petr.benes@gooddata.com>
             https://github.com/pbenes
  • Loading branch information
gdgate authored Nov 9, 2018
2 parents 7a7ebc1 + 9a2e525 commit 4e1266c
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 2 deletions.
80 changes: 80 additions & 0 deletions __mocks__/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,72 @@ export const visualizationObjects: [{ visualizationObject: VisualizationObject.I
contributor: '/gdc/account/profile/johndoe'
}
}
},
{
visualizationObject: {
content: {
buckets: [
{
localIdentifier: 'measures',
items: [
{
measure: {
localIdentifier: 'b5a12d1bf094469d9b4e7d5d2bb87287',
title: 'Avg. Amount',
definition: {
measureDefinition: {
item: {
uri: '/gdc/md/jm8bsdakbhujk1a254h25a6mtd6orn9g/obj/62827'
}
}
}
}
}
]
},
{
localIdentifier: 'view',
items: [
{
visualizationAttribute: {
localIdentifier: '02b7736f6bef48b1849798e430d837df',
displayForm: {
uri: '/gdc/md/jm8bsdakbhujk1a254h25a6mtd6orn9g/obj/324'
}
}
}
]
},
{
localIdentifier: 'segment',
items: [
{
visualizationAttribute: {
localIdentifier: 'bc5257e06a9342ec99854bd1a53f3262',
displayForm: {
uri: '/gdc/md/jm8bsdakbhujk1a254h25a6mtd6orn9g/obj/952'
}
}
}
]
}
],
visualizationClass: {
uri: '/gdc/md/myproject/obj/treemap'
}
},
meta: {
author: '/gdc/account/profile/9a4a028462b504f7ebe71d3c6a6e5786',
uri: '/gdc/md/myproject/obj/3',
tags: '',
created: new Date('2018-05-23T09:24:41Z'),
identifier: 'aacp5FkYehh3',
summary: '',
title: 'ONE-3417',
category: 'visualizationObject',
contributor: '/gdc/account/profile/9a4a028462b504f7ebe71d3c6a6e5786'
}
}
}
];

Expand Down Expand Up @@ -962,5 +1028,19 @@ export const visualizationClasses: [{ visualizationClass: VisualizationClass.IVi
uri: '/gdc/md/myproject/obj/table'
}
}
},
{
visualizationClass: {
content: {
url: 'local:treemap',
icon: '',
iconSelected: '',
checksum: ''
},
meta: {
title: 'Treemap',
uri: '/gdc/md/myproject/obj/treemap'
}
}
}
];
12 changes: 11 additions & 1 deletion src/components/uri/Visualization.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ import { LoadingComponent, ILoadingProps } from '../simple/LoadingComponent';
import { ErrorComponent, IErrorProps } from '../simple/ErrorComponent';
import { IDrillableItem, generateDimensions, RuntimeError } from '../../';
import { setTelemetryHeaders } from '../../helpers/utils';
import { getDefaultTreemapSort } from '../../helpers/sorts';
import { convertErrors, generateErrorMap, IErrorMap } from '../../helpers/errorHandlers';
import { isTreemap } from '../visualizations/utils/common';
export { Requireable };

const {
Expand Down Expand Up @@ -385,17 +387,25 @@ export class VisualizationWrapped
const afmWithFilters = AfmUtils.appendFilters(afm, attributeFilters, dateFilter);

const visualizationType: VisType = getVisualizationTypeFromVisualizationClass(visualizationClass);
// keep resultSpec creation in sync with AD
const resultSpecWithDimensions = {
...resultSpec,
dimensions: generateDimensions(mdObject.content, visualizationType)
};
const treemapDefaultSorting = isTreemap(visualizationType) ? {
sorts: getDefaultTreemapSort(afm, resultSpecWithDimensions)
} : {};
const resultSpecWithDimensionsAndSorting = {
...resultSpecWithDimensions,
...treemapDefaultSorting
};

return this.adapter.createDataSource(afmWithFilters)
.then((dataSource: IDataSource) => {
return {
type: visualizationType,
dataSource,
resultSpec: resultSpecWithDimensions,
resultSpec: resultSpecWithDimensionsAndSorting,
totals: mdObjectTotals,
mdObject
};
Expand Down
50 changes: 50 additions & 0 deletions src/components/uri/tests/Visualization.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import * as HttpStatusCodes from 'http-status-codes';
const projectId = 'myproject';
const CHART_URI = `/gdc/md/${projectId}/obj/1`;
const TABLE_URI = `/gdc/md/${projectId}/obj/2`;
const TREEMAP_URI = `/gdc/md/${projectId}/obj/3`;
const CHART_IDENTIFIER = 'chart';
const TABLE_IDENTIFIER = 'table';

Expand Down Expand Up @@ -86,6 +87,10 @@ function uriResolver(_sdk: SDK, _projectId: string, uri: string, identifier: str
return getResponse(CHART_URI, SLOW);
}

if (uri === TREEMAP_URI) {
return getResponse(TREEMAP_URI, FAST);
}

return Promise.reject('Unknown identifier');
}

Expand Down Expand Up @@ -470,4 +475,49 @@ describe('VisualizationWrapped', () => {
expect(mutatedSdk.project.getColorPaletteWithGuids).toHaveBeenCalledTimes(1);
});
});

it('should add default sorting to the Treemap', () => {
const props = {
sdk,
projectId,
uri: TREEMAP_URI,
fetchVisObject,
fetchVisualizationClass,
uriResolver,
intl,
BaseChartComponent: BaseChart
};

const wrapper = mount(
<VisualizationWrapped {...props as any} />
);

return testUtils.delay(FAST + 1).then(() => {
wrapper.update();
const BaseChartElement = wrapper.find(BaseChart).get(0);
expect(BaseChartElement.props.resultSpec).toEqual({
dimensions: [
{
itemIdentifiers: ['02b7736f6bef48b1849798e430d837df', 'bc5257e06a9342ec99854bd1a53f3262']
},
{
itemIdentifiers: ['measureGroup']
}
],
sorts: [
{
attributeSortItem: { attributeIdentifier: '02b7736f6bef48b1849798e430d837df', direction: 'asc' }
},
{
measureSortItem: {
direction: 'desc',
locators: [
{ measureLocatorItem: { measureIdentifier: 'b5a12d1bf094469d9b4e7d5d2bb87287' } }
]
}
}
]
});
});
});
});
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import * as PropTypes from './proptypes/index';
import { generateDimensions } from './helpers/dimensions';
import * as BucketNames from './constants/bucketNames';
import * as MeasureTitleHelper from './helpers/measureTitleHelper';
import * as SortsHelper from './helpers/sorts';
import DerivedMeasureTitleSuffixFactory from './factory/DerivedMeasureTitleSuffixFactory';
import ArithmeticMeasureTitleFactory from './factory/ArithmeticMeasureTitleFactory';
import { IDataSourceProviderInjectedProps } from './components/afm/DataSourceProvider';
Expand Down Expand Up @@ -120,5 +121,6 @@ export {
ChartTransformation,
Chart,
OverTimeComparisonType,
OverTimeComparisonTypes
OverTimeComparisonTypes,
SortsHelper
};

0 comments on commit 4e1266c

Please sign in to comment.