This PR follows #10700, it is the same refactor but for the workflows pages. - Duplicates the right drawer workflow pages for the command menu and replace the states used in these pages by component states - We store the component instance id upon navigation to restore the states when we navigate back to a page There are still states which are not component states inside the workflow diagram and workflow command menu pages, we should convert them in a futur refactor. `closeCommandMenu` was called programmatically in multiple places for the workflow, I refactored that to only rely on the click outside listener. This introduced a wiggling bug on the workflow canvas when we change node selection. This should be fixed in another PR by updating the canvas animation to take the animation values of the command menu instead. I'm thinking we could use [motion values](https://motion.dev/docs/react-motion-value) for this as I told you @Devessier
37 lines
1.3 KiB
TypeScript
37 lines
1.3 KiB
TypeScript
import { useRecoilCallback } from 'recoil';
|
|
|
|
import { useOpenEmailThreadRightDrawer } from '@/activities/emails/right-drawer/hooks/useOpenEmailThreadRightDrawer';
|
|
import { viewableRecordIdState } from '@/object-record/record-right-drawer/states/viewableRecordIdState';
|
|
import { useRightDrawer } from '@/ui/layout/right-drawer/hooks/useRightDrawer';
|
|
import { isRightDrawerOpenState } from '@/ui/layout/right-drawer/states/isRightDrawerOpenState';
|
|
|
|
export const useEmailThread = () => {
|
|
const { closeRightDrawer } = useRightDrawer();
|
|
const openEmailThreadRightDrawer = useOpenEmailThreadRightDrawer();
|
|
|
|
const openEmailThread = useRecoilCallback(
|
|
({ snapshot, set }) =>
|
|
(threadId: string) => {
|
|
const isRightDrawerOpen = snapshot
|
|
.getLoadable(isRightDrawerOpenState)
|
|
.getValue();
|
|
|
|
const viewableEmailThreadId = snapshot
|
|
.getLoadable(viewableRecordIdState)
|
|
.getValue();
|
|
|
|
if (isRightDrawerOpen && viewableEmailThreadId === threadId) {
|
|
set(viewableRecordIdState, null);
|
|
closeRightDrawer();
|
|
return;
|
|
}
|
|
|
|
openEmailThreadRightDrawer();
|
|
set(viewableRecordIdState, threadId);
|
|
},
|
|
[closeRightDrawer, openEmailThreadRightDrawer],
|
|
);
|
|
|
|
return { openEmailThread };
|
|
};
|