Skip to content

feat: add onPageUnload option in UI behind feature flag. #41008

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

Conversation

rahulbarwal
Copy link
Contributor

@rahulbarwal rahulbarwal commented Jun 20, 2025

Description

Problem

The action configuration UI lacked support for running actions specifically on page unload, limiting automation and flexibility for users.

Root cause

There was no ON_PAGE_UNLOAD option in the ActionRunBehaviour enum or related UI, and feature flag handling for this behavior was missing.

Solution

This PR handles the addition of the ON_PAGE_UNLOAD run behavior to the ActionRunBehaviour enum, updates UI and settings to support it, leverages feature flags for dynamic option availability, and adds tests to ensure robust behavior.

Fixes #40995
or
Fixes Issue URL

Warning

If no issue exists, please create an issue first, and check with the maintainers if the issue is valid.

Automation

/ok-to-test tags="@tag.JS"

🔍 Cypress test results

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/15774903938
Commit: fe0b500
Cypress dashboard.
Tags: @tag.JS
Spec:


Fri, 20 Jun 2025 09:27:32 UTC

Communication

Should the DevRel and Marketing teams inform users about this change?

  • Yes
  • No

Summary by CodeRabbit

  • New Features
    • Introduced a new "On page unload" run behavior option for actions and JS functions, allowing actions to be triggered when a page is unloaded.
    • Added a feature flag to enable or disable the "On page unload" run behavior.
  • Enhancements
    • Run behavior options in the editor now dynamically update based on feature flag settings, ensuring only valid options are shown.
  • Tests
    • Added comprehensive unit tests for utility functions handling run behavior options and defaults.

- Introduced a new action run behavior, ON_PAGE_UNLOAD, to the ActionRunBehaviour enum.
- Updated RUN_BEHAVIOR_VALUES to include the new ON_PAGE_UNLOAD option with appropriate labels and descriptions.
- Enhanced JSFunctionSettings component to utilize feature flags for determining available run behaviors.
- Added utility functions to manage run behavior options based on feature flags.
- Implemented tests for the new functionality to ensure correct behavior under various feature flag states.
@rahulbarwal rahulbarwal self-assigned this Jun 20, 2025
Copy link
Contributor

coderabbitai bot commented Jun 20, 2025

"""

Walkthrough

A new "On Page Unload" run behavior has been introduced for actions, including updates to the enum, UI options, feature flags, and supporting utility logic. The relevant UI components now dynamically display this option based on feature flags. Comprehensive unit tests have been added for the utility functions managing these behaviors.

Changes

File(s) / Grouped Files Change Summary
app/client/src/PluginActionEditor/types/PluginActionTypes.ts Added ON_PAGE_UNLOAD to ActionRunBehaviour enum.
app/client/src/ce/entities/FeatureFlag.ts Added feature flag release_jsobjects_onpageunloadactions_enabled to constants and default values.
app/client/src/constants/AppsmithActionConstants/formConfig/PluginSettings.ts Added "On page unload" option to RUN_BEHAVIOR_VALUES.
app/client/src/pages/Editor/JSEditor/JSEditorToolbar/components/JSFunctionSettings.tsx Updated to use new utility functions and feature flags for run behavior options; refactored option selection.
app/client/src/pages/Editor/JSEditor/JSEditorToolbar/components/utils.ts New utility functions for filtering and defaulting run behavior options based on feature flags.
app/client/src/pages/Editor/JSEditor/JSEditorToolbar/components/utils.test.ts New unit tests for run behavior utility functions, covering all flag and input combinations.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant UI_Component
    participant FeatureFlag
    participant Utils

    User->>UI_Component: Opens Action Settings
    UI_Component->>FeatureFlag: Check reactive & onPageUnload flags
    UI_Component->>Utils: getRunBehaviorOptionsBasedOnFeatureFlags(flags)
    Utils-->>UI_Component: Filtered run behavior options
    UI_Component->>User: Display options (including "On Page Unload" if enabled)
    User->>UI_Component: Selects run behavior
    UI_Component->>Utils: getDefaultRunBehaviorOptionWhenFeatureFlagIsDisabled(selected, flags)
    Utils-->>UI_Component: Default/fallback option if needed
    UI_Component->>User: Update selection in UI
Loading

Assessment against linked issues

Objective Addressed Explanation
UI displays a toggle/checkbox labeled “Run on Page Unload” in the action settings (#40995)
The toggle reflects the current value of ‎onPageUnload (#40995)
UI is consistent with existing design patterns (#40995)
Adds necessary unit tests (#40995)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes found.

Possibly related PRs

Suggested labels

IDE Product, Core Query Execution, IDE Pod, Integrations Product, Query Settings, Integrations Pod

Suggested reviewers

  • AmanAgarwal041

Poem

Actions now can bid adieu,
With "On Page Unload" in view.
Feature flags and tests align,
Options filtered, all by design.
The code is neat, the UI bright—
On page goodbye, things run just right! 🚀
"""


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 298bcfb and fe0b500.

📒 Files selected for processing (3)
  • app/client/src/constants/AppsmithActionConstants/formConfig/PluginSettings.ts (1 hunks)
  • app/client/src/pages/Editor/JSEditor/JSEditorToolbar/components/utils.test.ts (1 hunks)
  • app/client/src/pages/Editor/JSEditor/JSEditorToolbar/components/utils.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • app/client/src/constants/AppsmithActionConstants/formConfig/PluginSettings.ts
  • app/client/src/pages/Editor/JSEditor/JSEditorToolbar/components/utils.test.ts
  • app/client/src/pages/Editor/JSEditor/JSEditorToolbar/components/utils.ts
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: perform-test / client-build / client-build
  • GitHub Check: perform-test / rts-build / build
  • GitHub Check: client-check-cyclic-deps / check-cyclic-dependencies
  • GitHub Check: client-lint / client-lint
  • GitHub Check: client-unit-tests / client-unit-tests
  • GitHub Check: client-prettier / prettier-check
  • GitHub Check: client-build / client-build
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

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.

@github-actions github-actions bot added Javascript Product Issues related to users writing javascript in appsmith JS Objects Issues related to JS Objects Query Widgets & IDE Pod All issues related to Query, JS, Eval, Widgets & IDE Task A simple Todo Enhancement New feature or request labels Jun 20, 2025
Copy link
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: 2

🧹 Nitpick comments (1)
app/client/src/pages/Editor/JSEditor/JSEditorToolbar/components/utils.ts (1)

9-19: Solid filtering logic with minor type assertion consideration.

The filtering logic correctly excludes options based on feature flag states. The boolean conditions are clear and handle both feature flags appropriately.

The type assertion as SelectOptionProps[] on line 19 may be redundant if RUN_BEHAVIOR_VALUES is already properly typed, but it's not problematic.

Consider verifying if the type assertion is necessary:

-  ) as SelectOptionProps[];
+  );
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1789339 and ca6f1dd.

📒 Files selected for processing (6)
  • app/client/src/PluginActionEditor/types/PluginActionTypes.ts (1 hunks)
  • app/client/src/ce/entities/FeatureFlag.ts (2 hunks)
  • app/client/src/constants/AppsmithActionConstants/formConfig/PluginSettings.ts (1 hunks)
  • app/client/src/pages/Editor/JSEditor/JSEditorToolbar/components/JSFunctionSettings.tsx (2 hunks)
  • app/client/src/pages/Editor/JSEditor/JSEditorToolbar/components/utils.test.ts (1 hunks)
  • app/client/src/pages/Editor/JSEditor/JSEditorToolbar/components/utils.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: client-build / client-build
  • GitHub Check: client-unit-tests / client-unit-tests
  • GitHub Check: client-check-cyclic-deps / check-cyclic-dependencies
  • GitHub Check: client-prettier / prettier-check
  • GitHub Check: client-lint / client-lint
🔇 Additional comments (9)
app/client/src/PluginActionEditor/types/PluginActionTypes.ts (1)

9-9: LGTM! Clean enum addition.

The new ON_PAGE_UNLOAD enum member follows the established pattern and naming convention.

app/client/src/constants/AppsmithActionConstants/formConfig/PluginSettings.ts (1)

24-29: LGTM! Well-structured option addition.

The new "On page unload" option follows the established pattern with appropriate label, description, and enum value mapping.

app/client/src/pages/Editor/JSEditor/JSEditorToolbar/components/JSFunctionSettings.tsx (3)

58-60: Update feature flag reference after fixing typo.

This will need to be updated once the feature flag name typo is corrected in the FeatureFlag.ts file.

-  const isOnPageUnloadEnabled = useFeatureFlag(
-    FEATURE_FLAG.release_jsobjects_onpageunloadctions_enabled,
-  );
+  const isOnPageUnloadEnabled = useFeatureFlag(
+    FEATURE_FLAG.release_jsobjects_onpageunloadactions_enabled,
+  );

62-69: LGTM! Excellent use of memoization and utility functions.

The memoized options calculation prevents unnecessary re-computations and the utility function extraction improves maintainability.


73-83: LGTM! Clean default behavior handling.

The utility function properly handles edge cases when feature flags disable the current selection.

app/client/src/pages/Editor/JSEditor/JSEditorToolbar/components/utils.test.ts (2)

12-52: LGTM! Excellent comprehensive test coverage.

The matrix-based testing approach ensures all feature flag combinations are properly tested. Well-structured and thorough.


54-139: LGTM! Thorough edge case testing.

The test matrix covers all scenarios for default behavior selection when feature flags are disabled. Good use of data-driven testing.

app/client/src/pages/Editor/JSEditor/JSEditorToolbar/components/utils.ts (2)

1-8: Clean import structure and type definitions.

The imports are well-organized and appropriately typed. Good use of type imports where applicable.


21-47: Well-structured fallback logic with appropriate error handling.

The function correctly handles both disabled feature flag scenarios:

  • AUTOMATIC → ON_PAGE_LOAD when reactive actions disabled
  • ON_PAGE_UNLOAD → MANUAL when on page unload disabled

The use of nullish coalescing (??) provides proper fallback to null when expected options aren't found, which is good defensive programming.

@rahulbarwal rahulbarwal added the ok-to-test Required label for CI label Jun 20, 2025
@rahulbarwal
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/15774535342.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 41008.
recreate: .

Copy link

Deploy-Preview-URL: https://ce-41008.dp.appsmith.com

…UES in utils and tests

- Introduced JS_OBJECT_RUN_BEHAVIOR_VALUES to include the new ON_PAGE_UNLOAD action run behavior.
- Updated references in the JSEditor utility functions and tests to use the new constant for consistency and improved functionality.
- Ensured all related tests reflect the changes to maintain expected behavior under various feature flag states.
@rahulbarwal
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/15774924346.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 41008.
recreate: .

Copy link

Deploy-Preview-URL: https://ce-41008.dp.appsmith.com

Copy link
Contributor

@ankitakinger ankitakinger left a comment

Choose a reason for hiding this comment

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

LGTM

@rahulbarwal rahulbarwal merged commit 475939f into release Jun 23, 2025
43 checks passed
@rahulbarwal rahulbarwal deleted the rahulbarwal/issue40995/Task-UI-Components-Add-onPageUnload-Toggle-to-Action-Config branch June 23, 2025 08:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement New feature or request Javascript Product Issues related to users writing javascript in appsmith JS Objects Issues related to JS Objects ok-to-test Required label for CI Query Widgets & IDE Pod All issues related to Query, JS, Eval, Widgets & IDE Task A simple Todo
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Task]: UI Components: Add onPageUnload Toggle to Action Config
2 participants