-
Notifications
You must be signed in to change notification settings - Fork 8
[MRF-9] PLU-520: MRF context and refactor #1349
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
Open
pregnantboy
wants to merge
3
commits into
mrf/mrf-approve-reject-select
Choose a base branch
from
mrf/add-mrf-context-and-refactor
base: mrf/mrf-approve-reject-select
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -1,10 +1,6 @@ | ||||||||
| import { IStep } from '@plumber/types' | ||||||||
|
|
||||||||
| import { useContext, useMemo } from 'react' | ||||||||
|
|
||||||||
| import { EditorContext } from '@/contexts/Editor' | ||||||||
| import { FlowStep } from '@/exports/components' | ||||||||
| import { TOOLBOX_ACTIONS } from '@/helpers/toolbox' | ||||||||
| import { useStepMetadata } from '@/hooks/useStepMetadata' | ||||||||
|
|
||||||||
| import { ApproveReject } from '../FlowStep/components/ApproveReject' | ||||||||
|
|
@@ -15,50 +11,24 @@ export default function FlowStepWithAddButton({ | |||||||
| step, | ||||||||
| isLastStep, | ||||||||
| isNested, | ||||||||
| stepsBeforeGroup, | ||||||||
| groupedSteps, | ||||||||
| showAddButton = true, | ||||||||
| addButtonProps: { | ||||||||
| isHidden = false, | ||||||||
| isDisabled = false, | ||||||||
| showEmptyAction = false, | ||||||||
| }, | ||||||||
| }: { | ||||||||
| step: IStep | ||||||||
| isLastStep: boolean | ||||||||
| isNested?: boolean | ||||||||
| stepsBeforeGroup: IStep[] | ||||||||
| groupedSteps: IStep[][] | ||||||||
| showAddButton?: boolean | ||||||||
| addButtonProps: { | ||||||||
|
Contributor
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.
Suggested change
|
||||||||
| isHidden: boolean | ||||||||
| isDisabled: boolean | ||||||||
| showEmptyAction: boolean | ||||||||
| } | ||||||||
| }) { | ||||||||
| const { readOnly, allApps } = useContext(EditorContext) | ||||||||
|
|
||||||||
| const { isApprovalStep } = useStepMetadata(allApps, step) | ||||||||
|
|
||||||||
| const nonIfThenActionSteps = stepsBeforeGroup.filter( | ||||||||
| (step) => step.type === 'action' && step.key !== TOOLBOX_ACTIONS.IfThen, | ||||||||
| ) | ||||||||
|
|
||||||||
| // Disables last add step and hide in-between add step buttons | ||||||||
| const hasExactlyOneEmptyActionStep = | ||||||||
| nonIfThenActionSteps.length === 1 && !nonIfThenActionSteps[0].appKey | ||||||||
|
|
||||||||
| // Disables last add step button but show empty action instead | ||||||||
| const hasNoActionSteps = nonIfThenActionSteps.length === 0 | ||||||||
|
|
||||||||
| const getAddStepButtonProps = useMemo(() => { | ||||||||
| const shouldShowEmptyAction = hasNoActionSteps && !groupedSteps.length | ||||||||
| const shouldDisableButton = | ||||||||
| (hasExactlyOneEmptyActionStep || hasNoActionSteps) && !groupedSteps.length | ||||||||
|
|
||||||||
| return (isLastStep: boolean, stepId: string) => ({ | ||||||||
| isHidden: readOnly, | ||||||||
| showEmptyAction: shouldShowEmptyAction, | ||||||||
| isDisabled: shouldDisableButton, | ||||||||
| isLastStep, | ||||||||
| stepId, | ||||||||
| }) | ||||||||
| }, [ | ||||||||
| readOnly, | ||||||||
| hasNoActionSteps, | ||||||||
| groupedSteps.length, | ||||||||
| hasExactlyOneEmptyActionStep, | ||||||||
| ]) | ||||||||
| const { isApprovalStep } = useStepMetadata(step) | ||||||||
|
|
||||||||
| return ( | ||||||||
| <> | ||||||||
|
|
@@ -67,13 +37,16 @@ export default function FlowStepWithAddButton({ | |||||||
| isLastStep={isLastStep} | ||||||||
| isNested={isNested} | ||||||||
| // only allow reordering if there are more than 1 action steps | ||||||||
| allowReorder={nonIfThenActionSteps.length > 1} | ||||||||
| allowReorder={true} | ||||||||
|
Contributor
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. |
||||||||
| /> | ||||||||
| {isApprovalStep && <ApproveReject />} | ||||||||
|
|
||||||||
| {showAddButton && ( | ||||||||
| <AddStepButton {...getAddStepButtonProps(isLastStep, step.id)} /> | ||||||||
| )} | ||||||||
| <AddStepButton | ||||||||
| isLastStep={isLastStep} | ||||||||
| stepId={step.id} | ||||||||
| isHidden={isHidden} | ||||||||
| isDisabled={isDisabled} | ||||||||
| showEmptyAction={showEmptyAction} | ||||||||
| /> | ||||||||
| </> | ||||||||
| ) | ||||||||
| } | ||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -7,6 +7,7 @@ import EditorRightDrawer from '@/components/EditorRightDrawer' | |||||||
| import FlowStepGroup from '@/components/FlowStepGroup' | ||||||||
| import { SortableList } from '@/components/SortableList' | ||||||||
| import { EditorContext } from '@/contexts/Editor' | ||||||||
| import { MrfContextProvider } from '@/contexts/MrfContext' | ||||||||
| import { StepExecutionsToIncludeProvider } from '@/contexts/StepExecutionsToInclude' | ||||||||
| import { StepEnumType } from '@/graphql/__generated__/graphql' | ||||||||
| import { extractBranchesWithSteps, TOOLBOX_ACTIONS } from '@/helpers/toolbox' | ||||||||
|
|
@@ -25,7 +26,7 @@ type EditorProps = { | |||||||
| export default function Editor(props: EditorProps): React.ReactElement { | ||||||||
| const { isNested } = props | ||||||||
|
|
||||||||
| const { allApps, isDrawerOpen, isMobile, currentStepId, flow } = | ||||||||
| const { allApps, isDrawerOpen, isMobile, flow, readOnly, currentStepId } = | ||||||||
| useContext(EditorContext) | ||||||||
|
|
||||||||
| const { handleReorderUpdate } = useReorderSteps(flow.id) | ||||||||
|
|
@@ -43,6 +44,10 @@ export default function Editor(props: EditorProps): React.ReactElement { | |||||||
| [flow, rawSteps], | ||||||||
| ) | ||||||||
|
|
||||||||
| const currentStep = useMemo(() => { | ||||||||
| return steps.find((step) => step.id === currentStepId) | ||||||||
| }, [currentStepId, steps]) | ||||||||
|
|
||||||||
| const appsWithActions: IApp[] = allApps.filter( | ||||||||
| (app: IApp) => !!app.actions?.length, | ||||||||
| ) | ||||||||
|
|
@@ -61,7 +66,7 @@ export default function Editor(props: EditorProps): React.ReactElement { | |||||||
| ) | ||||||||
| }, [appsWithActions]) | ||||||||
|
|
||||||||
| const [triggerStep, stepsBeforeGroup, groupedSteps] = useMemo(() => { | ||||||||
| const [triggerStep, actionStepsBeforeGroup, groupedSteps] = useMemo(() => { | ||||||||
| if (!groupingActions) { | ||||||||
| return [null, [], []] | ||||||||
| } | ||||||||
|
|
@@ -92,42 +97,6 @@ export default function Editor(props: EditorProps): React.ReactElement { | |||||||
| : [triggerStep, steps.slice(1, groupStepIdx), branchesWithSteps] | ||||||||
| }, [groupingActions, steps]) | ||||||||
|
|
||||||||
| const flowStepGroupIconUrl = useMemo(() => { | ||||||||
| if (groupedSteps.length === 0) { | ||||||||
| return undefined | ||||||||
| } | ||||||||
| return appsWithActions.find((app) => app.key === groupedSteps[0][0].appKey) | ||||||||
| ?.iconUrl | ||||||||
| }, [appsWithActions, groupedSteps]) | ||||||||
|
|
||||||||
| // | ||||||||
| // Compute which steps are eligible for variable extraction. | ||||||||
| // Mainly for if-then branches where we do not want to include steps | ||||||||
| // from other branches. | ||||||||
| // | ||||||||
| // Note: | ||||||||
| // - we include some grouped steps as there is no longer a nested editor | ||||||||
| // - we identify the group by checking if the current step id is in the group | ||||||||
| // - for-each steps are always included | ||||||||
| const groupStepsToInclude = useMemo(() => { | ||||||||
| return groupedSteps.flatMap((group) => | ||||||||
| group.some((step) => step.id === currentStepId) || | ||||||||
| group.some((step) => step.key === TOOLBOX_ACTIONS.ForEach) | ||||||||
| ? group | ||||||||
| : [], | ||||||||
| ) | ||||||||
| }, [currentStepId, groupedSteps]) | ||||||||
|
|
||||||||
| const stepExecutionsToInclude = useMemo( | ||||||||
| () => | ||||||||
| new Set([ | ||||||||
| ...(triggerStep?.id ? [triggerStep.id] : []), | ||||||||
| ...stepsBeforeGroup.map((step) => step.id), | ||||||||
| ...groupStepsToInclude.map((s) => s.id), | ||||||||
| ]), | ||||||||
| [triggerStep, stepsBeforeGroup, groupStepsToInclude], | ||||||||
| ) | ||||||||
|
|
||||||||
| const handleReorderSteps = async (reorderedSteps: IStep[]) => { | ||||||||
| const stepPositions = reorderedSteps.map((step, index) => ({ | ||||||||
| id: step.id, | ||||||||
|
|
@@ -146,6 +115,21 @@ export default function Editor(props: EditorProps): React.ReactElement { | |||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
| const nonIfThenActionSteps = actionStepsBeforeGroup.filter( | ||||||||
| (step) => step.key !== TOOLBOX_ACTIONS.IfThen, | ||||||||
| ) | ||||||||
|
|
||||||||
| // Disables last add step and hide in-between add step buttons | ||||||||
| const hasExactlyOneEmptyActionStep = | ||||||||
| nonIfThenActionSteps.length === 1 && !nonIfThenActionSteps[0].appKey | ||||||||
|
|
||||||||
| // Disables last add step button but show empty action instead | ||||||||
| const hasNoActionSteps = nonIfThenActionSteps.length === 0 | ||||||||
| const shouldShowEmptyAction = hasNoActionSteps && !groupedSteps.length | ||||||||
| // for backwards compatibility where empty step is created | ||||||||
| const shouldDisableAddButton = | ||||||||
| (hasExactlyOneEmptyActionStep || hasNoActionSteps) && !groupedSteps.length | ||||||||
|
|
||||||||
| if (!appsWithActions || !groupingActions) { | ||||||||
| return ( | ||||||||
| <Center height="100vh" position="fixed" width="full" top={0} left={0}> | ||||||||
|
|
@@ -172,80 +156,92 @@ export default function Editor(props: EditorProps): React.ReactElement { | |||||||
| backgroundSize: '30px 30px', | ||||||||
| }} | ||||||||
| > | ||||||||
| <StepExecutionsToIncludeProvider value={stepExecutionsToInclude}> | ||||||||
| <Flex | ||||||||
| {...editorStyles.stepHeaderContainer} | ||||||||
| flex={isDrawerOpen ? (isMobile ? 0 : 1) : undefined} | ||||||||
| px={leftStepPadding} | ||||||||
| maxWidth={`calc(100% - ${ | ||||||||
| isDrawerOpen ? EDITOR_RIGHT_DRAWER_WIDTH : '0px' | ||||||||
| })`} | ||||||||
| <MrfContextProvider steps={steps}> | ||||||||
| <StepExecutionsToIncludeProvider | ||||||||
| groupedSteps={groupedSteps} | ||||||||
| triggerStep={triggerStep} | ||||||||
| actionStepsBeforeGroup={actionStepsBeforeGroup} | ||||||||
| > | ||||||||
| {triggerStep && ( | ||||||||
| <FlowStepWithAddButton | ||||||||
| step={triggerStep} | ||||||||
| isLastStep={ | ||||||||
| stepsBeforeGroup.length === 0 && groupedSteps.length === 0 | ||||||||
| } | ||||||||
| isNested={isNested} | ||||||||
| stepsBeforeGroup={stepsBeforeGroup} | ||||||||
| groupedSteps={groupedSteps} | ||||||||
| showAddButton={true} | ||||||||
| <Flex | ||||||||
| {...editorStyles.stepHeaderContainer} | ||||||||
| flex={isDrawerOpen ? (isMobile ? 0 : 1) : undefined} | ||||||||
| px={leftStepPadding} | ||||||||
| maxWidth={`calc(100% - ${ | ||||||||
| isDrawerOpen ? EDITOR_RIGHT_DRAWER_WIDTH : '0px' | ||||||||
| })`} | ||||||||
| > | ||||||||
| {triggerStep && ( | ||||||||
| <FlowStepWithAddButton | ||||||||
| step={triggerStep} | ||||||||
| isLastStep={ | ||||||||
| actionStepsBeforeGroup.length === 0 && | ||||||||
| groupedSteps.length === 0 | ||||||||
| } | ||||||||
| isNested={isNested} | ||||||||
| stepsBeforeGroup={[]} // no reason to pass in for this | ||||||||
| groupedSteps={groupedSteps} | ||||||||
| addButtonProps={{ | ||||||||
| isHidden: readOnly, | ||||||||
| isDisabled: shouldDisableAddButton, | ||||||||
| showEmptyAction: shouldShowEmptyAction, | ||||||||
| }} | ||||||||
| /> | ||||||||
| )} | ||||||||
|
|
||||||||
| <SortableList | ||||||||
| items={actionStepsBeforeGroup} | ||||||||
| onChange={handleReorderSteps} | ||||||||
| renderItem={(step, isOverlay) => { | ||||||||
| const { id, position } = step | ||||||||
| return ( | ||||||||
| <SortableList.Item id={id}> | ||||||||
| <Flex | ||||||||
| key={`${id}-${position}`} | ||||||||
| width={isDrawerOpen || isMobile ? '100%' : 'auto'} | ||||||||
| flexDir="column" | ||||||||
| position="relative" | ||||||||
| > | ||||||||
| <FlowStepWithAddButton | ||||||||
| step={step} | ||||||||
| isLastStep={position === steps.length} | ||||||||
| isNested={isNested} | ||||||||
| stepsBeforeGroup={actionStepsBeforeGroup} | ||||||||
| groupedSteps={groupedSteps} | ||||||||
|
Contributor
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.
Suggested change
|
||||||||
| addButtonProps={{ | ||||||||
| isHidden: readOnly || !!isOverlay, | ||||||||
| isDisabled: shouldDisableAddButton, | ||||||||
| showEmptyAction: shouldShowEmptyAction, | ||||||||
| }} | ||||||||
| /> | ||||||||
| </Flex> | ||||||||
| </SortableList.Item> | ||||||||
| ) | ||||||||
| }} | ||||||||
| /> | ||||||||
| )} | ||||||||
|
|
||||||||
| <SortableList | ||||||||
| items={stepsBeforeGroup} | ||||||||
| onChange={handleReorderSteps} | ||||||||
| renderItem={(step, isOverlay) => { | ||||||||
| const { id, position } = step | ||||||||
| return ( | ||||||||
| <SortableList.Item id={id}> | ||||||||
| <Flex | ||||||||
| key={`${id}-${position}`} | ||||||||
| width={isDrawerOpen || isMobile ? '100%' : 'auto'} | ||||||||
| flexDir="column" | ||||||||
| position="relative" | ||||||||
| > | ||||||||
| <FlowStepWithAddButton | ||||||||
| step={step} | ||||||||
| isLastStep={position === steps.length} | ||||||||
| isNested={isNested} | ||||||||
| stepsBeforeGroup={stepsBeforeGroup} | ||||||||
| groupedSteps={groupedSteps} | ||||||||
| showAddButton={!isOverlay} | ||||||||
| /> | ||||||||
| </Flex> | ||||||||
| </SortableList.Item> | ||||||||
| ) | ||||||||
| }} | ||||||||
| /> | ||||||||
| {groupedSteps.length > 0 && ( | ||||||||
| <FlowStepGroup | ||||||||
| stepsBeforeGroup={stepsBeforeGroup} | ||||||||
| groupedSteps={groupedSteps} | ||||||||
| /> | ||||||||
| )} | ||||||||
| </Flex> | ||||||||
| {/** HACKFIX (kevinkim-ogp): to ensure that the transitions are smooth */} | ||||||||
| <Flex | ||||||||
| {...editorStyles.dummyRightContainer} | ||||||||
| w={rightDrawerWidth} | ||||||||
| transform={rightDrawerTransform} | ||||||||
| /> | ||||||||
| <Flex | ||||||||
| {...editorStyles.rightDrawerContainer} | ||||||||
| w={rightDrawerWidth} | ||||||||
| visibility={isDrawerOpen ? 'visible' : 'hidden'} | ||||||||
| opacity={isDrawerOpen ? 1 : 0} | ||||||||
| transform={rightDrawerTransform} | ||||||||
| > | ||||||||
| <EditorRightDrawer | ||||||||
| flowStepGroupIconUrl={flowStepGroupIconUrl} | ||||||||
| steps={steps} | ||||||||
| {groupedSteps.length > 0 && ( | ||||||||
| <FlowStepGroup | ||||||||
| stepsBeforeGroup={actionStepsBeforeGroup} | ||||||||
| groupedSteps={groupedSteps} | ||||||||
| /> | ||||||||
| )} | ||||||||
| </Flex> | ||||||||
| {/** HACKFIX (kevinkim-ogp): to ensure that the transitions are smooth */} | ||||||||
| <Flex | ||||||||
| {...editorStyles.dummyRightContainer} | ||||||||
| w={rightDrawerWidth} | ||||||||
| transform={rightDrawerTransform} | ||||||||
| /> | ||||||||
| </Flex> | ||||||||
| </StepExecutionsToIncludeProvider> | ||||||||
| <Flex | ||||||||
| {...editorStyles.rightDrawerContainer} | ||||||||
| w={rightDrawerWidth} | ||||||||
| visibility={isDrawerOpen ? 'visible' : 'hidden'} | ||||||||
| opacity={isDrawerOpen ? 1 : 0} | ||||||||
| transform={rightDrawerTransform} | ||||||||
| > | ||||||||
| <EditorRightDrawer step={currentStep} /> | ||||||||
| </Flex> | ||||||||
| </StepExecutionsToIncludeProvider> | ||||||||
| </MrfContextProvider> | ||||||||
| </Flex> | ||||||||
| ) | ||||||||
| } | ||||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.

Uh oh!
There was an error while loading. Please reload this page.
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.