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
Fix waitForElement if element is already present
Oliver Güntherb6ec1941cff1
diff --git a/frontend/src/app/core/setup/globals/onboarding/helpers.ts b/frontend/src/app/core/setup/globals/onboarding/helpers.tsindex 804470ae0f9..2ee499c4dd2 100644--- a/frontend/src/app/core/setup/globals/onboarding/helpers.ts+++ b/frontend/src/app/core/setup/globals/onboarding/helpers.ts@@ -2,20 +2,46 @@ export const demoProjectName = 'Demo project';export const scrumDemoProjectName = 'Scrum project';export const onboardingTourStorageKey = 'openProject-onboardingTour';export type OnboardingTourNames = 'prepareBacklogs'|'backlogs'|'taskboard'|'homescreen'|'main';+export enum ProjectName {demo = 'demo',scrum = 'scrum',}-export function waitForElement(element:string, container:string, execFunction:Function) {+function matchingFilter(list:NodeListOf<HTMLElement>, filterFunction:(match:HTMLElement) => boolean):HTMLElement|null {+ for (let i = 0; i < list.length; i++) {+ if (filterFunction(list[i])) {+ return list[i];+ }+ }++ return null;+}++export function waitForElement(+ selector:string,+ containerSelector:string,+ execFunction:(match:HTMLElement) => void,+ filterFunction:(match:HTMLElement) => boolean = () => true,+):void {+ const container = document.querySelector(containerSelector) as HTMLElement;+ // If the element is ready immediately+ const initial = matchingFilter(container.querySelectorAll<HTMLElement>(selector), filterFunction);+ if (initial) {+ execFunction(initial);+ return;+ }+// Wait for the element to be readyconst observer = new MutationObserver((mutations, observerInstance) => {- if (jQuery(element).length) {- observerInstance.disconnect(); // stop observing- execFunction();+ const matches = matchingFilter(container.querySelectorAll<HTMLElement>(selector), filterFunction);+ if (matches) {+ execFunction(matches);+ observerInstance.disconnect();}});- observer.observe(jQuery(container)[0], {++ observer.observe(container, {childList: true,subtree: true,});diff --git a/frontend/src/app/core/setup/globals/onboarding/tours/boards_tour.ts b/frontend/src/app/core/setup/globals/onboarding/tours/boards_tour.tsindex 9701be66514..b6a7b542b94 100644--- a/frontend/src/app/core/setup/globals/onboarding/tours/boards_tour.ts+++ b/frontend/src/app/core/setup/globals/onboarding/tours/boards_tour.ts@@ -21,9 +21,12 @@ export function boardTourSteps(edition:'basic'|'enterprise', project:ProjectNamenextButton: { text: I18n.t('js.onboarding.buttons.next') },onNext() {jQuery('.board-view-menu-item ~ .toggler')[0].click();- waitForElement('.op-sidemenu--items', '#main-menu', () => {- jQuery(`.op-sidemenu--item-action:contains(${boardName})`)[0].click();- });+ waitForElement(+ '.op-sidemenu--item-action',+ '#main-menu',+ (match) => match.click(),+ (match) => !!match.textContent?.includes(boardName),+ );},},{diff --git a/frontend/src/app/core/setup/globals/onboarding/tours/team_planners_tour.ts b/frontend/src/app/core/setup/globals/onboarding/tours/team_planners_tour.tsindex 9b3eab46f7d..d46bd17c6ed 100644--- a/frontend/src/app/core/setup/globals/onboarding/tours/team_planners_tour.ts+++ b/frontend/src/app/core/setup/globals/onboarding/tours/team_planners_tour.ts@@ -9,9 +9,13 @@ export function teamPlannerTourSteps():OnboardingStep[] {nextButton: { text: I18n.t('js.onboarding.buttons.next') },onNext() {jQuery('.team-planner-view-menu-item ~ .toggler')[0].click();- waitForElement('.op-sidemenu--items', '#main-menu', () => {- jQuery(".op-sidemenu--item-action:contains('Team planner')")[0].click();- });++ waitForElement(+ '.op-sidemenu--item-action',+ '#main-menu',+ (match) => match.click(),+ (match) => !!match.textContent?.includes('Team planner'),+ );},},{