Skip to content

Add missing thumbnails for new applications#2030

Merged
Crabcyborg merged 2 commits into
masterfrom
add_missing_thumbnails_for_new_applications
Oct 4, 2024
Merged

Add missing thumbnails for new applications#2030
Crabcyborg merged 2 commits into
masterfrom
add_missing_thumbnails_for_new_applications

Conversation

@Crabcyborg
Copy link
Copy Markdown
Contributor

This update adds missing thumbnail images for 10 new applications.

Most are now using webp files, so some new logic was added to conditionally use webp vs png.

Screenshot 2024-10-04 at 15-47-53 Formidable Applications ‹ WordPress Develop — WordPress

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Oct 4, 2024

Walkthrough

The changes involve modifications to the FrmApplicationTemplate class and several JavaScript functions to enhance image handling capabilities, specifically supporting both PNG and WEBP formats. The init method now merges results from two methods for image keys, and a new method for WEBP images has been added. Additionally, JavaScript functions have been updated to conditionally set image filenames based on the image format and to clarify return types in specific functions.

Changes

File Path Change Summary
classes/models/FrmApplicationTemplate.php - Updated init method to merge results from get_template_keys_with_local_png_images() and get_template_keys_with_local_webp_images().
- Added private static function get_template_keys_with_local_webp_images().
- Renamed get_template_keys_with_local_images() to get_template_keys_with_local_png_images().
- Updated as_js_object method to include isWebp in $application array.
js/admin/applications.js - Modified createApplicationCard function to conditionally set filenameToUse based on data.isWebp and data.hasLiteThumbnail.
js/src/form-templates/elements/applicationTemplatesElement.js - Updated createTemplateItem function to include isWebp in the destructured template object for thumbnail URL logic.
- Modified createApplicationTemplates to explicitly return undefined when no applications are provided.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Application
    participant Template

    User->>Application: Request Application Data
    Application->>Template: Fetch Template Keys
    Template->>Template: get_template_keys_with_local_png_images()
    Template->>Template: get_template_keys_with_local_webp_images()
    Template-->>Application: Return Template Keys
    Application->>User: Display Application with Images
Loading

Possibly related PRs

  • form templates functionalities #1985: The changes in the main PR enhance the handling of image formats in the FrmApplicationTemplate class, which is directly related to the updates in the Cypress tests for form templates that include image source validation, particularly for WebP images.

Suggested reviewers

  • shervElmi

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
Copy Markdown
Contributor

@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: 1

🧹 Outside diff range and nitpick comments (3)
js/src/form-templates/elements/applicationTemplatesElement.js (1)

63-66: Approve the addition of webp support with a minor optimization suggestion.

The changes successfully implement the new logic for conditionally selecting between webp and png formats for thumbnails, aligning with the PR objectives. The implementation is correct and maintains backwards compatibility with the placeholder SVG fallback.

Consider optimizing the thumbnail URL selection logic for better readability:

-const thumbnailURL = hasLiteThumbnail ?
-	( isWebp ? `${thumbnailBaseURL}/${key}.webp` : `${thumbnailBaseURL}/${key}.png` ) :
-	`${thumbnailBaseURL}/placeholder.svg`;
+const thumbnailURL = hasLiteThumbnail
+	? `${thumbnailBaseURL}/${key}.${isWebp ? 'webp' : 'png'}`
+	: `${thumbnailBaseURL}/placeholder.svg`;

This refactoring maintains the same logic while making it slightly more concise and easier to read.

classes/models/FrmApplicationTemplate.php (2)

54-54: Update the @since tag with the correct version number

In the docblock for get_template_keys_with_local_webp_images(), the @since x.x tag should be updated to reflect the actual version number when this method was introduced.

Apply this diff to update the version number:

 /**
  * Newer templates now use .webp files instead of .png.
  *
- * @since x.x
+ * @since 6.0
  *
  * @return array<string>
  */

