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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2024 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 '../helpers/error';
  21. import { getJSON } from '../helpers/request';
  22. import { BranchParameters } from '../types/branch-like';
  23. import { MetricKey } from '../types/metrics';
  24. import { Paging } from '../types/types';
  25. export interface TimeMachineResponse {
  26. measures: {
  27. metric: MetricKey;
  28. history: Array<{ date: string; value?: string }>;
  29. }[];
  30. paging: Paging;
  31. }
  32. export function getTimeMachineData(
  33. data: {
  34. component?: string;
  35. from?: string;
  36. metrics: string;
  37. p?: number;
  38. ps?: number;
  39. to?: string;
  40. } & BranchParameters,
  41. ): Promise<TimeMachineResponse> {
  42. return getJSON('/api/measures/search_history', data).catch(throwGlobalError);
  43. }
  44. export function getAllTimeMachineData(
  45. data: {
  46. component?: string;
  47. metrics: string;
  48. from?: string;
  49. p?: number;
  50. to?: string;
  51. } & BranchParameters,
  52. prev?: TimeMachineResponse,
  53. ): Promise<TimeMachineResponse> {
  54. return getTimeMachineData({ ...data, ps: 1000 }).then((r) => {
  55. const result = prev
  56. ? {
  57. measures: prev.measures.map((measure, idx) => ({
  58. ...measure,
  59. history: measure.history.concat(r.measures[idx].history),
  60. })),
  61. paging: r.paging,
  62. }
  63. : r;
  64. if (result.paging.pageIndex * result.paging.pageSize >= result.paging.total) {
  65. return result;
  66. }
  67. return getAllTimeMachineData({ ...data, p: result.paging.pageIndex + 1 }, result);
  68. });
  69. }