Skip to content

Show addon install popup when clicking to locked template#705

Closed
truongwp wants to merge 7 commits into
masterfrom
quizzes-popup
Closed

Show addon install popup when clicking to locked template#705
truongwp wants to merge 7 commits into
masterfrom
quizzes-popup

Conversation

@truongwp
Copy link
Copy Markdown
Contributor

Todo:

  • Apply this for templates in Quizzes categories, not Contact form.
  • Update addon install URL.
  • Maybe remove or change ADDON text in the locked template.

What I did:

  • Check if template requires an addon and that addon is not installed, add 'addon' => 'slug' to the template array.
  • If template contains addon, show it as locked and add data-addon="slug" to the `
  • element.
  • When showing upgrade page of new form modal, check if <li> contains data-addon, change all text/image/url of upgrade content into addon install content. The addon install content is registered in global JS variable.

@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 21, 2022

Codecov Report

Attention: 25 lines in your changes are missing coverage. Please review.

Comparison is base (047aeaf) 29.27% compared to head (8b8716c) 27.58%.
Report is 4 commits behind head on master.

❗ Current head 8b8716c differs from pull request most recent head 4552a20. Consider uploading reports for the commit 4552a20 to get more accurate results

Files Patch % Lines
classes/controllers/FrmFormsController.php 0.00% 24 Missing ⚠️
classes/helpers/FrmAppHelper.php 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master     #705      +/-   ##
============================================
- Coverage     29.27%   27.58%   -1.70%     
+ Complexity     7266     6392     -874     
============================================
  Files           105       90      -15     
  Lines         23941    18850    -5091     
============================================
- Hits           7009     5199    -1810     
+ Misses        16932    13651    -3281     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Crabcyborg
Copy link
Copy Markdown
Contributor

Crabcyborg commented Feb 21, 2022

@truongwp I see an error when I try to test this.

Screen Shot 2022-02-21 at 9 57 29 AM

It looks like it's trying to access overlayStringElementMapping[ str ].innerText; but it looks like overlayStringElementMapping.content_heading is null for me so null.innerText is breaking.

(It looks like this is because I have an Elite license. It never includes the "upgrade" block in $blocks_to_render. If you have a license that supports quizzes, it should probably not require this block but allow you to download still.

@stephywells
Copy link
Copy Markdown
Contributor

@truongwp lets start with just what is needed for quizzes here. Do we need anything besides the added category in the list, and the template Id? I think if it's just that, we can release it before quizzes even.

Let's hold off on the rest of this so we can do it in a way that works more universally.

@truongwp
Copy link
Copy Markdown
Contributor Author

@stephywells Do you mean we just need the quiz template and the category, we don't need the install Quizzes popup?

@stephywells
Copy link
Copy Markdown
Contributor

@truongwp yes, exactly. For this PR, let's do it the same way the registration template works right now.

@truongwp
Copy link
Copy Markdown
Contributor Author

@stephywells This is the code set icon for Quizzes category: https://github.com/Strategy11/formidable-forms/pull/705/files#diff-c3f25890259e06951f6e9c7f66838c489ff9c9e0462fd21978a96d8a3e869159R1283

Look like the category for template is set outside plugin, we will get them via API.

Do we need to add Quizzes here? https://github.com/Strategy11/formidable-forms/blob/master/classes/controllers/FrmAddonsController.php#L118

@stephywells
Copy link
Copy Markdown
Contributor

stephywells commented Feb 22, 2022

@truongwp Yes, exactly. So we only need that line, and the line that adds the template id. But we should use a singular term so it matches the others (Quiz instead of Quizzes).

The id for this template will be 28109851.

Do we need to add Quizzes here? https://github.com/Strategy11/formidable-forms/blob/master/classes/controllers/FrmAddonsController.php#L118

Sure! That would be great!

@Crabcyborg Crabcyborg removed their request for review May 31, 2023 18:31
@Crabcyborg Crabcyborg removed the request for review from stephywells December 4, 2024 13:45
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Dec 4, 2024

Walkthrough

The pull request introduces several enhancements across multiple classes, primarily focusing on integrating addon requirements and improving template management. Key changes include the addition of methods to handle addon installation strings and the modification of existing methods to incorporate these new functionalities. The template listing logic is updated to reflect addon requirements, while the admin interface's JavaScript is enhanced for better user interaction and management of form actions. Overall, the changes aim to improve usability and maintainability within the application.

Changes

File Change Summary
classes/controllers/FrmFormsController.php - Added private static function add_addon_required(&$templates) to append addon requirement data to templates.
- Updated list_templates to call this new method.
classes/helpers/FrmAppHelper.php - Added private static function get_addon_install_strings() to return installation strings for the "quiz_maker" addon.
- Updated load_admin_wide_js() to include this new method.
- Added deprecation notice for jquery_ui_base_url().
classes/helpers/FrmFormsHelper.php - Added public static function maybe_add_sanitize_url_attr($url, $form_id) to handle URL sanitization.
- Updated template_icon() to include new entries for 'Survey' and 'Application Form'.
classes/views/frm-forms/list-template.php - Modified logic for $plan_required to allow marking templates as requiring an addon under specific conditions.
- Updated <li> output to include a new data-addon attribute.
js/formidable_admin.js - Added function changeUpgradeOverlayContent(addon) for dynamic modal updates.
- Enhanced event handling for locked templates and refined modal management.
- Improved field management and conditional logic handling.
- Cleaned up deprecated functions and improved user feedback mechanisms.

Possibly related PRs

Suggested labels

run analysis, run tests


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 (2)
js/formidable_admin.js (2)

Line range hint 8745-8952: Refactor to avoid using hasOwnProperty directly on objects

The code is using hasOwnProperty directly on objects in a few places:

if ( ! frm_admin_js.addonInstall.hasOwnProperty( addon ) ) {
    return;
}

if ( ! frm_admin_js.addonInstall.hasOwnProperty( 'upgrade' ) ) {
    // ...
}

It's recommended to use Object.hasOwn() instead to avoid potential issues if an object has a property named "hasOwnProperty".

Consider refactoring to:

if ( ! Object.hasOwn( frm_admin_js.addonInstall, addon ) ) {
    return;
}

if ( ! Object.hasOwn( frm_admin_js.addonInstall, 'upgrade' ) ) {
    // ...
}

This will make the code more robust and avoid relying on the hasOwnProperty method of the object itself.

🧰 Tools
🪛 Biome (1.9.4)

[error] 8898-8901: Do not access Object.prototype method 'hasOwnProperty' from target object.

It's recommended using Object.hasOwn() instead of using Object.hasOwnProperty().
See MDN web docs for more details.

(lint/suspicious/noPrototypeBuiltins)


[error] 8914-8914: Do not access Object.prototype method 'hasOwnProperty' from target object.

It's recommended using Object.hasOwn() instead of using Object.hasOwnProperty().
See MDN web docs for more details.

(lint/suspicious/noPrototypeBuiltins)

🪛 eslint

[error] 8897-8897: Identifier 'frm_admin_js' is not in camel case.

(camelcase)


[error] 8913-8913: Identifier 'frm_admin_js' is not in camel case.

(camelcase)


[error] 8923-8923: Identifier 'frm_admin_js' is not in camel case.

(camelcase)


[error] 8927-8927: Identifier 'frm_admin_js' is not in camel case.

(camelcase)


8897-8897: Use camelCase for frm_admin_js identifier

The frm_admin_js identifier is used in a few places but it's not following the camelCase naming convention. For consistency with the rest of the codebase, consider renaming it to frmAdminJs.

if ( ! frm_admin_js.addonInstall.hasOwnProperty( addon ) ) {
    return;
}

if ( ! frm_admin_js.addonInstall.hasOwnProperty( 'upgrade' ) ) {
    // ...
}

strings = frm_admin_js.addonInstall[ addon ];

strings.install_url = frm_admin_js.addonInstall.upgrade;

After renaming:

if ( ! frmAdminJs.addonInstall.hasOwnProperty( addon ) ) {
    return;
}

if ( ! frmAdminJs.addonInstall.hasOwnProperty( 'upgrade' ) ) {
    // ...
}

strings = frmAdminJs.addonInstall[ addon ];

strings.install_url = frmAdminJs.addonInstall.upgrade;

This will make the naming more consistent throughout the file.

Also applies to: 8913-8913, 8923-8923, 8927-8927

🧰 Tools
🪛 eslint

[error] 8897-8897: Identifier 'frm_admin_js' is not in camel case.

(camelcase)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 047aeaf and 563a194.

⛔ Files ignored due to path filters (1)
  • images/quizzes.png is excluded by !**/*.png, !**/*.png
📒 Files selected for processing (5)
  • classes/controllers/FrmFormsController.php (2 hunks)
  • classes/helpers/FrmAppHelper.php (2 hunks)
  • classes/helpers/FrmFormsHelper.php (1 hunks)
  • classes/views/frm-forms/list-template.php (2 hunks)
  • js/formidable_admin.js (3 hunks)
👮 Files not reviewed due to content moderation or server errors (3)
  • classes/views/frm-forms/list-template.php
  • classes/helpers/FrmFormsHelper.php
  • classes/controllers/FrmFormsController.php
🧰 Additional context used
🪛 Biome (1.9.4)
js/formidable_admin.js

[error] 8898-8901: Do not access Object.prototype method 'hasOwnProperty' from target object.

It's recommended using Object.hasOwn() instead of using Object.hasOwnProperty().
See MDN web docs for more details.

(lint/suspicious/noPrototypeBuiltins)


[error] 8914-8914: Do not access Object.prototype method 'hasOwnProperty' from target object.

It's recommended using Object.hasOwn() instead of using Object.hasOwnProperty().
See MDN web docs for more details.

(lint/suspicious/noPrototypeBuiltins)

🪛 eslint
js/formidable_admin.js

[error] 8897-8897: Identifier 'frm_admin_js' is not in camel case.

(camelcase)


[error] 8913-8913: Identifier 'frm_admin_js' is not in camel case.

(camelcase)


[error] 8923-8923: Identifier 'frm_admin_js' is not in camel case.

(camelcase)


[error] 8927-8927: Identifier 'frm_admin_js' is not in camel case.

(camelcase)

🔇 Additional comments (1)
classes/helpers/FrmAppHelper.php (1)

Line range hint 3126-3160: LGTM! Well-implemented dismissable warning message functionality

The new method provides a clean implementation for displaying and managing dismissable warning messages with proper:

  • AJAX handling
  • Nonce verification
  • Permission checks
  • Accessibility support

Comment thread classes/helpers/FrmAppHelper.php
@Crabcyborg
Copy link
Copy Markdown
Contributor

I'm going to close this for now for a couple reasons.

  1. It's so old that a lot needs to change now. There are merge conflicts, and this updates old removed code since this was part of the old new form modal which has been replaced by the form templates page.
  2. There are JS errors when you're using an Elite license because some of these expected elements don't exist.
  3. We have a new used_addons key that we can use instead of checking for specific hard coded categories. We'll need to adjust this logic to use that instead.

I figured out how to trigger this so I could get a screenshot of what it looked like.

Screen Shot 2024-12-04 at 9 59 25 AM

@Crabcyborg Crabcyborg closed this Dec 4, 2024
@Crabcyborg Crabcyborg deleted the quizzes-popup branch December 4, 2024 14:03
@Crabcyborg Crabcyborg restored the quizzes-popup branch December 4, 2024 14:03
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