Skip to content

Commit 1bebf98

Browse files
authored
Merge pull request #669 from finos/fix-exception-for-filter-labels
Fix exception for filter labels
2 parents e821170 + 10eeba5 commit 1bebf98

File tree

9 files changed

+112
-10
lines changed

9 files changed

+112
-10
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ website/i18n/*
116116
.idea
117117
cmake-build-debug
118118
.ipynb_checkpoints
119+
.python-version
119120

120121
package.json.lerna_backup
121122
website/static/css/material.dark.css

packages/perspective-viewer-d3fc/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"build:webpack:cjs": "webpack --color --config src/config/cjs.config.js",
3131
"build:webpack:umd": "webpack --color --config src/config/umd.config.js",
3232
"build:webpack": "npm-run-all build:webpack:cjs build:webpack:umd",
33-
"build": "npm-run-all --silent build:babel build:webpack",
33+
"build": "npm-run-all --silent build:babel build:webpack:cjs build:webpack:umd",
3434
"test:build": "cpx \"test/html/*\" dist/umd",
3535
"watch": "webpack --color --watch --config src/config/d3fc.watch.config.js",
3636
"test:run": "jest --silent --color 2>&1",

packages/perspective-viewer/package.json

+10-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
"build": "npm-run-all --silent build:babel build:webpack:cjs build:webpack:umd",
2323
"watch": "webpack --color --watch --config src/config/view.config.js",
2424
"test:build": "cpx \"test/html/*\" dist/umd && cpx \"test/csv/*\" dist/umd && cpx \"test/css/*\" dist/umd",
25-
"test:run": "jest --silent --color",
25+
"test:run": "jest --silent --color 2>&1",
26+
"test:unit": "jest --config=test/js/jest.unit.config.js --color --watch",
2627
"test": "npm-run-all test:build test:run",
2728
"clean": "rimraf dist",
2829
"clean:screenshots": "rimraf \"screenshots/**/*.@(failed|diff).png\"",
@@ -40,7 +41,14 @@
4041
"verbose": true,
4142
"testURL": "http://localhost/",
4243
"transform": {},
43-
"automock": false
44+
"automock": false,
45+
"transform": {
46+
".js$": "./test/js/transform.js",
47+
".html$": "html-loader-jest"
48+
},
49+
"setupFiles": [
50+
"./test/js/beforeEachSpec.js"
51+
]
4452
},
4553
"repository": {
4654
"type": "git",

packages/perspective-viewer/src/js/computed_column.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ class ComputedColumn extends HTMLElement {
138138
this.state.swap_target = false;
139139

140140
for (let i = 0; i < computation.num_params; i++) {
141-
this._input_columns.innerHTML += `<div class="psp-cc-computation__input-column"
142-
data-index="${i}"
141+
this._input_columns.innerHTML += `<div class="psp-cc-computation__input-column"
142+
data-index="${i}"
143143
drop-target>
144144
<span class="psp-label__requiredType ${input_type}"></span>
145145
<span class="psp-label__placeholder">Param ${i + 1}</span>

packages/perspective-viewer/src/js/viewer/dom_element.js

+13-5
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,13 @@ export class DomElement extends PerspectiveElement {
6565

6666
if (filter) {
6767
row.setAttribute("filter", filter);
68+
6869
if (type === "string") {
69-
const v = this._table.view({row_pivots: [name], aggregates: {}});
70-
v.to_json().then(json => {
71-
row.choices(json.slice(1, json.length).map(x => x.__ROW_PATH__));
72-
});
73-
v.delete();
70+
const view = this._table.view({row_pivots: [name], aggregates: {}});
71+
view.to_json().then(json => {
72+
row.choices(this._autocomplete_choices(json)) }
73+
);
74+
view.delete();
7475
}
7576
}
7677

@@ -294,4 +295,11 @@ export class DomElement extends PerspectiveElement {
294295
this.load(data);
295296
}
296297
}
298+
299+
_autocomplete_choices(json) {
300+
return json
301+
.slice(1, json.length)
302+
.map(x => x.__ROW_PATH__)
303+
.filter(x => (Array.isArray(x) ? x.filter(v => !!v).length > 0 : !!x));
304+
}
297305
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/******************************************************************************
2+
*
3+
* Copyright (c) 2017, the Perspective Authors.
4+
*
5+
* This file is part of the Perspective library, distributed under the terms of
6+
* the Apache License 2.0. The full license can be found in the LICENSE file.
7+
*
8+
*/
9+
10+
global.CustomEvent = () => {};
11+
global.customElements = {define: () => {}};
12+
global.HTMLElement = class {
13+
getAttribute() {}
14+
hasAttribute() {}
15+
removeAttribute() {}
16+
setAttribute() {}
17+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/******************************************************************************
2+
*
3+
* Copyright (c) 2017, the Perspective Authors.
4+
*
5+
* This file is part of the Perspective library, distributed under the terms of
6+
* the Apache License 2.0. The full license can be found in the LICENSE file.
7+
*
8+
*/
9+
10+
module.exports = {
11+
roots: ["unit"],
12+
verbose: true,
13+
testURL: "http://localhost/",
14+
automock: false,
15+
transform: {
16+
".js$": "./transform.js",
17+
".html$": "html-loader-jest"
18+
},
19+
setupFiles: ["./beforeEachSpec.js"]
20+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/******************************************************************************
2+
*
3+
* Copyright (c) 2017, the Perspective Authors.
4+
*
5+
* This file is part of the Perspective library, distributed under the terms of
6+
* the Apache License 2.0. The full license can be found in the LICENSE file.
7+
*
8+
*/
9+
10+
const config = require("../../babel.config.js");
11+
config.presets[0][1].modules = "auto";
12+
13+
module.exports = require("babel-jest").createTransformer(config);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/******************************************************************************
2+
*
3+
* Copyright (c) 2018, the Perspective Authors.
4+
*
5+
* This file is part of the Perspective library, distributed under the terms of
6+
* the Apache License 2.0. The full license can be found in the LICENSE file.
7+
*
8+
*/
9+
10+
import {DomElement} from "../../../src/js/viewer/dom_element";
11+
12+
jest.mock("../../../src/less/computed_column.less", () => jest.fn());
13+
14+
describe(DomElement, () => {
15+
describe("._autocomplete_choices", () => {
16+
let dom_element, json_choices;
17+
18+
beforeEach(() => {
19+
dom_element = new DomElement();
20+
json_choices = [
21+
{__ROW_PATH__: [], foo: 2},
22+
{__ROW_PATH__: [null], foo: 25},
23+
{__ROW_PATH__: ["somestring"], foo: 3},
24+
{__ROW_PATH__: ["otherstring"], foo: 3}
25+
];
26+
});
27+
28+
test("the first value and null values are filtered out", () => {
29+
expect(dom_element._autocomplete_choices(json_choices)).toEqual([
30+
["somestring"],
31+
["otherstring"]
32+
]);
33+
});
34+
});
35+
});

0 commit comments

Comments
 (0)