Skip to content

Commit c27ebd0

Browse files
committed
chore: useStepMetadata should read allApps from EditorContext
^ Conflicts: ^ packages/frontend/src/components/EditorRightDrawer/Step.tsx
1 parent 86af751 commit c27ebd0

File tree

10 files changed

+26
-52
lines changed

10 files changed

+26
-52
lines changed

packages/frontend/src/components/Editor/FlowStepWithAddButton.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import { IStep } from '@plumber/types'
22

3-
import { useContext } from 'react'
4-
5-
import { EditorContext } from '@/contexts/Editor'
63
import { FlowStep } from '@/exports/components'
74
import { useStepMetadata } from '@/hooks/useStepMetadata'
85

@@ -31,9 +28,7 @@ export default function FlowStepWithAddButton({
3128
showEmptyAction: boolean
3229
}
3330
}) {
34-
const { allApps } = useContext(EditorContext)
35-
36-
const { isApprovalStep } = useStepMetadata(allApps, step)
31+
const { isApprovalStep } = useStepMetadata(step)
3732

3833
return (
3934
<>

packages/frontend/src/components/Editor/index.tsx

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ type EditorProps = {
2626
export default function Editor(props: EditorProps): React.ReactElement {
2727
const { isNested } = props
2828

29-
const { allApps, isDrawerOpen, isMobile, flow, readOnly } =
29+
const { allApps, isDrawerOpen, isMobile, flow, readOnly, currentStepId } =
3030
useContext(EditorContext)
3131

3232
const { handleReorderUpdate } = useReorderSteps(flow.id)
@@ -44,6 +44,10 @@ export default function Editor(props: EditorProps): React.ReactElement {
4444
[flow, rawSteps],
4545
)
4646

47+
const currentStep = useMemo(() => {
48+
return steps.find((step) => step.id === currentStepId)
49+
}, [currentStepId, steps])
50+
4751
const appsWithActions: IApp[] = allApps.filter(
4852
(app: IApp) => !!app.actions?.length,
4953
)
@@ -93,14 +97,6 @@ export default function Editor(props: EditorProps): React.ReactElement {
9397
: [triggerStep, steps.slice(1, groupStepIdx), branchesWithSteps]
9498
}, [groupingActions, steps])
9599

96-
const flowStepGroupIconUrl = useMemo(() => {
97-
if (groupedSteps.length === 0) {
98-
return undefined
99-
}
100-
return appsWithActions.find((app) => app.key === groupedSteps[0][0].appKey)
101-
?.iconUrl
102-
}, [appsWithActions, groupedSteps])
103-
104100
const handleReorderSteps = async (reorderedSteps: IStep[]) => {
105101
const stepPositions = reorderedSteps.map((step, index) => ({
106102
id: step.id,
@@ -242,10 +238,7 @@ export default function Editor(props: EditorProps): React.ReactElement {
242238
opacity={isDrawerOpen ? 1 : 0}
243239
transform={rightDrawerTransform}
244240
>
245-
<EditorRightDrawer
246-
flowStepGroupIconUrl={flowStepGroupIconUrl}
247-
steps={steps}
248-
/>
241+
<EditorRightDrawer step={currentStep} />
249242
</Flex>
250243
</StepExecutionsToIncludeProvider>
251244
</MrfContextProvider>

packages/frontend/src/components/EditorRightDrawer/Step.tsx

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { IStep } from '@plumber/types'
22

3-
import { useCallback, useContext, useMemo } from 'react'
4-
import { CircularProgress, Flex, useDisclosure } from '@chakra-ui/react'
3+
import { Fragment, useCallback, useContext, useMemo } from 'react'
4+
import { Flex, useDisclosure } from '@chakra-ui/react'
55

66
import ChooseConnectionSubstep from '@/components/ChooseConnectionSubstep'
77
import FlowSubstep from '@/components/FlowSubstep'
@@ -17,22 +17,21 @@ import LearnFromGuideInfobox from './LearnFromGuideInfobox'
1717

1818
type StepProps = {
1919
step: IStep
20-
isLastStep: boolean
2120
}
2221

2322
export default function Step(props: StepProps): React.ReactElement | null {
24-
const { step, isLastStep } = props
23+
const { step } = props
2524

2625
const {
2726
isOpen: isModalOpen,
2827
onOpen: onModalOpen,
2928
onClose: onModalClose,
3029
} = useDisclosure()
3130

32-
const { allApps, onUpdateStep, resetTimestamp } = useContext(EditorContext)
31+
const { onUpdateStep, resetTimestamp } = useContext(EditorContext)
3332

3433
const { app, hasConnection, isTrigger, selectedActionOrTrigger, substeps } =
35-
useStepMetadata(allApps, step)
34+
useStepMetadata(step)
3635

3736
const handleSubmit = useCallback(
3837
(val: any) => {
@@ -46,10 +45,6 @@ export default function Step(props: StepProps): React.ReactElement | null {
4645
[substeps],
4746
)
4847

49-
if (!allApps) {
50-
return <CircularProgress isIndeterminate my={2} />
51-
}
52-
5348
return (
5449
<>
5550
<Flex w="100%" flexDir="column">
@@ -96,7 +91,8 @@ export default function Step(props: StepProps): React.ReactElement | null {
9691
<FlowStepConfigurationModal
9792
onClose={onModalClose}
9893
isTrigger={isTrigger}
99-
isLastStep={isLastStep}
94+
// this shouldnt matter here since it's just for reconnecting
95+
isLastStep={false}
10096
step={step}
10197
app={app}
10298
event={selectedActionOrTrigger}

packages/frontend/src/components/EditorRightDrawer/StepHeader.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ export default function StepHeader(props: StepHeaderProps) {
2525
} = useDisclosure()
2626

2727
const {
28-
allApps,
2928
readOnly: isReadOnlyEditor,
3029
shouldWarnOnLeave,
3130
onDrawerClose,
@@ -38,7 +37,7 @@ export default function StepHeader(props: StepHeaderProps) {
3837
defaultCaption,
3938
position,
4039
stepName: initialStepName,
41-
} = useStepMetadata(allApps, step)
40+
} = useStepMetadata(step)
4241

4342
const handleClose = () => {
4443
if (shouldWarnOnLeave) {

packages/frontend/src/components/EditorRightDrawer/index.tsx

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,23 @@
11
import { IStep } from '@plumber/types'
22

3-
import { useContext, useMemo } from 'react'
43
import { Flex } from '@chakra-ui/react'
54

6-
import { EditorContext } from '@/contexts/Editor'
75
import { useStepMetadata } from '@/hooks/useStepMetadata'
86

97
import Step from './Step'
108
import StepHeader from './StepHeader'
119
import { editorRightDrawerStyles as styles } from './styles'
1210

1311
interface EditorRightDrawerProps {
14-
flowStepGroupIconUrl?: string
15-
steps: IStep[]
12+
step?: IStep
1613
}
1714

1815
export default function EditorRightDrawer(props: EditorRightDrawerProps) {
19-
const { steps } = props
16+
const { step } = props
2017

21-
const { allApps, currentStepId } = useContext(EditorContext)
18+
const { hasConnection } = useStepMetadata(step)
2219

23-
const step = useMemo(() => {
24-
return steps.find((step) => step.id === currentStepId)
25-
}, [currentStepId, steps])
26-
const { hasConnection } = useStepMetadata(allApps, step)
27-
28-
if (!currentStepId || !step) {
20+
if (!step) {
2921
return null
3022
}
3123

@@ -40,7 +32,7 @@ export default function EditorRightDrawer(props: EditorRightDrawerProps) {
4032
>
4133
<StepHeader step={step} />
4234
<Flex {...styles.stepContentsWrapper} pt={hasConnection ? 0 : 4}>
43-
<Step step={step} isLastStep={step.position === steps.length} />
35+
<Step step={step} />
4436
</Flex>
4537
</Flex>
4638
)

packages/frontend/src/components/FlowStep/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export default function FlowStep(
7777
substeps,
7878
shouldShowDragHandle,
7979
isDeletable,
80-
} = useStepMetadata(allApps, step, true)
80+
} = useStepMetadata(step, true)
8181

8282
const {
8383
cancelRef,

packages/frontend/src/components/FlowStepGroup/Content/IfThen/HoverAddStepButton.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ export function HoverAddStepButton(
4040
const { isOpen, onOpen, onClose } = useDisclosure()
4141
const [isHovered, setIsHovered] = useState(false)
4242

43-
const { allApps, readOnly, isDrawerOpen } = useContext(EditorContext)
44-
const { shouldShowDragHandle } = useStepMetadata(allApps, step, allowReorder)
43+
const { readOnly, isDrawerOpen } = useContext(EditorContext)
44+
const { shouldShowDragHandle } = useStepMetadata(step, allowReorder)
4545

4646
const {
4747
cancelRef,

packages/frontend/src/components/FlowStepGroup/components/GroupStepWithAddButton.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ export default function GroupStepWithAddButton(
2626
isLastStep,
2727
isOverlay,
2828
allowReorder,
29-
3029
showEmptyAction,
3130
canChildStepsReorder,
3231
} = props

packages/frontend/src/components/FlowStepTestController/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ export default function FlowStepTestController(
114114
isMrfStep,
115115
selectedActionOrTrigger,
116116
substeps,
117-
} = useStepMetadata(allApps, step)
117+
} = useStepMetadata(step)
118118

119119
const {
120120
isTestSuccessful,

packages/frontend/src/hooks/useStepMetadata.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ interface UseStepMetadataResult {
3030
}
3131

3232
export function useStepMetadata(
33-
allApps: IApp[],
3433
step: IStep | undefined,
3534
allowReorder?: boolean,
3635
): UseStepMetadataResult {
37-
const { readOnly, isMobile, isDrawerOpen } = useContext(EditorContext)
36+
const { readOnly, isMobile, isDrawerOpen, allApps } =
37+
useContext(EditorContext)
3838

3939
const isCompleted = step?.status === 'completed'
4040
const isTrigger = step?.type === 'trigger'

0 commit comments

Comments
 (0)