OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Update hierarchical project dropdowns to fix keyboard behaviour
Benjamin Bädorf31ba7c1bf770
diff --git a/frontend/src/app/shared/components/header-project-select/header-project-select.component.html b/frontend/src/app/shared/components/header-project-select/header-project-select.component.htmlindex a1585747f26..b13f0896bef 100644--- a/frontend/src/app/shared/components/header-project-select/header-project-select.component.html+++ b/frontend/src/app/shared/components/header-project-select/header-project-select.component.html@@ -39,6 +39,8 @@data-qa-selector="op-header-project-select--search"data-modal-focus-catcher-container="true"(keydown)="searchableProjectListService.onKeydown($event, projects)"+ (inputFocus)="textFieldFocused = true"+ (inputBlur)="textFieldFocused = false"><spanslot="before"@@ -50,6 +52,7 @@<ul*ngIf="projects.length > 0; else noResultsTemplate"op-header-project-select-list+ [ngClass]="{ 'spot-list_active': textFieldFocused }"[projects]="projects"[searchText]="searchableProjectListService.searchText"[root]="true"diff --git a/frontend/src/app/shared/components/header-project-select/header-project-select.component.ts b/frontend/src/app/shared/components/header-project-select/header-project-select.component.tsindex eecafa0104d..220f1fdd140 100644--- a/frontend/src/app/shared/components/header-project-select/header-project-select.component.ts+++ b/frontend/src/app/shared/components/header-project-select/header-project-select.component.ts@@ -67,11 +67,13 @@ export const headerProjectSelectSelector = 'op-header-project-select';export class OpHeaderProjectSelectComponent extends UntilDestroyedMixin {@HostBinding('class.op-header-project-select') className = true;- dropModalOpen = false;+ public dropModalOpen = false;- canCreateNewProjects$ = this.currentUserService.hasCapabilities$('projects/create');+ public textFieldFocused = false;- projects$ = combineLatest([+ public canCreateNewProjects$ = this.currentUserService.hasCapabilities$('projects/create');++ public projects$ = combineLatest([this.searchableProjectListService.allProjects$,this.searchableProjectListService.searchText$.pipe(debounceTime(200)),]).pipe(@@ -95,7 +97,12 @@ export class OpHeaderProjectSelectComponent extends UntilDestroyedMixin {(list, project) => {const { ancestors } = project._links;- return insertInList(projects, project, list, ancestors);+ return insertInList(+ projects,+ project,+ list,+ ancestors,+ );},[] as IProjectData[],),@@ -145,7 +152,7 @@ export class OpHeaderProjectSelectComponent extends UntilDestroyedMixin {this.projects$.pipe(this.untilDestroyed()).subscribe((projects) => {- this.searchableProjectListService.resetActiveResult(projects[0]?.id);+ this.searchableProjectListService.resetActiveResult(projects);});}diff --git a/frontend/src/app/shared/components/header-project-select/insert-in-list.ts b/frontend/src/app/shared/components/header-project-select/insert-in-list.tsnew file mode 100644index 00000000000..952e3df98dc--- /dev/null+++ b/frontend/src/app/shared/components/header-project-select/insert-in-list.ts@@ -0,0 +1,60 @@+import { IProject } from 'core-app/core/state/projects/project.model';+import { IHalResourceLink } from 'core-app/core/state/hal-resource';+import { IProjectData } from 'core-app/shared/components/searchable-project-list/project-data';++const UNDISCLOSED_ANCESTOR = 'urn:openproject-org:api:v3:undisclosed';++// Helper function that recursively inserts a project into the hierarchy at the right place+export const insertInList = (+ projects:IProject[],+ project:IProject,+ list:IProjectData[],+ ancestors:IHalResourceLink[],+):IProjectData[] => {+ // In a set of projects, some of the ancestors may be undisclosed. The client then knows of its existence+ // but knows nothing more than that. Those projects receive an 'undisclosed' urn for their href. For building+ // the project hierarchy, they can be ignored.+ const visibleAncestors = ancestors.filter((ancestor) => ancestor.href !== UNDISCLOSED_ANCESTOR);++ if (!visibleAncestors.length) {+ return [+ ...list,+ {+ id: project.id,+ name: project.name,+ href: project._links.self.href,+ disabled: false,+ children: [],+ },+ ];+ }++ const ancestorHref = visibleAncestors[0].href;+ const ancestor:IProjectData|undefined = list.find((projectInList) => projectInList.href === ancestorHref);++ if (ancestor) {+ ancestor.children = insertInList(+ projects,+ project,+ ancestor.children,+ visibleAncestors.slice(1),+ );+ return [...list];+ }++ const ancestorProject = projects.find((projectInList) => projectInList._links.self.href === ancestorHref);+ if (!ancestorProject) {+ return [...list];+ }++ return [+ ...list,+ {+ id: ancestorProject.id,+ name: ancestorProject.name,+ href: ancestorProject._links.self.href,+ disabled: true,+ children: insertInList(projects, project, [], visibleAncestors.slice(1)),+ },+ ];+};diff --git a/frontend/src/app/shared/components/header-project-select/list/header-project-select-list.component.html b/frontend/src/app/shared/components/header-project-select/list/header-project-select-list.component.htmlindex 7933f18ec51..d242473594b 100644--- a/frontend/src/app/shared/components/header-project-select/list/header-project-select-list.component.html+++ b/frontend/src/app/shared/components/header-project-select/list/header-project-select-list.component.html@@ -5,6 +5,7 @@[attr.data-list-selector]="projectListItemIdentifier"><a+ tabindex="-1"*ngIf="!project.disabled"class="spot-list--item-action"[ngClass]="{diff --git a/frontend/src/app/shared/components/project-include/list/project-include-list.component.html b/frontend/src/app/shared/components/project-include/list/project-include-list.component.htmlindex d0660301050..284095f243f 100644--- a/frontend/src/app/shared/components/project-include/list/project-include-list.component.html+++ b/frontend/src/app/shared/components/project-include/list/project-include-list.component.html@@ -9,28 +9,29 @@class="spot-list--item-action op-project-include-list--item-action"(keydown.space)="changeSelected(project)"[ngClass]="{- 'spot-list--item-action_disabled': isDisabled(project),+ 'spot-list--item-action_disabled': project.disabled,'spot-list--item-action_active': (searchableProjectListService.activeItemID$ | async) === project.id}"[attr.data-list-selector]="projectListActionIdentifier"- [attr.data-list-disabled]="isDisabled(project) || undefined"+ [attr.data-list-disabled]="project.disabled || undefined"><spot-tooltipclass="op-project-include-list--tooltip"[alignment]="getTooltipAlignment(project, isFirst, isLast)"- [disabled]="!isDisabled(project)"+ [disabled]="!project.disabled"[dark]="true"><ng-container slot="trigger"><spot-checkbox+ [tabindex]="-1"[checked]="isChecked(project.href) || (includeSubprojects && parentChecked)"(change)="changeSelected(project)"- [disabled]="isDisabled(project)"+ [disabled]="project.disabled"[attr.data-qa-project-include-id]="project.id"[attr.data-qa-project-include-checked]="(isChecked(project.href) || (includeSubprojects && parentChecked)) ? 1 : 0"></spot-checkbox><div- class="spot-list--item-title spot-list--item-title_ellipsis"+ class="spot-list--item-title spot-list--item-title_ellipse-text"data-qa-selector="op-project-include-list--item-title"[opSearchHighlight]="searchText"[title]="project.name"diff --git a/frontend/src/app/shared/components/project-include/list/project-include-list.component.ts b/frontend/src/app/shared/components/project-include/list/project-include-list.component.tsindex 0e1d1c1aae2..6436a883e81 100644--- a/frontend/src/app/shared/components/project-include/list/project-include-list.component.ts+++ b/frontend/src/app/shared/components/project-include/list/project-include-list.component.ts@@ -55,18 +55,6 @@ export class OpProjectIncludeListComponent {readonly searchableProjectListService:SearchableProjectListService,) { }- public isDisabled(project:IProjectData):boolean {- if (project.disabled) {- return true;- }-- if (project.href === this.currentProjectHref) {- return true;- }-- return this.includeSubprojects && this.parentChecked;- }-public updateList(selected:string[]):void {this.update.emit(selected);}@@ -76,14 +64,13 @@ export class OpProjectIncludeListComponent {}public changeSelected(project:IProjectData):void {- const { href } = project;- const checked = this.isChecked(href);- const disabled = this.isDisabled(project);-- if (disabled) {+ if (project.disabled) {return;}+ const { href } = project;+ const checked = this.isChecked(href);+if (checked) {this.updateList(this.selected.filter((selectedHref) => selectedHref !== href));} else {diff --git a/frontend/src/app/shared/components/project-include/project-include.component.html b/frontend/src/app/shared/components/project-include/project-include.component.htmlindex 91bdb2834d5..c7f12a47a9b 100644--- a/frontend/src/app/shared/components/project-include/project-include.component.html+++ b/frontend/src/app/shared/components/project-include/project-include.component.html@@ -43,6 +43,8 @@data-list-focus-catcher-container="true"data-modal-focus-catcher-container="true"(keydown)="searchableProjectListService.onKeydown($event, projects)"+ (inputFocus)="textFieldFocused = true"+ (inputBlur)="textFieldFocused = false"><spanslot="before"@@ -54,6 +56,7 @@<ul*ngIf="projects.length > 0; else noResultsTemplate"class="op-project-include--list"+ [ngClass]="{ 'spot-list_active': textFieldFocused }"op-project-include-list[projects]="projects"[selected]="selectedProjects"diff --git a/frontend/src/app/shared/components/project-include/project-include.component.ts b/frontend/src/app/shared/components/project-include/project-include.component.tsindex c7623d47155..396357e2459 100644--- a/frontend/src/app/shared/components/project-include/project-include.component.ts+++ b/frontend/src/app/shared/components/project-include/project-include.component.ts@@ -14,8 +14,10 @@ import {distinctUntilChanged,filter,map,+ tap,mergeMap,shareReplay,+ skip,take,} from 'rxjs/operators';import { HalResource } from 'core-app/features/hal/resources/hal-resource';@@ -58,6 +60,8 @@ export class OpProjectIncludeComponent extends UntilDestroyedMixin implements Onpublic opened = false;+ public textFieldFocused = false;+public query$ = this.wpTableFilters.querySpace.query.values$();public displayModeOptions = [@@ -128,57 +132,91 @@ export class OpProjectIncludeComponent extends UntilDestroyedMixin implements Onpublic projects$ = combineLatest([this.searchableProjectListService.allProjects$,this.displayMode$.pipe(distinctUntilChanged()),- this.includeSubprojects$,+ this.includeSubprojects$.pipe(debounceTime(20)),this.searchableProjectListService.searchText$.pipe(debounceTime(200)),- ])- .pipe(- debounceTime(50),+ ]).pipe(mergeMap(([projects, displayMode, includeSubprojects, searchText]) => this.selectedProjects$.pipe(take(1),map((selected) => [projects, displayMode, includeSubprojects, searchText, selected]),)),map(- ([projects, displayMode, includeSubprojects, searchText, selected]:[IProject[], string, boolean, string, string[]]) => projects- .filter(- (project) => {- if (searchText.length) {- const matches = project.name.toLowerCase().includes(searchText.toLowerCase());-- if (!matches) {- return false;+ ([projects, displayMode, includeSubprojects, searchText, selected]:[IProject[], string, boolean, string, string[]]) => [+ projects+ .filter(+ (project) => {+ if (searchText.length) {+ const matches = project.name.toLowerCase().includes(searchText.toLowerCase());++ if (!matches) {+ return false;+ }+ }++ if (displayMode !== 'selected') {+ return true;}- }-- if (displayMode !== 'selected') {- return true;- }-- if (selected.includes(project._links.self.href)) {- return true;- }-- const hasSelectedAncestor = project._links.ancestors.reduce(- (anySelected, ancestor) => anySelected || selected.includes(ancestor.href),- false,- );-- if (includeSubprojects && hasSelectedAncestor) {- return true;- }-- return false;- },- )- .sort((a, b) => a._links.ancestors.length - b._links.ancestors.length)- .reduce(- (list, project) => {- const { ancestors } = project._links;-- return insertInList(projects, project, list, ancestors);- },- [] as IProjectData[],- ),++ if (selected.includes(project._links.self.href)) {+ return true;+ }++ const hasSelectedAncestor = project._links.ancestors.reduce(+ (anySelected, ancestor) => anySelected || selected.includes(ancestor.href),+ false,+ );++ if (includeSubprojects && hasSelectedAncestor) {+ return true;+ }++ return false;+ },+ )+ .sort((a, b) => a._links.ancestors.length - b._links.ancestors.length)+ .reduce(+ (list, project) => {+ const { ancestors } = project._links;++ return insertInList(+ projects,+ project,+ list,+ ancestors,+ );+ },+ [] as IProjectData[],+ ),+ includeSubprojects,+ ],),+ mergeMap(([projects, includeSubprojects]) => this.selectedProjects$.pipe(+ map((selected) => [projects, includeSubprojects, selected]),+ )),+ map(([projects, includeSubprojects, selected]: [IProjectData[], boolean, string[]]) => {+ const isDisabled = (project:IProjectData, parentChecked:boolean) => {+ if (project.disabled) {+ return true;+ }++ if (project.href === this.currentProjectService.apiv3Path) {+ return true;+ }++ return includeSubprojects && parentChecked;+ };++ const setDisabledStatus = (project:IProjectData, parentChecked:boolean):IProjectData => {+ return {+ ...project,+ disabled: isDisabled(project, parentChecked),+ children: project.children.map(+ (child) => setDisabledStatus(child, parentChecked || selected.includes(project.href)),+ ),+ };+ };++ return projects.map((project) => setDisabledStatus(project, false));+ }),map((projects) => recursiveSort(projects)),shareReplay(),);@@ -212,9 +250,13 @@ export class OpProjectIncludeComponent extends UntilDestroyedMixin implements Onsuper();this.projects$- .pipe(this.untilDestroyed())+ .pipe(+ this.untilDestroyed(),+ filter(p => p.length > 0),+ take(1),+ ).subscribe((projects) => {- this.searchableProjectListService.resetActiveResult(projects[0]?.id);+ this.searchableProjectListService.resetActiveResult(projects);});}diff --git a/frontend/src/app/shared/components/searchable-project-list/searchable-project-list.service.ts b/frontend/src/app/shared/components/searchable-project-list/searchable-project-list.service.tsindex ae14f085da0..c477fb0765f 100644--- a/frontend/src/app/shared/components/searchable-project-list/searchable-project-list.service.ts+++ b/frontend/src/app/shared/components/searchable-project-list/searchable-project-list.service.ts@@ -28,7 +28,7 @@ export class SearchableProjectListService {this.searchText$.next(val);}- activeItemID$ = new BehaviorSubject<ID>(0);+ activeItemID$ = new BehaviorSubject<ID|null>(null);searchText$ = new BehaviorSubject<string>('');@@ -103,11 +103,30 @@ export class SearchableProjectListService {});}- public resetActiveResult(id:ID):void {- this.activeItemID$.next(id);+ public resetActiveResult(projects:IProjectData[]):void {+ const findFirstNonDisabledID = (projects:IProjectData[]):ID|null => {+ for (let i = 0; i < projects.length; i++) {+ if (!projects[i].disabled) {+ return projects[i].id;+ }++ const childFound = findFirstNonDisabledID(projects[i].children);+ if (childFound !== null) {+ return childFound;+ }+ }++ return null;+ }++ this.activeItemID$.next(findFirstNonDisabledID(projects));}- private selectPreviousResult(id:ID, allProjects:IProjectData[]):void {+ private selectPreviousResult(activeID:ID|null, allProjects:IProjectData[]):void {+ if (activeID === null) {+ return;+ }+const findLastChild = (project:IProjectData):IProjectData => {if (project?.children?.length) {return findLastChild(project.children[project.children.length - 1]);@@ -116,14 +135,22 @@ export class SearchableProjectListService {return project;};- const findPreviousID = (projects:IProjectData[], parent?:IProjectData):ID|null => {+ const findPreviousID = (idOfCurrent:ID, projects:IProjectData[], parent?:IProjectData):ID|null => {for (let i = 0; i < projects.length; i++) {- if (projects[i].id === id) {+ if (projects[i].id === idOfCurrent) {const previous = findLastChild(projects[i - 1]) || projects[i - 1] || parent;- return previous?.id || null;+ if (!previous) {+ return null;+ }++ if (previous.disabled) {+ return findPreviousID(previous.id, allProjects);+ }++ return previous.id;}- const previous = findPreviousID(projects[i].children, projects[i]);+ const previous = findPreviousID(idOfCurrent, projects[i].children, projects[i]);if (previous !== null) {return previous;}@@ -132,19 +159,35 @@ export class SearchableProjectListService {return null;};- const foundPreviousID = findPreviousID(allProjects);- this.activeItemID$.next(foundPreviousID || allProjects[0]?.id || 0);+ const foundPreviousID = findPreviousID(activeID, allProjects);+ if (foundPreviousID !== null) {+ this.activeItemID$.next(foundPreviousID);+ } else {+ this.resetActiveResult(allProjects);+ }}- private selectNextResult(id:ID, allProjects:IProjectData[]):void {- const findNextID = (projects:IProjectData[], nextParent?:IProjectData):ID|null => {+ private selectNextResult(activeID:ID|null, allProjects:IProjectData[]):void {+ if (activeID === null) {+ return;+ }++ const findNextID = (idOfCurrent:ID, projects:IProjectData[], nextParent?:IProjectData):ID|null => {for (let i = 0; i < projects.length; i++) {- if (projects[i].id === id) {+ if (projects[i].id === idOfCurrent) {const next = projects[i].children[0] || projects[i + 1] || nextParent;- return next?.id || null;+ if (!next) {+ return null;+ }++ if (next.disabled) {+ return findNextID(next.id, allProjects);+ }++ return next.id;}- const next = findNextID(projects[i].children, projects[i + 1] || nextParent);+ const next = findNextID(idOfCurrent, projects[i].children, projects[i + 1] || nextParent);if (next !== null) {return next;}@@ -153,8 +196,12 @@ export class SearchableProjectListService {return null;};- const foundNextID = findNextID(allProjects);- this.activeItemID$.next(foundNextID || allProjects[0]?.id || 0);+ const foundNextID = findNextID(activeID, allProjects);+ if (foundNextID !== null) {+ this.activeItemID$.next(foundNextID);+ } else {+ this.resetActiveResult(allProjects);+ }}private activateSelectedResult(event:KeyboardEvent):void {diff --git a/frontend/src/app/spot/components/checkbox/checkbox.component.html b/frontend/src/app/spot/components/checkbox/checkbox.component.htmlindex 25ce0539775..9940edcf6c1 100644--- a/frontend/src/app/spot/components/checkbox/checkbox.component.html+++ b/frontend/src/app/spot/components/checkbox/checkbox.component.html@@ -5,6 +5,7 @@[disabled]="disabled"[checked]="checked"(change)="onStateChange()"+ [tabindex]="tabindex"#input/><span class="spot-checkbox--fake"></span>diff --git a/frontend/src/app/spot/components/checkbox/checkbox.component.ts b/frontend/src/app/spot/components/checkbox/checkbox.component.tsindex c7765cfd979..b54fa8965f9 100644--- a/frontend/src/app/spot/components/checkbox/checkbox.component.ts+++ b/frontend/src/app/spot/components/checkbox/checkbox.component.ts@@ -29,6 +29,8 @@ export class SpotCheckboxComponent implements ControlValueAccessor {@ViewChild('input') public input:ElementRef;+ @Input() tabindex = 0;+@Input() disabled = false;@Input() name = `spot-checkbox-${+(new Date())}`;diff --git a/frontend/src/app/spot/components/text-field/text-field.component.html b/frontend/src/app/spot/components/text-field/text-field.component.htmlindex 7569e2c0e77..f4f78fb949d 100644--- a/frontend/src/app/spot/components/text-field/text-field.component.html+++ b/frontend/src/app/spot/components/text-field/text-field.component.html@@ -5,8 +5,8 @@[disabled]="disabled"[placeholder]="placeholder"[(ngModel)]="value"- (focus)="focused = true"- (blur)="focused = false"+ (focus)="onInputFocus($event)"+ (blur)="onInputBlur($event)"#input/><buttondiff --git a/frontend/src/app/spot/components/text-field/text-field.component.ts b/frontend/src/app/spot/components/text-field/text-field.component.tsindex c574c4988e4..b594f5d626a 100644--- a/frontend/src/app/spot/components/text-field/text-field.component.ts+++ b/frontend/src/app/spot/components/text-field/text-field.component.ts@@ -6,6 +6,8 @@ import {HostBinding,HostListener,Input,+ Output,+ EventEmitter,} from '@angular/core';import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';@@ -49,6 +51,20 @@ export class SpotTextFieldComponent implements ControlValueAccessor {this.onTouched(value);}+ @Output() public inputFocus = new EventEmitter<FocusEvent>();++ @Output() public inputBlur = new EventEmitter<FocusEvent>();++ onInputFocus(event:FocusEvent):void {+ this.focused = true;+ this.inputFocus.next(event);+ }++ onInputBlur(event:FocusEvent):void {+ this.focused = false;+ this.inputBlur.next(event);+ }+writeValue(value:string) {this.value = value || '';}diff --git a/frontend/src/app/spot/styles/sass/components/list.sass b/frontend/src/app/spot/styles/sass/components/list.sassindex ee8684d155f..065aa19346d 100644--- a/frontend/src/app/spot/styles/sass/components/list.sass+++ b/frontend/src/app/spot/styles/sass/components/list.sass@@ -30,7 +30,6 @@&:focus@include spot-focus- &_active,&:hovercolor: var(--content-link-hover-active-color)background-color: $spot-color-basic-gray-6@@ -99,6 +98,11 @@&_compact &--item-floating-actionspadding: $spot-spacing-0_25 $spot-spacing-1+ &_active &--item-action_active+ color: var(--content-link-hover-active-color)+ background-color: $spot-color-basic-gray-6+ text-decoration: none+$item-list: ""@for $i from 0 through 10$item-list: list.append($item-list, ".spot-list--item")