Skip to content

Commit

Permalink
#3041 fix right click preset
Browse files Browse the repository at this point in the history
  • Loading branch information
StarlaStarla committed Oct 10, 2023
1 parent ec7aefc commit 63d20e7
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -1,43 +1,35 @@
import {
Item,
ItemParams,
Menu,
PredicateParams,
Separator,
} from 'react-contexify';
import { Item, ItemParams, Menu, Separator } from 'react-contexify';
import { openModal } from 'state/modal';
import { useAppDispatch } from 'hooks';
import { useAppDispatch, useAppSelector } from 'hooks';
import { ReactElement } from 'react';
import { CONTEXT_MENU_ID } from './types';
import { setActivePreset } from 'state/rna-builder';
import { selectActivePreset } from 'state/rna-builder';

export const RNAContextMenu = () => {
const dispatch = useAppDispatch();
const activePreset = useAppSelector(selectActivePreset);
const RNAMenus = [
{ name: 'duplicateandedit', title: 'Duplicate and Edit' },
{ name: 'edit', title: 'Edit', seperator: true },
{ name: 'deletepreset', title: 'Delete Preset' },
];

const isItemDisabled = (name: string) => {
return ({ props }: PredicateParams) => {
if (name === 'deletepreset' && props.preset?.default) {
return true;
}
return false;
};
if (name === 'deletepreset' && activePreset.default) {
return true;
}
return false;
};

const handleMenuChange = ({ id, props }: ItemParams) => {
switch (id) {
case 'duplicateandedit':
props.duplicatePreset(props.preset);
props.duplicatePreset();
break;
case 'edit':
props.activateEditMode();
break;
case 'deletepreset':
dispatch(setActivePreset(props.preset));
dispatch(openModal('delete'));
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ import { Modal } from 'components/shared/modal';
import { useCallback } from 'react';
import { ActionButton } from 'components/shared/actionButton';
import { useAppDispatch, useAppSelector } from 'hooks';
import { deletePreset, selectActivePreset } from 'state/rna-builder';
import {
deletePreset,
selectActivePreset,
selectPresets,
setActivePreset,
setIsEditMode,
} from 'state/rna-builder';

export interface Props {
onClose: () => void;
Expand All @@ -26,6 +32,7 @@ export interface Props {

const Delete = ({ isModalOpen, onClose }: Props) => {
const dispatch = useAppDispatch();
const presets = useAppSelector(selectPresets);
const activePreset = useAppSelector(selectActivePreset);
const onCloseCallback = useCallback(() => {
onClose();
Expand All @@ -38,6 +45,10 @@ const Delete = ({ isModalOpen, onClose }: Props) => {
const deleteHandler = () => {
onCloseCallback();
dispatch(deletePreset(activePreset));
dispatch(setIsEditMode(false));
if (presets.length !== 0) {
dispatch(setActivePreset(presets[0]));
}
};

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,6 @@ export const RnaAccordion = ({
} else setExpandedAccordion(rnaBuilderItem);
};

const handleContextMenu = (preset: IRnaPreset) => (event: TriggerEvent) => {
show({
event,
props: {
duplicatePreset,
activateEditMode,
preset,
},
});
};

const groupsData: IGroupsDataItem[] = [
{
groupName: RnaBuilderPresetsItem.Presets,
Expand Down Expand Up @@ -152,6 +141,17 @@ export const RnaAccordion = ({
dispatch(setActiveRnaBuilderItem(groupName));
};

const handleContextMenu = (preset: IRnaPreset) => (event: TriggerEvent) => {
dispatch(setActivePreset(preset));
show({
event,
props: {
duplicatePreset,
activateEditMode,
},
});
};

useEffect(() => {
setExpandedAccordion(activeRnaBuilderItem);
}, [activeRnaBuilderItem]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,21 @@ export const RnaBuilder = ({ libraryName }) => {
dispatch(setDefaultPresets(defaultPresets));
}, [dispatch]);

const duplicatePreset = (preset?: IRnaPreset) => {
const currentPreset = preset || activePreset;
const duplicatePreset = () => {
const duplicatedPreset = {
...currentPreset,
...activePreset,
presetInList: undefined,
name: `${currentPreset.name}_Copy`,
name: `${activePreset.name}_Copy`,
default: false,
};
dispatch(setActivePreset(duplicatedPreset));
dispatch(savePreset(duplicatedPreset));
setIsEditMode(true);
dispatch(setIsEditMode(true));
scrollToSelectedPreset(activePreset.name);
};

const activateEditMode = () => {
setIsEditMode(true);
dispatch(setIsEditMode(true));
};

return (
Expand Down

0 comments on commit 63d20e7

Please sign in to comment.