Skip to content
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

add global trigger warning #155

Merged
merged 3 commits into from
Oct 16, 2024

Conversation

koilebeit
Copy link

@koilebeit koilebeit commented Oct 10, 2024

Pull request

Proposed changes

First draft to solve #154
To discuss:

  • session storage or local storage
  • design of the trigger warning

Types of changes

  • New feature (non-breaking change which adds functionality).
  • Enhancement (non-breaking change which enhances functionality)
  • Bug Fix (non-breaking change which fixes an issue).
  • Breaking change (fix or feature that would cause existing functionality to change).

Checklist

  • I have read the CONTRIBUTING document.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

Summary by CodeRabbit

  • New Features

    • Introduced a dynamic trigger warning modal for sensitive content, enhancing user awareness.
    • Updated trigger warning text to provide a more comprehensive understanding of historical materials.
  • Bug Fixes

    • Removed outdated static alert for sensitive content from various pages, streamlining user experience.
  • Documentation

    • Deleted the sensible-inhalte.md page, previously outlining sensitive content warnings and related topics.

Copy link

changeset-bot bot commented Oct 10, 2024

⚠️ No Changeset found

Latest commit: 8c690e6

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

coderabbitai bot commented Oct 10, 2024

Walkthrough

The changes in this pull request involve modifications to the trigger warning settings for item pages and the introduction of a new modal component for displaying these warnings. The _data/theme.yml file has been updated to apply trigger warnings to the index.md page instead of individual item pages, with revised warning text. A new modal in _includes/feature/trigger-warning.html displays the warning, and JavaScript functionality in _includes/js/trigger-warning-js.html manages its visibility. Additionally, the previous alert system has been removed from various layout files, streamlining the presentation of sensitive content.

Changes

File Path Change Summary
_data/theme.yml Updated trigger warning settings to apply to index.md and revised warning text.
_includes/feature/trigger-warning.html Added a new modal component for displaying trigger warnings.
_includes/js/trigger-warning-js.html Introduced JavaScript functionality to manage the display of the trigger warning modal.
_layouts/browse.html Removed conditional block displaying a warning alert for sensitive content.
_layouts/item/item-page-base.html Removed inclusion of the trigger-warning.html component from the layout.
_layouts/item/item-page-full-width.html Removed inclusion of the trigger-warning.html template and updated comments.
pages/index.md Removed static alert for sensitive content and included new trigger warning components.
pages/sensible-inhalte.md Deleted page outlining sensitive content warnings and their purpose.

Possibly related issues

  • Global Trigger Warning (Global Trigger Warning #154): The changes in this PR align with the request for a global trigger warning that covers the entire display and is shown only once per visitor, as the new modal system addresses similar objectives.

🐇✨ In the meadow, where warnings bloom,
A modal now whispers, dispelling the gloom.
With history's tales, we tread with care,
A gentle reminder, for all who dare.
So hop along, dear friends, take heed,
For knowledge is power, and kindness, our creed! 🌼📜


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (4)
_includes/js/trigger-warning-js.html (3)

3-10: The hideWarning function looks good, with some suggestions for improvement.

The function correctly hides the modal and sets a session storage item. However, consider the following enhancements:

  1. Add error handling in case the modal element is not found.
  2. Consider using local storage instead of session storage if you want the warning to remain dismissed across sessions.
  3. Ensure that the Bootstrap library is properly loaded before this script runs.

Here's a suggested improvement:

function hideWarning() {
  const modal = document.getElementById('triggerWarning');
  if (!modal) {
    console.error('Trigger warning modal not found');
    return;
  }
  const bootstrapModal = bootstrap.Modal.getInstance(modal) || new bootstrap.Modal(modal);
  bootstrapModal.hide();

  // Use localStorage instead of sessionStorage if you want the dismissal to persist across sessions
  localStorage.setItem('triggerWarningDismissed', 'true');
}

13-21: The window onload event handler is functional, but could be improved.

The event handler correctly checks for previous dismissal and shows the modal if needed. However, consider the following enhancements:

  1. Add error handling for cases where 'triggerWarning' or 'proceedButton' elements are not found.
  2. Only create the modal instance if it's going to be shown.
  3. Consider using addEventListener('load', ...) instead of window.onload for better compatibility and to avoid potential overwrites.

Here's a suggested improvement:

window.addEventListener('load', function () {
  const triggerWarning = document.getElementById('triggerWarning');
  const proceedButton = document.getElementById('proceedButton');

  if (!triggerWarning || !proceedButton) {
    console.error('Required elements not found');
    return;
  }

  if (!sessionStorage.getItem('triggerWarningDismissed')) {
    const modal = new bootstrap.Modal(triggerWarning);
    modal.show();
  }

  proceedButton.addEventListener('click', hideWarning);
});

1-22: Overall, the trigger warning implementation is good, with room for improvement.

The script successfully implements a trigger warning modal using Bootstrap, with functionality to show the warning and remember when it has been dismissed. However, there are a few areas where the code could be enhanced:

  1. Improve error handling and add defensive coding practices.
  2. Consider the choice between sessionStorage and localStorage based on the desired persistence of the dismissal.
  3. Ensure that the code doesn't assume the availability of Bootstrap or certain DOM elements.

Next steps:

  1. Implement the suggested improvements in the previous comments.
  2. Add comments to explain the purpose of using session/local storage and any other non-obvious logic.
  3. Consider adding a configuration option to easily switch between session and local storage.
  4. Ensure that this script is loaded after Bootstrap in your HTML to avoid potential errors.
  5. Add unit tests to verify the functionality of the hideWarning function and the onload behavior.
_data/theme.yml (1)

22-23: Consider the implications of centralizing the trigger warning

The changes to the trigger warning configuration raise several points for consideration:

  1. Centralization: Moving the trigger warning to index.md centralizes the warning, but it may not adequately warn users accessing individual items directly. Consider implementing a system that displays the warning on both the index and item pages.

  2. Comprehensive text: The new warning text provides a more thorough explanation, which is commendable. However, its length might impact user experience and readability, especially on mobile devices.

  3. Language: Ensure that the German text aligns with your target audience. If you have a diverse user base, consider offering multilingual options.

  4. Accessibility: The length of the text might affect the layout and design of the index page. Consider ways to present the information that maintain both informativeness and good user experience, such as a collapsible section or a modal dialog.

To address these points, consider the following suggestions:

  1. Implement a system to show the warning on both index and item pages.
  2. Create a shorter version of the warning for immediate display, with an option to expand for more details.
  3. Offer language toggle for multilingual support if needed.
  4. Use a modal or collapsible section to present the full text without overwhelming the main page layout.

Would you like assistance in implementing any of these suggestions?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between d3c2ed6 and e254379.

📒 Files selected for processing (9)
  • _data/theme.yml (1 hunks)
  • _includes/feature/trigger-warning.html (1 hunks)
  • _includes/item/trigger-warning.html (0 hunks)
  • _includes/js/trigger-warning-js.html (1 hunks)
  • _layouts/browse.html (0 hunks)
  • _layouts/item/item-page-base.html (1 hunks)
  • _layouts/item/item-page-full-width.html (1 hunks)
  • pages/index.md (1 hunks)
  • pages/sensible-inhalte.md (0 hunks)
💤 Files with no reviewable changes (3)
  • _includes/item/trigger-warning.html
  • _layouts/browse.html
  • pages/sensible-inhalte.md
🧰 Additional context used
🔇 Additional comments (7)
_includes/feature/trigger-warning.html (1)

1-20: Good implementation of the trigger warning modal with some suggestions for improvement.

The modal structure is well-implemented using Bootstrap classes and includes appropriate ARIA attributes for accessibility. The dynamic content loading for the warning text is a good approach for maintainability.

Here are some suggestions for improvement:

  1. Consider moving inline styles to a separate CSS file for better maintainability.
  2. Make the button text "Verstanden" translatable for better internationalization support.
  3. Ensure consistency in language use. The default warning text is in English, while other content is in German.

Here's a suggested refactor for the button to make it translatable:

-        <button id="proceedButton" type="button" class="btn btn-primary mt-4" aria-label="Hinweis ausblenden">
-          Verstanden
-        </button>
+        <button id="proceedButton" type="button" class="btn btn-primary mt-4" aria-label="Hinweis ausblenden">
+          {{ site.data.theme['trigger-warning-button-text'] | default: 'Verstanden' }}
+        </button>

This change allows you to define the button text in your _data/theme.yml file, making it easier to translate or modify in the future.

To ensure consistency in language use and verify the default warning text, run the following script:

This script will help verify the language consistency and check if a German translation is provided in the theme configuration.

✅ Verification successful

Verification Successful: Language Consistency Confirmed

The default warning text in _includes/feature/trigger-warning.html is in English. However, a German translation is provided in _data/theme.yml, ensuring consistent language use when the German locale is active.

No further actions are required.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check the default warning text language and theme configuration

# Test 1: Check the default warning text in the file
echo "Default warning text in _includes/feature/trigger-warning.html:"
rg --type html "default: '.*'" _includes/feature/trigger-warning.html

# Test 2: Check if there's a German translation in the theme configuration
echo "\nChecking for German translation in _data/theme.yml:"
rg "trigger-warning-text:" _data/theme.yml -A 1

Length of output: 1241

_layouts/item/item-page-full-width.html (3)

3-3: LGTM: Comment update is consistent with changes.

The removal of "trigger-warning" from the comment accurately reflects the changes made to this template. This aligns with the PR objective of implementing a global trigger warning system.


Line range hint 1-54: LGTM: Template structure and functionality remain intact.

The overall structure and functionality of the template appear to be well-maintained:

  • It correctly extends the 'default' layout.
  • Essential components (breadcrumbs, title, citation box, rights box, browse buttons) are present.
  • The template handles both single items and compound objects appropriately.
  • Conditional logic for displaying different elements based on the item type is preserved.

The removal of the trigger warning inclusion hasn't negatively impacted the core functionality of the template. The changes align with the PR objective of implementing a global trigger warning system while maintaining the existing item page structure.


Line range hint 1-54: Verify removal of trigger warning inclusion.

The AI summary indicates that the line {% include item/trigger-warning.html %} has been removed from this template. This change is consistent with the PR objective of implementing a global trigger warning. However, we should verify that this removal doesn't negatively impact the page's functionality or user experience.

To confirm the removal and its impact, please run the following script:

This script will help ensure that:

  1. The trigger warning include has been completely removed from layout files.
  2. There are no lingering references to trigger warnings in other layout files.
  3. The new global trigger warning has been implemented in the appropriate include files.
✅ Verification successful

Trigger warning inclusion successfully removed from layout files.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the removal of trigger warning inclusion and check for any remaining references.

# Test 1: Check if the trigger-warning.html include has been completely removed
echo "Test 1: Checking for trigger-warning.html include"
rg --type html 'include.*trigger-warning.html' _layouts/

# Test 2: Search for any remaining references to trigger warnings in layout files
echo "Test 2: Searching for trigger warning references in layouts"
rg --type html 'trigger.?warning' _layouts/

# Test 3: Verify the new global trigger warning implementation
echo "Test 3: Checking for new global trigger warning implementation"
rg --type html 'trigger.?warning' _includes/

Length of output: 794

pages/index.md (1)

16-21: LGTM! Improved modular approach for trigger warnings.

The changes introduce a more flexible and modular approach to displaying trigger warnings. This is an improvement over the previous static alert, allowing for better customization and potentially enhanced user experience. The separation of HTML and JS components is a good practice for maintainability.

To ensure the new components are properly implemented, please run the following verification:

This script will help verify that the new components are in place and have the expected basic structure. Please review the output to ensure everything is set up correctly.

_layouts/item/item-page-base.html (2)

3-3: LGTM: Updated comment accurately reflects current layout functionality.

The modified comment correctly describes the current state of the layout, mentioning the addition of breadcrumbs and title at the top, as well as the retention of the citation box, rights box, and browse buttons at the bottom.


Line range hint 1-70: Verify global trigger warning implementation.

The removal of the trigger warning component from this layout aligns with the PR objective of implementing a global trigger warning. However, please ensure that:

  1. The global trigger warning is implemented effectively to cover all necessary content.
  2. Users are adequately warned before accessing potentially sensitive content on item pages.
  3. The new implementation (likely using session or local storage as mentioned in the PR description) is thoroughly tested across different scenarios.

To confirm the proper implementation of the global trigger warning, please run the following script:

This script will help verify that the global trigger warning is properly implemented and that individual trigger warnings have been removed from item pages.

✅ Verification successful

Global trigger warning implementation verified.

The global trigger warning component is present in _includes/feature/trigger-warning.html, and individual trigger warnings have been successfully removed from item pages. No related JavaScript issues were found.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of the global trigger warning

# Test 1: Check for the presence of the global trigger warning component
echo "Checking for global trigger warning component:"
rg --type html "trigger-warning"

# Test 2: Verify the removal of individual trigger warnings from item pages
echo "Verifying removal of individual trigger warnings:"
rg --type html "trigger-warning" _layouts/item/

# Test 3: Check for the presence of JavaScript related to trigger warnings
echo "Checking for trigger warning related JavaScript:"
rg --type js "triggerWarning|warning"

Length of output: 87692

Copy link
Member

@maehr maehr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@koilebeit Thanks for the PR! Nice work.

@maehr maehr requested a review from mtwente October 10, 2024 13:04
@koilebeit koilebeit requested a review from maehr October 10, 2024 13:59
@mtwente
Copy link
Member

mtwente commented Oct 15, 2024

I know the modal was supposed to cover the whole screen, but what do you think about the way this looks:

trigger_modal_85pct

I think it works well with the darkened background.

I added 85% opacity to the modal's backdrop, I could also go up to 90%. This way the users still get shown a glimpse of the website that they're on – or to put it differently: That they are in fact on a website that consists of more content than the trigger warning... And we have the logo + headline "Forschungsdatenplattform" already kind of visible in the background. The modal is centered horizontally and vertically on the screen.

P.S.: "Materialien auf dieser Datenbank"? Not in dieser Datenbank?

@maehr
Copy link
Member

maehr commented Oct 15, 2024

I know the modal was supposed to cover the whole screen, but what do you think about the way this looks:

trigger_modal_85pct I think it works well with the darkened background.

I added 85% opacity to the modal's backdrop, I could also go up to 90%. This way the users still get shown a glimpse of the website that they're on – or to put it differently: That they are in fact on a website that consists of more content than the trigger warning... And we have the logo + headline "Forschungsdatenplattform" already kind of visible in the background. The modal is centered horizontally and vertically on the screen.

P.S.: "Materialien auf dieser Datenbank"? Not in dieser Datenbank?

I like it 🥰 And. Also the the fixed typo

@mtwente
Copy link
Member

mtwente commented Oct 15, 2024

What do you think about using the term Content Note instead of Triggerwarnung? It's less of a buzzword and more neutral/descriptive (see here or here.)

@maehr
Copy link
Member

maehr commented Oct 15, 2024

What do you think about using the term Content Note instead of Triggerwarnung? It's less of a buzzword and more neutral/descriptive (see here or here.)

I guess that's better for our audience. Thanks for reaching

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (2)
_sass/_custom.scss (2)

211-213: LGTM: Appropriate background color for trigger warning modal.

The light yellow background (#fff3cd) is a good choice for the trigger warning modal, as it draws attention without being overly alarming. The use of the specific ID ensures that this style only applies to the trigger warning modal.

Consider adding a contrast check to ensure that the text color used in the modal has sufficient contrast with this background color for accessibility purposes.


220-230: LGTM with suggestions: Consistent styling for trigger warning button.

The .btn-triggerwarning class provides a consistent color scheme with the trigger warning modal, which is good for visual coherence. The focus state with box shadow enhances accessibility.

Consider the following enhancements for better user interaction feedback:

  1. Add a subtle background color change on hover for more noticeable feedback.
  2. Ensure the contrast ratio between text and background colors meets WCAG 2.1 Level AA standards for accessibility.

Here's a suggested modification:

.btn-triggerwarning {
    border-color: #3a1e3e;
    background-color: #3a1e3e;
    color: #fff3cd;
    &:hover {
        background-color: lighten(#3a1e3e, 10%);
        color: #ffe880;
    }
    &:focus {
        box-shadow: 0 0 0 0.25rem rgba(58, 30, 62, 0.5);
    }
}

This change lightens the background color on hover and adjusts the focus box shadow for better visibility.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 6a7eba0 and 8c690e6.

📒 Files selected for processing (3)
  • _data/theme.yml (1 hunks)
  • _includes/feature/trigger-warning.html (1 hunks)
  • _sass/_custom.scss (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • _data/theme.yml
  • _includes/feature/trigger-warning.html
🧰 Additional context used
🔇 Additional comments (3)
_sass/_custom.scss (3)

207-209: LGTM: Modal backdrop opacity set appropriately.

The opacity value of 0.8 for the modal backdrop provides a good balance, allowing some visibility of the underlying content while maintaining focus on the modal. This aligns well with the design discussion in the PR comments.


215-218: LGTM: Clear and contrasting selection style for trigger warning modal.

The dark purple selection background (#3a1e3e) with white text provides excellent contrast, enhancing readability and user experience when selecting text within the trigger warning modal. The specific ID usage ensures this style is applied only where intended.


206-230: Overall assessment: Well-implemented styles for trigger warning feature.

The new styles effectively implement the visual aspects of the trigger warning feature, aligning well with the PR objectives and previous discussions. The color scheme and design choices are appropriate for drawing attention to the warning without being overly alarming.

A few minor suggestions have been made to enhance accessibility and user interaction, particularly for the button styles. These small improvements could further refine the user experience.

To ensure consistency across the codebase, let's verify the usage of these new styles:

This script will help us confirm that the new styles are being applied correctly in the HTML templates.

@maehr maehr merged commit 7780d4e into Stadt-Geschichte-Basel:main Oct 16, 2024
2 checks passed
@koilebeit koilebeit deleted the global_triggerwarning branch October 17, 2024 06:23
@koilebeit koilebeit mentioned this pull request Oct 17, 2024
@coderabbitai coderabbitai bot mentioned this pull request Oct 25, 2024
7 tasks
@coderabbitai coderabbitai bot mentioned this pull request Nov 4, 2024
7 tasks
This was referenced Nov 15, 2024
@coderabbitai coderabbitai bot mentioned this pull request Dec 11, 2024
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants