Skip to content

Commit

Permalink
Re-add queryId to pass to the Submenu target url . Otherwise the wron…
Browse files Browse the repository at this point in the history
…g element will be highlighted in the submenu. This was accidentally removed during the refactoring of the boards submenu
  • Loading branch information
HDinger committed Jun 28, 2024
1 parent 0192773 commit 142b883
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 23 deletions.
16 changes: 15 additions & 1 deletion frontend/src/app/core/main-menu/submenu.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,30 @@ import { StateService } from '@uirouter/core';
export class SubmenuService {
constructor(protected $state:StateService) {}

reloadSubmenu():void {
reloadSubmenu(selectedQueryId:string|null):void {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
const menuIdentifier:string|undefined = this.$state.current.data.sideMenuOptions?.sidemenuId;

if (menuIdentifier) {
const menu = (document.getElementById(menuIdentifier) as HTMLElement&TurboElement);
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
const sideMenuOptions = this.$state.$current.data?.sideMenuOptions as { hardReloadOnBaseRoute?:boolean, defaultQuery?:string };
const currentSrc = menu.getAttribute('src');

if (currentSrc && menu) {
const frameUrl = new URL(currentSrc);
const defaultQuery = sideMenuOptions.defaultQuery;

if (selectedQueryId) {
// If there is a default query passed in the route definition, it means that id passed as argument and not as parameter,
// e.g. calendars/:id, team_planner/:id, ...
// Otherwise, we will just replace the params
if (defaultQuery) {
frameUrl.search = `?id=${selectedQueryId}`;
} else {
frameUrl.search = `?query_id=${selectedQueryId}`;
}
}

// Override the frame src to enforce a reload
menu.setAttribute('src', frameUrl.href);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,22 @@ import {
ToolbarButtonComponentDefinition,
ViewPartitionState,
} from 'core-app/features/work-packages/routing/partitioned-query-space-page/partitioned-query-space-page.component';
import { StateService, TransitionService } from '@uirouter/core';
import {
StateService,
TransitionService,
} from '@uirouter/core';
import { BoardFilterComponent } from 'core-app/features/boards/board/board-filter/board-filter.component';
import { Board } from 'core-app/features/boards/board/board';
import { ToastService } from 'core-app/shared/components/toaster/toast.service';
import { HalResourceNotificationService } from 'core-app/features/hal/services/hal-resource-notification.service';
import { BoardService } from 'core-app/features/boards/board/board.service';
import { DragAndDropService } from 'core-app/shared/helpers/drag-and-drop/drag-and-drop.service';
import { WorkPackageFilterButtonComponent } from 'core-app/features/work-packages/components/wp-buttons/wp-filter-button/wp-filter-button.component';
import { ZenModeButtonComponent } from 'core-app/features/work-packages/components/wp-buttons/zen-mode-toggle-button/zen-mode-toggle-button.component';
import { BoardsMenuButtonComponent } from 'core-app/features/boards/board/toolbar-menu/boards-menu-button.component';
import { RequestSwitchmap } from 'core-app/shared/helpers/rxjs/request-switchmap';
import { componentDestroyed } from '@w11k/ngx-componentdestroyed';
import {
catchError,
finalize,
take,
tap,
} from 'rxjs/operators';
import { I18nService } from 'core-app/core/i18n/i18n.service';
import { UntilDestroyedMixin } from 'core-app/shared/helpers/angular/until-destroyed.mixin';
Expand All @@ -35,11 +34,7 @@ import { BoardFiltersService } from 'core-app/features/boards/board/board-filter
import { CardViewHandlerRegistry } from 'core-app/features/work-packages/components/wp-card-view/event-handler/card-view-handler-registry';
import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';
import { OpTitleService } from 'core-app/core/html/op-title.service';
import {
EMPTY,
Observable,
of,
} from 'rxjs';
import { EMPTY } from 'rxjs';
import { SubmenuService } from 'core-app/core/main-menu/submenu.service';

export function boardCardViewHandlerFactory(injector:Injector) {
Expand Down Expand Up @@ -249,6 +244,6 @@ export class BoardPartitionedPageComponent extends UntilDestroyedMixin {
}

private reloadSidemenu():void {
this.submenuService.reloadSubmenu();
this.submenuService.reloadSubmenu(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ export class WorkPackagesListService {
// Reload the query, and then reload the menu
this.reloadQuery(createdQuery).subscribe(() => {
this.states.changes.queries.next(createdQuery.id);
this.reloadSidemenu();
this.reloadSidemenu(createdQuery.id);
});

return createdQuery;
Expand Down Expand Up @@ -313,7 +313,7 @@ export class WorkPackagesListService {
if (queryAccessibleByUser) {
void this.$state.go('.', { query_id: query.id, query_props: null }, { reload: true });
this.states.changes.queries.next(query.id);
this.reloadSidemenu();
this.reloadSidemenu(query.id);
} else {
this.navigateToDefaultQuery(query);
}
Expand Down Expand Up @@ -344,7 +344,7 @@ export class WorkPackagesListService {
this.toastService.addSuccess(this.I18n.t('js.notice_successful_update'));

this.states.changes.queries.next(query.id!);
this.reloadSidemenu();
this.reloadSidemenu(query.id);
});

return promise;
Expand Down Expand Up @@ -458,11 +458,11 @@ export class WorkPackagesListService {
void this.loadDefaultQuery(projectId);

this.states.changes.queries.next(query.id);
this.reloadSidemenu();
this.reloadSidemenu(null);
}
}

private reloadSidemenu():void {
this.submenuService.reloadSubmenu();
private reloadSidemenu(selectedQueryId:string|null):void {
this.submenuService.reloadSubmenu(selectedQueryId);
}
}
2 changes: 1 addition & 1 deletion modules/calendar/spec/features/query_handling_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
calendar_page.expect_and_dismiss_toaster(message: I18n.t("js.notice_successful_create"))

# The saved query appears in the side menu...
query_menu.expect_item "I am your Query"
query_menu.expect_item "I am your Query", selected: true
query_menu.expect_item saved_query.name

# .. but not in the work packages module
Expand Down
2 changes: 1 addition & 1 deletion modules/team_planner/spec/features/query_handling_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
team_planner.expect_and_dismiss_toaster(message: I18n.t("js.notice_successful_create"))

# The saved query appears in the side menu...
query_menu.expect_item "I am your Query"
query_menu.expect_item "I am your Query", selected: true

# .. but not in the work packages module
work_package_page.visit!
Expand Down
6 changes: 3 additions & 3 deletions spec/features/views/shared_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
settings_menu.open_and_save_query "My first query"
query_title.expect_not_changed
query_title.expect_title "My first query"
query_menu.expect_item "My first query"
query_menu.expect_item "My first query", selected: true

# Change the filter again
filters.add_filter_by "% Complete", "is", ["25"], "percentageDone"
Expand All @@ -55,7 +55,7 @@
settings_menu.open_and_save_query_as "My second query"
query_title.expect_not_changed
query_title.expect_title "My second query"
query_menu.expect_item "My second query"
query_menu.expect_item "My second query", selected: true
query_menu.expect_item "My first query"

# Rename a query
Expand All @@ -67,7 +67,7 @@

query_title.expect_not_changed
query_title.expect_title "My second query (renamed)"
query_menu.expect_item "My second query (renamed)"
query_menu.expect_item "My second query (renamed)", selected: true
query_menu.expect_item "My first query"

# Delete a query
Expand Down

0 comments on commit 142b883

Please sign in to comment.