-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
base: next
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 = () => { | ||
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, | ||
|
@@ -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'; | ||
|
@@ -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, | ||
|
@@ -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, | ||
|
@@ -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> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Step Conditions button in the |
||
|
||
{!isSupportedStep && ( | ||
<SidebarContent> | ||
<SdkBanner /> | ||
|
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} /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved the shared code to the There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> | ||
</> | ||
); | ||
}; |
There was a problem hiding this comment.
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.