From 3ad02e4e9b3df20a69126301ca5b98b31c991dee Mon Sep 17 00:00:00 2001 From: CJ Cenizal Date: Mon, 11 Jul 2016 18:08:22 -0700 Subject: [PATCH 1/7] Allow user to pin/unpin the sidebar, and store preference in localStorage. - Add "Expand/Collapse" button to sidebar. - Add appSwitcherState service. - Add support for "classes" attribute to app-switcher-link. - Remove animation from sidebar, and no longer expand on hover. - Add default tooltips for sidebar items. --- .../kibana/public/assets/play-circle.svg | 3 +++ src/ui/public/chrome/chrome.html | 16 +++++++++-- src/ui/public/chrome/chrome.js | 2 ++ .../directives/app_switcher/app_switcher.html | 2 +- .../directives/app_switcher/app_switcher.js | 11 +++++++- .../directives/app_switcher/app_switcher.less | 11 +++----- .../__tests__/app-switcher-link.js | 11 ++++++++ .../app_switcher_link/app_switcher_link.html | 4 +-- .../app_switcher_link/app_switcher_link.js | 3 ++- .../app_switcher_link/app_switcher_link.less | 27 ++++++++++++++----- src/ui/public/chrome/directives/kbn_chrome.js | 25 ++++++++++++++++- .../chrome/services/app_switcher_state.js | 16 +++++++++++ src/ui/public/chrome/services/index.js | 1 + src/ui/public/styles/variables/for-theme.less | 2 -- 14 files changed, 111 insertions(+), 23 deletions(-) create mode 100644 src/core_plugins/kibana/public/assets/play-circle.svg create mode 100644 src/ui/public/chrome/services/app_switcher_state.js create mode 100644 src/ui/public/chrome/services/index.js diff --git a/src/core_plugins/kibana/public/assets/play-circle.svg b/src/core_plugins/kibana/public/assets/play-circle.svg new file mode 100644 index 00000000000000..d668d52587b846 --- /dev/null +++ b/src/core_plugins/kibana/public/assets/play-circle.svg @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/src/ui/public/chrome/chrome.html b/src/ui/public/chrome/chrome.html index 42b78e7ee7f397..f1d7d43cb4897e 100644 --- a/src/ui/public/chrome/chrome.html +++ b/src/ui/public/chrome/chrome.html @@ -1,7 +1,10 @@
-
diff --git a/src/ui/public/chrome/chrome.js b/src/ui/public/chrome/chrome.js index 6e7a2b8d6f4bc4..5819426d9c833b 100644 --- a/src/ui/public/chrome/chrome.js +++ b/src/ui/public/chrome/chrome.js @@ -10,8 +10,10 @@ import 'ui/timefilter'; import 'ui/notify'; import 'ui/private'; import 'ui/promises'; +import 'ui/storage'; import 'ui/directives/kbn_src'; import 'ui/watch_multi'; +import './services'; let chrome = {}; let internals = _.defaults( diff --git a/src/ui/public/chrome/directives/app_switcher/app_switcher.html b/src/ui/public/chrome/directives/app_switcher/app_switcher.html index 7d8291bc26ae51..221ba32ee3ca1d 100644 --- a/src/ui/public/chrome/directives/app_switcher/app_switcher.html +++ b/src/ui/public/chrome/directives/app_switcher/app_switcher.html @@ -3,7 +3,7 @@ ng-repeat="link in switcher.shownNavLinks" app-switcher-link-is-active="link.active" app-switcher-link-is-disabled="!switcher.isNavLinkEnabled(link)" - app-switcher-link-tooltip="link.tooltip" + app-switcher-link-tooltip="getTooltip(link)" app-switcher-link-on-click="switcher.ensureNavigation($event, link)" app-switcher-link-href="link.active ? link.url : (link.lastSubUrl || link.url)" app-switcher-link-icon="link.icon" diff --git a/src/ui/public/chrome/directives/app_switcher/app_switcher.js b/src/ui/public/chrome/directives/app_switcher/app_switcher.js index 3181f88d62cdce..072b6abc49c9fd 100644 --- a/src/ui/public/chrome/directives/app_switcher/app_switcher.js +++ b/src/ui/public/chrome/directives/app_switcher/app_switcher.js @@ -57,7 +57,7 @@ uiModules restrict: 'E', template: appSwitcherTemplate, controllerAs: 'switcher', - controller($scope, appSwitcherEnsureNavigation) { + controller($scope, appSwitcherEnsureNavigation, appSwitcherState) { // since we render this in an isolate scope we can't "require: ^chrome", but // rather than remove all helpfull checks we can just check here. if (!$scope.chrome || !$scope.chrome.getNavLinks) { @@ -72,6 +72,15 @@ uiModules // links don't cause full-navigation events in certain scenarios // so we force them when needed this.ensureNavigation = appSwitcherEnsureNavigation; + + $scope.getTooltip = link => { + // If the sidebar is open then we don't need to show the title because + // it will already be visible. + if (appSwitcherState.isOpen()) { + return link.tooltip; + } + return link.tooltip ? link.title + ' - ' + link.tooltip : link.title; + }; } }; }); diff --git a/src/ui/public/chrome/directives/app_switcher/app_switcher.less b/src/ui/public/chrome/directives/app_switcher/app_switcher.less index 0d22b23c0aa0a0..5243082114bdb5 100644 --- a/src/ui/public/chrome/directives/app_switcher/app_switcher.less +++ b/src/ui/public/chrome/directives/app_switcher/app_switcher.less @@ -4,7 +4,7 @@ body { overflow-x: hidden; } .app-links-wrapper { - width: @as-open-width; + width: @as-closed-width; position: fixed; left: 0; top: 0; @@ -12,15 +12,14 @@ body { overflow-x: hidden; } z-index: 0; background-color: @app-links-wrapper-background; overflow: hidden; - transition: width @transition-time; - transition-delay: @transition-delay; - &:hover { + &.is-app-links-wrapper-open { + width: @as-open-width; .app-title { display: inline-block; } + .app-wrapper { - transform: translateX(@as-open-width - @as-closed-width); + left: @as-open-width; } } @@ -47,8 +46,6 @@ body { overflow-x: hidden; } .app-wrapper { .real-flex-parent(); position: absolute; - transition: transform @transition-time; - transition-delay: @transition-delay; left: @as-closed-width; top: 0; right: 0; diff --git a/src/ui/public/chrome/directives/app_switcher_link/__tests__/app-switcher-link.js b/src/ui/public/chrome/directives/app_switcher_link/__tests__/app-switcher-link.js index 25768f2072893b..e1b922afa4e7b4 100644 --- a/src/ui/public/chrome/directives/app_switcher_link/__tests__/app-switcher-link.js +++ b/src/ui/public/chrome/directives/app_switcher_link/__tests__/app-switcher-link.js @@ -28,6 +28,7 @@ describe('appSwitcherLink directive', () => { app-switcher-link-kbn-route="appSwitcherLinkKbnRoute" app-switcher-link-icon="appSwitcherLinkIcon" app-switcher-link-title="appSwitcherLinkTitle" + app-switcher-link-classes="appSwitcherLinkClasses" /> `; @@ -207,5 +208,15 @@ describe('appSwitcherLink directive', () => { expect(link.attr('title')).to.be(attrs.appSwitcherLinkTitle); }); }); + + describe('appSwitcherLinkClasses attribute', () => { + it('is applied to the link', () => { + const attrs = { + appSwitcherLinkClasses: 'new classes', + }; + const element = create(attrs); + expect(element.attr('class')).to.contain(attrs.appSwitcherLinkClasses); + }); + }); }); }); diff --git a/src/ui/public/chrome/directives/app_switcher_link/app_switcher_link.html b/src/ui/public/chrome/directives/app_switcher_link/app_switcher_link.html index 6a7843d0430cf6..8b7f06883df620 100644 --- a/src/ui/public/chrome/directives/app_switcher_link/app_switcher_link.html +++ b/src/ui/public/chrome/directives/app_switcher_link/app_switcher_link.html @@ -1,9 +1,9 @@