From 55db90d3ab1d3ae8fef8c450b72c351978a67ab0 Mon Sep 17 00:00:00 2001 From: spalger Date: Mon, 4 Apr 2016 14:57:45 -0700 Subject: [PATCH] [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. + `); + } }; /**