diff --git a/frontend/app/components/wp-panels/keep-tab/keep-tab.service.test.ts b/frontend/app/components/wp-panels/keep-tab/keep-tab.service.test.ts index f00914f95c..8e085f14ac 100644 --- a/frontend/app/components/wp-panels/keep-tab/keep-tab.service.test.ts +++ b/frontend/app/components/wp-panels/keep-tab/keep-tab.service.test.ts @@ -107,6 +107,21 @@ describe('keepTab service', () => { }); }); + describe('when opening show#activity', () => { + beforeEach(() => { + var includes = sinon.stub($state, 'includes'); + includes.withArgs('work-packages.show.*').returns(true); + includes.withArgs('work-packages.list.details.*').returns(false); + + $state.current.name = 'work-packages.show.activity'; + $rootScope.$emit('$stateChangeSuccess', $state.current); + }); + + it('should set the tab to overview', () => { + expect(keepTab.currentDetailsState).to.eq('work-packages.list.details.overview'); + }); + }); + describe('when opening a details route', () => { beforeEach(() => { var includes = sinon.stub($state, 'includes'); diff --git a/frontend/app/components/wp-panels/keep-tab/keep-tab.service.ts b/frontend/app/components/wp-panels/keep-tab/keep-tab.service.ts index c05ecddeda..fee263b0c5 100644 --- a/frontend/app/components/wp-panels/keep-tab/keep-tab.service.ts +++ b/frontend/app/components/wp-panels/keep-tab/keep-tab.service.ts @@ -35,8 +35,8 @@ export class KeepTabService { 'ngInject'; this.updateTabs(); - $rootScope.$on('$stateChangeSuccess', () => { - this.updateTabs(); + $rootScope.$on('$stateChangeSuccess', (_event, toState) => { + this.updateTabs(toState); }); } @@ -66,20 +66,33 @@ export class KeepTabService { return this.currentTab; } + protected notify() { + // Notify when updated + this.subject.onNext({ + show: this.currentShowState, + details: this.currentDetailsState + }); + } + protected updateTab(stateName:string) { if (this.$state.includes(stateName)) { const current = this.$state.current.name; this.currentTab = current.split('.').pop(); - // Notify when updated - this.subject.onNext({ - show: this.currentShowState, - details: this.currentDetailsState - }); + this.notify(); } } - protected updateTabs() { + protected updateTabs(toState?:any) { + + // Ignore the switch from show#activity to details#activity + // and show details#overview instead + + if (toState && toState.name === 'work-packages.show.activity') { + this.currentTab = 'overview'; + return this.notify(); + } + this.updateTab('work-packages.show.*'); this.updateTab('work-packages.list.details.*'); }