79-85: Consider sorting the template keys alphabetically

For better readability and maintainability, consider sorting the array of template keys alphabetically.

Apply this diff to sort the array:

    	return array(
+			'business-directory',
			'business-hours',
-			'business-directory',
			'faq-template-wordpress',
			'product-review',
			'real-estate-listings',
			'restaurant-menu',
			'team-directory',
		);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between eef27ba and 2f04750.

⛔ Files ignored due to path filters (1)
  • images/applications/thumbnails/business-directory.png is excluded by !**/*.png, !**/*.png
📒 Files selected for processing (3)
  • classes/models/FrmApplicationTemplate.php (2 hunks)
  • js/admin/applications.js (1 hunks)
  • js/src/form-templates/elements/applicationTemplatesElement.js (1 hunks)
🔇 Additional comments (5)
js/src/form-templates/elements/applicationTemplatesElement.js (2)

Line range hint 1-108: Overall implementation aligns well with PR objectives.

The changes successfully introduce support for webp thumbnails while maintaining backwards compatibility. The code is well-structured and follows good practices. The minor suggestions provided should help improve readability and maintainability.


Line range hint 23-26: Approve the change to return undefined instead of null.

The modification to return undefined instead of null when no applications are provided aligns with JavaScript best practices. This change enhances code clarity and consistency.

To ensure this change doesn't introduce unexpected behavior, please run the following script to check for any code that might be relying on the previous null return value:

✅ Verification successful

Verification Complete: No dependencies found on null returned from createApplicationTemplates.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for potential usage of createApplicationTemplates that might expect null

# Test: Search for createApplicationTemplates usage
rg --type javascript -A 5 'createApplicationTemplates\s*\(' | grep -E '(===|!==)\s*null'

Length of output: 125


Script:

#!/bin/bash
# Description: Search for potential usage of createApplicationTemplates that might expect null

# Corrected Test: Search for createApplicationTemplates usage in JavaScript files
rg --type js -A 5 'createApplicationTemplates\s*\(' | grep -E '(===|!==)\s*null'

Length of output: 82

classes/models/FrmApplicationTemplate.php (3)

44-47: LGTM!

The merging of PNG and WEBP image keys into self::$keys_with_images is correctly implemented.


181-181: LGTM!

The addition of the isWebp flag correctly identifies applications using WEBP images.


77-77: Ensure all references to the renamed method are updated

The method get_template_keys_with_local_images() has been renamed to get_template_keys_with_local_png_images(). Please verify that all references to the old method name have been updated throughout the codebase.

Run the following script to check for any occurrences of get_template_keys_with_local_images():

✅ Verification successful

All references to get_template_keys_with_local_images have been successfully updated.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for references to the old method name in PHP files.
# Test: Find any occurrences of 'get_template_keys_with_local_images'. Expect: No matches.

rg --type php 'get_template_keys_with_local_images'

Length of output: 51


Script:

#!/bin/bash
# Description: Perform a comprehensive search for 'get_template_keys_with_local_images' in all PHP files, including different cases.
# Test: Expect no matches if the method has been correctly renamed.

rg --type php --ignore-case 'get_template_keys_with_local_images'

Length of output: 65


Script:

#!/bin/bash
# Description: Use ast-grep to find all calls to 'get_template_keys_with_local_images' in PHP files.
# Test: Expect no matches if all references have been updated to 'get_template_keys_with_local_png_images'.

ast-grep --lang php --pattern '$_->get_template_keys_with_local_images($_, $_)'

Length of output: 81

Comment thread js/admin/applications.js
Copy link
Copy Markdown
Contributor

@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: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 2f04750 and 09aaec9.

📒 Files selected for processing (1)
  • tests/cypress/e2e/Form Templates/FormTemplates.cy.js (1 hunks)

Comment thread tests/cypress/e2e/Form Templates/FormTemplates.cy.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant