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

feat(dashboard): edit step conditions drawer #7417

Open
wants to merge 3 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { RiCloseLine, RiGuideFill } from 'react-icons/ri';
import { useNavigate } from 'react-router-dom';

import { CompactButton } from '@/components/primitives/button-compact';
import { StepDrawer } from '@/components/workflow-editor/steps/step-drawer';
import { useWorkflow } from '@/components/workflow-editor/workflow-provider';
import { useFeatureFlag } from '@/hooks/use-feature-flag';
import { FeatureFlagsKeysEnum } from '@novu/shared';
import { Button } from '@/components/primitives/button';

export const EditStepConditions = () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The empty edit step conditions drawer. In the upcoming PRs I'll add the conditions editor and form and will restructure components in the body.

const navigate = useNavigate();
const { workflow, step } = useWorkflow();
const isStepConditionsEnabled = useFeatureFlag(FeatureFlagsKeysEnum.IS_STEP_CONDITIONS_ENABLED);

if (!workflow || !step) {
return null;
}

if (!isStepConditionsEnabled) {
navigate('..', { relative: 'path' });
return null;
}

return (
<StepDrawer title={`Edit ${step?.name} Conditions`}>
<header className="flex flex-row items-center gap-3 px-3 py-1.5">
<div className="mr-auto flex items-center gap-2.5 py-2 text-sm font-medium">
<RiGuideFill className="size-4" />
<span>Step Conditions</span>
</div>

<CompactButton
icon={RiCloseLine}
variant="ghost"
className="size-6"
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
navigate('..', { relative: 'path' });
}}
>
<span className="sr-only">Close</span>
</CompactButton>
</header>
<div className="mt-auto flex justify-end border-t border-neutral-200 p-3">
<Button type="submit" variant="secondary">
Save Conditions
</Button>
</div>
</StepDrawer>
);
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
FeatureFlagsKeysEnum,
IEnvironment,
StepDataDto,
StepTypeEnum,
Expand All @@ -10,7 +11,14 @@ import {
import { AnimatePresence, motion } from 'motion/react';
import { HTMLAttributes, ReactNode, useCallback, useEffect, useMemo, useState } from 'react';
import { useForm } from 'react-hook-form';
import { RiArrowLeftSLine, RiArrowRightSLine, RiCloseFill, RiDeleteBin2Line, RiPencilRuler2Fill } from 'react-icons/ri';
import {
RiArrowLeftSLine,
RiArrowRightSLine,
RiCloseFill,
RiDeleteBin2Line,
RiGuideFill,
RiPencilRuler2Fill,
} from 'react-icons/ri';
import { Link, useNavigate } from 'react-router-dom';

import { ConfirmationModal } from '@/components/confirmation-modal';
Expand Down Expand Up @@ -48,6 +56,7 @@ import {
} from '@/utils/constants';
import { buildRoute, ROUTES } from '@/utils/routes';
import { CompactButton } from '../../primitives/button-compact';
import { useFeatureFlag } from '@/hooks/use-feature-flag';

const STEP_TYPE_TO_INLINE_CONTROL_VALUES: Record<StepTypeEnum, () => React.JSX.Element | null> = {
[StepTypeEnum.DELAY]: DelayControlValues,
Expand Down Expand Up @@ -84,7 +93,7 @@ export const ConfigureStepForm = (props: ConfigureStepFormProps) => {
const { step, workflow, update, environment } = props;
const navigate = useNavigate();
const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false);

const isStepConditionsEnabled = useFeatureFlag(FeatureFlagsKeysEnum.IS_STEP_CONDITIONS_ENABLED);
const supportedStepTypes = [
StepTypeEnum.IN_APP,
StepTypeEnum.SMS,
Expand Down Expand Up @@ -308,6 +317,28 @@ export const ConfigureStepForm = (props: ConfigureStepFormProps) => {
</>
)}

{isStepConditionsEnabled && (
<>
<SidebarContent>
<Link to={'./conditions'} relative="path" state={{ stepType: step.type }}>
<Button
variant="secondary"
mode="outline"
className="flex w-full justify-start gap-1.5 text-xs font-medium"
>
<RiGuideFill className="h-4 w-4 text-neutral-600" />
Step Conditions
<span className="ml-auto flex items-center gap-0.5">
<span>0</span>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now, I've hardcoded the value until we have the same logic so we can calculate it

<RiArrowRightSLine className="ml-auto h-4 w-4 text-neutral-600" />
</span>
</Button>
</Link>
</SidebarContent>
<Separator />
</>
)}
Comment on lines +320 to +340
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Step Conditions button in the Configure Step sidebar


{!isSupportedStep && (
<SidebarContent>
<SdkBanner />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,78 +1,17 @@
import { motion } from 'motion/react';
import { useNavigate } from 'react-router-dom';

import { Sheet, SheetContentBase, SheetDescription, SheetPortal, SheetTitle } from '@/components/primitives/sheet';
import { ConfigureStepTemplateForm } from '@/components/workflow-editor/steps/configure-step-template-form';
import { VisuallyHidden } from '@/components/primitives/visually-hidden';
import { PageMeta } from '@/components/page-meta';
import { useWorkflow } from '@/components/workflow-editor/workflow-provider';
import { StepTypeEnum } from '@novu/shared';
import { cn } from '@/utils/ui';

const transitionSetting = { ease: [0.29, 0.83, 0.57, 0.99], duration: 0.4 };
const stepTypeToClassname: Record<string, string | undefined> = {
[StepTypeEnum.IN_APP]: 'sm:max-w-[600px]',
[StepTypeEnum.EMAIL]: 'sm:max-w-[800px]',
};
import { StepDrawer } from './step-drawer';
import { ConfigureStepTemplateForm } from './configure-step-template-form';

export const ConfigureStepTemplate = () => {
const navigate = useNavigate();
const { workflow, update, step } = useWorkflow();
const handleCloseSheet = () => {
if (step) {
// Do not use relative path here, calling twice will result in moving further back
navigate(`../steps/${step.slug}`);
}
};

if (!workflow || !step) {
return null;
}

return (
<>
<PageMeta title={`Edit ${step?.name}`} />
<Sheet modal={false} open>
<motion.div
initial={{
opacity: 0,
}}
animate={{
opacity: 1,
}}
exit={{
opacity: 0,
}}
className="fixed inset-0 z-50 h-screen w-screen bg-black/20"
transition={transitionSetting}
/>
<SheetPortal>
<SheetContentBase asChild onInteractOutside={handleCloseSheet} onEscapeKeyDown={handleCloseSheet}>
<motion.div
initial={{
x: '100%',
}}
animate={{
x: 0,
}}
exit={{
x: '100%',
}}
transition={transitionSetting}
className={cn(
'bg-background fixed inset-y-0 right-0 z-50 flex h-full w-3/4 flex-col border-l shadow-lg outline-none sm:max-w-[600px]',
stepTypeToClassname[step.type]
)}
>
<VisuallyHidden>
<SheetTitle />
<SheetDescription />
</VisuallyHidden>
<ConfigureStepTemplateForm workflow={workflow} step={step} update={update} />
</motion.div>
</SheetContentBase>
</SheetPortal>
</Sheet>
</>
<StepDrawer title={`Edit ${step?.name}`}>
<ConfigureStepTemplateForm workflow={workflow} step={step} update={update} />
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved the shared code to the StepDrawer which is used to edit step template and conditions

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lovely

</StepDrawer>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { motion } from 'motion/react';
import { useNavigate } from 'react-router-dom';

import { Sheet, SheetContentBase, SheetDescription, SheetPortal, SheetTitle } from '@/components/primitives/sheet';
import { VisuallyHidden } from '@/components/primitives/visually-hidden';
import { PageMeta } from '@/components/page-meta';
import { useWorkflow } from '@/components/workflow-editor/workflow-provider';
import { StepTypeEnum } from '@novu/shared';
import { cn } from '@/utils/ui';

const transitionSetting = { ease: [0.29, 0.83, 0.57, 0.99], duration: 0.4 };
const stepTypeToClassname: Record<string, string | undefined> = {
[StepTypeEnum.IN_APP]: 'sm:max-w-[600px]',
[StepTypeEnum.EMAIL]: 'sm:max-w-[800px]',
};

export const StepDrawer = ({ children, title }: { children: React.ReactNode; title?: string }) => {
const navigate = useNavigate();
const { workflow, step } = useWorkflow();
const handleCloseSheet = () => {
if (step) {
// Do not use relative path here, calling twice will result in moving further back
navigate(`../steps/${step.slug}`);
}
};

if (!workflow || !step) {
return null;
}

return (
<>
<PageMeta title={title} />
<Sheet modal={false} open>
<motion.div
initial={{
opacity: 0,
}}
animate={{
opacity: 1,
}}
exit={{
opacity: 0,
}}
className="fixed inset-0 z-50 h-screen w-screen bg-black/20"
transition={transitionSetting}
/>
<SheetPortal>
<SheetContentBase asChild onInteractOutside={handleCloseSheet} onEscapeKeyDown={handleCloseSheet}>
<motion.div
initial={{
x: '100%',
}}
animate={{
x: 0,
}}
exit={{
x: '100%',
}}
transition={transitionSetting}
className={cn(
'bg-background fixed inset-y-0 right-0 z-50 flex h-full w-3/4 flex-col border-l shadow-lg outline-none sm:max-w-[600px]',
stepTypeToClassname[step.type]
)}
>
<VisuallyHidden>
<SheetTitle />
<SheetDescription />
</VisuallyHidden>
{children}
</motion.div>
</SheetContentBase>
</SheetPortal>
</Sheet>
</>
);
};
5 changes: 5 additions & 0 deletions apps/dashboard/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { ConfigureStepTemplate } from '@/components/workflow-editor/steps/config
import { RedirectToLegacyStudioAuth } from './pages/redirect-to-legacy-studio-auth';
import { CreateIntegrationSidebar } from './components/integrations/components/create-integration-sidebar';
import { UpdateIntegrationSidebar } from './components/integrations/components/update-integration-sidebar';
import { EditStepConditions } from '@/components/workflow-editor/steps/conditions/edit-step-conditions';

initializeSentry();
overrideZodErrorMap();
Expand Down Expand Up @@ -125,6 +126,10 @@ const router = createBrowserRouter([
element: <ConfigureStepTemplate />,
path: ROUTES.EDIT_STEP_TEMPLATE,
},
{
element: <EditStepConditions />,
path: ROUTES.EDIT_STEP_CONDITIONS,
},
{
element: <ChannelPreferences />,
path: ROUTES.EDIT_WORKFLOW_PREFERENCES,
Expand Down
1 change: 1 addition & 0 deletions apps/dashboard/src/utils/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const ROUTES = {
EDIT_WORKFLOW_PREFERENCES: 'preferences',
EDIT_STEP: 'steps/:stepSlug',
EDIT_STEP_TEMPLATE: 'steps/:stepSlug/edit',
EDIT_STEP_CONDITIONS: 'steps/:stepSlug/conditions',
INTEGRATIONS: '/integrations',
INTEGRATIONS_CONNECT: '/integrations/connect',
INTEGRATIONS_CONNECT_PROVIDER: '/integrations/connect/:providerId',
Expand Down
1 change: 1 addition & 0 deletions packages/shared/src/types/feature-flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@ export enum FeatureFlagsKeysEnum {
IS_USAGE_ALERTS_ENABLED = 'IS_USAGE_ALERTS_ENABLED',
IS_USE_MERGED_DIGEST_ID_ENABLED = 'IS_USE_MERGED_DIGEST_ID_ENABLED',
IS_V2_ENABLED = 'IS_V2_ENABLED',
IS_STEP_CONDITIONS_ENABLED = 'IS_STEP_CONDITIONS_ENABLED',
}
Loading