Sfoglia il codice sorgente

Add limit/marker query params to transfers and deployments list requests

Signed-off-by: Mihaela Balutoiu <mbalutoiu@cloudbasesolutions.com>
Mihaela Balutoiu 1 mese fa
parent
commit
ee061fa823
2 ha cambiato i file con 33 aggiunte e 32 eliminazioni
  1. 16 16
      src/sources/DeploymentSource.ts
  2. 17 16
      src/sources/TransferSource.ts

+ 16 - 16
src/sources/DeploymentSource.ts

@@ -18,7 +18,7 @@ import {
   DeploymentItemOptions,
   DeploymentItemOptions,
   UserScriptData,
   UserScriptData,
 } from "@src/@types/MainItem";
 } from "@src/@types/MainItem";
-import { ProgressUpdate, Task } from "@src/@types/Task";
+import { ProgressUpdate } from "@src/@types/Task";
 import { INSTANCE_OSMORPHING_MINION_POOL_MAPPINGS } from "@src/components/modules/WizardModule/WizardOptions";
 import { INSTANCE_OSMORPHING_MINION_POOL_MAPPINGS } from "@src/components/modules/WizardModule/WizardOptions";
 import { OptionsSchemaPlugin } from "@src/plugins";
 import { OptionsSchemaPlugin } from "@src/plugins";
 import DefaultOptionsSchemaPlugin from "@src/plugins/default/OptionsSchemaPlugin";
 import DefaultOptionsSchemaPlugin from "@src/plugins/default/OptionsSchemaPlugin";
@@ -45,27 +45,27 @@ class DeploymentSourceUtils {
       return a.index - b.index;
       return a.index - b.index;
     });
     });
   }
   }
-
-  static sortDeployments(deployments: any[]) {
-    deployments.sort(
-      (a: any, b: any) =>
-        new Date(b.created_at).getTime() - new Date(a.created_at).getTime(),
-    );
-
-    deployments.forEach((deployment: { tasks: Task[] }) => {
-      sortTasks(deployment.tasks, DeploymentSourceUtils.sortTaskUpdates);
-    });
-  }
 }
 }
 
 
 class DeploymentSource {
 class DeploymentSource {
-  async getDeployments(skipLog?: boolean): Promise<DeploymentItem[]> {
+  async getDeployments(options?: {
+    skipLog?: boolean;
+    limit?: number;
+    marker?: string | null;
+  }): Promise<DeploymentItem[]> {
+    const params: string[] = [];
+    if (options?.marker) {
+      params.push(`marker=${encodeURIComponent(options.marker)}`);
+    }
+    if (options?.limit !== undefined) {
+      params.push(`limit=${options.limit}`);
+    }
+    const queryString = params.length > 0 ? `?${params.join("&")}` : "";
     const response = await Api.send({
     const response = await Api.send({
-      url: `${configLoader.config.servicesUrls.coriolis}/${Api.projectId}/deployments`,
-      skipLog,
+      url: `${configLoader.config.servicesUrls.coriolis}/${Api.projectId}/deployments${queryString}`,
+      skipLog: options?.skipLog,
     });
     });
     const deployments = response.data.deployments;
     const deployments = response.data.deployments;
-    DeploymentSourceUtils.sortDeployments(deployments);
     return deployments;
     return deployments;
   }
   }
 
 

+ 17 - 16
src/sources/TransferSource.ts

@@ -83,14 +83,6 @@ export class TransferSourceUtils {
     return executions.filter(execution => execution.deleted_at == null);
     return executions.filter(execution => execution.deleted_at == null);
   }
   }
 
 
-  static sortTransfers(transfers: TransferItem[]) {
-    transfers.sort(
-      (a, b) =>
-        new Date(b.updated_at || b.created_at).getTime() -
-        new Date(a.updated_at || a.created_at).getTime(),
-    );
-  }
-
   static sortExecutions(executions: Execution[]) {
   static sortExecutions(executions: Execution[]) {
     executions.sort((a, b) => a.number - b.number);
     executions.sort((a, b) => a.number - b.number);
   }
   }
@@ -104,17 +96,26 @@ export class TransferSourceUtils {
 }
 }
 
 
 class TransferSource {
 class TransferSource {
-  async getTransfers(
-    skipLog?: boolean,
-    quietError?: boolean,
-  ): Promise<TransferItem[]> {
+  async getTransfers(options?: {
+    skipLog?: boolean;
+    quietError?: boolean;
+    limit?: number;
+    marker?: string | null;
+  }): Promise<TransferItem[]> {
+    const params: string[] = ["sort_key=updated_at", "sort_dir=desc"];
+    if (options?.marker) {
+      params.push(`marker=${encodeURIComponent(options.marker)}`);
+    }
+    if (options?.limit !== undefined) {
+      params.push(`limit=${options.limit}`);
+    }
+    const queryString = `?${params.join("&")}`;
     const response = await Api.send({
     const response = await Api.send({
-      url: `${configLoader.config.servicesUrls.coriolis}/${Api.projectId}/transfers`,
-      skipLog,
-      quietError,
+      url: `${configLoader.config.servicesUrls.coriolis}/${Api.projectId}/transfers${queryString}`,
+      skipLog: options?.skipLog,
+      quietError: options?.quietError,
     });
     });
     const transfers: TransferItem[] = response.data.transfers;
     const transfers: TransferItem[] = response.data.transfers;
-    TransferSourceUtils.sortTransfers(transfers);
     return transfers;
     return transfers;
   }
   }