Reduce code complexity on /ee/app/models/burndown

Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.

While reviewing https://dev.gitlab.org/gitlab/gitlab-ee/merge_requests/776, I took a peek at the Burndown model and it was somewhat complicated to understand what it's exactly doing.

I few ideas to reduce the complexity:

  • Replace to_json method with a serializer. Serializers are recommended on our app/serializers/readme.md
  • Convert this class to a service.
    • Should this class be a model?
    • Doing a quick grep, it seems this class is mostly used on FE. It's only used on the BE by milestones_helper:
> grep -nr 'Burndown' ee/app/
ee/app//models/burndown.rb:3:class Burndown
ee/app//models/ee/global_milestone.rb:10:    # can't present Burndown charts since they don't have
ee/app//views/shared/promotions/_promote_burndown_charts.html.haml:13:            Upgrade your plan to improve milestones with Burndown Charts.
ee/app//views/shared/promotions/_promote_burndown_charts.html.haml:15:            Improve milestones with Burndown Charts.
ee/app//views/shared/promotions/_promote_burndown_charts.html.haml:17:          Burndown Charts are visual representations of the progress of completing a milestone. At a glance, you see the current state for the completion a given milestone. Without them, you would have to organize the data from the milestone and plot it yourself to have the same sense of progress.
ee/app//views/shared/milestones/_burndown.html.haml:10:      Burndown chart
ee/app//views/shared/milestones/_burndown.html.haml:26:          Burndown chart
ee/app//assets/javascripts/burndown_chart/burndown_chart.js:30:export default class BurndownChart {
ee/app//assets/javascripts/burndown_chart/index.js:3:import BurndownChart from './burndown_chart';
ee/app//assets/javascripts/burndown_chart/index.js:24:    const chart = new BurndownChart({ container, startDate, dueDate });
ee/app//assets/javascripts/pages/projects/milestones/show/index.js:3:import initBurndownChart from 'ee/burndown_chart';
ee/app//assets/javascripts/pages/projects/milestones/show/index.js:7:  initBurndownChart();
ee/app//assets/javascripts/pages/groups/milestones/show/index.js:3:import initBurndownChart from 'ee/burndown_chart';
ee/app//assets/javascripts/pages/groups/milestones/show/index.js:7:  initBurndownChart();
ee/app//helpers/ee/milestones_helper.rb:6:      Burndown.new(milestone) if milestone.supports_burndown_charts?

cc @jarka

Edited by 🤖 GitLab Bot 🤖