Skip to content
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

fix(web): Use initial Workflow Preferences state to determine override state #6591

Merged

Conversation

rifont
Copy link
Contributor

@rifont rifont commented Sep 30, 2024

What changed? Why was the change needed?

  • Use initial Workflow Preferences state to determine override state
  • Modify form state population to set default only if it's not set already
    • This is necessary due to the Preferences resource being fetched over API from a child component not present in the main view, we need to ensure the form state is only updated on the Preferences panel component initial render

Screenshots

https://www.loom.com/share/8b5aa3e3f8a749f48ff6b0d4425bb48d?sid=237293f4-746d-4cda-a46c-0350b62456db

Expand for optional sections

Related enterprise PR

Special notes for your reviewer


useEffect(() => {
if (workflowUserPreferences !== undefined) {
if (workflowUserPreferences !== undefined && getValues('preferences') === undefined) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using the form state to retain context of the form values, only setting the form values if it wasn't set already. This prevents the Preferences component state from being reset to null when the API fetch occurs on component render.

@@ -47,7 +47,7 @@ export const WorkflowSubscriptionPreferences: FC<WorkflowSubscriptionPreferences
updateWorkflowPreferences,
arePreferencesDisabled,
}) => {
const [isOverridingPreferences, setIsOverridingPreferences] = useState(false);
const [isOverridingPreferences, setIsOverridingPreferences] = useState(workflowUserPreferences !== null);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fix to ensure the initial state for preference override toggle is correct to ensure the useEffect condition that resets the form value isn't fired on initial render.

Copy link

linear bot commented Sep 30, 2024

@rifont rifont merged commit f0f56ef into next Sep 30, 2024
27 checks passed
@rifont rifont deleted the nv-4322-workflow-preferences-are-lost-when-not-saved-immediately branch September 30, 2024 10:33
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.

2 participants