Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid filters #375

Merged
merged 15 commits into from
Jan 14, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Separated data and valid filter checks
  • Loading branch information
Ro4052 committed Jan 7, 2019
commit a7dcb9ff763df2df00e2f16663c609f7a39a08b9
20 changes: 13 additions & 7 deletions packages/perspective/src/js/perspective.js
Original file line number Diff line number Diff line change
Expand Up @@ -856,11 +856,6 @@ export default function(Module) {
return computed_schema;
};

table.prototype._valid_filter = function(filter, isDateFilter) {
const value = isDateFilter(filter[0]) ? new DateParser().parse(filter[2]) : filter[2];
return typeof value !== "undefined" && value !== null;
};

/**
* The computed schema of this {@link table}. Returns a schema of only computed
* columns added by the user, the keys of which are computed columns and the values an
Expand All @@ -874,6 +869,17 @@ export default function(Module) {
return this._computed_schema();
};

table.prototype._is_date_filter = function(schema) {
return key => schema[key] === "datetime" || schema[key] === "date";
};

table.prototype._valid_filter = function(filter) {
const schema = this._schema();
const isDateFilter = this._is_date_filter(schema);
const value = isDateFilter(filter[0]) ? new DateParser().parse(filter[2]) : filter[2];
return typeof value !== "undefined" && value !== null;
};

/**
* Create a new {@link view} from this table with a specified
* configuration.
Expand Down Expand Up @@ -976,11 +982,11 @@ export default function(Module) {

if (config.filter) {
let schema = this._schema();
let isDateFilter = key => schema[key] === "datetime" || schema[key] === "date";
let isDateFilter = this._is_date_filter(schema);
let validFilter = this._valid_filter;
filters = config.filter
.filter(filter => {
return validFilter(filter, isDateFilter);
return validFilter(filter);
})
.map(filter => {
if (isDateFilter(filter[0])) {
Expand Down