Skip to content

Commit

Permalink
targets: sync local with remotes changes in targets
Browse files Browse the repository at this point in the history
  • Loading branch information
agnlez committed Apr 18, 2024
1 parent fffb8ae commit 09f3a9e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const SplitFeaturesBulkActionMenu = ({
}: {
features: (Feature & { name: string; marxanSettings: { prop?: number; fpf?: number } })[];
selectedFeatureIds: Feature['id'][];
onDone: () => void;
onDone: (res?: unknown) => void;
}): JSX.Element => {
const { query } = useRouter();
const { pid, sid } = query as { pid: string; sid: string };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const DeleteModal = ({
features: any[];
selectedFeaturesIds: Feature['id'][];
onDismiss?: ModalProps['onDismiss'];
onDone?: () => void;
onDone?: (res?: unknown) => void;
}): JSX.Element => {
const queryClient = useQueryClient();
const { query } = useRouter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const EditModal = ({
}: {
selectedFeatures: (Feature & { name: string; marxanSettings: { prop?: number; fpf?: number } })[];
handleModal: (modalKey: 'split' | 'edit' | 'delete', isVisible: boolean) => void;
onDone?: () => void;
onDone?: (res?: unknown) => void;
}): JSX.Element => {
const { addToast } = useToasts();
const { query } = useRouter();
Expand Down Expand Up @@ -136,8 +136,8 @@ const EditModal = ({
data,
},
{
onSuccess: () => {
onDone?.();
onSuccess: (res) => {
onDone?.(res);
handleModal('edit', false);

addToast(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChangeEvent, ComponentProps, useCallback, useEffect, useMemo, useState } from 'react';
import { ChangeEvent, ComponentProps, useCallback, useMemo, useState } from 'react';

import { useQueryClient } from 'react-query';

Expand Down Expand Up @@ -415,23 +415,25 @@ const TargetAndSPFFeatures = (): JSX.Element => {
[selectedFeaturesQuery.data, queryClient, sid, selectedFeaturesMutation]
);

const displayBulkActions = selectedFeatureIds.length > 0;
const displaySaveButton = selectedFeaturesQuery.data?.length > 0;
const onDoneEditing = useCallback((res: { data: { features: any[] } }) => {
setSelectedFeatureIds([]);
const { features } = res?.data || {};

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

const displayBulkActions = selectedFeatureIds.length > 0;
const displaySaveButton = selectedFeaturesQuery.data?.length > 0;

return (
<>
Expand Down Expand Up @@ -524,9 +526,7 @@ const TargetAndSPFFeatures = (): JSX.Element => {
<FeaturesBulkActionMenu
features={targetedFeatures}
selectedFeatureIds={selectedFeatureIds}
onDone={() => {
setSelectedFeatureIds([]);
}}
onDone={onDoneEditing}
/>
)}
</Section>
Expand Down

0 comments on commit 09f3a9e

Please sign in to comment.