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

do some validation on filters before updating the map #355

Merged
merged 1 commit into from
Nov 29, 2023

Conversation

struan
Copy link
Member

@struan struan commented Nov 28, 2023

Highlight empty filters and also prevent the map updating if there are empty filters.
Also ignore empty filters at the back end to avoid 500 errors

Fixes #328

@struan struan requested a review from zarino November 28, 2023 14:43
Copy link

codecov bot commented Nov 28, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (636a86a) 82.24% compared to head (7d0ec5d) 82.30%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #355      +/-   ##
==========================================
+ Coverage   82.24%   82.30%   +0.06%     
==========================================
  Files          87       87              
  Lines        2636     2645       +9     
  Branches      275      276       +1     
==========================================
+ Hits         2168     2177       +9     
  Misses        404      404              
  Partials       64       64              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@struan struan force-pushed the 328-null-filter-error branch from c3c5dac to 5e6297d Compare November 29, 2023 09:46
Copy link
Member

@zarino zarino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally this seems good to me, and it works locally, so I guess we could merge and deploy.

But I’ve left comments with one suggestion on simplified javascript, and some pondering of the best time to display the is-invalid styling on the inputs. I wonder whether you have any thoughts?

@@ -245,9 +245,21 @@ const app = createApp({

return url
},
filtersValid() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@struan You could use Array.prototype.every for this, which is a bit simpler to follow, I think:

filtersValid() {
  return this.filters.every(function(filter){
    return filter.selectedValue !== "";
  });
}

<input v-else-if="filter.data_type == 'integer'" type="text" inputmode="numeric" pattern="[0-9]*" v-model="filter.selectedValue" class="form-control form-control-sm flex-grow-1 flex-shrink-1">
<input v-else type="text" v-model="filter.selectedValue" class="form-control form-control-sm flex-grow-1 flex-shrink-1">
<input v-else-if="filter.data_type == 'integer'" type="text" inputmode="numeric" pattern="[0-9]*" v-model="filter.selectedValue" class="form-control form-control-sm flex-grow-1 flex-shrink-1" :class="{ 'is-invalid': filter.selectedValue === '' }">
<input v-else type="text" v-model="filter.selectedValue" class="form-control form-control-sm flex-grow-1 flex-shrink-1" :class="{ 'is-invalid': filter.selectedValue === '' }">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure whether this is what you intended, but it appears this is-invalid class is only applied after the input has been edited at least once before. ie: when the input is brand new (and, in most cases, empty), it’s not marked as is-invalid, but if you enter some text, then delete it, the input is correctly marked as is-invalid.

TBH this actually feels ok to me – always feels nasty immediately displaying an empty input as invalid, before the user’s had a chance to modify it. But I guess it begs the question – why display invalid classes at all, if there are cases where an empty input might sneak through regardless. 🤷

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess an alternative (although, with more complex JavaScript) would be to only mark the inputs as invalid after the user has pressed the "Update map" / "Update table" button.

At least then you’d also get some interactive feedback when you press the button and nothing happens. Right now, as it is, if you miss (or misunderstand) the invalid styling, it just feels like the button is broken and not responding to clicks.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory everything has a default value so we should never show an empty box initially.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The filter for "MP positions (job titles)" just presents a free text input, and doesn’t have a default value.

It looks like "MP Select Committee memberships" also displays a free text input – but TBH I think that’s a bug, and it should actually be displaying a <select multiple> like the "MP APPG memberships" dataset.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh yes, those. As you say though I think it's fine. FWIW, I think the select committee one is ok text. There's 50 odd committees at the moment which is a fairly unwieldy dropdown.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, a free text match on committee name makes sense, but not when it’s prefixed by "is one of" and followed by the ctrl-click/cmd-click help text (both of which should only be displayed next to a <select multiple>)…

Screenshot 2023-11-29 at 14 46 55

Anyway, that feels like a separate ticket though.

@struan struan force-pushed the 328-null-filter-error branch from 5e6297d to 9ebd96a Compare November 29, 2023 14:55
Highlight empty filters and also prevent the map updating if there are
empty filters.
Also ignore empty filters at the back end to avoid 500 errors

Fixes #328
@struan struan force-pushed the 328-null-filter-error branch from 9ebd96a to 7d0ec5d Compare November 29, 2023 14:56
@struan struan merged commit 7d0ec5d into main Nov 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Null value in an int filter results in 500 error
2 participants