Преглед изворни кода

Fix pagination boundary edge case for transfers, deployments, and executions

Signed-off-by: Mihaela Balutoiu <mbalutoiu@cloudbasesolutions.com>
Mihaela Balutoiu пре 1 месец
родитељ
комит
37d6c9a4f1
4 измењених фајлова са 62 додато и 34 уклоњено
  1. 2 0
      src/sources/DeploymentSource.ts
  2. 2 0
      src/sources/TransferSource.ts
  3. 24 10
      src/stores/DeploymentStore.ts
  4. 34 24
      src/stores/TransferStore.ts

+ 2 - 0
src/sources/DeploymentSource.ts

@@ -50,6 +50,7 @@ class DeploymentSourceUtils {
 class DeploymentSource {
 class DeploymentSource {
   async getDeployments(options?: {
   async getDeployments(options?: {
     skipLog?: boolean;
     skipLog?: boolean;
+    quietError?: boolean;
     limit?: number;
     limit?: number;
     marker?: string | null;
     marker?: string | null;
   }): Promise<DeploymentItem[]> {
   }): Promise<DeploymentItem[]> {
@@ -64,6 +65,7 @@ class DeploymentSource {
     const response = await Api.send({
     const response = await Api.send({
       url: `${configLoader.config.servicesUrls.coriolis}/${Api.projectId}/deployments${queryString}`,
       url: `${configLoader.config.servicesUrls.coriolis}/${Api.projectId}/deployments${queryString}`,
       skipLog: options?.skipLog,
       skipLog: options?.skipLog,
+      quietError: options?.quietError,
     });
     });
     const deployments = response.data.deployments;
     const deployments = response.data.deployments;
     return deployments;
     return deployments;

+ 2 - 0
src/sources/TransferSource.ts

@@ -150,6 +150,7 @@ class TransferSource {
     options?: {
     options?: {
       limit?: number;
       limit?: number;
       marker?: string | null;
       marker?: string | null;
+      quietError?: boolean;
     },
     },
   ): Promise<Execution[]> {
   ): Promise<Execution[]> {
     const params: string[] = [];
     const params: string[] = [];
@@ -162,6 +163,7 @@ class TransferSource {
     const queryString = params.length > 0 ? `?${params.join("&")}` : "";
     const queryString = params.length > 0 ? `?${params.join("&")}` : "";
     const response = await Api.send({
     const response = await Api.send({
       url: `${configLoader.config.servicesUrls.coriolis}/${Api.projectId}/transfers/${transferId}/executions${queryString}`,
       url: `${configLoader.config.servicesUrls.coriolis}/${Api.projectId}/transfers/${transferId}/executions${queryString}`,
+      quietError: options?.quietError,
     });
     });
     const executions: Execution[] = response.data.executions;
     const executions: Execution[] = response.data.executions;
     return executions;
     return executions;

+ 24 - 10
src/stores/DeploymentStore.ts

@@ -75,22 +75,28 @@ class DeploymentStore {
       this.loading = true;
       this.loading = true;
     }
     }
 
 
+    const marker = this.deploymentPageMarkers[this.deploymentsPage - 1] ?? null;
+    const isPaginationRequest = marker !== null;
+
     try {
     try {
-      const marker =
-        this.deploymentPageMarkers[this.deploymentsPage - 1] ?? null;
       const raw = await DeploymentSource.getDeployments({
       const raw = await DeploymentSource.getDeployments({
         skipLog: options?.skipLog,
         skipLog: options?.skipLog,
-        limit: this.deploymentsItemsPerPage + 1,
+        quietError: isPaginationRequest,
+        limit: this.deploymentsItemsPerPage,
         marker,
         marker,
       });
       });
-      const hasNextPage = raw.length > this.deploymentsItemsPerPage;
-      const deployments = hasNextPage
-        ? raw.slice(0, this.deploymentsItemsPerPage)
-        : raw;
-      const nextMarker =
-        deployments.length > 0 ? deployments[deployments.length - 1].id : null;
+      if (isPaginationRequest && raw.length === 0) {
+        runInAction(() => {
+          this.deploymentsHasNextPage = false;
+          this.deploymentsPage = Math.max(1, this.deploymentsPage - 1);
+          this.loading = false;
+        });
+        return;
+      }
+      const hasNextPage = raw.length === this.deploymentsItemsPerPage;
+      const nextMarker = raw.length > 0 ? raw[raw.length - 1].id : null;
       runInAction(() => {
       runInAction(() => {
-        this.deployments = deployments;
+        this.deployments = raw;
         this.deploymentsHasNextPage = hasNextPage;
         this.deploymentsHasNextPage = hasNextPage;
         if (nextMarker !== null) {
         if (nextMarker !== null) {
           this.deploymentPageMarkers[this.deploymentsPage] = nextMarker;
           this.deploymentPageMarkers[this.deploymentsPage] = nextMarker;
@@ -99,6 +105,14 @@ class DeploymentStore {
         this.deploymentsLoaded = true;
         this.deploymentsLoaded = true;
       });
       });
     } catch (ex) {
     } catch (ex) {
+      if (isPaginationRequest) {
+        runInAction(() => {
+          this.deploymentsHasNextPage = false;
+          this.deploymentsPage = Math.max(1, this.deploymentsPage - 1);
+          this.loading = false;
+        });
+        return;
+      }
       runInAction(() => {
       runInAction(() => {
         this.loading = false;
         this.loading = false;
       });
       });

+ 34 - 24
src/stores/TransferStore.ts

@@ -117,15 +117,12 @@ class TransferStore {
 
 
     try {
     try {
       const raw = await TransferSource.getExecutions(transferId, {
       const raw = await TransferSource.getExecutions(transferId, {
-        limit: this.executionsPageSize + 1,
+        limit: this.executionsPageSize,
       });
       });
-      const hasOlderPage = raw.length > this.executionsPageSize;
-      const executions = hasOlderPage
-        ? raw.slice(0, this.executionsPageSize)
-        : raw;
-      TransferSourceUtils.sortExecutions(executions);
+      const hasOlderPage = raw.length === this.executionsPageSize;
+      TransferSourceUtils.sortExecutions(raw);
       runInAction(() => {
       runInAction(() => {
-        this.executionsList = executions;
+        this.executionsList = raw;
         this.executionsHasOlderPage = hasOlderPage;
         this.executionsHasOlderPage = hasOlderPage;
         this.executionsLoading = false;
         this.executionsLoading = false;
       });
       });
@@ -152,21 +149,20 @@ class TransferStore {
 
 
     try {
     try {
       const raw = await TransferSource.getExecutions(transferId, {
       const raw = await TransferSource.getExecutions(transferId, {
-        limit: this.executionsPageSize + 1,
+        limit: this.executionsPageSize,
         marker,
         marker,
+        quietError: true,
       });
       });
-      const hasOlderPage = raw.length > this.executionsPageSize;
-      const executions = hasOlderPage
-        ? raw.slice(0, this.executionsPageSize)
-        : raw;
-      TransferSourceUtils.sortExecutions(executions);
+      const hasOlderPage = raw.length === this.executionsPageSize;
+      TransferSourceUtils.sortExecutions(raw);
       runInAction(() => {
       runInAction(() => {
-        this.executionsList = [...executions, ...this.executionsList];
+        this.executionsList = [...raw, ...this.executionsList];
         this.executionsHasOlderPage = hasOlderPage;
         this.executionsHasOlderPage = hasOlderPage;
         this.executionsLoading = false;
         this.executionsLoading = false;
       });
       });
     } catch (err) {
     } catch (err) {
       runInAction(() => {
       runInAction(() => {
+        this.executionsHasOlderPage = false;
         this.executionsLoading = false;
         this.executionsLoading = false;
       });
       });
       console.error(err);
       console.error(err);
@@ -197,21 +193,35 @@ class TransferStore {
       this.loading = true;
       this.loading = true;
     }
     }
 
 
+    const marker = this.transferPageMarkers[this.transfersPage - 1] ?? null;
+    const isPaginationRequest = marker !== null;
+
     try {
     try {
-      const marker = this.transferPageMarkers[this.transfersPage - 1] ?? null;
       const raw = await TransferSource.getTransfers({
       const raw = await TransferSource.getTransfers({
         skipLog: options?.skipLog,
         skipLog: options?.skipLog,
-        quietError: options?.quietError,
-        limit: this.transfersItemsPerPage + 1,
+        quietError: options?.quietError || isPaginationRequest,
+        limit: this.transfersItemsPerPage,
         marker,
         marker,
       });
       });
-      const hasNextPage = raw.length > this.transfersItemsPerPage;
-      const transfers = hasNextPage
-        ? raw.slice(0, this.transfersItemsPerPage)
-        : raw;
-      const nextMarker =
-        transfers.length > 0 ? transfers[transfers.length - 1].id : null;
-      this.getTransfersSuccess(transfers, hasNextPage, nextMarker);
+      if (isPaginationRequest && raw.length === 0) {
+        runInAction(() => {
+          this.transfersHasNextPage = false;
+          this.transfersPage = Math.max(1, this.transfersPage - 1);
+        });
+        return;
+      }
+      const hasNextPage = raw.length === this.transfersItemsPerPage;
+      const nextMarker = raw.length > 0 ? raw[raw.length - 1].id : null;
+      this.getTransfersSuccess(raw, hasNextPage, nextMarker);
+    } catch (err) {
+      if (isPaginationRequest) {
+        runInAction(() => {
+          this.transfersHasNextPage = false;
+          this.transfersPage = Math.max(1, this.transfersPage - 1);
+        });
+        return;
+      }
+      throw err;
     } finally {
     } finally {
       this.getTransfersDone();
       this.getTransfersDone();
     }
     }