You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

time-machine.ts 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2021 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. import throwGlobalError from '../app/utils/throwGlobalError';
  21. import { getJSON } from '../helpers/request';
  22. import { BranchParameters } from '../types/branch-like';
  23. interface TimeMachineResponse {
  24. measures: {
  25. metric: string;
  26. history: Array<{ date: string; value?: string }>;
  27. }[];
  28. paging: T.Paging;
  29. }
  30. export function getTimeMachineData(
  31. data: {
  32. component: string;
  33. from?: string;
  34. metrics: string;
  35. p?: number;
  36. ps?: number;
  37. to?: string;
  38. } & BranchParameters
  39. ): Promise<TimeMachineResponse> {
  40. return getJSON('/api/measures/search_history', data).catch(throwGlobalError);
  41. }
  42. export function getAllTimeMachineData(
  43. data: {
  44. component: string;
  45. metrics: string;
  46. from?: string;
  47. p?: number;
  48. to?: string;
  49. } & BranchParameters,
  50. prev?: TimeMachineResponse
  51. ): Promise<TimeMachineResponse> {
  52. return getTimeMachineData({ ...data, ps: 1000 }).then(r => {
  53. const result = prev
  54. ? {
  55. measures: prev.measures.map((measure, idx) => ({
  56. ...measure,
  57. history: measure.history.concat(r.measures[idx].history)
  58. })),
  59. paging: r.paging
  60. }
  61. : r;
  62. if (result.paging.pageIndex * result.paging.pageSize >= result.paging.total) {
  63. return result;
  64. }
  65. return getAllTimeMachineData({ ...data, p: result.paging.pageIndex + 1 }, result);
  66. });
  67. }