From 99265ecb5d8d5d51a375aced6849dab8b6d3a638 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Fri, 18 Jan 2019 18:14:46 +0000 Subject: [PATCH] fixup move permalink update to history fn. --- .../cypress/integration/around_filters.js | 2 +- web/js/map-OpenLayers.js | 27 ++++++++++--------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/.cypress/cypress/integration/around_filters.js b/.cypress/cypress/integration/around_filters.js index c7d193abd84..7bd0298563f 100644 --- a/.cypress/cypress/integration/around_filters.js +++ b/.cypress/cypress/integration/around_filters.js @@ -19,7 +19,7 @@ describe('Around page filtering and push state', function() { 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.url().should('include', 'status=closed,fixed'); cy.get('#status_2').should('be.checked'); cy.go('back'); cy.wait('@update-results'); diff --git a/web/js/map-OpenLayers.js b/web/js/map-OpenLayers.js index 043878b676d..01698386512 100644 --- a/web/js/map-OpenLayers.js +++ b/web/js/map-OpenLayers.js @@ -428,12 +428,6 @@ $.extend(fixmystreet.utils, { function categories_or_status_changed() { // If the category or status has changed we need to re-fetch map markers fixmystreet.markers.refresh({force: true}); - - // Ensure the permalink control is updated when the filters change - var permalink_controls = fixmystreet.map.getControlsByClass(/Permalink/); - if (permalink_controls.length) { - permalink_controls[0].updateLink(); - } } function replace_query_parameter(qs, id, key) { @@ -472,6 +466,17 @@ $.extend(fixmystreet.utils, { return new_url; } + function update_history(qs, data) { + var new_url = update_url(qs); + history.pushState(data, null, new_url); + + // Ensure the permalink control is updated when the filters change + var permalink_controls = fixmystreet.map.getControlsByClass(/Permalink/); + if (permalink_controls.length) { + permalink_controls[0].updateLink(); + } + } + function page_changed_history() { if (!('pushState' in history)) { return; @@ -486,10 +491,9 @@ $.extend(fixmystreet.utils, { } else { delete qs.p; } - var new_url = update_url(qs); - history.pushState({ + update_history(new_url, { page_change: { 'page': page, 'show_old_reports': show_old_reports } - }, null, new_url); + }); } function categories_or_status_changed_history() { @@ -502,10 +506,9 @@ $.extend(fixmystreet.utils, { var sort_key = replace_query_parameter(qs, 'sort', 'sort'); var show_old_reports = replace_query_parameter(qs, 'show_old_reports', 'show_old_reports'); delete qs.p; - var new_url = update_url(qs); - history.pushState({ + update_history(qs, { filter_change: { 'filter_categories': filter_categories, 'statuses': filter_statuses, 'sort': sort_key, 'show_old_reports': show_old_reports } - }, null, new_url); + }); } function setup_inspector_marker_drag() {