From fb86b4dd50ad68b8f14351037d077d6cf9bc82b5 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Mon, 1 Oct 2018 15:00:59 +0100 Subject: Fix history API bug. replace_query_parameter() was stringifying select multiples, meaning they were incorrectly recorded by the pushState and thus breaking on navigation. --- .cypress/cypress/integration/around_filters.js | 12 ++++++++++++ CHANGELOG.md | 1 + web/js/map-OpenLayers.js | 26 +++++++++++++++++--------- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/.cypress/cypress/integration/around_filters.js b/.cypress/cypress/integration/around_filters.js index 18a086e29..3facf9e8c 100644 --- a/.cypress/cypress/integration/around_filters.js +++ b/.cypress/cypress/integration/around_filters.js @@ -27,6 +27,12 @@ describe('Around page filtering and push state', function() { cy.should('not.contain', 'Street light not working'); cy.url().should('not.include', 'fixed'); cy.get('#status_2').should('not.be.checked'); + cy.go('forward'); + cy.wait('@update-results'); + cy.contains('1 to 6 of 6'); + cy.contains('Street light not working'); + cy.url().should('include', 'status=closed%2Cfixed'); + cy.get('#status_2').should('be.checked'); }); it('allows me to filter by report category', function() { @@ -47,6 +53,12 @@ describe('Around page filtering and push state', function() { cy.contains('1 to 4 of 4'); cy.contains('Loose drain cover'); cy.should('not.contain', 'Large pothole'); + cy.go('back'); + cy.go('back'); + cy.wait('@update-results'); + cy.url().should('include', 'filter_category=Potholes'); + cy.contains('1 to 4 of 4'); + cy.contains('Large pothole'); }); it('allows me to sort', function() { diff --git a/CHANGELOG.md b/CHANGELOG.md index 642facde6..53a9752c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ - Do not scan through all problems to show /_dev pages. - Say “Set password”, not Change, if no password set. - Do not lose from_body field when edited by non-superuser admin. + - Fix history API bug with category/state selection. - Development improvements: - Cobrand hook for disabling updates on individual problems. - Cobrand hook for disallowing title moderation. #2228 diff --git a/web/js/map-OpenLayers.js b/web/js/map-OpenLayers.js index efa457928..30223d21d 100644 --- a/web/js/map-OpenLayers.js +++ b/web/js/map-OpenLayers.js @@ -412,17 +412,25 @@ $.extend(fixmystreet.utils, { } function replace_query_parameter(qs, id, key) { - var value = $('#' + id).val(); - if ( $('#' + id).prop('type') == 'checkbox' ) { - value = $('#' + id).prop('checked') ? '1' : ''; - } else if (value) { - value = (typeof value === 'string') ? value : fixmystreet.utils.array_to_csv_line(value); + var value, + $el = $('#' + id); + if (!$el[0]) { + return; } - - if (value) { - qs[key] = value; + if ( $el[0].type === 'checkbox' ) { + value = $el[0].checked ? '1' : ''; + if (value) { + qs[key] = value; + } else { + delete qs[key]; + } } else { - delete qs[key]; + value = $el.val(); + if (value) { + qs[key] = (typeof value === 'string') ? value : fixmystreet.utils.array_to_csv_line(value); + } else { + delete qs[key]; + } } return value; } -- cgit v1.2.3