Created
July 15, 2021 11:42
-
-
Save lukaszhanusik/35f43718e14023e045e8c5291c086059 to your computer and use it in GitHub Desktop.
LWC Workspace API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
// NOTE: WorkspaceAPI implementation in LWC directly. To be explored | |
invokeWorkspaceAPI(methodName, methodArgs) { | |
console.log('invokeWorkspaceAPI: '); | |
return new Promise((resolve, reject) => { | |
const apiEvent = new CustomEvent("internalapievent", { | |
bubbles: true, | |
composed: true, | |
cancelable: false, | |
detail: { | |
category: "workspaceAPI", | |
methodName: methodName, | |
methodArgs: methodArgs, | |
callback: (err, response) => { | |
if (err) { | |
return reject(err); | |
} else { | |
return resolve(response); | |
} | |
} | |
} | |
}); | |
window.dispatchEvent(apiEvent); | |
this.dispatchEvent(apiEvent); | |
}); | |
} | |
openQuickTextSubtab() { | |
// HACK | |
let recordId = '5747a0000000EneAAE'; | |
this.invokeWorkspaceAPI('isConsoleNavigation').then(isConsole => { | |
console.log('WorkspaceAPI: isConsole: ', isConsole); | |
if (isConsole) { | |
this.invokeWorkspaceAPI('getFocusedTabInfo').then(focusedTab => { | |
this.invokeWorkspaceAPI('closeTab', { | |
tabId: focusedTab.tabId, | |
}).then(tabId => { | |
console.log('SubTab ID: ', tabId); | |
}); | |
// this.invokeWorkspaceAPI('openSubtab', { | |
// parentTabId: focusedTab.tabId, | |
// recordId: recordId, | |
// focus: true | |
// }).then(tabId => { | |
// console.log('SubTab ID: ', tabId); | |
// }); | |
}); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment