Skip to content

Commit 54093d0

Browse files
authored
PLU-407: execution back button (#851)
## Problem User need to use browser back button to return to 'Executions for Pipe' page when viewing a specific Execution. ## Solution **Improvements**: - Add a back button next to the Pipe name ## Before & After Screenshots **BEFORE**: <img width="1512" alt="Screenshot 2025-02-07 at 11 51 31 AM" src="https://github.com/user-attachments/assets/cda35b6e-1381-45ee-9b38-18fca0d693ce" /> **AFTER**: <img width="1512" alt="Screenshot 2025-02-07 at 11 52 10 AM" src="https://github.com/user-attachments/assets/5b3c01fc-28d5-4d56-99e8-9bae3529f426" /> ## Tests - [x] Back button navigates back to the executions list of the correct Pipe
1 parent 4690694 commit 54093d0

File tree

3 files changed

+47
-13
lines changed

3 files changed

+47
-13
lines changed

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

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,44 @@
11
import type { IExecution } from '@plumber/types'
22

3-
import { Fragment, ReactElement } from 'react'
4-
import { Flex, Stack, Text } from '@chakra-ui/react'
5-
import { Tooltip } from '@opengovsg/design-system-react'
3+
import { Fragment, ReactElement, useCallback } from 'react'
4+
import { BiChevronLeft } from 'react-icons/bi'
5+
import { useNavigate, useSearchParams } from 'react-router-dom'
6+
import { Flex, Icon, Link, Stack, Text } from '@chakra-ui/react'
7+
import { Button, Tooltip } from '@opengovsg/design-system-react'
68
import { DateTime } from 'luxon'
79

10+
import * as URLS from '@/config/urls'
11+
812
type ExecutionHeaderProps = {
913
execution: IExecution
1014
}
1115

12-
function ExecutionName(props: Pick<IExecution['flow'], 'name'>) {
16+
function ExecutionName(props: Pick<IExecution['flow'], 'name' | 'id'>) {
17+
const { id, name } = props
18+
const [searchParams] = useSearchParams()
19+
const navigate = useNavigate()
20+
const backToPage = searchParams.get('backToPage')
21+
22+
const handleBack = useCallback(() => {
23+
let backUrl = URLS.EXECUTIONS_FOR_FLOW(id)
24+
25+
if (backToPage && /^\d+$/.test(backToPage)) {
26+
backUrl += `?page=${backToPage}`
27+
}
28+
navigate(backUrl)
29+
}, [navigate, id, backToPage])
30+
1331
return (
14-
<Text textStyle="h4" mb={4}>
15-
{props.name}
16-
</Text>
32+
<Flex gap={2} alignItems="center">
33+
<Button as={Link} variant="link" onClick={handleBack}>
34+
<Icon
35+
boxSize={6}
36+
color="interaction.support.disabled-content"
37+
as={BiChevronLeft}
38+
/>
39+
</Button>
40+
<Text textStyle="h4">{name}</Text>
41+
</Flex>
1742
)
1843
}
1944

@@ -48,6 +73,7 @@ export default function ExecutionHeader(
4873
props: ExecutionHeaderProps,
4974
): ReactElement {
5075
const { execution } = props
76+
const { flow } = execution
5177

5278
if (!execution) {
5379
return <Fragment />
@@ -58,13 +84,14 @@ export default function ExecutionHeader(
5884
<Stack
5985
direction={{ base: 'column', sm: 'row' }}
6086
justifyContent="space-between"
87+
alignItems="center"
6188
>
62-
<ExecutionDate createdAt={execution.createdAt} />
89+
<ExecutionName name={flow.name} id={flow.id} />
6390
<ExecutionId id={execution.id} />
6491
</Stack>
6592

66-
<Stack direction="row">
67-
<ExecutionName name={execution.flow.name} />
93+
<Stack direction="row" justifyContent="flex-end">
94+
<ExecutionDate createdAt={execution.createdAt} />
6895
</Stack>
6996
</Stack>
7097
)

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,21 @@ import * as URLS from '@/config/urls'
2323

2424
type ExecutionRowProps = {
2525
execution: IExecution
26+
page: number
2627
}
2728

2829
export default function ExecutionRow(props: ExecutionRowProps): ReactElement {
29-
const { execution } = props
30+
const { execution, page } = props
3031
const { flow, executionSteps } = execution
3132

3233
const createdAt = DateTime.fromMillis(parseInt(execution.createdAt, 10))
3334
const relativeCreatedAt = createdAt.toRelative()
3435

3536
return (
36-
<Link to={URLS.EXECUTION(execution.id)} data-test="execution-row">
37+
<Link
38+
to={`${URLS.EXECUTION(execution.id)}?backToPage=${page}`}
39+
data-test="execution-row"
40+
>
3741
<Card
3842
boxShadow="none"
3943
_hover={{ bg: 'interaction.muted.neutral.hover' }}

packages/frontend/src/pages/ExecutionsForFlow/index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ interface ExecutionsListProps {
2323
executions: IExecution[]
2424
isSearching: boolean
2525
isLoading: boolean
26+
page: number
2627
}
2728

2829
const getLimitAndOffset = (page: number) => ({
@@ -38,6 +39,7 @@ function ExecutionsList({
3839
executions,
3940
isLoading,
4041
isSearching,
42+
page,
4143
}: ExecutionsListProps) {
4244
const hasExecutions = executions.length > 0
4345

@@ -67,7 +69,7 @@ function ExecutionsList({
6769
return (
6870
<>
6971
{executions.map((execution) => (
70-
<ExecutionRow key={execution.id} execution={execution} />
72+
<ExecutionRow key={execution.id} execution={execution} page={page} />
7173
))}
7274
</>
7375
)
@@ -149,6 +151,7 @@ export default function ExecutionsForFlowPage() {
149151
executions={executions}
150152
isLoading={isLoading}
151153
isSearching={isSearching}
154+
page={page}
152155
/>
153156
{hasPagination && (
154157
<Flex justifyContent="center" mt={6}>

0 commit comments

Comments
 (0)