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

Revert browse #193

Merged
merged 3 commits into from
Dec 5, 2024
Merged

Revert browse #193

merged 3 commits into from
Dec 5, 2024

Conversation

maehr
Copy link
Member

@maehr maehr commented Dec 4, 2024

Pull request

Proposed changes

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 new utility for retrieving theme icons based on various media types and configurations.
    • Added a shuffle function to randomize item displays.
  • Bug Fixes

    • Improved handling of item images and thumbnail icons in the card generation process.
  • Refactor

    • Streamlined item handling and rendering logic for better performance and readability.
    • Updated function definitions for clarity and consistency.
  • Documentation

    • Enhanced comments for better understanding of utility usage and parameters.

Copy link

changeset-bot bot commented Dec 4, 2024

⚠️ No Changeset found

Latest commit: e7606a1

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

@maehr maehr requested a review from Copilot December 4, 2024 11:04

Choose a reason for hiding this comment

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

Copilot reviewed 4 out of 4 changed files in this pull request and generated no suggestions.

@maehr maehr requested a review from koilebeit December 4, 2024 11:04
Copy link

coderabbitai bot commented Dec 4, 2024

Warning

Rate limit exceeded

@maehr has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 25 minutes and 47 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between c9a193c and e7606a1.

Walkthrough

The pull request introduces changes primarily to three files: _includes/helpers/get-icon-svg.html, _includes/helpers/get-icon.js, and _includes/js/browse-js.html. It enhances the Liquid template utility for icon retrieval, modifies the logic for selecting icons in JavaScript, and refactors the item handling and rendering process. Key updates include new parameters for icon types, streamlined item creation logic, and improved structure for event listeners and functions.

Changes

File Path Change Summary
_includes/helpers/get-icon-svg.html New file created to enhance icon retrieval based on template and type parameters.
_includes/helpers/get-icon.js Modified getIcon function to remove the "geodata" check and add a condition for "record".
_includes/js/browse-js.html Refactored item handling, changed variable declarations from const to var, and redefined several functions for clarity and efficiency.

Assessment against linked issues

Objective Addressed Explanation
Placeholder for objects without thumbnail yet (#191) The changes do not ensure a placeholder icon is displayed when a thumbnail is missing.

Possibly related PRs

Suggested reviewers

  • koilebeit

🐇 In the code we hop and play,
New icons brighten up the way.
With functions spruced and items neat,
Our project now feels quite complete!
So let’s rejoice, with joy we sing,
For every change, a happy spring! 🌼


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/helpers/get-icon.js (2)

5-13: Consider defensive programming improvements

While the parameter handling is good, we could make it more robust.

 function getIcon(objectTemplate,objectFormat,svgType) {
     var iconTemplate, iconId, iconTitle;
-    if (objectTemplate && objectTemplate != "") {
+    if (objectTemplate && typeof objectTemplate === 'string' && objectTemplate.trim() !== "") {
         iconTemplate = objectTemplate;
-    } else if (objectFormat && objectFormat != "") {
+    } else if (objectFormat && typeof objectFormat === 'string' && objectFormat.trim() !== "") {
         iconTemplate = objectFormat;
     } else {
-        iconTemplate = ""
+        iconTemplate = "";
     }

43-52: Consider extracting SVG templates to constants

The SVG markup is repeated across conditions with slight variations.

+    const SVG_TEMPLATES = {
+        thumb: '<svg class="bi text-body img-fluid" fill="currentColor" role="img"><title>${title}</title><use xlink:href="{{ "/assets/lib/cb-icons.svg" | relative_url }}#${id}"/></svg>',
+        hidden: '<svg class="bi icon-sprite" aria-hidden="true"><use xlink:href="{{ "/assets/lib/cb-icons.svg" | relative_url }}#${id}"/></svg>',
+        default: '<svg class="bi icon-sprite" aria-label="${title}"><use xlink:href="{{ "/assets/lib/cb-icons.svg" | relative_url }}#${id}"/></svg>'
+    };
+
     if (svgType == "thumb") {
-        return '<svg class="bi text-body img-fluid" fill="currentColor" role="img"><title>' + iconTitle + '</title><use xlink:href="{{ "/assets/lib/cb-icons.svg" | relative_url }}#' + iconId + '"/></svg>';
+        return SVG_TEMPLATES.thumb.replace('${title}', iconTitle).replace('${id}', iconId);
     } else if (svgType == "hidden") {
-        return '<svg class="bi icon-sprite" aria-hidden="true"><use xlink:href="{{ "/assets/lib/cb-icons.svg" | relative_url }}#' + iconId + '"/></svg>';
+        return SVG_TEMPLATES.hidden.replace('${id}', iconId);
     } else {
-        return '<svg class="bi icon-sprite" aria-label="' + iconTitle + '"><use xlink:href="{{ "/assets/lib/cb-icons.svg" | relative_url }}#' + iconId + '"/></svg>';
+        return SVG_TEMPLATES.default.replace('${title}', iconTitle).replace('${id}', iconId);
     }
_includes/js/browse-js.html (2)

73-77: Consider uncommenting media type section

The commented-out media type section could provide additional context for items. Consider either removing it completely or documenting why it's commented out.


86-116: Optimize filterItems performance

The current implementation rebuilds all cards on every filter operation.

Consider these optimizations:

  1. Debounce the filter operation
  2. Use DocumentFragment for batch DOM updates
  3. Consider virtual scrolling for large datasets
 function filterItems(arr,q) {
     loadingIcon.classList.remove("d-none");
+    const fragment = document.createDocumentFragment();
     // ... filtering logic ...
     var cards = "";
     for (var i = 0, len = filteredItems.length; i < len; i++) {
         cards += makeCard(filteredItems[i]);
     }
-    browseItemsDiv.innerHTML = cards;
+    const temp = document.createElement('div');
+    temp.innerHTML = cards;
+    while (temp.firstChild) {
+        fragment.appendChild(temp.firstChild);
+    }
+    browseItemsDiv.innerHTML = '';
+    browseItemsDiv.appendChild(fragment);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 42dd6de and 9a6c3d9.

📒 Files selected for processing (4)
  • _includes/helpers/get-icon-svg.html (1 hunks)
  • _includes/helpers/get-icon.js (1 hunks)
  • _includes/js/browse-js.html (1 hunks)
  • _includes/js/get-icon.js (0 hunks)
💤 Files with no reviewable changes (1)
  • _includes/js/get-icon.js
🔇 Additional comments (3)
_includes/helpers/get-icon-svg.html (2)

1-13: Well-documented template utility

The comments clearly explain the purpose and usage of the utility, making it maintainable.


14-18: Verify icon asset availability

The implementation looks correct, but we need to ensure the referenced icon assets exist.

✅ Verification successful

Icon assets are properly configured and available

The verification shows that the icon implementation is correct and the assets are properly configured:

  1. The theme.yml file contains explicit icon mappings for all required icons used in the template:

    • icon-image: image
    • icon-audio: soundwave
    • icon-video: film
    • icon-pdf: file-pdf
    • icon-record: file-text
    • icon-panorama: image-alt
    • icon-compound-object: collection
    • icon-multiple: postcard
    • icon-default: file-earmark
  2. The required icon sprite file cb-icons.svg exists at the correct location assets/lib/cb-icons.svg and is dynamically generated using the configured icon mappings.

  3. The icon mappings use standard Bootstrap Icons which are available in the codebase as verified by the presence of corresponding SVG files in assets/lib/icons/.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the icon assets exist in the expected location

# Check if the SVG sprite file exists
fd -g 'cb-icons.svg' assets/lib/

# List all icon IDs defined in the SVG sprite
if [ -f "assets/lib/cb-icons.svg" ]; then
    rg -o 'id="icon-[^"]+"' assets/lib/cb-icons.svg
fi

Length of output: 143


Script:

#!/bin/bash
# Let's try a different approach to check the SVG content
cat assets/lib/cb-icons.svg

# Also check if there are any other icon-related SVG files
fd -e svg

Length of output: 58326


Script:

#!/bin/bash
# Let's check the content of theme_icons data file since cb-icons.svg is dynamically generated
fd -g '*theme_icons*' -t f

# Also check if there are any icon-related configuration files
fd -g '*icon*.yml' -t f

Length of output: 54


Script:

#!/bin/bash
# Let's check the _data directory for theme configuration
fd -g '*.yml' _data/

# And check if there are any icon-related files in _data
ls -la _data/ 2>/dev/null

# Also check the theme configuration in root
fd -g '_config.yml'

Length of output: 838


Script:

#!/bin/bash
# Let's check the theme.yml content for icon configurations
cat _data/theme.yml

# Also check _config.yml for any icon-related settings
cat _config.yml

Length of output: 10687

_includes/js/browse-js.html (1)

31-38: Proper implementation of placeholder icons

The code correctly implements the placeholder icon functionality when thumbnails are missing, which directly addresses the PR objective.

@maehr maehr requested a review from mtwente December 4, 2024 16:25
@maehr maehr merged commit fbef9d5 into Stadt-Geschichte-Basel:main Dec 5, 2024
3 checks passed
@maehr maehr deleted the revert_browse branch December 5, 2024 07:12
@mtwente mtwente mentioned this pull request Dec 8, 2024
mtwente added a commit that referenced this pull request Dec 16, 2024
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.

Placeholder for objects without thumbnail yet
2 participants