-
Notifications
You must be signed in to change notification settings - Fork 4.5k
fix: API Body format focus retention #37150
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ import type { AppState } from "ee/reducers"; | |
| import { createSelector } from "reselect"; | ||
|
|
||
| import { POST_BODY_FORM_DATA_KEY } from "./constants"; | ||
| import { POST_BODY_FORMAT_OPTIONS } from "../constants/CommonApiConstants"; | ||
|
|
||
| export const getActionEditorSavingMap = (state: AppState) => | ||
| state.ui.pluginActionEditor.isSaving; | ||
|
|
@@ -37,19 +38,25 @@ export const isActionDeleting = (id: string) => | |
| (deletingMap) => id in deletingMap && deletingMap[id], | ||
| ); | ||
|
|
||
| type GetFormData = ( | ||
| state: AppState, | ||
| id: string, | ||
| ) => { label: string; value: string } | undefined; | ||
| export const getFormData = (state: AppState) => | ||
| state.ui.pluginActionEditor.formData; | ||
|
Comment on lines
+41
to
+42
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider creating memoized selectors for specific form data fields. Direct state access might cause unnecessary re-renders in components that only need specific parts of formData. Consider creating specific selectors using createSelector: export const getSpecificFormData = (key: string) =>
createSelector([getFormData], (formData) => formData[key]); |
||
|
|
||
| export const getPostBodyFormat: GetFormData = (state, id) => { | ||
| const formData = state.ui.pluginActionEditor.formData; | ||
| type GetFormPostBodyFormat = (state: AppState) => { | ||
| label: string; | ||
| value: string; | ||
| }; | ||
|
|
||
| export const getPostBodyFormat: GetFormPostBodyFormat = (state) => { | ||
| const formData = getFormData(state); | ||
|
|
||
| if (id in formData) { | ||
| return formData[id][POST_BODY_FORM_DATA_KEY]; | ||
| if (POST_BODY_FORM_DATA_KEY in formData) { | ||
| return formData[POST_BODY_FORM_DATA_KEY]; | ||
| } | ||
|
|
||
| return undefined; | ||
| return { | ||
| label: POST_BODY_FORMAT_OPTIONS.NONE, | ||
| value: POST_BODY_FORMAT_OPTIONS.NONE, | ||
| }; | ||
|
Comment on lines
+49
to
+59
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Memoize the selector to prevent unnecessary recalculations. While the implementation is correct, it should be memoized to prevent unnecessary recalculations. Consider this implementation: export const getPostBodyFormat: GetFormPostBodyFormat = createSelector(
[getFormData],
(formData) => {
if (POST_BODY_FORM_DATA_KEY in formData) {
return formData[POST_BODY_FORM_DATA_KEY];
}
return {
label: POST_BODY_FORMAT_OPTIONS.NONE,
value: POST_BODY_FORMAT_OPTIONS.NONE,
};
}
); |
||
| }; | ||
| export const getPluginActionConfigSelectedTab = (state: AppState) => | ||
| state.ui.pluginActionEditor.selectedConfigTab; | ||
|
|
||
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.
Remove redundant
defaultValueprop inSelectcomponentUsing both
defaultValueandvaluein a controlled component can cause confusion and potential bugs. Sincevalueis already managing the selected option,defaultValueis unnecessary and should be removed.Apply this diff to remove the redundant prop:
<Select data-testid="t--api-body-tab-switch" - defaultValue={postBodyFormat.value} onSelect={updateBodyContentType} value={postBodyFormat.value} >📝 Committable suggestion