Repository navigation
Dynamically calculate the space the warning bar will take, instead of hard-coding 100px #26041
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
klaustopher
wants to merge
1
commit into
dev
Choose a base branch
from
warning-bar-size
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,8 @@ | ||
| <% if show_warning_bar? %> | ||
| <div class="warning-bar--wrapper"> | ||
| <%= render partial: "warning_bar/host_and_protocol_mismatch" if render_host_and_protocol_mismatch? %> | ||
| <%= render partial: "warning_bar/pending_migrations" if render_pending_migrations_warning? %> | ||
| <%= render partial: "warning_bar/unsupported_browser" if unsupported_browser? %> | ||
| <%= render partial: "warning_bar/missing_wp_edit_role_workflows" if render_workflow_missing_warning? %> | ||
| <div class="warning-bar--wrapper" data-controller="warning-bar"> | ||
| <% if show_warning_bar? %> | ||
| <%= render partial: "warning_bar/host_and_protocol_mismatch" if render_host_and_protocol_mismatch? %> | ||
| <%= render partial: "warning_bar/pending_migrations" if render_pending_migrations_warning? %> | ||
| <%= render partial: "warning_bar/unsupported_browser" if unsupported_browser? %> | ||
| <%= render partial: "warning_bar/missing_wp_edit_role_workflows" if render_workflow_missing_warning? %> | ||
| <% end %> | ||
| </div> | ||
| <% end %> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
frontend/src/stimulus/controllers/dynamic/warning-bar.controller.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| //-- copyright | ||
| // OpenProject is an open source project management software. | ||
| // Copyright (C) the OpenProject GmbH | ||
| // | ||
| // This program is free software; you can redistribute it and/or | ||
| // modify it under the terms of the GNU General Public License version 3. | ||
| // | ||
| // OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: | ||
| // Copyright (C) 2006-2013 Jean-Philippe Lang | ||
| // Copyright (C) 2010-2013 the ChiliProject Team | ||
| // | ||
| // This program is free software; you can redistribute it and/or | ||
| // modify it under the terms of the GNU General Public License | ||
| // as published by the Free Software Foundation; either version 2 | ||
| // of the License, or (at your option) any later version. | ||
| // | ||
| // This program is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU General Public License for more details. | ||
| // | ||
| // You should have received a copy of the GNU General Public License | ||
| // along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
| // | ||
| // See COPYRIGHT and LICENSE files for more details. | ||
| //++ | ||
|
|
||
| import { waitFor } from '@testing-library/dom'; | ||
|
|
||
| import WarningBarController from './warning-bar.controller'; | ||
| import { setupStimulusTest, type StimulusTestContext } from 'core-stimulus/test-helpers'; | ||
|
|
||
| describe('WarningBarController', () => { | ||
| let ctx:StimulusTestContext; | ||
|
|
||
| const warningBarHeight = () => document.documentElement.style.getPropertyValue('--warning-bar-height'); | ||
|
|
||
| beforeEach(async () => { | ||
| ctx = await setupStimulusTest({ | ||
| controllers: { 'warning-bar': WarningBarController }, | ||
| }); | ||
| }); | ||
|
|
||
| afterEach(() => ctx.dispose()); | ||
|
|
||
| it('publishes the height of the bar', async () => { | ||
| await ctx.mount(` | ||
| <div data-controller="warning-bar"> | ||
| <div style="height: 42px"></div> | ||
| </div> | ||
| `); | ||
|
|
||
| await waitFor(() => { | ||
| expect(warningBarHeight()).toBe('42px'); | ||
| }); | ||
| }); | ||
|
|
||
| it('publishes the new height when the bar grows', async () => { | ||
| await ctx.mount(` | ||
| <div data-controller="warning-bar"> | ||
| <div id="banner" style="height: 42px"></div> | ||
| </div> | ||
| `); | ||
| await waitFor(() => expect(warningBarHeight()).toBe('42px')); | ||
|
|
||
| document.getElementById('banner')!.style.height = '80px'; | ||
|
|
||
| await waitFor(() => { | ||
| expect(warningBarHeight()).toBe('80px'); | ||
| }); | ||
| }); | ||
|
|
||
| it('publishes no height for an empty bar', async () => { | ||
| await ctx.mount('<div data-controller="warning-bar"></div>'); | ||
|
|
||
| await waitFor(() => { | ||
| expect(warningBarHeight()).toBe('0px'); | ||
| }); | ||
| }); | ||
|
|
||
| it('removes the height when the bar is removed', async () => { | ||
| await ctx.mount(` | ||
| <div data-controller="warning-bar"> | ||
| <div style="height: 42px"></div> | ||
| </div> | ||
| `); | ||
| await waitFor(() => expect(warningBarHeight()).toBe('42px')); | ||
|
|
||
| document.querySelector('[data-controller="warning-bar"]')!.remove(); | ||
|
|
||
| await waitFor(() => { | ||
| expect(warningBarHeight()).toBe(''); | ||
| }); | ||
| }); | ||
| }); |
46 changes: 46 additions & 0 deletions
46
frontend/src/stimulus/controllers/dynamic/warning-bar.controller.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| //-- copyright | ||
| // OpenProject is an open source project management software. | ||
| // Copyright (C) the OpenProject GmbH | ||
| // | ||
| // This program is free software; you can redistribute it and/or | ||
| // modify it under the terms of the GNU General Public License version 3. | ||
| // | ||
| // OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: | ||
| // Copyright (C) 2006-2013 Jean-Philippe Lang | ||
| // Copyright (C) 2010-2013 the ChiliProject Team | ||
| // | ||
| // This program is free software; you can redistribute it and/or | ||
| // modify it under the terms of the GNU General Public License | ||
| // as published by the Free Software Foundation; either version 2 | ||
| // of the License, or (at your option) any later version. | ||
| // | ||
| // This program is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU General Public License for more details. | ||
| // | ||
| // You should have received a copy of the GNU General Public License | ||
| // along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
| // | ||
| // See COPYRIGHT and LICENSE files for more details. | ||
| //++ | ||
|
|
||
| import { Controller } from '@hotwired/stimulus'; | ||
|
|
||
| export default class WarningBarController extends Controller<HTMLElement> { | ||
| private resizeObserver:ResizeObserver; | ||
|
|
||
| connect() { | ||
| this.resizeObserver = new ResizeObserver(() => this.publishHeight()); | ||
| this.resizeObserver.observe(this.element); | ||
| } | ||
|
|
||
| disconnect() { | ||
| this.resizeObserver.disconnect(); | ||
| document.documentElement.style.removeProperty('--warning-bar-height'); | ||
| } | ||
|
|
||
| private publishHeight() { | ||
| document.documentElement.style.setProperty('--warning-bar-height', `${this.element.offsetHeight}px`); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not a big fan of running a resizeObserver constantly even if the bar is not shown at all. Why did you move the div which registers the controller outside the check?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because
show_warning_bar?will not be the only condition. In the PR it will render the sudo banner inside this as well. So the wrapper is always present, just without any content.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A resize observer is not really "running" anything. It is invoked when a resize happens, not constantly running a loop and polling for changes.