@@ -491,30 +491,42 @@ export default function (context) {
491491 * @param {string } [options.pane] To open a specific dashboard pane
492492 * @returns {Promise<void> }
493493 */
494- async function showDashboard ( subject , options = { } ) {
494+ function closeDashboard ( ) {
495495 const dashboardContainer = getDashboardContainer ( )
496496 const outlineContainer = getOutlineContainer ( )
497+ dashboardContainer . innerHTML = ''
498+ hideGlobalContainer ( dashboardContainer )
499+ showGlobalContainer ( outlineContainer )
500+ }
497501
498- function showContainer ( container ) {
499- container . removeAttribute ( 'hidden' )
500- container . style . display = ''
501- }
502+ // Register the closeDashboard listener only once
503+ authSession . events . on ( 'logout' , closeDashboard )
502504
503- function hideContainer ( container ) {
504- container . setAttribute ( 'hidden' , '' )
505- container . style . display = 'none'
506- }
505+ function showGlobalContainer ( container ) {
506+ container . removeAttribute ( 'hidden' )
507+ container . style . display = ''
508+ }
509+
510+ function hideGlobalContainer ( container ) {
511+ container . setAttribute ( 'hidden' , '' )
512+ container . style . display = 'none'
513+ }
507514
508- // reuse existing dashboard if already rendered for the requested pane
515+ async function showDashboard ( subject , options = { } ) {
516+ const dashboardContainer = getDashboardContainer ( )
517+ const outlineContainer = getOutlineContainer ( )
518+
519+ // reuse existing dashboard if already rendered for the same pane and subject
509520 if ( dashboardContainer . childNodes . length > 0 ) {
510521 const existingDashboard = dashboardContainer . firstElementChild
511522 if (
512523 existingDashboard &&
513524 options . pane &&
514- existingDashboard . dataset . globalPaneName === options . pane
525+ existingDashboard . dataset . globalPaneName === options . pane &&
526+ existingDashboard . dataset . subject === ( subject && subject . value || '' )
515527 ) {
516- hideContainer ( outlineContainer )
517- showContainer ( dashboardContainer )
528+ hideGlobalContainer ( outlineContainer )
529+ showGlobalContainer ( dashboardContainer )
518530 return
519531 }
520532 dashboardContainer . innerHTML = ''
@@ -529,18 +541,15 @@ export default function (context) {
529541 }
530542 )
531543
532- // close the dashboard if user log out
533544 authSession . events . on ( 'logout' , closeDashboard )
545+ if ( subject && subject . value ) {
546+ dashboard . dataset . subject = subject . value
547+ }
534548
535549 // finally - switch to showing dashboard
536- hideContainer ( outlineContainer )
537- showContainer ( dashboardContainer )
550+ hideGlobalContainer ( outlineContainer )
551+ showGlobalContainer ( dashboardContainer )
538552 dashboardContainer . appendChild ( dashboard )
539-
540- function closeDashboard ( ) {
541- hideContainer ( dashboardContainer )
542- showContainer ( outlineContainer )
543- }
544553 }
545554 this . showDashboard = showDashboard
546555
0 commit comments