Jelajahi Sumber

Fix empty `executions` after `get_transfer` optimization

The transfer details endpoint no longer returns the
execution history (executions is now an empty list),
so the UI can no longer read execution data off
the transfer payload.

Signed-off-by: Mihaela Balutoiu <mbalutoiu@cloudbasesolutions.com>
Mihaela Balutoiu 6 hari lalu
induk
melakukan
147347542c

+ 2 - 2
cypress/e2e/transfers/transfers-list.cy.ts

@@ -147,8 +147,8 @@ describe("Replicas list", () => {
     cy.get("div[class^='ActionDropdown__Wrapper']").click();
     cy.loadFixtures(["transfers/replicas"], (results: any[]) => {
       const transfers = results[0].transfers;
-      cy.intercept(`**/coriolis/**/transfers/${transfers[0].id}*`, {
-        fixture: "transfers/replica-unexecuted",
+      cy.intercept(`**/coriolis/**/transfers/${transfers[0].id}/executions*`, {
+        body: { executions: [] },
       }).as("transfer");
 
       cy.get("div[class^='ActionDropdown__ListItem']")

+ 5 - 3
src/components/modules/TransferModule/TransferDetailsContent/TransferDetailsContent.tsx

@@ -124,13 +124,15 @@ class TransferDetailsContent extends React.Component<Props, State> {
   };
 
   getLastExecution() {
-    return this.props.item?.executions?.length
-      ? this.props.item.executions[this.props.item.executions.length - 1]
+    return this.props.executions?.length
+      ? this.props.executions[this.props.executions.length - 1]
       : null;
   }
 
   getStatus() {
-    return this.getLastExecution()?.status;
+    return (
+      this.props.item?.last_execution_status || this.getLastExecution()?.status
+    );
   }
 
   isEndpointMissing() {

+ 9 - 4
src/components/smart/TransferDetailsPage/TransferDetailsPage.tsx

@@ -221,14 +221,17 @@ class TransferDetailsPage extends React.Component<Props, State> {
   }
 
   getLastExecution() {
-    if (this.transfer?.executions?.length) {
-      return this.transfer.executions[this.transfer.executions.length - 1];
+    const executions = transferStore.executionsList;
+    if (executions.length) {
+      return executions[executions.length - 1];
     }
     return null;
   }
 
   getStatus() {
-    return this.getLastExecution()?.status;
+    return (
+      this.transfer?.last_execution_status || this.getLastExecution()?.status
+    );
   }
 
   getTransferItemType(): string {
@@ -978,7 +981,9 @@ class TransferDetailsPage extends React.Component<Props, State> {
         />
         {this.state.showDeleteTransferConfirmation ? (
           <DeleteTransferModal
-            hasDisks={transferStore.testTransferHasDisks(this.transfer)}
+            hasDisks={transferStore.testTransferHasDisks(
+              transferStore.executionsList,
+            )}
             onRequestClose={() => this.handleCloseDeleteTransferConfirmation()}
             onDeleteTransfer={() => {
               this.handleDeleteTransferConfirmation();

+ 4 - 5
src/sources/TransferSource.ts

@@ -218,12 +218,11 @@ class TransferSource {
     let lastExecutionId = options.executionId;
 
     if (!lastExecutionId) {
-      const transferDetails = await this.getTransferDetails({
-        transferId: options.transferId,
+      const executions = await this.getExecutions(options.transferId, {
+        limit: 1,
       });
-      const lastExecution =
-        transferDetails.executions[transferDetails.executions.length - 1];
-      if (lastExecution.status !== "RUNNING") {
+      const lastExecution = executions[0];
+      if (!lastExecution || lastExecution.status !== "RUNNING") {
         return options.transferId;
       }
       lastExecutionId = lastExecution.id;

+ 17 - 15
src/stores/TransferStore.ts

@@ -68,7 +68,7 @@ class TransferStore {
 
   @observable startingExecution = false;
 
-  @observable transfersWithDisks: TransferItemDetails[] = [];
+  @observable transfersWithDisks: TransferItem[] = [];
 
   @observable transfersWithDisksLoading = false;
 
@@ -534,14 +534,14 @@ class TransferStore {
     await TransferSource.update(options);
   }
 
-  testTransferHasDisks(transfer: TransferItemDetails | null) {
-    if (!transfer || !transfer.executions || transfer.executions.length === 0) {
+  testTransferHasDisks(executions: Execution[]) {
+    if (!executions || executions.length === 0) {
       return false;
     }
-    if (!transfer.executions.find(e => e.type === "transfer_execution")) {
+    if (!executions.find(e => e.type === "transfer_execution")) {
       return false;
     }
-    const lastExecution = transfer.executions[transfer.executions.length - 1];
+    const lastExecution = executions[executions.length - 1];
     if (
       lastExecution.type === "transfer_disks_delete" &&
       lastExecution.status === "COMPLETED"
@@ -556,19 +556,21 @@ class TransferStore {
     this.transfersWithDisksLoading = true;
 
     try {
-      const transferDetails = await Promise.all(
-        transfers.map(transfer =>
-          TransferSource.getTransferDetails({
-            transferId: transfer.id,
-            includeTaskInfo: true,
-          }),
-        ),
+      const results = await Promise.all(
+        transfers.map(async transfer => {
+          const executions = await TransferSource.getExecutions(transfer.id, {
+            limit: this.executionsPageSize,
+            quietError: true,
+          });
+          TransferSourceUtils.sortExecutions(executions);
+          return { transfer, hasDisks: this.testTransferHasDisks(executions) };
+        }),
       );
 
       runInAction(() => {
-        this.transfersWithDisks = transferDetails.filter(r =>
-          this.testTransferHasDisks(r),
-        );
+        this.transfersWithDisks = results
+          .filter(r => r.hasDisks)
+          .map(r => r.transfer);
       });
     } finally {
       runInAction(() => {