Skip to content

feat: Add confirmation dialog before saving a Cloud Config parameter that has been modified since loading it #2770

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

Open
wants to merge 5 commits into
base: alpha
Choose a base branch
from

Conversation

dblythy
Copy link
Member

@dblythy dblythy commented Apr 27, 2025

New Pull Request Checklist

Issue Description

Closes: #2567

Approach

TODOs before merging

  • Add tests
  • Add changes to documentation (guides, repository pages, in-code descriptions)

Summary by CodeRabbit

  • New Features

    • Added a confirmation dialog to warn users when saving parameters modified by others, allowing review before overwriting.
  • Bug Fixes

    • Fixed a missing closing brace in the .noScroll CSS class for correct styling.
  • Style

    • Added a new .confirmConfig CSS class to improve modal layout.

Copy link

I will reformat the title to use the proper commit message syntax.

@parse-github-assistant parse-github-assistant bot changed the title feat: confirmation on config param update feat: Confirmation on config param update Apr 27, 2025
Copy link

parse-github-assistant bot commented Apr 27, 2025

🚀 Thanks for opening this pull request! We appreciate your effort in improving the project. Please let us know once your pull request is ready for review.

@parseplatformorg
Copy link
Contributor

parseplatformorg commented Apr 27, 2025

🎉 Snyk checks have passed. No issues have been found so far.

security/snyk check is complete. No issues have been found. (View Details)

Copy link

uffizzi-cloud bot commented Apr 27, 2025

Uffizzi Ephemeral Environment deployment-63191

⌚ Updated Apr 27, 2025, 10:30 UTC

☁️ https://app.uffizzi.com/github.com/parse-community/parse-dashboard/pull/2770

📄 View Application Logs etc.

What is Uffizzi? Learn more

@dblythy dblythy requested a review from a team April 27, 2025 10:48
Copy link

coderabbitai bot commented Apr 28, 2025

📝 Walkthrough

"""

Walkthrough

The changes introduce concurrency conflict detection when saving configuration parameters in the dashboard. The Config React component now fetches the latest parameter value from the server before saving. If the value has changed since it was last loaded, a confirmation modal prompts the user before overwriting. This is achieved by updating the saveParam method to perform the check and by adding a modal dialog for user confirmation. Additionally, a missing closing brace was fixed in the .noScroll CSS class, and a new .confirmConfig class was added.

Changes

File(s) Change Summary
src/dashboard/Data/Config/Config.react.js Added concurrency check in saveParam, introduced confirmation modal, updated method to async, and added state.
src/dashboard/Data/Browser/Browser.scss Fixed missing closing brace for .noScroll and added new .confirmConfig class with padding.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ConfigComponent
    participant Server
    participant Modal

    User->>ConfigComponent: Initiate saveParam(name, value)
    ConfigComponent->>Server: Fetch latest config data
    Server-->>ConfigComponent: Return latest config data
    ConfigComponent->>ConfigComponent: Compare cached vs latest value
    alt Values differ and not override
        ConfigComponent->>Modal: Show confirmation dialog
        Modal->>User: Prompt to confirm overwrite
        User->>Modal: Click "Continue"
        Modal->>ConfigComponent: Confirm overwrite
        ConfigComponent->>ConfigComponent: Call saveParam with override
        ConfigComponent->>Server: Save parameter (override)
    else Values same or override
        ConfigComponent->>Server: Save parameter
    end
    Server-->>ConfigComponent: Save response
Loading

Assessment against linked issues

Objective Addressed Explanation
Reload Cloud Config param before updating and warn user if value has changed (#2567)
"""

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between da808c3 and aea4d1f.

📒 Files selected for processing (1)
  • src/dashboard/Data/Config/Config.react.js (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/dashboard/Data/Config/Config.react.js
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Docker linux/amd64

🪧 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 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.

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

🧹 Nitpick comments (4)
src/dashboard/Data/Browser/Browser.scss (1)

275-276: Fix the spelling error in the class name

There's a typo in the class name .confimConfig - it's missing the letter "r" and should be .confirmConfig.

-.confimConfig {
+.confirmConfig {
  padding: 10px 20px;
}
src/dashboard/Data/Config/Config.react.js (3)

108-130: Fix the class name reference to match the CSS

The implementation of the confirmation modal looks good, but there's a typo in the class name. The CSS class is misspelled as .confimConfig (missing an "r"), and the same typo is reflected here.

-          <div className={[browserStyles.confimConfig]}>
+          <div className={[browserStyles.confirmConfig]}>

This change should be made after fixing the class name in the CSS file.


274-294: Great implementation of concurrency conflict detection

The async saveParam implementation with concurrency checking is a valuable improvement that prevents accidental overwrites when multiple users edit the same parameter.

Consider the following improvements:

  1. Add error handling for the fetch operation
  2. Clean up this.confirmData after it's used to prevent memory leaks
 async saveParam({ name, value, type, masterKeyOnly, override }) {
   const cachedParams = this.cacheData.get('params');
   const cachedValue = cachedParams.get(name);

-  await this.props.config.dispatch(ActionTypes.FETCH);
+  try {
+    await this.props.config.dispatch(ActionTypes.FETCH);
+  } catch (error) {
+    // Handle fetch error gracefully
+    console.error('Failed to fetch latest config data:', error);
+    // Continue with save operation as we can't verify concurrency
+  }
   const fetchedParams = this.props.config.data.get('params');

   if (cachedValue !== fetchedParams.get(name) && !override) {
     this.setState({
       confirmModalOpen: true,
       modalOpen: false,
     });
     this.confirmData = {
       name,
       value,
       type,
       masterKeyOnly,
     };
     return;
   }

And in the onConfirm handler for the modal:

 onConfirm={() => {
   this.setState({ confirmModalOpen: false });
   this.saveParam({
     ...this.confirmData,
     override: true,
   });
+  // Clean up confirmData after use
+  this.confirmData = null;
 }}

117-123: Clean up confirmData after use

To prevent potential memory leaks, clean up the confirmData property after it's used.

onConfirm={() => {
  this.setState({ confirmModalOpen: false });
  this.saveParam({
    ...this.confirmData,
    override: true,
  });
+  // Clean up confirmData after use
+  this.confirmData = null;
}}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bcce5c5 and 334e952.

📒 Files selected for processing (2)
  • src/dashboard/Data/Browser/Browser.scss (1 hunks)
  • src/dashboard/Data/Config/Config.react.js (5 hunks)
🔇 Additional comments (4)
src/dashboard/Data/Browser/Browser.scss (1)

271-273: Good fix for the missing closing brace

Adding the missing closing brace for the .noScroll class fixes a CSS syntax error that could have caused styling issues.

src/dashboard/Data/Config/Config.react.js (3)

42-42: LGTM: Added state variable for modal control

Good addition of the confirmModalOpen state to control the visibility of the confirmation modal.


63-63: LGTM: Caching data for concurrency checks

Good approach to cache the config data for later comparison when saving parameters.


281-293:

❌ Incorrect review comment

Verify behavior when the parameter is being created

For a new parameter that doesn't exist yet, the cachedValue and fetchedParams.get(name) might both be undefined, potentially bypassing the conflict detection. Consider adding a check to handle this case.


🏁 Script executed:

#!/bin/bash
# Check if there's specific handling for new parameters in the codebase

echo "Checking how new parameters are created and saved..."
rg -A 5 -B 5 'createParameter|Adding.*parameter' --type js

echo "Looking for other saveParam calls to understand parameter creation flow..."
rg 'saveParam\(' --type js

echo "Examining whether the equality check handles undefined values correctly..."
rg 'cachedValue.*!==.*fetchedParams' --type js

Length of output: 3825


🏁 Script executed:

#!/bin/bash
sed -n '200,360p' src/dashboard/Data/Config/Config.react.js

Length of output: 4998


🏁 Script executed:

#!/bin/bash
rg -n 'cacheData' src/dashboard/Data/Config/Config.react.js

Length of output: 177


No change needed for new parameter creation

The conflict check (cachedValue !== fetchedParams.get(name)) intentionally allows both values to be undefined, so creating a brand-new parameter proceeds without triggering the confirmation modal. Special-casing the “new parameter” scenario isn’t necessary.

Likely an incorrect or invalid review comment.

coderabbitai[bot]
coderabbitai bot previously approved these changes Apr 28, 2025
Signed-off-by: Manuel <5673677+mtrezza@users.noreply.github.com>
coderabbitai[bot]
coderabbitai bot previously approved these changes Apr 29, 2025
@mtrezza mtrezza closed this Apr 29, 2025
@mtrezza mtrezza reopened this Apr 29, 2025
@mtrezza mtrezza changed the title feat: Confirmation on config param update feat: Add confirmation dialog before saving a Cloud Config parameter that has been modified since loading the parameter Apr 29, 2025
@mtrezza mtrezza changed the title feat: Add confirmation dialog before saving a Cloud Config parameter that has been modified since loading the parameter feat: Add confirmation dialog before saving a Cloud Config parameter that has been modified since loading it Apr 29, 2025
Copy link

uffizzi-cloud bot commented Apr 29, 2025

Uffizzi Ephemeral Environment deployment-63245

⌚ Updated Apr 29, 2025, 01:30 UTC

☁️ https://app.uffizzi.com/github.com/parse-community/parse-dashboard/pull/2770

📄 View Application Logs etc.

What is Uffizzi? Learn more

Copy link
Member

@mtrezza mtrezza left a comment

Choose a reason for hiding this comment

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

  • Shows dialog when editing in same dashboard instance:
    https://github.com/user-attachments/assets/c3a48989-4e78-4aa8-937b-1d00350499a4
  • The most likely user behavior when seeing the dialog will be to cancel, reload the page, investigate the current value and perhaps redo the edit. It's rather unlikely that a user will just continue, without even knowing what will be overwritten. Therefore I think we should fetch the parameter from the server right before showing the edit dialog. The issue is more likely to occur the longer the dashboard page has been open, e.g. in a separate browser tab. Reloading the param right before editing will mitigate the issue in the first place.
  • How does the UI handle long loading fetch - how does the user experience while waiting?
  • How is failed fetch handled? I assume a failed save shows an error message, does this also invoke that error message?

Signed-off-by: Manuel <5673677+mtrezza@users.noreply.github.com>
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.

Reload Cloud Config param before updating
3 participants