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
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ export const CloudWorkflowSettingsSidePanel: FC<CloudWorkflowSettingsSidePanelPr
const { templateId: workflowId = '' } = useParams<{ templateId: string }>();
const [searchParams] = useSearchParams();
const { isLoading, workflowUserPreferences, workflowResourcePreferences } = useCloudWorkflowPreferences(workflowId);
const { setValue } = useFormContext<WorkflowDetailFormContext>();
const { setValue, getValues } = useFormContext<WorkflowDetailFormContext>();

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.

setValue('preferences', workflowUserPreferences, { shouldDirty: false });
}
}, [setValue, workflowUserPreferences]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.

// Use the user preferences if they exist, otherwise fall back to the resource preferences
const [preferences, setPreferences] = useState<WorkflowPreferences>(
workflowUserPreferences || workflowResourcePreferences!
Expand Down
Loading