From 55db90d3ab1d3ae8fef8c450b72c351978a67ab0 Mon Sep 17 00:00:00 2001 From: spalger Date: Mon, 4 Apr 2016 14:57:45 -0700 Subject: [PATCH 1/9] [state] add configurable warning level based on url length --- src/ui/public/config/defaults.js | 11 ++++++++++- src/ui/public/state_management/state.js | 12 ++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/ui/public/config/defaults.js b/src/ui/public/config/defaults.js index e5c3590653d48..2f0703d2b0e22 100644 --- a/src/ui/public/config/defaults.js +++ b/src/ui/public/config/defaults.js @@ -228,6 +228,15 @@ export default function configDefaultsProvider() { value: 5000, description: 'The time in milliseconds which an information notification ' + 'will be displayed on-screen for. Setting to Infinity will disable.' - } + }, + 'warn:urlLength': { + value: 1900, + description: ` + When the application url reaches this length we will start warning about + potential issues. Internet Explorer supports urls up to + 2,083 characters long. + If IE compatibility is not important this can probably be disabled (set to 0). + `, + }, }; }; diff --git a/src/ui/public/state_management/state.js b/src/ui/public/state_management/state.js index dfc0f8c62b7ec..683d880e4c80d 100644 --- a/src/ui/public/state_management/state.js +++ b/src/ui/public/state_management/state.js @@ -6,7 +6,8 @@ import EventsProvider from 'ui/events'; import Notifier from 'ui/notify/notifier'; -export default function StateProvider(Private, $rootScope, $location) { +export default function StateProvider(Private, $rootScope, $location, config) { + var notify = new Notifier(); var Events = Private(EventsProvider); _.class(State).inherits(Events); @@ -44,7 +45,6 @@ export default function StateProvider(Private, $rootScope, $location) { try { return search[this._urlParam] ? rison.decode(search[this._urlParam]) : null; } catch (e) { - var notify = new Notifier(); notify.error('Unable to parse URL'); search[this._urlParam] = rison.encode(this._defaults); $location.search(search).replace(); @@ -107,6 +107,14 @@ export default function StateProvider(Private, $rootScope, $location) { } else { $location.search(search); } + + const warnLength = config.get('warn:urlLength'); + if (warnLength && $location.absUrl().length > warnLength) { + notify.warning(` + The URL has gotten big and may cause Kibana + to stop working. Please simplify the data on screen. + `); + } }; /** From 64699aa53df0f20fd4a962dbd3e14a092b9d8355 Mon Sep 17 00:00:00 2001 From: spalger Date: Mon, 4 Apr 2016 15:14:06 -0700 Subject: [PATCH 2/9] [state] add a hard length limit that will start throwing errors --- src/ui/public/config/defaults.js | 6 +++++- src/ui/public/state_management/state.js | 14 ++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/ui/public/config/defaults.js b/src/ui/public/config/defaults.js index 2f0703d2b0e22..b7b5645eff681 100644 --- a/src/ui/public/config/defaults.js +++ b/src/ui/public/config/defaults.js @@ -229,7 +229,7 @@ export default function configDefaultsProvider() { description: 'The time in milliseconds which an information notification ' + 'will be displayed on-screen for. Setting to Infinity will disable.' }, - 'warn:urlLength': { + 'url:warnLength': { value: 1900, description: ` When the application url reaches this length we will start warning about @@ -238,5 +238,9 @@ export default function configDefaultsProvider() { If IE compatibility is not important this can probably be disabled (set to 0). `, }, + 'url:limit': { + value: 2082, + description: 'When the application url reaches this length we will start to aggressively fail.', + }, }; }; diff --git a/src/ui/public/state_management/state.js b/src/ui/public/state_management/state.js index 683d880e4c80d..66bd09dad3432 100644 --- a/src/ui/public/state_management/state.js +++ b/src/ui/public/state_management/state.js @@ -108,8 +108,18 @@ export default function StateProvider(Private, $rootScope, $location, config) { $location.search(search); } - const warnLength = config.get('warn:urlLength'); - if (warnLength && $location.absUrl().length > warnLength) { + const urlLength = $location.absUrl().length; + const warnLength = config.get('url:warnLength'); + const failLength = config.get('url:limit'); + + if (failLength && urlLength >= failLength) { + throw new TypeError(` + The URL has gotten too big and kibana can no longer + continue. Please refresh to return to your previous state. + `); + } + + if (warnLength && urlLength >= warnLength) { notify.warning(` The URL has gotten big and may cause Kibana to stop working. Please simplify the data on screen. From 1dace5c5a3a585a699d079865320129130df0357 Mon Sep 17 00:00:00 2001 From: spalger Date: Wed, 6 Apr 2016 01:50:55 -0700 Subject: [PATCH 3/9] [dashboard] cleanup quietly to prevent error --- src/plugins/kibana/public/dashboard/directives/grid.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/plugins/kibana/public/dashboard/directives/grid.js b/src/plugins/kibana/public/dashboard/directives/grid.js index be11359dded3d..99945519a7f23 100644 --- a/src/plugins/kibana/public/dashboard/directives/grid.js +++ b/src/plugins/kibana/public/dashboard/directives/grid.js @@ -83,14 +83,15 @@ app.directive('dashboardGrid', function ($compile, Notifier) { }); $scope.$on('$destroy', function () { + safeLayout.cancel(); $window.off('resize', safeLayout); if (!gridster) return; gridster.$widgets.each(function (i, el) { const panel = getPanelFor(el); - removePanel(panel); // stop any animations panel.$el.stop(); + removePanel(panel, true); // not that we will, but lets be safe makePanelSerializeable(panel); }); @@ -125,9 +126,9 @@ app.directive('dashboardGrid', function ($compile, Notifier) { } // tell gridster to remove the panel, and cleanup our metadata - function removePanel(panel) { + function removePanel(panel, silent) { // remove from grister 'silently' (don't reorganize after) - gridster.remove_widget(panel.$el); + gridster.remove_widget(panel.$el, silent); // destroy the scope panel.$scope.$destroy(); From 8b4ebf5fcfb3d119da21dc88c46acedc55582370 Mon Sep 17 00:00:00 2001 From: spalger Date: Wed, 6 Apr 2016 01:51:47 -0700 Subject: [PATCH 4/9] [errorview] add url overflow display --- src/ui/public/chrome/chrome.js | 1 + .../error_url_overflow.html | 23 +++++++++++++ .../error_url_overflow/error_url_overflow.js | 34 +++++++++++++++++++ .../error_url_overflow.less | 7 ++++ src/ui/public/state_management/state.js | 11 ++++-- 5 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 src/ui/public/error_url_overflow/error_url_overflow.html create mode 100644 src/ui/public/error_url_overflow/error_url_overflow.js create mode 100644 src/ui/public/error_url_overflow/error_url_overflow.less diff --git a/src/ui/public/chrome/chrome.js b/src/ui/public/chrome/chrome.js index cb0e2bd6c3e4a..dda8a876ca4a9 100644 --- a/src/ui/public/chrome/chrome.js +++ b/src/ui/public/chrome/chrome.js @@ -10,6 +10,7 @@ import 'ui/timefilter'; import 'ui/private'; import 'ui/promises'; import 'ui/directives/kbn_src'; +import '../error_url_overflow'; var chrome = {}; var internals = _.defaults( diff --git a/src/ui/public/error_url_overflow/error_url_overflow.html b/src/ui/public/error_url_overflow/error_url_overflow.html new file mode 100644 index 0000000000000..67439b99e560a --- /dev/null +++ b/src/ui/public/error_url_overflow/error_url_overflow.html @@ -0,0 +1,23 @@ +
+ + +

Your URL

+
{{controller.url}}
+ +

Tips

+
    +
  • + Saved objects can sometimes persist some unexpectedly large values that get put into the url when they load. You may be able to edit these saved objects in the "objects" section of the settings app. +
  • +
  • + Sometimes dashboards with too many panels can cause the state + to grow in length very quickly. +
  • +
  • + Maybe you could temporarily raise the uri:limit setting in the advanced settings app. +
  • +
+
diff --git a/src/ui/public/error_url_overflow/error_url_overflow.js b/src/ui/public/error_url_overflow/error_url_overflow.js new file mode 100644 index 0000000000000..88799bd2a7ecc --- /dev/null +++ b/src/ui/public/error_url_overflow/error_url_overflow.js @@ -0,0 +1,34 @@ +import uiRoutes from 'ui/routes'; +import uiModules from 'ui/modules'; + +import './error_url_overflow.less'; +import template from './error_url_overflow.html'; + +export function OverflowedUrlStoreProvider() { + let value; + return { + set(v) { value = v; }, + get() { return value; }, + clear() { value = null; } + }; +} + +uiRoutes +.when('/error/url-overflow', { + template, + controllerAs: 'controller', + controller: class OverflowController { + constructor(Private, config, $scope) { + const overflowedUrlStore = Private(OverflowedUrlStoreProvider); + this.url = overflowedUrlStore.get(); + overflowedUrlStore.clear(); + + if (!this.url) { + window.location.hash = '#/'; + return; + } + + this.limit = config.get('url:limit'); + } + } +}); diff --git a/src/ui/public/error_url_overflow/error_url_overflow.less b/src/ui/public/error_url_overflow/error_url_overflow.less new file mode 100644 index 0000000000000..efc1e066d38c8 --- /dev/null +++ b/src/ui/public/error_url_overflow/error_url_overflow.less @@ -0,0 +1,7 @@ +.error-url-overflow-app { + padding: 25px; + + pre { + white-space: pre-wrap; + } +} diff --git a/src/ui/public/state_management/state.js b/src/ui/public/state_management/state.js index 66bd09dad3432..68014b9bf729c 100644 --- a/src/ui/public/state_management/state.js +++ b/src/ui/public/state_management/state.js @@ -4,11 +4,13 @@ import applyDiff from 'ui/utils/diff_object'; import qs from 'ui/utils/query_string'; import EventsProvider from 'ui/events'; import Notifier from 'ui/notify/notifier'; - +import KbnUrlProvider from 'ui/url'; +import { OverflowedUrlStoreProvider } from 'ui/error_url_overflow'; export default function StateProvider(Private, $rootScope, $location, config) { var notify = new Notifier(); var Events = Private(EventsProvider); + var overflowedUrlStore = Private(OverflowedUrlStoreProvider); _.class(State).inherits(Events); function State(urlParam, defaults) { @@ -108,11 +110,16 @@ export default function StateProvider(Private, $rootScope, $location, config) { $location.search(search); } - const urlLength = $location.absUrl().length; + if (overflowedUrlStore.get()) return; + + const absUrl = $location.absUrl(); + const urlLength = absUrl.length; const warnLength = config.get('url:warnLength'); const failLength = config.get('url:limit'); if (failLength && urlLength >= failLength) { + overflowedUrlStore.set(absUrl); + window.location.hash = '#/error/url-overflow'; throw new TypeError(` The URL has gotten too big and kibana can no longer continue. Please refresh to return to your previous state. From e308db927c9895e330a04fb3a8dccf7dc86aec22 Mon Sep 17 00:00:00 2001 From: spalger Date: Wed, 6 Apr 2016 02:05:13 -0700 Subject: [PATCH 5/9] [errorview] persist the overflow url so that refresh works --- .../error_url_overflow/error_url_overflow.js | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/ui/public/error_url_overflow/error_url_overflow.js b/src/ui/public/error_url_overflow/error_url_overflow.js index 88799bd2a7ecc..f40356fbbb5a7 100644 --- a/src/ui/public/error_url_overflow/error_url_overflow.js +++ b/src/ui/public/error_url_overflow/error_url_overflow.js @@ -4,12 +4,28 @@ import uiModules from 'ui/modules'; import './error_url_overflow.less'; import template from './error_url_overflow.html'; +const key = 'error/url-overflow/url'; +const store = window.sessionStorage || { + getItem() {}, + setItem() {}, + removeItem() {}, +}; + export function OverflowedUrlStoreProvider() { - let value; + let value = store.getItem(key); + return { - set(v) { value = v; }, - get() { return value; }, - clear() { value = null; } + set(v) { + value = v; + store.setItem(key, value); + }, + get() { + return value; + }, + clear() { + value = null; + store.removeItem(key); + } }; } @@ -21,7 +37,6 @@ uiRoutes constructor(Private, config, $scope) { const overflowedUrlStore = Private(OverflowedUrlStoreProvider); this.url = overflowedUrlStore.get(); - overflowedUrlStore.clear(); if (!this.url) { window.location.hash = '#/'; @@ -29,6 +44,8 @@ uiRoutes } this.limit = config.get('url:limit'); + + $scope.$on('$destroy', () => overflowedUrlStore.clear()); } } }); From 281b38b4afcae934a19edfd29ac14a3b52d68c73 Mon Sep 17 00:00:00 2001 From: spalger Date: Fri, 15 Apr 2016 16:38:05 -0700 Subject: [PATCH 6/9] [config] remove url limit config, it should adapt automatically --- src/ui/public/config/defaults.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/ui/public/config/defaults.js b/src/ui/public/config/defaults.js index b7b5645eff681..3597af8ab268e 100644 --- a/src/ui/public/config/defaults.js +++ b/src/ui/public/config/defaults.js @@ -238,9 +238,5 @@ export default function configDefaultsProvider() { If IE compatibility is not important this can probably be disabled (set to 0). `, }, - 'url:limit': { - value: 2082, - description: 'When the application url reaches this length we will start to aggressively fail.', - }, }; }; From 116521c6be68676ac2c808bfb065d209f3fa708c Mon Sep 17 00:00:00 2001 From: spalger Date: Fri, 15 Apr 2016 16:40:18 -0700 Subject: [PATCH 7/9] [chrome] rework url overflow detection The previous version of this pr relied on the State service to catch times when the URL would grow out of control. While overflows will commonly occur in the State service, this didn't handle urls that were navigated to using a link. They worked because the state service would eventually be called, but the failure was unexpected and required interaction to trigger. This new approach does the checking at a higher level, in the chrome. We also removed the `url:limit` configuration value in favor of browser detection (I was not able to find or come up with a way to quietly and quickly feature detect this). The new limits are 2000 characters for IE and 25000 for all other browsers. --- src/ui/public/chrome/api/angular.js | 29 ++++++++- src/ui/public/chrome/chrome.js | 1 - .../error_url_overflow.html | 35 +++++------ .../error_url_overflow/error_url_overflow.js | 41 +++--------- .../url_overflow_service.js | 62 +++++++++++++++++++ src/ui/public/state_management/state.js | 29 +-------- 6 files changed, 117 insertions(+), 80 deletions(-) create mode 100644 src/ui/public/error_url_overflow/url_overflow_service.js diff --git a/src/ui/public/chrome/api/angular.js b/src/ui/public/chrome/api/angular.js index 587c327758fb1..602b8a64ac15f 100644 --- a/src/ui/public/chrome/api/angular.js +++ b/src/ui/public/chrome/api/angular.js @@ -1,5 +1,9 @@ import _ from 'lodash'; +import { format as formatUrl, parse as parseUrl } from 'url'; + import modules from 'ui/modules'; +import Notifier from 'ui/notify/notifier'; +import { UrlOverflowServiceProvider } from '../../error_url_overflow'; module.exports = function (chrome, internals) { @@ -26,7 +30,7 @@ module.exports = function (chrome, internals) { return a.href; }())) .config(chrome.$setupXsrfRequestInterceptor) - .run(($location) => { + .run(($location, $rootScope, Private) => { chrome.getFirstPathSegment = () => { return $location.path().split('/')[1]; }; @@ -34,6 +38,29 @@ module.exports = function (chrome, internals) { chrome.getBreadcrumbs = () => { return $location.path().split('/').slice(1); }; + + const notify = new Notifier(); + const urlOverflow = Private(UrlOverflowServiceProvider); + const check = (event) => { + if ($location.path() === '/error/url-overflow') return; + + try { + if (urlOverflow.check($location.absUrl()) <= 150) { + notify.warning(` + The URL has gotten big and may cause Kibana + to stop working. Please simplify the data on screen. + `); + } + } catch (e) { + const { host, path, search, protocol } = parseUrl(window.location.href); + // rewrite the entire url to force the browser to reload and + // discard any potentially unstable state from before + window.location.href = formatUrl({ host, path, search, protocol, hash: '#/error/url-overflow' }); + } + }; + + $rootScope.$on('$routeUpdate', check); + $rootScope.$on('$routeChangeStart', check); }); require('../directives')(chrome, internals); diff --git a/src/ui/public/chrome/chrome.js b/src/ui/public/chrome/chrome.js index 899286093f9cb..c0f980c993b0e 100644 --- a/src/ui/public/chrome/chrome.js +++ b/src/ui/public/chrome/chrome.js @@ -10,7 +10,6 @@ import 'ui/timefilter'; import 'ui/private'; import 'ui/promises'; import 'ui/directives/kbn_src'; -import '../error_url_overflow'; import 'ui/watch_multi'; let chrome = {}; diff --git a/src/ui/public/error_url_overflow/error_url_overflow.html b/src/ui/public/error_url_overflow/error_url_overflow.html index 67439b99e560a..a69ce9975352e 100644 --- a/src/ui/public/error_url_overflow/error_url_overflow.html +++ b/src/ui/public/error_url_overflow/error_url_overflow.html @@ -1,23 +1,18 @@
- +

+ Woah there! +

+

+ That's a big URL you have there. I have some unfortunate news: Your browser doesn't play nice with Kibana's bacon-double-cheese-burger-with-extra-fries sized URL. To keep you from running into problems Kibana limits URLs in your browser to {{controller.limit}} characters for your safety. +

-

Your URL

-
{{controller.url}}
- -

Tips

-
    -
  • - Saved objects can sometimes persist some unexpectedly large values that get put into the url when they load. You may be able to edit these saved objects in the "objects" section of the settings app. -
  • -
  • - Sometimes dashboards with too many panels can cause the state - to grow in length very quickly. -
  • -
  • - Maybe you could temporarily raise the uri:limit setting in the advanced settings app. -
  • -
+

Ok, how do I fix this?

+

This usually only happens with big, complex dashboards, so you have some options:

+
    +
  1. Remove some stuff from your dashboard. This will reduce the length of the URL and keep IE in a good place.
  2. +
  3. Don't use IE. Every other supported browser we know of doesn't have this limit.
  4. +
+
+
+

Foot note: Party size candy bars are tiny. Party size sub sandwiches are massive. Really makes you think.

diff --git a/src/ui/public/error_url_overflow/error_url_overflow.js b/src/ui/public/error_url_overflow/error_url_overflow.js index f40356fbbb5a7..f8897beff7314 100644 --- a/src/ui/public/error_url_overflow/error_url_overflow.js +++ b/src/ui/public/error_url_overflow/error_url_overflow.js @@ -1,33 +1,12 @@ import uiRoutes from 'ui/routes'; import uiModules from 'ui/modules'; +import KbnUrlProvider from 'ui/url'; import './error_url_overflow.less'; import template from './error_url_overflow.html'; +import { UrlOverflowServiceProvider } from './url_overflow_service'; -const key = 'error/url-overflow/url'; -const store = window.sessionStorage || { - getItem() {}, - setItem() {}, - removeItem() {}, -}; - -export function OverflowedUrlStoreProvider() { - let value = store.getItem(key); - - return { - set(v) { - value = v; - store.setItem(key, value); - }, - get() { - return value; - }, - clear() { - value = null; - store.removeItem(key); - } - }; -} +export * from './url_overflow_service'; uiRoutes .when('/error/url-overflow', { @@ -35,17 +14,17 @@ uiRoutes controllerAs: 'controller', controller: class OverflowController { constructor(Private, config, $scope) { - const overflowedUrlStore = Private(OverflowedUrlStoreProvider); - this.url = overflowedUrlStore.get(); + const kbnUrl = Private(KbnUrlProvider); + const urlOverflow = Private(UrlOverflowServiceProvider); - if (!this.url) { - window.location.hash = '#/'; + if (!urlOverflow.get()) { + kbnUrl.redirectPath('/'); return; } - this.limit = config.get('url:limit'); - - $scope.$on('$destroy', () => overflowedUrlStore.clear()); + this.url = urlOverflow.get(); + this.limit = urlOverflow.failLength(); + $scope.$on('$destroy', () => urlOverflow.clear()); } } }); diff --git a/src/ui/public/error_url_overflow/url_overflow_service.js b/src/ui/public/error_url_overflow/url_overflow_service.js new file mode 100644 index 0000000000000..ae07e91d1c27e --- /dev/null +++ b/src/ui/public/error_url_overflow/url_overflow_service.js @@ -0,0 +1,62 @@ + +export class UrlOverflowService { + constructor() { + const key = 'error/url-overflow/url'; + const store = window.sessionStorage || { + getItem() {}, + setItem() {}, + removeItem() {}, + }; + + // FIXME: Couldn't find a way to test for browser compatibility without + // complex redirect and cookie based "feature-detection" page, so going + // with user-agent detection for now. + this._ieLike = /(;MSIE |Edge\/\d)/.test(window.navigator.userAgent); + + this._val = store.getItem(key); + this._sync = () => { + if (this._val == null) store.removeItem(key); + else store.setItem(key, this._val); + }; + } + + failLength() { + return this._ieLike ? 2000 : 25000; + } + + set(v) { + this._val = v; + this._sync(); + } + + get() { + return this._val; + } + + check(absUrl) { + if (!this.get()) { + const urlLength = absUrl.length; + const remaining = this.failLength() - urlLength; + + if (remaining > 0) { + return remaining; + } + + this.set(absUrl); + } + + throw new Error(` + The URL has gotten too big and kibana can no longer + continue. Please refresh to return to your previous state. + `); + } + + clear() { + this._val = undefined; + this._sync(); + } +} + +export function UrlOverflowServiceProvider() { + return new UrlOverflowService(); +} diff --git a/src/ui/public/state_management/state.js b/src/ui/public/state_management/state.js index a24c5ee306dae..a927a39742945 100644 --- a/src/ui/public/state_management/state.js +++ b/src/ui/public/state_management/state.js @@ -5,12 +5,10 @@ import qs from 'ui/utils/query_string'; import EventsProvider from 'ui/events'; import Notifier from 'ui/notify/notifier'; import KbnUrlProvider from 'ui/url'; -import { OverflowedUrlStoreProvider } from 'ui/error_url_overflow'; -export default function StateProvider(Private, $rootScope, $location, config) { - const notify = new Notifier(); +const notify = new Notifier(); +export default function StateProvider(Private, $rootScope, $location) { const Events = Private(EventsProvider); - const overflowedUrlStore = Private(OverflowedUrlStoreProvider); _.class(State).inherits(Events); function State(urlParam, defaults) { @@ -109,29 +107,6 @@ export default function StateProvider(Private, $rootScope, $location, config) { } else { $location.search(search); } - - if (overflowedUrlStore.get()) return; - - const absUrl = $location.absUrl(); - const urlLength = absUrl.length; - const warnLength = config.get('url:warnLength'); - const failLength = config.get('url:limit'); - - if (failLength && urlLength >= failLength) { - overflowedUrlStore.set(absUrl); - window.location.hash = '#/error/url-overflow'; - throw new TypeError(` - The URL has gotten too big and kibana can no longer - continue. Please refresh to return to your previous state. - `); - } - - if (warnLength && urlLength >= warnLength) { - notify.warning(` - The URL has gotten big and may cause Kibana - to stop working. Please simplify the data on screen. - `); - } }; /** From b333c514cc44df787b6fe997dc6f70a04755498e Mon Sep 17 00:00:00 2001 From: spalger Date: Tue, 26 Apr 2016 11:52:29 -0500 Subject: [PATCH 8/9] [ui/config] remove unused default --- src/ui/public/config/defaults.js | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/ui/public/config/defaults.js b/src/ui/public/config/defaults.js index f747c216e5f9a..6b2bb73c18c92 100644 --- a/src/ui/public/config/defaults.js +++ b/src/ui/public/config/defaults.js @@ -237,14 +237,5 @@ export default function configDefaultsProvider() { description: 'The time in milliseconds which an information notification ' + 'will be displayed on-screen for. Setting to Infinity will disable.' }, - 'url:warnLength': { - value: 1900, - description: ` - When the application url reaches this length we will start warning about - potential issues. Internet Explorer supports urls up to - 2,083 characters long. - If IE compatibility is not important this can probably be disabled (set to 0). - `, - }, }; }; From 8b978818fca895400aac640391d253528586ae50 Mon Sep 17 00:00:00 2001 From: spalger Date: Wed, 27 Apr 2016 18:24:17 -0500 Subject: [PATCH 9/9] [urlOverflow] assign magic numbers to variables --- src/ui/public/chrome/api/angular.js | 4 +++- src/ui/public/error_url_overflow/url_overflow_service.js | 7 +++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/ui/public/chrome/api/angular.js b/src/ui/public/chrome/api/angular.js index 602b8a64ac15f..33903e279f59e 100644 --- a/src/ui/public/chrome/api/angular.js +++ b/src/ui/public/chrome/api/angular.js @@ -5,6 +5,8 @@ import modules from 'ui/modules'; import Notifier from 'ui/notify/notifier'; import { UrlOverflowServiceProvider } from '../../error_url_overflow'; +const URL_LIMIT_WARN_WITHIN = 150; + module.exports = function (chrome, internals) { chrome.getFirstPathSegment = _.noop; @@ -45,7 +47,7 @@ module.exports = function (chrome, internals) { if ($location.path() === '/error/url-overflow') return; try { - if (urlOverflow.check($location.absUrl()) <= 150) { + if (urlOverflow.check($location.absUrl()) <= URL_LIMIT_WARN_WITHIN) { notify.warning(` The URL has gotten big and may cause Kibana to stop working. Please simplify the data on screen. diff --git a/src/ui/public/error_url_overflow/url_overflow_service.js b/src/ui/public/error_url_overflow/url_overflow_service.js index ae07e91d1c27e..5282b74004175 100644 --- a/src/ui/public/error_url_overflow/url_overflow_service.js +++ b/src/ui/public/error_url_overflow/url_overflow_service.js @@ -1,3 +1,6 @@ +const URL_MAX_IE = 2000; +const URL_MAX_OTHERS = 25000; +const IE_REGEX = /(;MSIE |Edge\/\d)/; export class UrlOverflowService { constructor() { @@ -11,7 +14,7 @@ export class UrlOverflowService { // FIXME: Couldn't find a way to test for browser compatibility without // complex redirect and cookie based "feature-detection" page, so going // with user-agent detection for now. - this._ieLike = /(;MSIE |Edge\/\d)/.test(window.navigator.userAgent); + this._ieLike = IE_REGEX.test(window.navigator.userAgent); this._val = store.getItem(key); this._sync = () => { @@ -21,7 +24,7 @@ export class UrlOverflowService { } failLength() { - return this._ieLike ? 2000 : 25000; + return this._ieLike ? URL_MAX_IE : URL_MAX_OTHERS; } set(v) {