diff --git a/libs/domains/environment-logs/feature/src/lib/environment-stages/environment-stages.spec.tsx b/libs/domains/environment-logs/feature/src/lib/environment-stages/environment-stages.spec.tsx index 54aa7bdfe91..1b47992f464 100644 --- a/libs/domains/environment-logs/feature/src/lib/environment-stages/environment-stages.spec.tsx +++ b/libs/domains/environment-logs/feature/src/lib/environment-stages/environment-stages.spec.tsx @@ -15,6 +15,7 @@ describe('EnvironmentStages', () => { }, environmentStatus: { state: 'RUNNING', + last_deployment_id: 'exec-1', }, hideSkipped: false, setHideSkipped: jest.fn(), @@ -54,7 +55,7 @@ describe('EnvironmentStages', () => { const logLink = screen.getByText('Pre-check logs').closest('a') expect(logLink).toHaveAttribute( 'href', - ENVIRONMENT_LOGS_URL('org-1', 'proj-1', 'env-1') + ENVIRONMENT_PRE_CHECK_LOGS_URL() + ENVIRONMENT_LOGS_URL('org-1', 'proj-1', 'env-1') + ENVIRONMENT_PRE_CHECK_LOGS_URL('exec-1') ) }) }) diff --git a/libs/domains/environment-logs/feature/src/lib/environment-stages/environment-stages.tsx b/libs/domains/environment-logs/feature/src/lib/environment-stages/environment-stages.tsx index c749a8145d8..a7075bef88b 100644 --- a/libs/domains/environment-logs/feature/src/lib/environment-stages/environment-stages.tsx +++ b/libs/domains/environment-logs/feature/src/lib/environment-stages/environment-stages.tsx @@ -32,7 +32,7 @@ export function EnvironmentStages({ setHideSkipped, children, }: EnvironmentStagesProps) { - const executionId = environmentStatus.last_deployment_id ?? undefined + const executionId = environmentStatus.last_deployment_id return (
@@ -75,21 +75,26 @@ export function EnvironmentStages({
-
- - - - - Pre-check logs - - -
+ {executionId && ( +
+ + + + + Pre-check logs + + +
+ )}
diff --git a/libs/domains/service-logs/feature/src/lib/deployment-logs-placeholder/deployment-logs-placeholder.spec.tsx b/libs/domains/service-logs/feature/src/lib/deployment-logs-placeholder/deployment-logs-placeholder.spec.tsx index 309ca6c2e70..c1a118acf84 100644 --- a/libs/domains/service-logs/feature/src/lib/deployment-logs-placeholder/deployment-logs-placeholder.spec.tsx +++ b/libs/domains/service-logs/feature/src/lib/deployment-logs-placeholder/deployment-logs-placeholder.spec.tsx @@ -22,14 +22,14 @@ describe('DeploymentLogsPlaceholder', () => { const props: DeploymentLogsPlaceholderProps = { serviceStatus: undefined, itemsLength: 0, - deploymentHistoryEnvironment: [], + environmentDeploymentHistory: [], } it('should render deployment history', () => { renderWithProviders( { renderWithProviders( false) - const deploymentsByServiceId = mergeDeploymentServices(deploymentHistoryEnvironment).filter( + const deploymentsByServiceId = mergeDeploymentServices(environmentDeploymentHistory).filter( (deploymentHistory) => deploymentHistory.identifier.service_id === serviceId ) diff --git a/libs/domains/service-logs/feature/src/lib/hooks/use-deployment-logs/use-deployment-logs.ts b/libs/domains/service-logs/feature/src/lib/hooks/use-deployment-logs/use-deployment-logs.ts index 7c34cea94bd..06a876b92b5 100644 --- a/libs/domains/service-logs/feature/src/lib/hooks/use-deployment-logs/use-deployment-logs.ts +++ b/libs/domains/service-logs/feature/src/lib/hooks/use-deployment-logs/use-deployment-logs.ts @@ -6,6 +6,7 @@ import { useEnvironment } from '@qovery/domains/environments/feature' import { QOVERY_WS } from '@qovery/shared/util-node-env' import { useReactQueryWsSubscription } from '@qovery/state/util-queries' import { ServiceStageIdsContext } from '../../service-stage-ids-context/service-stage-ids-context' +import { useDeploymentHistory } from '../use-deployment-history/use-deployment-history' export interface UseDeploymentLogsProps { organizationId?: string @@ -31,6 +32,7 @@ export function useDeploymentLogs({ versionId, }: UseDeploymentLogsProps) { const { hash } = useLocation() + const { data: deploymentHistory = [] } = useDeploymentHistory({ environmentId: environmentId ?? '' }) const { data: environment } = useEnvironment({ environmentId }) // States for controlling log actions, showing new, previous or paused logs @@ -60,6 +62,9 @@ export function useDeploymentLogs({ [setMessageChunks] ) + // XXX: If we don't have a version, it works like WS otherwise, it works like a REST API + const isLatestVersion = deploymentHistory[0]?.identifier.execution_id === versionId + useReactQueryWsSubscription({ url: QOVERY_WS + '/deployment/logs', urlSearchParams: { @@ -67,7 +72,7 @@ export function useDeploymentLogs({ cluster: environment?.cluster_id, project: projectId, environment: environmentId, - version: versionId, + version: isLatestVersion ? undefined : versionId, }, enabled: Boolean(organizationId) && Boolean(environment?.cluster_id) && Boolean(projectId) && Boolean(environmentId), diff --git a/libs/domains/service-logs/feature/src/lib/list-deployment-logs/list-deployment-logs.spec.tsx b/libs/domains/service-logs/feature/src/lib/list-deployment-logs/list-deployment-logs.spec.tsx index c8c6b718467..0e75040716e 100644 --- a/libs/domains/service-logs/feature/src/lib/list-deployment-logs/list-deployment-logs.spec.tsx +++ b/libs/domains/service-logs/feature/src/lib/list-deployment-logs/list-deployment-logs.spec.tsx @@ -21,17 +21,22 @@ jest.mock('react-router-dom', () => ({ }), })) +jest.mock('../hooks/use-deployment-history/use-deployment-history', () => ({ + ...jest.requireActual('../hooks/use-deployment-history/use-deployment-history'), + useDeploymentHistory: () => ({ + data: [ + { + identifier: { + execution_id: '4', + }, + }, + ], + }), +})) + describe('ListDeploymentLogs', () => { const mockEnvironment = environmentFactoryMock(1)[0] - const mockDeploymentHistoryEnvironment: DeploymentHistoryEnvironmentV2[] = [ - { - identifier: { - execution_id: '4', - }, - }, - ] - const mockServiceStatus: Status = { id: '111', state: 'DELETE_ERROR', @@ -120,23 +125,13 @@ describe('ListDeploymentLogs', () => { it('should render successfully', () => { const { baseElement } = renderWithProviders( - + ) expect(baseElement).toBeTruthy() }) it('should display logs', () => { - renderWithProviders( - - ) + renderWithProviders() expect(screen.getByText('Log 1')).toBeInTheDocument() expect(screen.getByText('Log 2')).toBeInTheDocument() @@ -144,11 +139,7 @@ describe('ListDeploymentLogs', () => { it('should filter logs by stage step', async () => { const { userEvent } = renderWithProviders( - + ) const buildButton = screen.getByRole('button', { name: /build/i }) @@ -165,13 +156,7 @@ describe('ListDeploymentLogs', () => { data: { state: 'BUILDING' }, }) - renderWithProviders( - - ) + renderWithProviders() expect(screen.getByText('Streaming deployment logs')).toBeInTheDocument() }) diff --git a/libs/domains/service-logs/feature/src/lib/list-deployment-logs/list-deployment-logs.tsx b/libs/domains/service-logs/feature/src/lib/list-deployment-logs/list-deployment-logs.tsx index f3ad5772e38..2564941f2ca 100644 --- a/libs/domains/service-logs/feature/src/lib/list-deployment-logs/list-deployment-logs.tsx +++ b/libs/domains/service-logs/feature/src/lib/list-deployment-logs/list-deployment-logs.tsx @@ -7,13 +7,7 @@ import { useReactTable, } from '@tanstack/react-table' import download from 'downloadjs' -import { - type DeploymentHistoryEnvironmentV2, - type Environment, - type EnvironmentStatus, - type Stage, - type Status, -} from 'qovery-typescript-axios' +import { type Environment, type EnvironmentStatus, type Stage, type Status } from 'qovery-typescript-axios' import { memo, useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react' import { useLocation, useParams } from 'react-router-dom' import { match } from 'ts-pattern' @@ -22,6 +16,7 @@ import { ENVIRONMENT_LOGS_URL, ENVIRONMENT_STAGES_URL, SERVICE_LOGS_URL } from ' import { Button, Icon, Indicator, Link, TablePrimitives } from '@qovery/shared/ui' import { DeploymentLogsPlaceholder } from '../deployment-logs-placeholder/deployment-logs-placeholder' import HeaderLogs from '../header-logs/header-logs' +import { useDeploymentHistory } from '../hooks/use-deployment-history/use-deployment-history' import { type EnvironmentLogIds, useDeploymentLogs } from '../hooks/use-deployment-logs/use-deployment-logs' import { ProgressIndicator } from '../progress-indicator/progress-indicator' import { ServiceStageIdsContext } from '../service-stage-ids-context/service-stage-ids-context' @@ -126,19 +121,12 @@ const getFilterStep = (step: EnvironmentEngineStep): FilterType => export interface ListDeploymentLogsProps { environment: Environment - deploymentHistoryEnvironment: DeploymentHistoryEnvironmentV2[] serviceStatus: Status stage?: Stage environmentStatus?: EnvironmentStatus } -export function ListDeploymentLogs({ - environment, - deploymentHistoryEnvironment, - environmentStatus, - serviceStatus, - stage, -}: ListDeploymentLogsProps) { +export function ListDeploymentLogs({ environment, environmentStatus, serviceStatus, stage }: ListDeploymentLogsProps) { const { hash } = useLocation() const { organizationId, projectId, serviceId, versionId } = useParams() const refScrollSection = useRef(null) @@ -150,6 +138,7 @@ export function ListDeploymentLogs({ const { data: service } = useService({ environmentId: environment.id, serviceId }) const { data: deploymentStatus } = useDeploymentStatus({ environmentId: environment.id, serviceId }) + const { data: environmentDeploymentHistory = [] } = useDeploymentHistory({ environmentId: environment.id }) const { data: logs = [], pauseLogs, @@ -272,7 +261,7 @@ export function ListDeploymentLogs({ [columnFilters] ) - const isLastVersion = deploymentHistoryEnvironment?.[0]?.identifier.execution_id === versionId || !versionId + const isLastVersion = environmentDeploymentHistory?.[0]?.identifier.execution_id === versionId || !versionId const isDeploymentProgressing = isLastVersion ? match(deploymentStatus?.state) .with( @@ -302,8 +291,8 @@ export function ListDeploymentLogs({ environmentStatus={environmentStatus} deploymentHistory={ versionId - ? deploymentHistoryEnvironment.find((d) => d.identifier.execution_id === versionId) - : deploymentHistoryEnvironment[0] + ? environmentDeploymentHistory.find((d) => d.identifier.execution_id === versionId) + : environmentDeploymentHistory[0] } >
@@ -365,7 +354,7 @@ export function ListDeploymentLogs({
@@ -426,11 +415,13 @@ export function ListDeploymentLogs({ )} - + {isLastVersion && ( + + )} ) diff --git a/libs/domains/services/feature/src/lib/redeploy-modal/__snapshots__/redeploy-modal.spec.tsx.snap b/libs/domains/services/feature/src/lib/redeploy-modal/__snapshots__/redeploy-modal.spec.tsx.snap index c3050e2e1ac..f789a869152 100644 --- a/libs/domains/services/feature/src/lib/redeploy-modal/__snapshots__/redeploy-modal.spec.tsx.snap +++ b/libs/domains/services/feature/src/lib/redeploy-modal/__snapshots__/redeploy-modal.spec.tsx.snap @@ -33,12 +33,12 @@ exports[`RedeployModal should match snapshot 1`] = ` value="redeploy" />