Skip to content

Commit

Permalink
BUGFIX: ONE-3321 Fix heatmap without viewBy (columns) attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-nejezchleb committed Sep 3, 2018
1 parent a3fce2b commit 7553681
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 9 deletions.
19 changes: 12 additions & 7 deletions src/helpers/dimensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,21 +336,26 @@ export function generateDimensions(
}

export function generateStackedDimensions(buckets: VisualizationObject.IBucket[]): AFM.IDimension[] {
const stackByAttribute = buckets.find(bucket => bucket.localIdentifier === STACK).items[0] as
VisualizationObject.IVisualizationAttribute;
const viewBucket = buckets.find(bucket => bucket.localIdentifier === ATTRIBUTE);
const stackBucket = buckets.find(bucket => bucket.localIdentifier === STACK);

const viewByAttribute = buckets.find(bucket => bucket.localIdentifier === ATTRIBUTE).items[0] as
const viewByAttribute = viewBucket && viewBucket.items[0] as
VisualizationObject.IVisualizationAttribute;
const stackByAttribute = stackBucket && stackBucket.items[0] as
VisualizationObject.IVisualizationAttribute;

const stackByAttributeLocalIdentifier = stackByAttribute.visualizationAttribute.localIdentifier;
const viewByAttributeLocalIdentifier = viewByAttribute.visualizationAttribute.localIdentifier;
const stackByAttributeLocalIdentifier = stackByAttribute ?
stackByAttribute.visualizationAttribute.localIdentifier : undefined;
const viewByAttributeLocalIdentifier = viewByAttribute ?
viewByAttribute.visualizationAttribute.localIdentifier : undefined;

return [
{
itemIdentifiers: [stackByAttributeLocalIdentifier]
itemIdentifiers: stackByAttributeLocalIdentifier ? [stackByAttributeLocalIdentifier] : []
},
{
itemIdentifiers: [viewByAttributeLocalIdentifier, MEASUREGROUP]
itemIdentifiers: viewByAttributeLocalIdentifier ?
[viewByAttributeLocalIdentifier, MEASUREGROUP] : [MEASUREGROUP]
}
];
}
Expand Down
53 changes: 52 additions & 1 deletion src/helpers/tests/dimensions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import cloneDeep = require('lodash/cloneDeep');
import update = require('lodash/update');

import { VisualizationTypes } from '../../constants/visualizationTypes';
import { generateDimensions, getHeadlinesDimensions, getPivotTableDimensions } from '../dimensions';
import {
generateDimensions,
getHeadlinesDimensions,
getPivotTableDimensions,
generateStackedDimensions
} from '../dimensions';
import { visualizationObjects } from '../../../__mocks__/fixtures';

function getVisualization(name: string): VisualizationObject.IVisualizationObjectContent {
Expand Down Expand Up @@ -635,3 +640,49 @@ describe('generateDimensions', () => {
});
});
});

describe('generateStackedDimensions', () => {
it('measure and stack by only', () => {
const expectedDimensions: AFM.IDimension[] = [
{
itemIdentifiers: ['a2']
},
{
itemIdentifiers: ['measureGroup']
}
];

const buckets = [
{
localIdentifier: 'measures',
items: [{
measure: {
localIdentifier: 'm1',
title: '# Accounts with AD Query',
definition: {
measureDefinition: {
item: {
uri: '/gdc/md/myproject/obj/m1'
}
}
}
}
}]
},
{
localIdentifier: 'stack',
items: [{
visualizationAttribute: {
localIdentifier: 'a2',
displayForm: {
uri: '/gdc/md/myproject/obj/a2'
}
}
}]
}
];

expect(generateStackedDimensions(buckets))
.toEqual(expectedDimensions);
});
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 15 additions & 1 deletion stories/core_components/Heatmap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ storiesOf('Core components/Heatmap', module)
</div>
)
))
.add('metric and attribute', () => (
.add('metric and columns', () => (
screenshotWrap(
<div style={wrapperStyle}>
<Heatmap
Expand All @@ -64,6 +64,20 @@ storiesOf('Core components/Heatmap', module)
</div>
)
))
.add('metric and rows', () => (
screenshotWrap(
<div style={wrapperStyle}>
<Heatmap
projectId="storybook"
measure={MEASURE_1}
segmentBy={ATTRIBUTE_2}
onError={onErrorHandler}
LoadingComponent={null}
ErrorComponent={null}
/>
</div>
)
))
.add('metric row column with row alias', () => (
screenshotWrap(
<div style={wrapperStyle}>
Expand Down

0 comments on commit 7553681

Please sign in to comment.