Commit 1dd797d7 authored by Mark Florian's avatar Mark Florian

Merge branch '246531-optimize-layout_nav-for-main-js-loading' into 'master'

Optimize layout_nav for main.js loading

Closes #246531

See merge request gitlab-org/gitlab!41705
parents 113f54fb 81b3f18d
import $ from 'jquery'; import $ from 'jquery';
import ContextualSidebar from './contextual_sidebar'; import ContextualSidebar from './contextual_sidebar';
import initFlyOutNav from './fly_out_nav'; import initFlyOutNav from './fly_out_nav';
import initWhatsNew from '~/whats_new';
function hideEndFade($scrollingTabs) { function hideEndFade($scrollingTabs) {
$scrollingTabs.each(function scrollTabsLoop() { $scrollingTabs.each(function scrollTabsLoop() {
...@@ -14,6 +13,17 @@ function hideEndFade($scrollingTabs) { ...@@ -14,6 +13,17 @@ function hideEndFade($scrollingTabs) {
function initDeferred() { function initDeferred() {
$(document).trigger('init.scrolling-tabs'); $(document).trigger('init.scrolling-tabs');
const whatsNewTriggerEl = document.querySelector('.js-whats-new-trigger');
if (whatsNewTriggerEl) {
whatsNewTriggerEl.addEventListener('click', () => {
import(/* webpackChunkName: 'whatsNewApp' */ '~/whats_new')
.then(({ default: initWhatsNew }) => {
initWhatsNew();
})
.catch(() => {});
});
}
} }
export default function initLayoutNav() { export default function initLayoutNav() {
...@@ -21,7 +31,6 @@ export default function initLayoutNav() { ...@@ -21,7 +31,6 @@ export default function initLayoutNav() {
contextualSidebar.bindEvents(); contextualSidebar.bindEvents();
initFlyOutNav(); initFlyOutNav();
initWhatsNew();
// We need to init it on DomContentLoaded as others could also call it // We need to init it on DomContentLoaded as others could also call it
$(document).on('init.scrolling-tabs', () => { $(document).on('init.scrolling-tabs', () => {
......
...@@ -30,8 +30,11 @@ export default { ...@@ -30,8 +30,11 @@ export default {
return features; return features;
}, },
}, },
mounted() {
this.openDrawer();
},
methods: { methods: {
...mapActions(['closeDrawer']), ...mapActions(['openDrawer', 'closeDrawer']),
}, },
}; };
</script> </script>
......
<script>
import { mapActions } from 'vuex';
import { GlButton } from '@gitlab/ui';
export default {
components: {
GlButton,
},
methods: {
...mapActions(['openDrawer']),
},
};
</script>
<template>
<li>
<gl-button variant="link" @click="openDrawer">{{ __("See what's new at GitLab") }}</gl-button>
</li>
</template>
import Vue from 'vue'; import Vue from 'vue';
import App from './components/app.vue'; import App from './components/app.vue';
import Trigger from './components/trigger.vue';
import store from './store'; import store from './store';
export default () => { let whatsNewApp;
const whatsNewElm = document.getElementById('whats-new-app');
// eslint-disable-next-line no-new
new Vue({
el: whatsNewElm,
store,
components: {
App,
},
render(createElement) {
return createElement('app', {
props: {
features: whatsNewElm.getAttribute('data-features'),
},
});
},
});
// eslint-disable-next-line no-new export default () => {
new Vue({ if (whatsNewApp) {
el: document.getElementById('whats-new-trigger'), store.dispatch('openDrawer');
store, } else {
components: { const whatsNewElm = document.getElementById('whats-new-app');
Trigger,
},
render(createElement) { whatsNewApp = new Vue({
return createElement('trigger'); el: whatsNewElm,
}, store,
}); components: {
App,
},
render(createElement) {
return createElement('app', {
props: {
features: whatsNewElm.getAttribute('data-features'),
},
});
},
});
}
}; };
- if ::Feature.enabled?(:whats_new_dropdown) - if ::Feature.enabled?(:whats_new_dropdown)
- if ::Feature.enabled?(:whats_new_drawer) - if ::Feature.enabled?(:whats_new_drawer)
#whats-new-trigger %li
%button.js-whats-new-trigger{ type: 'button' }
= _("See what's new at GitLab")
- else - else
%li %li
= link_to _("See what's new at GitLab"), "#{promo_url}/releases/gitlab-com/", target: '_blank', rel: 'noopener noreferrer', data: { track_event: 'click_whats_new', track_property: 'question_menu' } = link_to _("See what's new at GitLab"), "#{promo_url}/releases/gitlab-com/", target: '_blank', rel: 'noopener noreferrer', data: { track_event: 'click_whats_new', track_property: 'question_menu' }
...@@ -15,6 +15,7 @@ describe('App', () => { ...@@ -15,6 +15,7 @@ describe('App', () => {
const buildWrapper = () => { const buildWrapper = () => {
actions = { actions = {
openDrawer: jest.fn(),
closeDrawer: jest.fn(), closeDrawer: jest.fn(),
}; };
...@@ -48,6 +49,10 @@ describe('App', () => { ...@@ -48,6 +49,10 @@ describe('App', () => {
expect(getDrawer().exists()).toBe(true); expect(getDrawer().exists()).toBe(true);
}); });
it('dispatches openDrawer when mounted', () => {
expect(actions.openDrawer).toHaveBeenCalled();
});
it('dispatches closeDrawer when clicking close', () => { it('dispatches closeDrawer when clicking close', () => {
getDrawer().vm.$emit('close'); getDrawer().vm.$emit('close');
expect(actions.closeDrawer).toHaveBeenCalled(); expect(actions.closeDrawer).toHaveBeenCalled();
......
import { createLocalVue, mount } from '@vue/test-utils';
import Vuex from 'vuex';
import { GlButton } from '@gitlab/ui';
import Trigger from '~/whats_new/components/trigger.vue';
const localVue = createLocalVue();
localVue.use(Vuex);
describe('Trigger', () => {
let wrapper;
let store;
let actions;
let state;
beforeEach(() => {
actions = {
openDrawer: jest.fn(),
};
state = {
open: true,
};
store = new Vuex.Store({
actions,
state,
});
wrapper = mount(Trigger, {
localVue,
store,
});
});
afterEach(() => {
wrapper.destroy();
});
it('dispatches openDrawer when clicking close', () => {
wrapper.find(GlButton).vm.$emit('click');
expect(actions.openDrawer).toHaveBeenCalled();
});
});
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment