diff --git a/app/layout/project/sidebar/scenario/grid-setup/features/add/list/component.tsx b/app/layout/project/sidebar/scenario/grid-setup/features/add/list/component.tsx index 96135d8274..87ab8a1bfa 100644 --- a/app/layout/project/sidebar/scenario/grid-setup/features/add/list/component.tsx +++ b/app/layout/project/sidebar/scenario/grid-setup/features/add/list/component.tsx @@ -37,10 +37,12 @@ export const ScenariosFeaturesList = ({ onContinue }): JSX.Element => { const scenarioSlice = getScenarioEditSlice(sid); const { setFeatures, setLayerSettings, setSelectedFeatures, setSelectedContinuousFeatures } = scenarioSlice.actions; - const { selectedFeatures, selectedContinuousFeatures, layerSettings } = useSelector( + const { selectedFeatures, selectedContinuousFeatures, layerSettings, features } = useSelector( (state) => state[`/scenarios/${sid}/edit`] ); + console.log({ featuresRedux: features }); + const dispatch = useDispatch(); const queryClient = useQueryClient(); const editable = useCanEditScenario(pid, sid); @@ -204,6 +206,7 @@ export const ScenariosFeaturesList = ({ onContinue }): JSX.Element => { const onSubmit = useCallback( (values) => { const { features } = values; + console.log({ onSubmit: features }); const data = getFeaturesRecipe(features); setSubmitting(true); diff --git a/app/layout/project/sidebar/scenario/grid-setup/features/targets/list/component.tsx b/app/layout/project/sidebar/scenario/grid-setup/features/targets/list/component.tsx index 542a5c9ae1..7cf70b3b77 100644 --- a/app/layout/project/sidebar/scenario/grid-setup/features/targets/list/component.tsx +++ b/app/layout/project/sidebar/scenario/grid-setup/features/targets/list/component.tsx @@ -12,7 +12,6 @@ import { useDebouncedCallback } from 'use-debounce'; import { useSaveSelectedFeatures, useSelectedFeatures, useTargetedFeatures } from 'hooks/features'; import { useCanEditScenario } from 'hooks/permissions'; -import { useToasts } from 'hooks/toast'; import Button from 'components/button'; import ConfirmationPrompt from 'components/confirmation-prompt'; @@ -26,8 +25,6 @@ export const ScenariosFeaturesTargets = ({ onGoBack }: { onGoBack: () => void }) const [confirmationTarget, setConfirmationTarget] = useState(null); const [confirmationFPF, setConfirmationFPF] = useState(null); - const { addToast } = useToasts(); - const queryClient = useQueryClient(); const { query } = useRouter(); const { pid, sid } = query as { pid: string; sid: string }; @@ -131,93 +128,77 @@ export const ScenariosFeaturesTargets = ({ onGoBack }: { onGoBack: () => void }) }, []); const onSubmit = useCallback( - (values, form) => { + (values) => { const { features } = values; - const featuresFieldTouched = form.getFieldState('features')?.dirty; - - if (featuresFieldTouched) { - setSubmitting(true); - - const data = { - status: 'created', - features: selectedFeaturesData.map((sf) => { - const { featureId, kind, geoprocessingOperations } = sf; - - if (kind === 'withGeoprocessing') { - return { - featureId, - kind, - geoprocessingOperations: geoprocessingOperations.map((go) => { - const { splits } = go; - - return { - ...go, - splits: splits - .filter((s) => { - return features.find((f) => { - return f.parentId === featureId && f.value === s.value; - }); - }) - .map((s) => { - const { target, fpf } = features.find((f) => { - return f.parentId === featureId && f.value === s.value; - }); - - return { - ...s, - marxanSettings: { - prop: target / 100 || 0.5, - fpf, - }, - }; - }), - }; - }), - }; - } - - const { target, fpf = 1 } = features.find((f) => f.featureId === featureId); + setSubmitting(true); + + const data = { + status: 'created', + features: selectedFeaturesData.map((sf) => { + const { featureId, kind, geoprocessingOperations } = sf; + + if (kind === 'withGeoprocessing') { return { featureId, kind, - marxanSettings: { - prop: target / 100 || 0.5, - fpf, - }, + geoprocessingOperations: geoprocessingOperations.map((go) => { + const { splits } = go; + + return { + ...go, + splits: splits + .filter((s) => { + return features.find((f) => { + return f.parentId === featureId && f.value === s.value; + }); + }) + .map((s) => { + const { target, fpf } = features.find((f) => { + return f.parentId === featureId && f.value === s.value; + }); + + return { + ...s, + marxanSettings: { + prop: target / 100 || 0.5, + fpf, + }, + }; + }), + }; + }), }; - }), - }; + } - selectedFeaturesMutation.mutate( - { - id: `${sid}`, - data, - }, - { - onSuccess: async () => { - await queryClient.invalidateQueries(['selected-features', sid]); - }, - onSettled: () => { - setSubmitting(false); + const { target, fpf = 1 } = features.find((f) => f.featureId === featureId); + return { + featureId, + kind, + marxanSettings: { + prop: target / 100 || 0.5, + fpf, }, - } - ); - } - if (!featuresFieldTouched) { - addToast( - 'save-selected-features', - <> -
-No modifications have been made to the selected features.
- >, - { - level: 'info', - } - ); - } + }; + }), + }; + + selectedFeaturesMutation.mutate( + { + id: `${sid}`, + data, + }, + { + onSuccess: async () => { + await queryClient.invalidateQueries(['selected-features', sid]); + }, + onSettled: () => { + setSubmitting(false); + }, + } + ); }, - [sid, queryClient, selectedFeaturesData, selectedFeaturesMutation, addToast] + [sid, queryClient, selectedFeaturesData, selectedFeaturesMutation] ); const toggleSeeOnMap = useCallback(