-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
- Loading branch information
Showing
13 changed files
with
203 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
65 changes: 65 additions & 0 deletions
65
...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,65 @@ | ||
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, ApiAction, Property } from "entities/Action"; | ||
import { getDatasources } from "ee/selectors/modulesSelector"; | ||
|
||
function useGetFormActionValues() { | ||
const formValues = useSelector( | ||
getFormValues(API_EDITOR_FORM_NAME), | ||
) as ApiAction; | ||
|
||
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[]; | ||
|
||
const datasources = useSelector(getDatasources); | ||
|
||
let datasourceFromAction: Action["datasource"] | undefined = get( | ||
formValues, | ||
"datasource", | ||
); | ||
|
||
if (datasourceFromAction && datasourceFromAction.hasOwnProperty("id")) { | ||
datasourceFromAction = datasources.find( | ||
(d) => d.id === datasourceFromAction?.id, | ||
); | ||
} | ||
|
||
const currentEnvironment = useSelector(getCurrentEnvironmentId); | ||
|
||
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.