Skip to content

Commit

Permalink
Fixed a regression in table visualisation row selection (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
piter75 authored May 25, 2018
1 parent a69f72e commit 4a4a405
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 3 deletions.
22 changes: 22 additions & 0 deletions src/common/models/essence/essence.mocha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ import { expect } from 'chai';
import { testImmutableClass } from 'immutable-class-tester';

import { $ } from 'plywood';
import { Highlight } from "..";
import { MANIFESTS } from "../../manifests";
import { LINE_CHART_MANIFEST } from "../../manifests/line-chart/line-chart";
import { TABLE_MANIFEST } from "../../manifests/table/table";
import { HighlightFixtures } from "../highlight/highlight.fixtures";
import { MeasureFixtures } from "../measure/measure.fixtures";
import { Essence, EssenceJS, VisStrategy } from './essence';
import { DataCube, Introspection } from "../data-cube/data-cube";
Expand Down Expand Up @@ -105,6 +107,26 @@ describe('Essence', () => {
], { context });
});

describe("removes highlight when necessary", () => {
const { lineChartWithAddedMeasure, lineChartWithAvgAddedMeasure, tableNoMeasure } = HighlightFixtures;

const tests: {highlight: Highlight, expected: Highlight, description: string}[] = [
{ highlight: lineChartWithAddedMeasure(), expected: lineChartWithAddedMeasure(), description: "is kept when measure is selected" },
{ highlight: tableNoMeasure(), expected: tableNoMeasure(), description: "is kept when contains no measure" },
{ highlight: lineChartWithAvgAddedMeasure(), expected: null, description: "is removed when measure is not selected" }
];

tests.forEach(({ highlight, expected, description }) => {
it(`highlight ${description}`, () => {
const essenceValue = EssenceMock.wikiTable().valueOf();
const essenceValueWithHighlight = { ...essenceValue, highlight };
const essenceWithHighlight = new Essence(essenceValueWithHighlight);

expect(essenceWithHighlight.highlight).to.deep.equal(expected);

});
});
});

describe('errors', () => {
it('must have context', () => {
Expand Down
6 changes: 3 additions & 3 deletions src/common/models/essence/essence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,9 @@ export class Essence implements Instance<EssenceValue, EssenceJS> {

if (!dataCube) throw new Error('Essence must have a dataCube');

function isHighlightMeasureVisible(highlight: Highlight): boolean {
function hasNoMeasureOrMeasureIsSelected(highlight: Highlight): boolean {
if (!highlight || !highlight.measure)
return false;
return true;

const { measure } = highlight;
return multiMeasureMode ? selectedMeasures.has(measure) : measure === singleMeasure;
Expand Down Expand Up @@ -292,7 +292,7 @@ export class Essence implements Instance<EssenceValue, EssenceJS> {
this.pinnedDimensions = pinnedDimensions;
this.colors = colors;
this.pinnedSort = pinnedSort;
this.highlight = isHighlightMeasureVisible(highlight) ? highlight : null;
this.highlight = hasNoMeasureOrMeasureIsSelected(highlight) ? highlight : null;
this.compare = compare;
this.visResolve = visResolve;
}
Expand Down
50 changes: 50 additions & 0 deletions src/common/models/highlight/highlight.fixtures.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright 2017-2018 Allegro.pl
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { Filter } from "..";
import { LineChart } from "../../../client/visualizations/line-chart/line-chart";
import { Table } from "../../../client/visualizations/table/table";
import { FilterClauseFixtures } from "../filter-clause/filter-clause.fixtures";
import { Highlight } from "./highlight";

export class HighlightFixtures {
static tableNoMeasure(): Highlight {
const channelInFilterClause = FilterClauseFixtures.stringIn("channel", ["en"]);
return new Highlight({
owner: Table.id,
measure: null,
delta: Filter.fromClause(channelInFilterClause)
});
}

static lineChartWithAvgAddedMeasure(): Highlight {
const channelInFilterClause = FilterClauseFixtures.stringIn("channel", ["en"]);
return new Highlight({
owner: LineChart.id,
measure: "avg_added",
delta: Filter.fromClause(channelInFilterClause)
});
}

static lineChartWithAddedMeasure(): Highlight {
const channelInFilterClause = FilterClauseFixtures.stringIn("channel", ["en"]);
return new Highlight({
owner: LineChart.id,
measure: "added",
delta: Filter.fromClause(channelInFilterClause)
});
}
}

0 comments on commit 4a4a405

Please sign in to comment.