forked from appsmithorg/appsmith
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: [Plugin Action Form] Common Editor State (appsmithorg#36512)
## Description Passes the correct states for the Common Editor form in the Plugin Action Form. - Uses a hook to pass the form states as already implemented - Uses helper functions to get the header and params count from the said state - As a side effect I can remove these from the original implementation since the invocation is now in the common `RequestTabs` components - Updates the `changeActionCall` hook to only be called if the action changes - Updates the tests to reflect this EE PR to track tests: https://github.com/appsmithorg/appsmith-ee/pull/5217 Parts of appsmithorg#36154 ## Communication Should the DevRel and Marketing teams inform users about this change? - [ ] Yes - [x] No <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes - **New Features** - Introduced a custom hook for streamlined retrieval of action-related values in forms. - Added utility functions for counting valid headers and parameters. - **Improvements** - Simplified component interfaces by removing unnecessary properties related to headers and parameters. - Enhanced type safety for header and parameter properties. - Refined tab rendering logic for better user experience. - **Bug Fixes** - Adjusted logic to ensure actions are dispatched only on changes to action IDs. - **Documentation** - Updated relevant documentation to reflect changes in component props and functionalities. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
- Loading branch information
Showing
13 changed files
with
216 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
...r/components/PluginActionForm/components/CommonEditorForm/hooks/useGetFormActionValues.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { getFormValues } from "redux-form"; | ||
import { API_EDITOR_FORM_NAME } from "ee/constants/forms"; | ||
import { getCurrentEnvironmentId } from "ee/selectors/environmentSelectors"; | ||
import get from "lodash/get"; | ||
import { useSelector } from "react-redux"; | ||
import { | ||
type Action, | ||
type ApiAction, | ||
isAPIAction, | ||
type Property, | ||
} from "entities/Action"; | ||
import { getDatasources } from "ee/selectors/entitiesSelector"; | ||
|
||
function useGetFormActionValues() { | ||
const formValues = useSelector(getFormValues(API_EDITOR_FORM_NAME)) as Action; | ||
const datasources = useSelector(getDatasources); | ||
const currentEnvironment = useSelector(getCurrentEnvironmentId); | ||
|
||
// In an unlikely scenario where form is not initialised, | ||
// return empty values to avoid form ui issues | ||
if (!isAPIAction(formValues)) { | ||
return { | ||
actionHeaders: [], | ||
actionParams: [], | ||
autoGeneratedHeaders: [], | ||
datasourceParams: [], | ||
datasourceHeaders: [], | ||
}; | ||
} | ||
|
||
const actionHeaders = get( | ||
formValues, | ||
"actionConfiguration.headers", | ||
[], | ||
) as Property[]; | ||
|
||
const autoGeneratedHeaders: ApiAction["actionConfiguration"]["autoGeneratedHeaders"] = | ||
get(formValues, "actionConfiguration.autoGeneratedHeaders", []); | ||
|
||
const actionParams = get( | ||
formValues, | ||
"actionConfiguration.queryParameters", | ||
[], | ||
) as Property[]; | ||
|
||
let datasourceFromAction: Action["datasource"] | undefined = get( | ||
formValues, | ||
"datasource", | ||
); | ||
|
||
if (datasourceFromAction && Object.hasOwn(datasourceFromAction, "id")) { | ||
datasourceFromAction = datasources.find( | ||
(d) => d.id === datasourceFromAction?.id, | ||
); | ||
} | ||
|
||
const datasourceHeaders = get( | ||
datasourceFromAction, | ||
`datasourceStorages.${currentEnvironment}.datasourceConfiguration.headers`, | ||
[], | ||
) as Property[]; | ||
|
||
const datasourceParams = get( | ||
datasourceFromAction, | ||
`datasourceStorages.${currentEnvironment}.datasourceConfiguration.queryParameters`, | ||
[], | ||
) as Property[]; | ||
|
||
return { | ||
actionHeaders, | ||
autoGeneratedHeaders, | ||
actionParams, | ||
datasourceHeaders, | ||
datasourceParams, | ||
}; | ||
} | ||
|
||
export default useGetFormActionValues; |
22 changes: 22 additions & 0 deletions
22
...onEditor/components/PluginActionForm/components/CommonEditorForm/utils/getHeadersCount.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import getValidProperties from "./getValidProperties"; | ||
import type { Property } from "entities/Action"; | ||
|
||
function getHeadersCount( | ||
actionHeaders?: Property[], | ||
datasourceHeaders?: Property[], | ||
autoGeneratedActionHeaders?: Property[], | ||
): number { | ||
const validActionHeaders = getValidProperties(actionHeaders); | ||
const validDatasourceHeaders = getValidProperties(datasourceHeaders); | ||
const validAutoGeneratedHeaders = getValidProperties( | ||
autoGeneratedActionHeaders, | ||
); | ||
|
||
return ( | ||
validActionHeaders.length + | ||
validDatasourceHeaders.length + | ||
validAutoGeneratedHeaders.length | ||
); | ||
} | ||
|
||
export default getHeadersCount; |
14 changes: 14 additions & 0 deletions
14
...ionEditor/components/PluginActionForm/components/CommonEditorForm/utils/getParamsCount.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import type { Property } from "entities/Action"; | ||
import getValidProperties from "./getValidProperties"; | ||
|
||
function getParamsCount( | ||
actionParams?: Property[], | ||
datasourceParams?: Property[], | ||
) { | ||
const validActionParams = getValidProperties(actionParams); | ||
const validDatasourceParams = getValidProperties(datasourceParams); | ||
|
||
return validActionParams.length + validDatasourceParams.length; | ||
} | ||
|
||
export default getParamsCount; |
11 changes: 11 additions & 0 deletions
11
...ditor/components/PluginActionForm/components/CommonEditorForm/utils/getValidProperties.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import type { Property } from "entities/Action"; | ||
|
||
function getValidProperties(value?: Property[]) { | ||
if (!Array.isArray(value)) { | ||
return []; | ||
} | ||
|
||
return value.filter((v) => v.key && v.key !== ""); | ||
} | ||
|
||
export default getValidProperties; |
2 changes: 2 additions & 0 deletions
2
...PluginActionEditor/components/PluginActionForm/components/CommonEditorForm/utils/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { default as getHeadersCount } from "./getHeadersCount"; | ||
export { default as getParamsCount } from "./getParamsCount"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.