From dde36c5675c7c4a366743f53ce94993af1952565 Mon Sep 17 00:00:00 2001 From: salesforce-suyash-more Date: Tue, 2 Jul 2024 19:36:19 +0530 Subject: [PATCH] moved focus logic to RD2 _EnablementDelegateHelper.js added he 'setFocus' method in RD2 _EnablementDelegateHelper.js and invoked it from RD2_EnablementDelegateController.js. --- .../RD2_EnablementDelegateController.js | 24 +++++++++---------- .../RD2_EnablementDelegateHelper.js | 19 ++++++++++++++- 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/force-app/main/default/aura/RD2_EnablementDelegate/RD2_EnablementDelegateController.js b/force-app/main/default/aura/RD2_EnablementDelegate/RD2_EnablementDelegateController.js index 2bce9583561..06f1524d7e3 100644 --- a/force-app/main/default/aura/RD2_EnablementDelegate/RD2_EnablementDelegateController.js +++ b/force-app/main/default/aura/RD2_EnablementDelegate/RD2_EnablementDelegateController.js @@ -28,13 +28,16 @@ helper.handleBatchEvent(component, event, 'v.dryRunBatch'); helper.refreshDryRun(component); helper.refreshEnable(component); - window.setTimeout(function() { - var dryRunJob = component.find("dryRun2Job"); - if (event.Hp.batchProgress.status === "Completed") { - dryRunJob.getElement().setAttribute('tabindex', '0'); - dryRunJob.getElement().focus(); + var status = event.Hp.batchProgress.status; + var dryRunJob = component.find("dryRunJob"); + if (["Completed", "Aborted"].includes(status)) { + if(dryRunJob){ + helper.setFocus(component, 'dryRunJob'); } - }, 0); + else{ + helper.setFocus(component, 'dryRun2Job'); + } + } }, handleDryRunError: function (component, event, helper) { helper.handleBatchError(component, event, 'dryRun'); @@ -51,13 +54,10 @@ handleMigrationStatusChange: function (component, event, helper) { helper.handleBatchEvent(component, event, 'v.migrationBatch'); helper.refreshMigration(component); - window.setTimeout(function() { - var migrationJob = component.find("migrationJob"); - if (event.Hp.batchProgress.status === "Completed") { - migrationJob.getElement().setAttribute('tabindex', '0'); - migrationJob.getElement().focus(); + var status = event.Hp.batchProgress.status; + if (["Completed", "Aborted"].includes(status)) { + helper.setFocus(component, 'migrationJob'); } - }, 0); }, handleMigrationError: function (component, event, helper) { helper.handleBatchError(component, event, 'migration'); diff --git a/force-app/main/default/aura/RD2_EnablementDelegate/RD2_EnablementDelegateHelper.js b/force-app/main/default/aura/RD2_EnablementDelegate/RD2_EnablementDelegateHelper.js index 45f96989f3c..9a18f91f260 100644 --- a/force-app/main/default/aura/RD2_EnablementDelegate/RD2_EnablementDelegateHelper.js +++ b/force-app/main/default/aura/RD2_EnablementDelegate/RD2_EnablementDelegateHelper.js @@ -599,5 +599,22 @@ hideSpinner: function (component, element) { var spinner = component.find(element); $A.util.addClass(spinner, 'slds-hide'); - } + }, + /** + * @description: Autofocus + */ + setFocus: function (component, elementId) { + window.setTimeout(() => { + try { var element = component.find(elementId); + if (element) { + element.getElement().setAttribute('tabindex', '0'); + element.getElement().focus(); + element.getElement().setAttribute('tabindex', '-1'); + } + } catch (error) { + console.error('Error setting focus on element:', error); + + } + }, 0); + } })