Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: sidebar intercepting workflow editor #3968

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions apps/web/src/pages/templates/workflow/SideBar/AddStepMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { When } from '../../../../components/utils/When';
import { colors, DragButton, Tooltip } from '../../../../design-system';
import { useEnvController } from '../../../../hooks';
import { channels, NodeTypeEnum } from '../../../../utils/channels';
import { TOP_ROW_HEIGHT } from '../WorkflowEditor';

export function AddStepMenu({
setDragging,
Expand Down Expand Up @@ -79,6 +80,7 @@ const StyledNav = styled.div`
background: ${({ theme }) => (theme.colorScheme === 'dark' ? colors.B15 : colors.white)};
border-radius: 12px;
z-index: 3;
margin-top: -${TOP_ROW_HEIGHT}px;
`;

const StyledDraggableNode = styled.div`
Expand Down
102 changes: 23 additions & 79 deletions apps/web/src/pages/templates/workflow/SideBar/Sidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
import styled from '@emotion/styled';
import { Container, Flex, Group, Stack, useMantineColorScheme } from '@mantine/core';
import { useDidUpdate, useTimeout } from '@mantine/hooks';
import { colors } from '@novu/notification-center';
import { useState } from 'react';
import { Background, BackgroundVariant } from 'react-flow-renderer';
import { useFormContext } from 'react-hook-form';
import { Link, useNavigate, useOutletContext } from 'react-router-dom';
import { When } from '../../../../components/utils/When';
import { Button } from '../../../../design-system';
import { Settings } from '../../../../design-system/icons';
import { Stack, useMantineColorScheme } from '@mantine/core';
import { useOutletContext } from 'react-router-dom';
import { useEnvController } from '../../../../hooks';
import { IForm } from '../../components/formTypes';
import { UpdateButton } from '../../components/UpdateButton';
import { useBasePath } from '../../hooks/useBasePath';
import { TOP_ROW_HEIGHT } from '../WorkflowEditor';
import { AddStepMenu } from './AddStepMenu';

export const Sidebar = () => {
Expand All @@ -24,77 +14,31 @@ export const Sidebar = () => {
const { setDragging }: any = useOutletContext();
const { readonly } = useEnvController();

const navigate = useNavigate();
const basePath = useBasePath();

const {
formState: { isDirty },
} = useFormContext<IForm>();
const [shouldPulse, setShouldPulse] = useState(false);

useDidUpdate(() => {
if (isDirty) {
return;
}
setShouldPulse(true);
start();
}, [isDirty]);

const { start } = useTimeout(() => {
setShouldPulse(false);
}, 5000);
if (readonly) {
return null;
}

return (
<Flex direction="column" sx={{ height: '100%' }}>
<Container fluid sx={{ width: '100%', paddingLeft: 0, height: '74px' }}>
<Stack
justify="center"
sx={{
height: '100%',
}}
>
<Group>
<UpdateButton />
<Button
pulse={shouldPulse}
onClick={() => {
navigate(basePath + '/snippet');
}}
data-test-id="get-snippet-btn"
>
Get Snippet
</Button>
<Link data-test-id="settings-page" to="settings">
<Settings />
</Link>
</Group>
</Stack>
</Container>
<When truthy={!readonly}>
<div style={{ position: 'relative', flex: '1 1 auto' }}>
<SideBarWrapper dark={colorScheme === 'dark'}>
<AddStepMenu setDragging={setDragging} onDragStart={onDragStart} />
</SideBarWrapper>
<Background
size={1}
gap={10}
variant={BackgroundVariant.Dots}
color={colorScheme === 'dark' ? colors.BGDark : colors.BGLight}
/>
</div>
</When>
</Flex>
<SideBarWrapper dark={colorScheme === 'dark'}>
<Stack
sx={{
height: '100%',
}}
justify="center"
align="center"
>
<AddStepMenu setDragging={setDragging} onDragStart={onDragStart} />
</Stack>
</SideBarWrapper>
);
};

const SideBarWrapper = styled.div<{ dark: boolean }>`
position: relative;

background: ${({ dark }) => (dark ? colors.B15 : colors.B98)};
position: absolute;
top: ${TOP_ROW_HEIGHT}px;
bottom: 0;
background: transparent;
height: 100%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: flex-end;
padding-right: 8px;
right: 8px;
z-index: 9999;
`;
21 changes: 17 additions & 4 deletions apps/web/src/pages/templates/workflow/WorkflowEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import AddNode from './workflow/node-types/AddNode';
import ChannelNode from './workflow/node-types/ChannelNode';
import TriggerNode from './workflow/node-types/TriggerNode';

const TOP_ROW_HEIGHT = 74;
export const TOP_ROW_HEIGHT = 74;

const nodeTypes = {
channelNode: ChannelNode,
Expand Down Expand Up @@ -220,10 +220,22 @@ const WorkflowEditor = () => {
<Group>
<NameInput />
<Group>
<When truthy={pathname !== basePath}>
<UpdateButton />
</When>
<UpdateButton />
</Group>
<When truthy={pathname === basePath}>
<Button
pulse={shouldPulse}
onClick={() => {
navigate(basePath + '/snippet');
}}
data-test-id="get-snippet-btn"
>
Get Snippet
</Button>
<Link data-test-id="settings-page" to="settings">
<Settings />
</Link>
</When>
</Group>
</Stack>
</Container>
Expand All @@ -245,6 +257,7 @@ const WorkflowEditor = () => {
style={{
width: 'auto',
minHeight: '600px',
position: 'relative',
}}
>
<Outlet
Expand Down
Loading