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
User preferences for Create/Edit method #9830
User preferences for Create/Edit method #9830
Conversation
This PR is dependent on #9386 for the dynamic extensions |
/retest |
5dd36e2
to
a4819fc
Compare
/retest |
1 similar comment
/retest |
5fd7e5b
to
cbdff26
Compare
@@ -29,6 +35,7 @@ type SyncedEditorFieldProps = { | |||
name: string; | |||
formContext: EditorContext<SanitizeToForm>; | |||
yamlContext: EditorContext<SanitizeToYAML>; | |||
lastViewedEditorTypeUserSettingKey: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we keep the prop name shorter? Maybe just userSettingsKey
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we use lastViewUserSettingKey
?
WDYT?
return field.value as EditorType; | ||
}; | ||
|
||
const [activeEditorType, setActiveEditorType] = React.useState<EditorType>(getEditorType); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need another state for editor type? Wouldn't the formik state value work here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated to custom hook
@@ -120,7 +155,15 @@ const SyncedEditorField: React.FC<SyncedEditorFieldProps> = ({ | |||
setDisabledFormAlert(formContext.isDisabled); | |||
}, [formContext.isDisabled]); | |||
|
|||
return ( | |||
React.useEffect(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need this effect?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we need this to update the last viewed user setting when the component loads.
this becomes useful when the last viewed type is different from the preferred type.
setLastViewedEditorType(activeEditorType); | ||
setFieldValue(name, activeEditorType); | ||
} | ||
// eslint-disable-next-line react-hooks/exhaustive-deps |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a comment why the linting is disabled here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
const [ | ||
lastViewedEditorType, | ||
setLastViewedEditorType, | ||
lastViewedEditorTypeLoaded, | ||
] = useUserSettings<EditorType>(lastViewedEditorTypeUserSettingKey); | ||
const [preferredEditorType, preferredEditorTypeLoaded] = usePreferredCreateEditMethod(); | ||
|
||
const getEditorType = (): EditorType => { | ||
if ( | ||
preferredEditorType && | ||
preferredEditorType !== PREFERRED_CREATE_EDIT_METHOD_USER_SETTING_VALUE_LATEST | ||
) { | ||
return preferredEditorType as EditorType; | ||
} | ||
if (lastViewedEditorType) { | ||
return lastViewedEditorType; | ||
} | ||
return initialType; | ||
}; | ||
const [type, setType] = React.useState<EditorType>(getEditorType()); | ||
|
||
const loaded = preferredEditorTypeLoaded || lastViewedEditorTypeLoaded; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like most of this can be extracted out into a separate hook since its being used in SyncedEditorField
as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as per discussion, updated to a custom hook.
cbdff26
to
efa4e75
Compare
efa4e75
to
d07d518
Compare
d07d518
to
4a709ba
Compare
/retest |
/retest-required Please review the full test history for this PR and help us cut down flakes. |
5 similar comments
/retest-required Please review the full test history for this PR and help us cut down flakes. |
/retest-required Please review the full test history for this PR and help us cut down flakes. |
/retest-required Please review the full test history for this PR and help us cut down flakes. |
/retest-required Please review the full test history for this PR and help us cut down flakes. |
/retest-required Please review the full test history for this PR and help us cut down flakes. |
6f06e03
to
01c3d4b
Compare
01c3d4b
to
ce4fdfc
Compare
/retest |
/retest-required |
ce4fdfc
to
7e269ed
Compare
/retest-required |
/retest |
7e269ed
to
90cf12e
Compare
90cf12e
to
0237b41
Compare
0237b41
to
3c94897
Compare
React.useEffect(() => { | ||
if (resourceLoaded) { | ||
const editorType: EditorType = getEditorType(); | ||
setLastViewedEditorType(editorType); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should avoid setting the last viewed editor type when resources are just loaded.
Just because the user opens a form, its not required to save the current state. We should wrap this with an if state if this is different then before OR better, just don't do this. This is always a patch network call, a kubernetes write operation, just because the user opens a form. Does it also work if we just skip this line?
setLastViewedEditorType(editorType); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will raise a bug for this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is required when the lastEditorType
doesn't exist or when it is different from the preferredEditorType only when the form loads
Its working fine. I will create a bug (ODC-6302) that we should avoid unnecessary API calls. /lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: invincibleJai, jerolimov, nemesis09, rohitkrai03 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/retest |
Epic:
https://issues.redhat.com/browse/ODC-5227
Story:
https://issues.redhat.com/browse/ODC-5959
Analysis/Root cause:
As a user, I need the ability to set/edit my preferences for Create/Edit method (form or yaml) through user preferences.
Solution/Description:
This PR uses the dynamic extension added in #9386 to contribute user preference for Create/Edit method.
preferredCreateEditMethod
can be set from User Preferences pagepreferredCreateEditMethod
will be used for default option whenSyncedEditorField
loadspreferredCreateEditMethod
is not defined,lastViewedEditorType
for the coomponent will be used from user settingspreferredCreateEditMethod
andlastViewedEditorType
are not defined, the initial value passed to formik field will be usedSyncedEditorField
will have its own user setting forlastViewedEditorType
Screens:
Test Coverage:
Browser conformation: