Skip to content

Conversation

@priscilawebdev
Copy link
Member

@priscilawebdev priscilawebdev commented May 23, 2025

Currently, the 'Create Project' and 'Configure SDK' buttons are disabled/busy only while the project creation process is ongoing. However, in addition to the project creation, there are two other asynchronous requests that may be triggered and could potentially fail. Because these additional requests are not accounted for, the buttons may become enabled prematurely and users could again fire other requests. Ideally, the buttons should remain disabled and indicate a busy state until all related mutations have fully completed - successfully or not - before allowing further user interaction. This PR updates the code fixing it.

Before

Screen.Recording.2025-05-23.at.09.36.42.mov

After

Screen.Recording.2025-05-23.at.09.28.52.mov

closes TET-532

@github-actions github-actions bot added the Scope: Frontend Automatically applied to PRs that change frontend components label May 23, 2025
@priscilawebdev priscilawebdev force-pushed the priscila/fix/project-creation/disable-the-button-until-all-mutations-are-complete branch from 69e7bb6 to 1d33844 Compare May 23, 2025 08:02
@priscilawebdev priscilawebdev changed the base branch from master to priscila/ref/project-creation/introduce-use-create-project-rules-hook May 23, 2025 08:04
@priscilawebdev priscilawebdev force-pushed the priscila/fix/project-creation/disable-the-button-until-all-mutations-are-complete branch from 1d33844 to ccd66cb Compare May 23, 2025 08:22
Comment on lines +522 to +523
disabled={!(canUserCreateProject && formErrorCount === 0)}
busy={createProjectAndRules.isPending}
Copy link
Member Author

Choose a reason for hiding this comment

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

we should make a distinction between busy and disabled here


const handleProjectCreation = useCallback(
async (data: FormData) => {
setErrors(undefined);
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the only part slightly outside the scope of this PR, but I think it's reasonable to include it. We should clear the errors when the submit button is clicked again.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I’m wondering why we keep track of the error state manually? useMutation handles errors and returns them as part of the return value:

const { error } = useMutation(...)

and it will get re-set automatically if you fire the mutation again. So I think we should be able to get rid of that useState completely.

Copy link
Member Author

Choose a reason for hiding this comment

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

@TkDodo yes! great idea. now that we have all mutations in useCreateProjectAndRules we can get rid of setErrors. will update the code

@priscilawebdev priscilawebdev requested a review from TkDodo May 23, 2025 08:25
@priscilawebdev priscilawebdev marked this pull request as ready for review May 23, 2025 08:25
@priscilawebdev priscilawebdev requested a review from a team as a code owner May 23, 2025 08:25
Comment on lines 54 to 61
const notificationRule = await createNotificationAction({
shouldCreateRule: alertRuleConfig?.shouldCreateRule,
name: project.name,
projectSlug: project.slug,
conditions: alertRuleConfig?.conditions,
actionMatch: alertRuleConfig?.actionMatch,
frequency: alertRuleConfig?.frequency,
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this mutation isn’t dependent on createProjectRules, but it still fires after that one has finished, and it won’t run at all if that one error’d.

We could probably fire createProjectRules.mutateAsync and createNotificationAction in parallel, and then await both promises with Promise.all at the end.

Copy link
Member Author

Choose a reason for hiding this comment

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

the creation of a rule requires a project slug and name, that is why the project's mutation has to run first. Does that make sense?

Copy link
Collaborator

Choose a reason for hiding this comment

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

yes, that makes sense, but I’m talking about this code block:

      if (alertRuleConfig?.shouldCreateCustomRule) {
        const ruleData = await createProjectRules.mutateAsync({
          projectSlug: project.slug,
          name: project.name,
          conditions: alertRuleConfig?.conditions,
          actions: alertRuleConfig?.actions,
          actionMatch: alertRuleConfig?.actionMatch,
          frequency: alertRuleConfig?.frequency,
        });

        ruleIds.push(ruleData.id);
      }

if shouldCreateCustomRule is true, we call await createProjectRules.mutateAsync, and then await createNotificationAction, so they run in serial. but since createNotificationAction does not depend on any result from createProjectRules.mutateAsync, they could run in parallel. Something like:

const projectRulesPromise = alertRuleConfig?.shouldCreateCustomRule ? createProjectRuels.mutateAsync(...) : undefined

const notificationRulePromise = createNotificationAction(...)

const rules = await Promise.all([
  projectRulesPromise,
  notificationRulePromise,
]);

then, you can get ruleIds by mapping over rules


const handleProjectCreation = useCallback(
async (data: FormData) => {
setErrors(undefined);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I’m wondering why we keep track of the error state manually? useMutation handles errors and returns them as part of the return value:

const { error } = useMutation(...)

and it will get re-set automatically if you fire the mutation again. So I think we should be able to get rid of that useState completely.

Copy link
Collaborator

@TkDodo TkDodo left a comment

Choose a reason for hiding this comment

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

awesome work 🙌

…ect-rules-hook' of github.com:getsentry/sentry into priscila/ref/project-creation/introduce-use-create-project-rules-hook
…ect-rules-hook' into priscila/fix/project-creation/disable-the-button-until-all-mutations-are-complete
priscilawebdev added a commit that referenced this pull request Jun 2, 2025
This hook was introduced to follow our standard use of react-query and
will be used in this
[PR](#92183).
Base automatically changed from priscila/ref/project-creation/introduce-use-create-project-rules-hook to master June 2, 2025 08:56
andrewshie-sentry pushed a commit that referenced this pull request Jun 2, 2025
This hook was introduced to follow our standard use of react-query and
will be used in this
[PR](#92183).
@codecov
Copy link

codecov bot commented Jun 3, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #92183      +/-   ##
==========================================
- Coverage   87.89%   86.80%   -1.10%     
==========================================
  Files       10253    10170      -83     
  Lines      587976   582124    -5852     
  Branches    22831    22526     -305     
==========================================
- Hits       516818   505304   -11514     
- Misses      70712    76373    +5661     
- Partials      446      447       +1     

@priscilawebdev priscilawebdev merged commit f1a18ad into master Jun 3, 2025
42 checks passed
@priscilawebdev priscilawebdev deleted the priscila/fix/project-creation/disable-the-button-until-all-mutations-are-complete branch June 3, 2025 06:21
andrewshie-sentry pushed a commit that referenced this pull request Jun 3, 2025
…complete (#92183)

Currently, the 'Create Project' and 'Configure SDK' buttons are
disabled/busy only while the project creation process is ongoing.
However, in addition to the project creation, there are two other
asynchronous requests that may be triggered and could potentially fail.
Because these additional requests are not accounted for, the buttons may
become enabled prematurely and users could again fire other requests.
Ideally, the buttons should remain disabled and indicate a busy state
until all related mutations have fully completed 
closes TET-532
@github-actions github-actions bot locked and limited conversation to collaborators Jun 18, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Scope: Frontend Automatically applied to PRs that change frontend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants