Skip to content

Commit a6a446e

Browse files
committed
fix: split up the executions and execution for pipe pages
1 parent 4de6158 commit a6a446e

File tree

9 files changed

+224
-190
lines changed

9 files changed

+224
-190
lines changed

packages/backend/src/helpers/generate-error-email.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@ export function createBodyErrorMessage(
2121
const currDateTime = DateTime.now().toFormat('MMM dd yyyy, hh:mm a')
2222
const searchParams = new URLSearchParams()
2323
searchParams.set('status', 'failure')
24-
searchParams.set('pipeId', pipeId)
2524

2625
const appPrefixUrl = appConfig.isDev ? appConfig.webAppUrl : appConfig.baseUrl
27-
const redirectUrl = `/executions?${searchParams.toString()}`
26+
const redirectUrl = `/execution-pipe/${pipeId}?${searchParams.toString()}`
2827
const formattedUrl = `${appPrefixUrl}${redirectUrl}`
2928

3029
const bodyMessage = `

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ export default function FlowRow(props: FlowRowProps): ReactElement {
5858
sx={{ cursor: 'pointer' }}
5959
p={0}
6060
as={Link}
61-
to={isExecution ? URLS.EXECUTION_FLOW(flow.id) : URLS.FLOW(flow.id)}
61+
to={
62+
isExecution ? URLS.EXECUTIONS_FOR_FLOW(flow.id) : URLS.FLOW(flow.id)
63+
}
6264
display="flex"
6365
alignItems="center"
6466
justifyContent="stretch"

packages/frontend/src/components/Layout/NavigationSidebar.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useContext } from 'react'
2-
import { Link, useMatch } from 'react-router-dom'
2+
import { Link, matchPath, useLocation } from 'react-router-dom'
33
import { Box, Text } from '@chakra-ui/react'
44
import {
55
Badge,
@@ -20,8 +20,12 @@ function NavigationSidebarItem({
2020
link,
2121
closeDrawer,
2222
}: NavigationSidebarItemProps): JSX.Element {
23-
const { to, Icon: icon, text } = link
24-
const selected = useMatch({ path: to, end: true })
23+
const { pathname } = useLocation()
24+
25+
const { to, Icon: icon, text, otherLinks } = link
26+
const selected = [to, ...(otherLinks || [])].some((link) =>
27+
matchPath(link, pathname),
28+
)
2529

2630
return (
2731
<SidebarItem

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export type DrawerLink = {
2323
Icon: React.ElementType
2424
text: string
2525
to: string
26+
otherLinks?: string[]
2627
isBottom?: boolean
2728
badge?: string
2829
}
@@ -47,6 +48,7 @@ const drawerLinks = [
4748
Icon: BiHistory,
4849
text: 'Executions',
4950
to: URLS.EXECUTIONS,
51+
otherLinks: [URLS.EXECUTIONS_FOR_FLOW_PATTERN, URLS.EXECUTION_PATTERN],
5052
},
5153
{
5254
Icon: BiBookOpen,

packages/frontend/src/config/urls.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
export const CONNECTIONS = '/connections'
22
export const EXECUTIONS = '/executions'
33
export const EXECUTION_PATTERN = '/executions/:executionId'
4-
export const EXECUTION_FLOW = (pipeId: string): string =>
5-
`/executions?pipeId=${pipeId}`
4+
export const EXECUTIONS_FOR_FLOW_PATTERN = '/execution-pipe/:flowId'
5+
export const EXECUTIONS_FOR_FLOW = (flowId: string): string =>
6+
`/execution-pipe/${flowId}`
67
export const EXECUTION = (executionId: string): string =>
78
`/executions/${executionId}`
9+
810
export const ROOT = '/'
911

1012
export const FOUR_O_FOUR = '/404'

packages/frontend/src/pages/Executions/components/ExecutionListPage.tsx renamed to packages/frontend/src/pages/Executions/ExecutionsForFlowPage.tsx

Lines changed: 56 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
import type { IExecution, IFlow } from '@plumber/types'
1+
import type { IExecution } from '@plumber/types'
22

3+
import { useEffect } from 'react'
4+
import { useParams } from 'react-router-dom'
35
import { useQuery } from '@apollo/client'
46
import { Center, Flex } from '@chakra-ui/react'
57
import { Pagination } from '@opengovsg/design-system-react'
@@ -10,9 +12,10 @@ import NoResultFound from '@/components/NoResultFound'
1012
import PageTitle from '@/components/PageTitle'
1113
import PrimarySpinner from '@/components/PrimarySpinner'
1214
import { GET_EXECUTIONS } from '@/graphql/queries/get-executions'
15+
import { GET_FLOW } from '@/graphql/queries/get-flow'
1316
import { usePaginationAndFilter } from '@/hooks/usePaginationAndFilter'
1417

15-
import StatusInput from './StatusInput'
18+
import StatusInput from './components/StatusInput'
1619

1720
const RESULTS_PER_PAGE = 10
1821

@@ -27,6 +30,10 @@ const getLimitAndOffset = (page: number) => ({
2730
offset: (page - 1) * RESULTS_PER_PAGE,
2831
})
2932

33+
type ExecutionsForFlowParams = {
34+
flowId: string
35+
}
36+
3037
function ExecutionsList({
3138
executions,
3239
isLoading,
@@ -66,30 +73,65 @@ function ExecutionsList({
6673
)
6774
}
6875

69-
export default function ExecutionList({ flow }: { flow: IFlow }) {
76+
export default function ExecutionsForFlowPage() {
77+
const { flowId } = useParams() as ExecutionsForFlowParams
78+
7079
const { page, setSearchParams, status, isSearching } =
7180
usePaginationAndFilter()
72-
const { id: flowId, name: flowName } = flow
73-
const { data: executionsData, loading } = useQuery(GET_EXECUTIONS, {
74-
variables: {
75-
...getLimitAndOffset(page),
76-
status,
77-
flowId,
78-
},
79-
fetchPolicy: 'cache-and-network',
81+
82+
const { data: flowData, loading: isFlowLoading } = useQuery(GET_FLOW, {
83+
variables: { id: flowId },
8084
skip: !flowId,
8185
})
8286

87+
const { data: executionsData, loading: isExecutionsLoading } = useQuery(
88+
GET_EXECUTIONS,
89+
{
90+
variables: {
91+
...getLimitAndOffset(page),
92+
status,
93+
flowId,
94+
},
95+
skip: !flowId,
96+
},
97+
)
98+
8399
const { pageInfo, edges } = executionsData?.getExecutions || {}
84100
const executions: IExecution[] =
85101
edges?.map(({ node }: { node: IExecution }) => {
86102
return {
87103
...node,
88-
flow,
104+
flow: flowData?.getFlow,
89105
}
90106
}) ?? []
91107
const totalCount: number = pageInfo?.totalCount ?? 0
92-
const hasPagination = !loading && totalCount > RESULTS_PER_PAGE
108+
const isLoading = isExecutionsLoading || isFlowLoading
109+
const hasPagination = !isLoading && totalCount > RESULTS_PER_PAGE
110+
111+
// ensure invalid pages won't be accessed even after deleting flows
112+
const lastPage = Math.ceil(totalCount / RESULTS_PER_PAGE)
113+
114+
useEffect(() => {
115+
// Defer the search params update till after the initial render
116+
if (lastPage !== 0 && page > lastPage) {
117+
setSearchParams({ page: lastPage })
118+
}
119+
}, [lastPage, page, setSearchParams])
120+
121+
if (isLoading) {
122+
return (
123+
<Center mt={8}>
124+
<PrimarySpinner fontSize="4xl" />
125+
</Center>
126+
)
127+
}
128+
129+
if (!flowData?.getFlow) {
130+
return <NoResultFound description="Flow not found" />
131+
}
132+
133+
const { name: flowName } = flowData.getFlow
134+
93135
return (
94136
<Container py={9}>
95137
<PageTitle
@@ -105,7 +147,7 @@ export default function ExecutionList({ flow }: { flow: IFlow }) {
105147
/>
106148
<ExecutionsList
107149
executions={executions}
108-
isLoading={loading}
150+
isLoading={isLoading}
109151
isSearching={isSearching}
110152
/>
111153
{hasPagination && (

packages/frontend/src/pages/Executions/components/FlowListPage.tsx

Lines changed: 0 additions & 156 deletions
This file was deleted.

0 commit comments

Comments
 (0)