diff --git a/packages/zowe-explorer/src/job/ZosJobsProvider.ts b/packages/zowe-explorer/src/job/ZosJobsProvider.ts index 4e477883dd..249107cea0 100644 --- a/packages/zowe-explorer/src/job/ZosJobsProvider.ts +++ b/packages/zowe-explorer/src/job/ZosJobsProvider.ts @@ -455,17 +455,19 @@ export class ZosJobsProvider extends ZoweTreeProvider implements IZoweTree !(temp.label === node.label && temp.contextValue.startsWith(node.contextValue)) - ); - // Remove profile node from Favorites if it contains no more favorites. - if (profileNodeInFavorites.children.length < 1) { - return this.removeFavProfile(profileName, false); - } - if (startLength !== profileNodeInFavorites.children.length) { - await this.updateFavorites(); - this.refreshElement(this.mFavoriteSession); + if (profileNodeInFavorites) { + const startLength = profileNodeInFavorites.children.length; + profileNodeInFavorites.children = profileNodeInFavorites.children.filter( + (temp) => !(temp.label === node.label && temp.contextValue.startsWith(node.contextValue)) + ); + // Remove profile node from Favorites if it contains no more favorites. + if (profileNodeInFavorites.children.length < 1) { + return this.removeFavProfile(profileName, false); + } + if (startLength !== profileNodeInFavorites.children.length) { + await this.updateFavorites(); + this.refreshElement(this.mFavoriteSession); + } } return; }