diff options
author | Phil Hughes <me@iamphill.com> | 2019-07-01 11:40:29 +0100 |
---|---|---|
committer | Phil Hughes <me@iamphill.com> | 2019-07-01 11:40:29 +0100 |
commit | 12413158fddf093e9b2cc8d00d66f8c6833a260c (patch) | |
tree | 43145fa434253b12c382812e0477a55155a3346c /app/assets/javascripts/branches | |
parent | 8775e4a1faf13a01451e71ea9ef729dc52e6d3c1 (diff) | |
download | gitlab-ce-12413158fddf093e9b2cc8d00d66f8c6833a260c.tar.gz |
Fetch branch diverging counts from API
Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/46139
Diffstat (limited to 'app/assets/javascripts/branches')
-rw-r--r-- | app/assets/javascripts/branches/divergence_graph.js | 62 |
1 files changed, 44 insertions, 18 deletions
diff --git a/app/assets/javascripts/branches/divergence_graph.js b/app/assets/javascripts/branches/divergence_graph.js index 670e8e9eb60..96bc6a5f8e8 100644 --- a/app/assets/javascripts/branches/divergence_graph.js +++ b/app/assets/javascripts/branches/divergence_graph.js @@ -1,23 +1,49 @@ import Vue from 'vue'; +import { __ } from '../locale'; +import createFlash from '../flash'; +import axios from '../lib/utils/axios_utils'; import DivergenceGraph from './components/divergence_graph.vue'; -export default () => { - document.querySelectorAll('.js-branch-divergence-graph').forEach(el => { - const { distance, aheadCount, behindCount, defaultBranch, maxCommits } = el.dataset; - - return new Vue({ - el, - render(h) { - return h(DivergenceGraph, { - props: { - defaultBranch, - distance: distance ? parseInt(distance, 10) : null, - aheadCount: parseInt(aheadCount, 10), - behindCount: parseInt(behindCount, 10), - maxCommits: parseInt(maxCommits, 10), - }, - }); - }, - }); +export function createGraphVueApp(el, data, maxCommits) { + return new Vue({ + el, + render(h) { + return h(DivergenceGraph, { + props: { + defaultBranch: 'master', + distance: data.distance ? parseInt(data.distance, 10) : null, + aheadCount: parseInt(data.ahead, 10), + behindCount: parseInt(data.behind, 10), + maxCommits, + }, + }); + }, }); +} + +export default endpoint => { + const names = [...document.querySelectorAll('.js-branch-item')].map( + ({ dataset }) => dataset.name, + ); + return axios + .get(endpoint, { + params: { names }, + }) + .then(({ data }) => { + const maxCommits = Object.entries(data).reduce((acc, [, val]) => { + const max = Math.max(...Object.values(val)); + return max > acc ? max : acc; + }, 100); + + Object.entries(data).forEach(([branchName, val]) => { + const el = document.querySelector(`.js-branch-${branchName} .js-branch-divergence-graph`); + + if (!el) return; + + createGraphVueApp(el, val, maxCommits); + }); + }) + .catch(() => + createFlash(__('Error fetching diverging counts for branches. Please try again.')), + ); }; |