From 35d653420f627e2c1cb53125c2752073dc23c46a Mon Sep 17 00:00:00 2001 From: Viktor Vorona Date: Thu, 15 Jun 2023 14:33:41 +0200 Subject: [PATCH] SONAR-19538 Add loading status to Project Import/Export page --- .../js/api/mocks/ComputeEngineServiceMock.ts | 18 +++++++++++++++--- .../js/apps/projectDump/ProjectDumpApp.tsx | 2 +- .../__tests__/ProjectDumpApp-it.tsx | 2 ++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/server/sonar-web/src/main/js/api/mocks/ComputeEngineServiceMock.ts b/server/sonar-web/src/main/js/api/mocks/ComputeEngineServiceMock.ts index 0fb9b667164..d1a3b9bf592 100644 --- a/server/sonar-web/src/main/js/api/mocks/ComputeEngineServiceMock.ts +++ b/server/sonar-web/src/main/js/api/mocks/ComputeEngineServiceMock.ts @@ -117,6 +117,17 @@ export default class ComputeEngineServiceMock { ); }); + results.sort((a, b) => { + const getMaxDate = (t: Task) => + Math.max( + +new Date(t.submittedAt), + +new Date(t.startedAt ?? 0), + +new Date(t.executedAt ?? 0) + ); + + return getMaxDate(b) - getMaxDate(a); + }); + if (data.onlyCurrents) { // This is more complex in real life, but it's a good enough approximation to suit tests. results = Object.values(groupBy(results, (t) => t.componentKey)) @@ -125,13 +136,14 @@ export default class ComputeEngineServiceMock { } const page = data.p ?? 1; - const paginationIndex = (page - 1) * PAGE_SIZE; + const pageSize = data.ps ?? PAGE_SIZE; + const paginationIndex = (page - 1) * pageSize; return Promise.resolve({ - tasks: results.slice(paginationIndex, paginationIndex + PAGE_SIZE), + tasks: results.slice(paginationIndex, paginationIndex + pageSize), paging: { pageIndex: page, - pageSize: PAGE_SIZE, + pageSize, total: results.length, }, }); diff --git a/server/sonar-web/src/main/js/apps/projectDump/ProjectDumpApp.tsx b/server/sonar-web/src/main/js/apps/projectDump/ProjectDumpApp.tsx index 9e67eeeca00..f054795c1e0 100644 --- a/server/sonar-web/src/main/js/apps/projectDump/ProjectDumpApp.tsx +++ b/server/sonar-web/src/main/js/apps/projectDump/ProjectDumpApp.tsx @@ -71,7 +71,7 @@ export class ProjectDumpApp extends React.Component { const data: ActivityRequestParameters = { type, component, - onlyCurrents: true, + ps: 1, status: [ TaskStatuses.Pending, TaskStatuses.InProgress, diff --git a/server/sonar-web/src/main/js/apps/projectDump/__tests__/ProjectDumpApp-it.tsx b/server/sonar-web/src/main/js/apps/projectDump/__tests__/ProjectDumpApp-it.tsx index e926d657f91..61d838ee777 100644 --- a/server/sonar-web/src/main/js/apps/projectDump/__tests__/ProjectDumpApp-it.tsx +++ b/server/sonar-web/src/main/js/apps/projectDump/__tests__/ProjectDumpApp-it.tsx @@ -120,6 +120,7 @@ it('should show pending->in progress->failed export', async () => { componentKey: COMPONENT_KEY, type: TaskTypes.ProjectExport, status: TaskStatuses.Failed, + executedAt: '2023-06-08T12:05:00Z', }); jest.runOnlyPendingTimers(); expect(await ui.failedExport.find()).toBeInTheDocument(); @@ -165,6 +166,7 @@ it('should show pending->in progress->failed import', async () => { componentKey: COMPONENT_KEY, type: TaskTypes.ProjectImport, status: TaskStatuses.Failed, + executedAt: '2023-06-08T12:05:00Z', }); jest.runOnlyPendingTimers(); expect(await ui.failedImport.find()).toBeInTheDocument(); -- 2.39.5