-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add "inputType" and "query" to query params (#737)
Add query params inputType and query, and update components
- Loading branch information
1 parent
e4e4d88
commit ccca673
Showing
11 changed files
with
117 additions
and
57 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
3 changes: 3 additions & 0 deletions
3
src/views/domain-workflows/config/domain-workflows-page-size.config.ts
This file contains 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const DOMAIN_WORKFLOWS_PAGE_SIZE = 10; | ||
|
||
export default DOMAIN_WORKFLOWS_PAGE_SIZE; |
This file contains 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
4 changes: 4 additions & 0 deletions
4
src/views/domain-workflows/domain-workflows-header/domain-workflows-header.types.ts
This file contains 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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { type ListWorkflowsRequestQueryParams } from '@/route-handlers/list-workflows/list-workflows.types'; | ||
|
||
export type DomainWorkflowsHeaderInputType = | ||
ListWorkflowsRequestQueryParams['inputType']; |
1 change: 0 additions & 1 deletion
1
src/views/domain-workflows/domain-workflows-table/domain-workflows-table.constants.ts
This file was deleted.
Oops, something went wrong.
58 changes: 14 additions & 44 deletions
58
src/views/domain-workflows/domain-workflows-table/domain-workflows-table.tsx
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { | ||
type RouteParams as ListWorkflowsRouteParams, | ||
type ListWorkflowsRequestQueryParams, | ||
} from '@/route-handlers/list-workflows/list-workflows.types'; | ||
|
||
export type UseListWorkflowsParams = ListWorkflowsRouteParams & | ||
Omit<ListWorkflowsRequestQueryParams, 'pageSize'> & { pageSize?: number }; |
This file contains 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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
'use client'; | ||
import { useMemo } from 'react'; | ||
|
||
import { useInfiniteQuery } from '@tanstack/react-query'; | ||
import queryString from 'query-string'; | ||
|
||
import { | ||
type ListWorkflowsResponse, | ||
type ListWorkflowsRequestQueryParams, | ||
} from '@/route-handlers/list-workflows/list-workflows.types'; | ||
import request from '@/utils/request'; | ||
import { type RequestError } from '@/utils/request/request-error'; | ||
|
||
import DOMAIN_WORKFLOWS_PAGE_SIZE from '../config/domain-workflows-page-size.config'; | ||
import { type UseListWorkflowsParams } from '../domain-workflows.types'; | ||
|
||
export default function useListWorkflows({ | ||
domain, | ||
cluster, | ||
pageSize = DOMAIN_WORKFLOWS_PAGE_SIZE, | ||
...requestQueryParams | ||
}: UseListWorkflowsParams) { | ||
const queryResult = useInfiniteQuery<ListWorkflowsResponse, RequestError>({ | ||
queryKey: [ | ||
'listWorkflows', | ||
{ domain, cluster, ...requestQueryParams, pageSize }, | ||
], | ||
queryFn: async ({ pageParam }) => | ||
request( | ||
queryString.stringifyUrl({ | ||
url: `/api/domains/${domain}/${cluster}/workflows`, | ||
query: { | ||
...requestQueryParams, | ||
pageSize: pageSize.toString(), | ||
nextPage: pageParam as string, | ||
} as const satisfies ListWorkflowsRequestQueryParams, | ||
}) | ||
).then((res) => res.json()), | ||
initialPageParam: undefined, | ||
getNextPageParam: (lastPage) => { | ||
if (!lastPage.nextPage) return undefined; | ||
return lastPage.nextPage; | ||
}, | ||
retry: false, | ||
refetchOnWindowFocus: (query) => query.state.status !== 'error', | ||
}); | ||
|
||
const workflows = useMemo(() => { | ||
if (!queryResult.data) return []; | ||
return queryResult.data.pages.flatMap((page) => page.workflows ?? []); | ||
}, [queryResult.data]); | ||
|
||
return { | ||
workflows, | ||
...queryResult, | ||
}; | ||
} |