Skip to content

Commit 913bc6c

Browse files
committed
refactor: useStepMetadata hook
1 parent 7528745 commit 913bc6c

File tree

3 files changed

+7
-22
lines changed

3 files changed

+7
-22
lines changed

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,7 @@ export default function FlowStep(
7777
substeps,
7878
shouldShowDragHandle,
7979
isDeletable,
80-
} = useStepMetadata(
81-
allApps,
82-
step,
83-
readOnly,
84-
allowReorder,
85-
isMobile,
86-
isDrawerOpen,
87-
)
80+
} = useStepMetadata(allApps, step, true)
8881

8982
const {
9083
cancelRef,

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

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

43-
const { allApps, readOnly, isMobile, isDrawerOpen } =
44-
useContext(EditorContext)
45-
const { shouldShowDragHandle } = useStepMetadata(
46-
allApps,
47-
step,
48-
readOnly,
49-
allowReorder,
50-
isMobile,
51-
isDrawerOpen,
52-
)
43+
const { allApps, readOnly, isDrawerOpen } = useContext(EditorContext)
44+
const { shouldShowDragHandle } = useStepMetadata(allApps, step, allowReorder)
5345

5446
const {
5547
cancelRef,

packages/frontend/src/hooks/useStepMetadata.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { IAction, IApp, IStep, ISubstep, ITrigger } from '@plumber/types'
22

3-
import { useMemo } from 'react'
3+
import { useContext, useMemo } from 'react'
44
import get from 'lodash/get'
55

6+
import { EditorContext } from '@/contexts/Editor'
67
import { FORMSG_APP_KEY, MRF_ACTION_KEY } from '@/helpers/formsg'
78
import getStepName from '@/helpers/getStepName'
89
import {
@@ -31,11 +32,10 @@ interface UseStepMetadataResult {
3132
export function useStepMetadata(
3233
allApps: IApp[],
3334
step: IStep | undefined,
34-
readOnly?: boolean,
3535
allowReorder?: boolean,
36-
isMobile?: boolean,
37-
isDrawerOpen?: boolean,
3836
): UseStepMetadataResult {
37+
const { readOnly, isMobile, isDrawerOpen } = useContext(EditorContext)
38+
3939
const isCompleted = step?.status === 'completed'
4040
const isTrigger = step?.type === 'trigger'
4141
const isIfThenStep = step ? checkIfThenStep(step) : false

0 commit comments

Comments
 (0)