-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Plugin Action Editor] Query Form evaluation
- Loading branch information
Showing
4 changed files
with
118 additions
and
18 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
22 changes: 22 additions & 0 deletions
22
.../PluginActionEditor/components/PluginActionForm/components/UQIEditor/hooks/useFormData.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 { useSelector } from "react-redux"; | ||
import { getFormValues } from "redux-form"; | ||
import { QUERY_EDITOR_FORM_NAME } from "ee/constants/forms"; | ||
import type { QueryAction, SaaSAction } from "entities/Action"; | ||
import { getFormEvaluationState } from "selectors/formSelectors"; | ||
|
||
export const useFormData = () => { | ||
const data = useSelector(getFormValues(QUERY_EDITOR_FORM_NAME)) as | ||
| QueryAction | ||
| SaaSAction; | ||
|
||
const formEvaluation = useSelector(getFormEvaluationState); | ||
|
||
let evaluationState = {}; | ||
|
||
// Fetching evaluations state only once the formData is populated | ||
if (!!data) { | ||
evaluationState = formEvaluation[data.id]; | ||
} | ||
|
||
return { data, evaluationState }; | ||
}; |
60 changes: 60 additions & 0 deletions
60
...mponents/PluginActionForm/components/UQIEditor/hooks/useGoogleSheetsSetDefaultProperty.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,60 @@ | ||
import { useEffect } from "react"; | ||
import { PluginPackageName } from "entities/Action"; | ||
import { merge } from "lodash"; | ||
import { getConfigInitialValues } from "components/formControls/utils"; | ||
import { diff, type Diff } from "deep-diff"; | ||
import { getPathAndValueFromActionDiffObject } from "utils/getPathAndValueFromActionDiffObject"; | ||
import { setActionProperty } from "actions/pluginActionActions"; | ||
import { usePluginActionContext } from "../../../../../PluginActionContext"; | ||
import { useDispatch } from "react-redux"; | ||
|
||
export const useGoogleSheetsSetDefaultProperty = () => { | ||
const { | ||
action, | ||
editorConfig, | ||
plugin: { packageName }, | ||
settingsConfig, | ||
} = usePluginActionContext(); | ||
|
||
const dispatch = useDispatch(); | ||
|
||
useEffect( | ||
function setDefaultValuesForGoogleSheets() { | ||
if (packageName === PluginPackageName.GOOGLE_SHEETS) { | ||
const initialValues = {}; | ||
|
||
merge( | ||
initialValues, | ||
getConfigInitialValues(editorConfig as Record<string, unknown>[]), | ||
); | ||
|
||
merge( | ||
initialValues, | ||
getConfigInitialValues(settingsConfig as Record<string, unknown>[]), | ||
); | ||
|
||
// initialValues contains merge of action, editorConfig, settingsConfig and will be passed to redux form | ||
merge(initialValues, action); | ||
|
||
// @ts-expect-error: Types are not available | ||
const actionObjectDiff: undefined | Diff<Action | undefined, Action>[] = | ||
diff(action, initialValues); | ||
|
||
const { path = "", value = "" } = { | ||
...getPathAndValueFromActionDiffObject(actionObjectDiff), | ||
}; | ||
|
||
if (value && path) { | ||
dispatch( | ||
setActionProperty({ | ||
actionId: action.id, | ||
propertyName: path, | ||
value, | ||
}), | ||
); | ||
} | ||
} | ||
}, | ||
[action, dispatch, editorConfig, packageName, settingsConfig], | ||
); | ||
}; |
21 changes: 21 additions & 0 deletions
21
...ionEditor/components/PluginActionForm/components/UQIEditor/hooks/useInitFormEvaluation.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,21 @@ | ||
import { useEffect } from "react"; | ||
import { initFormEvaluations } from "actions/evaluationActions"; | ||
import { useDispatch } from "react-redux"; | ||
import { usePluginActionContext } from "../../../../../PluginActionContext"; | ||
|
||
export const useInitFormEvaluation = () => { | ||
const dispatch = useDispatch(); | ||
|
||
const { | ||
action: { baseId }, | ||
editorConfig, | ||
settingsConfig, | ||
} = usePluginActionContext(); | ||
|
||
useEffect( | ||
function formEvaluationInit() { | ||
dispatch(initFormEvaluations(editorConfig, settingsConfig, baseId)); | ||
}, | ||
[baseId, dispatch, editorConfig, settingsConfig], | ||
); | ||
}; |