|
| 1 | +import { useEffect } from 'react' |
| 2 | +import { useNavigate, useParams } from 'react-router-dom' |
| 3 | + |
| 4 | +import { |
| 5 | + useGetRepoWebhookExecutionQuery, |
| 6 | + useRetriggerRepoWebhookExecutionMutation |
| 7 | +} from '@harnessio/code-service-client' |
| 8 | +import { RepoWebhookExecutionDetailsPage, WebhookExecutionType } from '@harnessio/ui/views' |
| 9 | + |
| 10 | +import { useRoutes } from '../../framework/context/NavigationContext' |
| 11 | +import { useThemeStore } from '../../framework/context/ThemeContext' |
| 12 | +import { useGetRepoRef } from '../../framework/hooks/useGetRepoPath' |
| 13 | +import { useTranslationStore } from '../../i18n/stores/i18n-store' |
| 14 | +import { PathParams } from '../../RouteDefinitions' |
| 15 | +import { useWebhookStore } from './stores/webhook-store' |
| 16 | + |
| 17 | +export const WebhookExecutionDetailsContainer = () => { |
| 18 | + const { repoId, spaceId, webhookId, executionId } = useParams<PathParams>() |
| 19 | + const repo_ref = useGetRepoRef() |
| 20 | + const { setExecutionId, updateExecution } = useWebhookStore() |
| 21 | + const navigate = useNavigate() |
| 22 | + const routes = useRoutes() |
| 23 | + |
| 24 | + useEffect(() => { |
| 25 | + setExecutionId(parseInt(executionId ?? '')) |
| 26 | + }, [setExecutionId, executionId]) |
| 27 | + |
| 28 | + const { data: { body: execution } = {} } = useGetRepoWebhookExecutionQuery( |
| 29 | + { |
| 30 | + repo_ref: repo_ref ?? '', |
| 31 | + webhook_identifier: parseInt(webhookId ?? ''), |
| 32 | + webhook_execution_id: parseInt(executionId ?? ''), |
| 33 | + queryParams: {} |
| 34 | + }, |
| 35 | + { |
| 36 | + enabled: !!repo_ref && !!webhookId && !!executionId |
| 37 | + } |
| 38 | + ) |
| 39 | + |
| 40 | + const { mutate: retriggerExecution, isLoading: isTriggeringExecution } = useRetriggerRepoWebhookExecutionMutation( |
| 41 | + {}, |
| 42 | + { |
| 43 | + onSuccess: data => { |
| 44 | + updateExecution(data.body as WebhookExecutionType) |
| 45 | + navigate(routes.toRepoWebhookExecutionDetails({ spaceId, repoId, webhookId, executionId: `${data.body.id}` })) |
| 46 | + } |
| 47 | + } |
| 48 | + ) |
| 49 | + |
| 50 | + useEffect(() => { |
| 51 | + if (execution) { |
| 52 | + updateExecution(execution as WebhookExecutionType) |
| 53 | + } |
| 54 | + }, [execution, updateExecution]) |
| 55 | + |
| 56 | + const handleRetriggerExecution = () => { |
| 57 | + retriggerExecution({ |
| 58 | + repo_ref: repo_ref ?? '', |
| 59 | + webhook_identifier: parseInt(webhookId ?? ''), |
| 60 | + webhook_execution_id: parseInt(executionId ?? '') |
| 61 | + }) |
| 62 | + } |
| 63 | + |
| 64 | + return ( |
| 65 | + <RepoWebhookExecutionDetailsPage |
| 66 | + useWebhookStore={useWebhookStore} |
| 67 | + useTranslationStore={useTranslationStore} |
| 68 | + isLoading={isTriggeringExecution} |
| 69 | + handleRetriggerExecution={handleRetriggerExecution} |
| 70 | + useThemeStore={useThemeStore} |
| 71 | + /> |
| 72 | + ) |
| 73 | +} |
0 commit comments