diff options
author | Filipa Lacerda <filipa@gitlab.com> | 2017-04-06 00:55:49 +0100 |
---|---|---|
committer | Kamil Trzcinski <ayufan@ayufan.eu> | 2017-04-06 23:50:37 +0200 |
commit | f66e1c173406d2e447d46aab99f51c1277c801bc (patch) | |
tree | 58104264d835dd5f8e1607afbaf548362ddb56d8 | |
parent | 9e89c93e167d66644fd771b106be5ce01b899fcf (diff) | |
download | gitlab-ce-f66e1c173406d2e447d46aab99f51c1277c801bc.tar.gz |
Destroys pipeline table component when we change tabs in order to stop polling
-rw-r--r-- | app/assets/javascripts/commit/pipelines/pipelines_bundle.js | 7 | ||||
-rw-r--r-- | app/assets/javascripts/commit/pipelines/pipelines_table.js | 19 | ||||
-rw-r--r-- | app/assets/javascripts/merge_request_tabs.js | 26 |
3 files changed, 29 insertions, 23 deletions
diff --git a/app/assets/javascripts/commit/pipelines/pipelines_bundle.js b/app/assets/javascripts/commit/pipelines/pipelines_bundle.js index a92e068ca5a..cb20c2b54cf 100644 --- a/app/assets/javascripts/commit/pipelines/pipelines_bundle.js +++ b/app/assets/javascripts/commit/pipelines/pipelines_bundle.js @@ -8,10 +8,8 @@ Vue.use(VueResource); /** * Commits View > Pipelines Tab > Pipelines Table. - * Merge Request View > Pipelines Tab > Pipelines Table. * * Renders Pipelines table in pipelines tab in the commits show view. - * Renders Pipelines table in pipelines tab in the merge request show view. */ $(() => { @@ -20,13 +18,14 @@ $(() => { gl.commits.pipelines = gl.commits.pipelines || {}; if (gl.commits.PipelinesTableBundle) { + document.querySelector('#commit-pipeline-table-view').removeChild(this.pipelinesTableBundle.$el); gl.commits.PipelinesTableBundle.$destroy(true); } const pipelineTableViewEl = document.querySelector('#commit-pipeline-table-view'); - gl.commits.pipelines.PipelinesTableBundle = new CommitPipelinesTable(); if (pipelineTableViewEl && pipelineTableViewEl.dataset.disableInitialization === undefined) { - gl.commits.pipelines.PipelinesTableBundle.$mount(pipelineTableViewEl); + gl.commits.pipelines.PipelinesTableBundle = new CommitPipelinesTable().$mount(); + document.querySelector('#commit-pipeline-table-view').appendChild(this.pipelinesTableBundle.$el); } }); diff --git a/app/assets/javascripts/commit/pipelines/pipelines_table.js b/app/assets/javascripts/commit/pipelines/pipelines_table.js index 2d6df95ffbb..da9707549f9 100644 --- a/app/assets/javascripts/commit/pipelines/pipelines_table.js +++ b/app/assets/javascripts/commit/pipelines/pipelines_table.js @@ -22,6 +22,7 @@ import Poll from '../../lib/utils/poll'; */ export default Vue.component('pipelines-table', { + components: { 'pipelines-table-component': PipelinesTableComponent, 'error-state': ErrorState, @@ -67,11 +68,13 @@ export default Vue.component('pipelines-table', { * */ beforeMount() { - this.endpoint = this.$el.dataset.endpoint; - this.helpPagePath = this.$el.dataset.helpPagePath; + const element = document.querySelector('#commit-pipeline-table-view'); + + this.endpoint = element.dataset.endpoint; + this.helpPagePath = element.dataset.helpPagePath; this.service = new PipelinesService(this.endpoint); - const poll = new Poll({ + this.poll = new Poll({ resource: this.service, method: 'getPipelines', successCallback: this.successCallback, @@ -81,14 +84,14 @@ export default Vue.component('pipelines-table', { if (!Visibility.hidden()) { this.isLoading = true; - poll.makeRequest(); + this.poll.makeRequest(); } Visibility.change(() => { if (!Visibility.hidden()) { - poll.restart(); + this.poll.restart(); } else { - poll.stop(); + this.poll.stop(); } }); @@ -108,6 +111,10 @@ export default Vue.component('pipelines-table', { eventHub.$off('refreshPipelines'); }, + destroyed() { + this.poll.stop(); + }, + methods: { fetchPipelines() { this.isLoading = true; diff --git a/app/assets/javascripts/merge_request_tabs.js b/app/assets/javascripts/merge_request_tabs.js index 3c4e6102469..7cb42a172af 100644 --- a/app/assets/javascripts/merge_request_tabs.js +++ b/app/assets/javascripts/merge_request_tabs.js @@ -99,9 +99,10 @@ import './flash'; .off('click', this.clickTab); } - destroy() { - this.unbindEvents(); + destroyPipelinesView() { if (this.commitPipelinesTable) { + document.querySelector('#commit-pipeline-table-view') + .removeChild(this.commitPipelinesTable.$el); this.commitPipelinesTable.$destroy(); } } @@ -128,6 +129,7 @@ import './flash'; this.loadCommits($target.attr('href')); this.expandView(); this.resetViewContainer(); + this.destroyPipelinesView(); } else if (this.isDiffAction(action)) { this.loadDiff($target.attr('href')); if (Breakpoints.get().getBreakpointSize() !== 'lg') { @@ -136,12 +138,14 @@ import './flash'; if (this.diffViewType() === 'parallel') { this.expandViewContainer(); } + this.destroyPipelinesView(); } else if (action === 'pipelines') { this.resetViewContainer(); - this.loadPipelines(); + this.mountPipelinesView(); } else { this.expandView(); this.resetViewContainer(); + this.destroyPipelinesView(); } if (this.setUrl) { this.setCurrentAction(action); @@ -227,16 +231,12 @@ import './flash'; }); } - loadPipelines() { - if (this.pipelinesLoaded) { - return; - } - const pipelineTableViewEl = document.querySelector('#commit-pipeline-table-view'); - // Could already be mounted from the `pipelines_bundle` - if (pipelineTableViewEl) { - this.commitPipelinesTable = new CommitPipelinesTable().$mount(pipelineTableViewEl); - } - this.pipelinesLoaded = true; + mountPipelinesView() { + this.commitPipelinesTable = new CommitPipelinesTable().$mount(); + // $mount(el) replaces the el with the new rendered component. We need it in order to mount + // it everytime this tab is clicked - https://vuejs.org/v2/api/#vm-mount + document.querySelector('#commit-pipeline-table-view') + .appendChild(this.commitPipelinesTable.$el); } loadDiff(source) { |