Skip to content

Commit

Permalink
fixes target/spf values after editing one of them
Browse files Browse the repository at this point in the history
  • Loading branch information
agnlez committed Mar 11, 2024
1 parent f261c38 commit 27ca4f3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const SplitFeaturesBulkActionMenu = ({
selectedFeatureIds,
onDone,
}: {
features: (Feature & { name: string })[];
features: (Feature & { name: string; marxanSettings: { prop?: number; fpf?: number } })[];
selectedFeatureIds: Feature['id'][];
onDone: () => void;
}): JSX.Element => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const EditModal = ({
handleModal,
onDone,
}: {
selectedFeatures: (Feature & { name: string })[];
selectedFeatures: (Feature & { name: string; marxanSettings: { prop?: number; fpf?: number } })[];
handleModal: (modalKey: 'split' | 'edit' | 'delete', isVisible: boolean) => void;
onDone?: () => void;
}): JSX.Element => {
Expand Down Expand Up @@ -178,8 +178,9 @@ const EditModal = ({
return (
<FormRFF<FormValues>
initialValues={{
target: 50,
spf: 1,
target:
(selectedFeatures?.length === 1 && selectedFeatures?.[0]?.marxanSettings?.prop) || 50,
spf: (selectedFeatures?.length === 1 && selectedFeatures?.[0]?.marxanSettings?.fpf) || 1,
}}
ref={formRef}
onSubmit={onEditSubmit}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChangeEvent, ComponentProps, useCallback, useMemo, useState } from 'react';
import { ChangeEvent, ComponentProps, useCallback, useEffect, useMemo, useState } from 'react';

import { useQueryClient } from 'react-query';

Expand Down Expand Up @@ -418,6 +418,21 @@ const TargetAndSPFFeatures = (): JSX.Element => {
const displayBulkActions = selectedFeatureIds.length > 0;
const displaySaveButton = selectedFeaturesQuery.data?.length > 0;

useEffect(() => {
setFeatureValues((prevValues) => ({
...prevValues,
...selectedFeaturesQuery.data?.reduce((acc, { id, marxanSettings }) => {
return {
...acc,
[id]: {
target: marxanSettings?.prop * 100,
spf: marxanSettings?.fpf,
},
};
}, {}),
}));
}, [selectedFeaturesQuery.data]);

return (
<>
<Section className="relative flex flex-col space-y-4 overflow-hidden">
Expand Down

0 comments on commit 27ca4f3

Please sign in to comment.