Skip to content

Commit 7f5b585

Browse files
committed
fix(deployment-logs): redirect latest version and dark mode modal redeploy
1 parent e1165cb commit 7f5b585

14 files changed

Lines changed: 146 additions & 131 deletions

File tree

libs/domains/environment-logs/feature/src/lib/environment-stages/environment-stages.spec.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ describe('EnvironmentStages', () => {
1515
},
1616
environmentStatus: {
1717
state: 'RUNNING',
18+
last_deployment_id: 'exec-1',
1819
},
1920
hideSkipped: false,
2021
setHideSkipped: jest.fn(),
@@ -54,7 +55,7 @@ describe('EnvironmentStages', () => {
5455
const logLink = screen.getByText('Pre-check logs').closest('a')
5556
expect(logLink).toHaveAttribute(
5657
'href',
57-
ENVIRONMENT_LOGS_URL('org-1', 'proj-1', 'env-1') + ENVIRONMENT_PRE_CHECK_LOGS_URL()
58+
ENVIRONMENT_LOGS_URL('org-1', 'proj-1', 'env-1') + ENVIRONMENT_PRE_CHECK_LOGS_URL('exec-1')
5859
)
5960
})
6061
})

libs/domains/environment-logs/feature/src/lib/environment-stages/environment-stages.tsx

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export function EnvironmentStages({
3232
setHideSkipped,
3333
children,
3434
}: EnvironmentStagesProps) {
35-
const executionId = environmentStatus.last_deployment_id ?? undefined
35+
const executionId = environmentStatus.last_deployment_id
3636

3737
return (
3838
<div className="h-[calc(100vh-64px)] w-[calc(100vw-64px)] p-1">
@@ -75,21 +75,26 @@ export function EnvironmentStages({
7575
</span>
7676
</div>
7777
</div>
78-
<div className="flex flex-col gap-1.5 bg-neutral-800 p-1.5">
79-
<NavLink
80-
to={
81-
ENVIRONMENT_LOGS_URL(environment.organization.id, environment.project.id, environment.id) +
82-
ENVIRONMENT_PRE_CHECK_LOGS_URL(executionId)
83-
}
84-
className="flex w-full items-center gap-2.5 rounded border border-neutral-400 bg-neutral-550 px-2.5 py-2 hover:border-brand-400"
85-
>
86-
<span className="flex h-8 w-8 items-center justify-center rounded-full border border-neutral-400 text-neutral-250">
87-
<Icon iconName="list-check" iconStyle="solid" />
88-
</span>
89-
<span className="text-sm">Pre-check logs</span>
90-
<StatusChip className="ml-auto" status={preCheckStage.status} />
91-
</NavLink>
92-
</div>
78+
{executionId && (
79+
<div className="flex flex-col gap-1.5 bg-neutral-800 p-1.5">
80+
<NavLink
81+
to={
82+
ENVIRONMENT_LOGS_URL(
83+
environment.organization.id,
84+
environment.project.id,
85+
environment.id
86+
) + ENVIRONMENT_PRE_CHECK_LOGS_URL(executionId)
87+
}
88+
className="flex w-full items-center gap-2.5 rounded border border-neutral-400 bg-neutral-550 px-2.5 py-2 hover:border-brand-400"
89+
>
90+
<span className="flex h-8 w-8 items-center justify-center rounded-full border border-neutral-400 text-neutral-250">
91+
<Icon iconName="list-check" iconStyle="solid" />
92+
</span>
93+
<span className="text-sm">Pre-check logs</span>
94+
<StatusChip className="ml-auto" status={preCheckStage.status} />
95+
</NavLink>
96+
</div>
97+
)}
9398
</div>
9499
<div className="mt-4 w-4">
95100
<svg xmlns="http://www.w3.org/2000/svg" width="17" height="9" fill="none" viewBox="0 0 17 9">

libs/domains/service-logs/feature/src/lib/deployment-logs-placeholder/deployment-logs-placeholder.spec.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ describe('DeploymentLogsPlaceholder', () => {
2222
const props: DeploymentLogsPlaceholderProps = {
2323
serviceStatus: undefined,
2424
itemsLength: 0,
25-
deploymentHistoryEnvironment: [],
25+
environmentDeploymentHistory: [],
2626
}
2727

2828
it('should render deployment history', () => {
2929
renderWithProviders(
3030
<DeploymentLogsPlaceholder
3131
itemsLength={1}
32-
deploymentHistoryEnvironment={[
32+
environmentDeploymentHistory={[
3333
{
3434
identifier: {
3535
execution_id: 'exec-1',
@@ -98,7 +98,7 @@ describe('DeploymentLogsPlaceholder', () => {
9898
renderWithProviders(
9999
<DeploymentLogsPlaceholder
100100
itemsLength={0}
101-
deploymentHistoryEnvironment={[]}
101+
environmentDeploymentHistory={[]}
102102
serviceStatus={{
103103
id: '0',
104104
state: 'DEPLOYED',

libs/domains/service-logs/feature/src/lib/deployment-logs-placeholder/deployment-logs-placeholder.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,13 @@ function DeploymentHistoryPlaceholder({
7373
export interface DeploymentLogsPlaceholderProps {
7474
serviceStatus?: Status
7575
itemsLength?: number
76-
deploymentHistoryEnvironment?: DeploymentHistoryEnvironmentV2[]
76+
environmentDeploymentHistory?: DeploymentHistoryEnvironmentV2[]
7777
}
7878

7979
export function DeploymentLogsPlaceholder({
8080
serviceStatus,
8181
itemsLength,
82-
deploymentHistoryEnvironment,
82+
environmentDeploymentHistory,
8383
}: DeploymentLogsPlaceholderProps) {
8484
const { environmentId = '', serviceId = '' } = useParams()
8585

@@ -105,7 +105,7 @@ export function DeploymentLogsPlaceholder({
105105
)
106106
.otherwise(() => false)
107107

108-
const deploymentsByServiceId = mergeDeploymentServices(deploymentHistoryEnvironment).filter(
108+
const deploymentsByServiceId = mergeDeploymentServices(environmentDeploymentHistory).filter(
109109
(deploymentHistory) => deploymentHistory.identifier.service_id === serviceId
110110
)
111111

libs/domains/service-logs/feature/src/lib/hooks/use-deployment-logs/use-deployment-logs.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { useEnvironment } from '@qovery/domains/environments/feature'
66
import { QOVERY_WS } from '@qovery/shared/util-node-env'
77
import { useReactQueryWsSubscription } from '@qovery/state/util-queries'
88
import { ServiceStageIdsContext } from '../../service-stage-ids-context/service-stage-ids-context'
9+
import { useDeploymentHistory } from '../use-deployment-history/use-deployment-history'
910

1011
export interface UseDeploymentLogsProps {
1112
organizationId?: string
@@ -31,6 +32,7 @@ export function useDeploymentLogs({
3132
versionId,
3233
}: UseDeploymentLogsProps) {
3334
const { hash } = useLocation()
35+
const { data: deploymentHistory = [] } = useDeploymentHistory({ environmentId: environmentId ?? '' })
3436
const { data: environment } = useEnvironment({ environmentId })
3537

3638
// States for controlling log actions, showing new, previous or paused logs
@@ -60,14 +62,17 @@ export function useDeploymentLogs({
6062
[setMessageChunks]
6163
)
6264

65+
// XXX: If we don't have a version, it works like WS otherwise, it works like a REST API
66+
const isLatestVersion = deploymentHistory[0]?.identifier.execution_id === versionId
67+
6368
useReactQueryWsSubscription({
6469
url: QOVERY_WS + '/deployment/logs',
6570
urlSearchParams: {
6671
organization: organizationId,
6772
cluster: environment?.cluster_id,
6873
project: projectId,
6974
environment: environmentId,
70-
version: versionId,
75+
version: isLatestVersion ? undefined : versionId,
7176
},
7277
enabled:
7378
Boolean(organizationId) && Boolean(environment?.cluster_id) && Boolean(projectId) && Boolean(environmentId),

libs/domains/service-logs/feature/src/lib/list-deployment-logs/list-deployment-logs.spec.tsx

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,22 @@ jest.mock('react-router-dom', () => ({
2121
}),
2222
}))
2323

24+
jest.mock('../hooks/use-deployment-history/use-deployment-history', () => ({
25+
...jest.requireActual('../hooks/use-deployment-history/use-deployment-history'),
26+
useDeploymentHistory: () => ({
27+
data: [
28+
{
29+
identifier: {
30+
execution_id: '4',
31+
},
32+
},
33+
],
34+
}),
35+
}))
36+
2437
describe('ListDeploymentLogs', () => {
2538
const mockEnvironment = environmentFactoryMock(1)[0]
2639

27-
const mockDeploymentHistoryEnvironment: DeploymentHistoryEnvironmentV2[] = [
28-
{
29-
identifier: {
30-
execution_id: '4',
31-
},
32-
},
33-
]
34-
3540
const mockServiceStatus: Status = {
3641
id: '111',
3742
state: 'DELETE_ERROR',
@@ -120,35 +125,21 @@ describe('ListDeploymentLogs', () => {
120125

121126
it('should render successfully', () => {
122127
const { baseElement } = renderWithProviders(
123-
<ListDeploymentLogs
124-
environment={mockEnvironment}
125-
deploymentHistoryEnvironment={mockDeploymentHistoryEnvironment}
126-
serviceStatus={mockServiceStatus}
127-
/>
128+
<ListDeploymentLogs environment={mockEnvironment} serviceStatus={mockServiceStatus} />
128129
)
129130
expect(baseElement).toBeTruthy()
130131
})
131132

132133
it('should display logs', () => {
133-
renderWithProviders(
134-
<ListDeploymentLogs
135-
environment={mockEnvironment}
136-
deploymentHistoryEnvironment={mockDeploymentHistoryEnvironment}
137-
serviceStatus={mockServiceStatus}
138-
/>
139-
)
134+
renderWithProviders(<ListDeploymentLogs environment={mockEnvironment} serviceStatus={mockServiceStatus} />)
140135

141136
expect(screen.getByText('Log 1')).toBeInTheDocument()
142137
expect(screen.getByText('Log 2')).toBeInTheDocument()
143138
})
144139

145140
it('should filter logs by stage step', async () => {
146141
const { userEvent } = renderWithProviders(
147-
<ListDeploymentLogs
148-
environment={mockEnvironment}
149-
deploymentHistoryEnvironment={mockDeploymentHistoryEnvironment}
150-
serviceStatus={mockServiceStatus}
151-
/>
142+
<ListDeploymentLogs environment={mockEnvironment} serviceStatus={mockServiceStatus} />
152143
)
153144

154145
const buildButton = screen.getByRole('button', { name: /build/i })
@@ -165,13 +156,7 @@ describe('ListDeploymentLogs', () => {
165156
data: { state: 'BUILDING' },
166157
})
167158

168-
renderWithProviders(
169-
<ListDeploymentLogs
170-
environment={mockEnvironment}
171-
deploymentHistoryEnvironment={mockDeploymentHistoryEnvironment}
172-
serviceStatus={mockServiceStatus}
173-
/>
174-
)
159+
renderWithProviders(<ListDeploymentLogs environment={mockEnvironment} serviceStatus={mockServiceStatus} />)
175160

176161
expect(screen.getByText('Streaming deployment logs')).toBeInTheDocument()
177162
})

libs/domains/service-logs/feature/src/lib/list-deployment-logs/list-deployment-logs.tsx

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,7 @@ import {
77
useReactTable,
88
} from '@tanstack/react-table'
99
import download from 'downloadjs'
10-
import {
11-
type DeploymentHistoryEnvironmentV2,
12-
type Environment,
13-
type EnvironmentStatus,
14-
type Stage,
15-
type Status,
16-
} from 'qovery-typescript-axios'
10+
import { type Environment, type EnvironmentStatus, type Stage, type Status } from 'qovery-typescript-axios'
1711
import { memo, useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react'
1812
import { useLocation, useParams } from 'react-router-dom'
1913
import { match } from 'ts-pattern'
@@ -22,6 +16,7 @@ import { ENVIRONMENT_LOGS_URL, ENVIRONMENT_STAGES_URL, SERVICE_LOGS_URL } from '
2216
import { Button, Icon, Indicator, Link, TablePrimitives } from '@qovery/shared/ui'
2317
import { DeploymentLogsPlaceholder } from '../deployment-logs-placeholder/deployment-logs-placeholder'
2418
import HeaderLogs from '../header-logs/header-logs'
19+
import { useDeploymentHistory } from '../hooks/use-deployment-history/use-deployment-history'
2520
import { type EnvironmentLogIds, useDeploymentLogs } from '../hooks/use-deployment-logs/use-deployment-logs'
2621
import { ProgressIndicator } from '../progress-indicator/progress-indicator'
2722
import { ServiceStageIdsContext } from '../service-stage-ids-context/service-stage-ids-context'
@@ -126,19 +121,12 @@ const getFilterStep = (step: EnvironmentEngineStep): FilterType =>
126121

127122
export interface ListDeploymentLogsProps {
128123
environment: Environment
129-
deploymentHistoryEnvironment: DeploymentHistoryEnvironmentV2[]
130124
serviceStatus: Status
131125
stage?: Stage
132126
environmentStatus?: EnvironmentStatus
133127
}
134128

135-
export function ListDeploymentLogs({
136-
environment,
137-
deploymentHistoryEnvironment,
138-
environmentStatus,
139-
serviceStatus,
140-
stage,
141-
}: ListDeploymentLogsProps) {
129+
export function ListDeploymentLogs({ environment, environmentStatus, serviceStatus, stage }: ListDeploymentLogsProps) {
142130
const { hash } = useLocation()
143131
const { organizationId, projectId, serviceId, versionId } = useParams()
144132
const refScrollSection = useRef<HTMLDivElement>(null)
@@ -150,6 +138,7 @@ export function ListDeploymentLogs({
150138

151139
const { data: service } = useService({ environmentId: environment.id, serviceId })
152140
const { data: deploymentStatus } = useDeploymentStatus({ environmentId: environment.id, serviceId })
141+
const { data: environmentDeploymentHistory = [] } = useDeploymentHistory({ environmentId: environment.id })
153142
const {
154143
data: logs = [],
155144
pauseLogs,
@@ -272,7 +261,7 @@ export function ListDeploymentLogs({
272261
[columnFilters]
273262
)
274263

275-
const isLastVersion = deploymentHistoryEnvironment?.[0]?.identifier.execution_id === versionId || !versionId
264+
const isLastVersion = environmentDeploymentHistory?.[0]?.identifier.execution_id === versionId || !versionId
276265
const isDeploymentProgressing = isLastVersion
277266
? match(deploymentStatus?.state)
278267
.with(
@@ -302,8 +291,8 @@ export function ListDeploymentLogs({
302291
environmentStatus={environmentStatus}
303292
deploymentHistory={
304293
versionId
305-
? deploymentHistoryEnvironment.find((d) => d.identifier.execution_id === versionId)
306-
: deploymentHistoryEnvironment[0]
294+
? environmentDeploymentHistory.find((d) => d.identifier.execution_id === versionId)
295+
: environmentDeploymentHistory[0]
307296
}
308297
>
309298
<div className="flex items-center gap-4">
@@ -365,7 +354,7 @@ export function ListDeploymentLogs({
365354
<DeploymentLogsPlaceholder
366355
serviceStatus={serviceStatus}
367356
itemsLength={logs.length}
368-
deploymentHistoryEnvironment={deploymentHistoryEnvironment}
357+
environmentDeploymentHistory={environmentDeploymentHistory}
369358
/>
370359
</div>
371360
</div>
@@ -426,11 +415,13 @@ export function ListDeploymentLogs({
426415
<ProgressIndicator className="mb-2 pl-2" pauseLogs={pauseLogs} message="Streaming deployment logs" />
427416
)}
428417
</div>
429-
<ShowNewLogsButton
430-
pauseLogs={pauseLogs}
431-
setPauseLogs={setPauseLogs}
432-
newMessagesAvailable={newMessagesAvailable}
433-
/>
418+
{isLastVersion && (
419+
<ShowNewLogsButton
420+
pauseLogs={pauseLogs}
421+
setPauseLogs={setPauseLogs}
422+
newMessagesAvailable={newMessagesAvailable}
423+
/>
424+
)}
434425
</div>
435426
</div>
436427
)

libs/domains/services/feature/src/lib/redeploy-modal/__snapshots__/redeploy-modal.spec.tsx.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ exports[`RedeployModal should match snapshot 1`] = `
3333
value="redeploy"
3434
/>
3535
<label
36-
class="font-medium leading-5 text-neutral-400 text-ssm"
36+
class="font-medium leading-5 text-neutral-400 dark:text-neutral-50 text-ssm"
3737
for="redeploy"
3838
>
3939
Redeploy
4040
<p
41-
class="mt-1 text-xs font-normal text-neutral-350"
41+
class="mt-1 text-xs font-normal text-neutral-350 dark:text-neutral-50"
4242
>
4343
This action will not restart your service but it will allow to align again your configuration with your cluster.
4444
</p>
@@ -55,12 +55,12 @@ exports[`RedeployModal should match snapshot 1`] = `
5555
value="restart"
5656
/>
5757
<label
58-
class="font-medium leading-5 text-neutral-400 text-ssm"
58+
class="font-medium leading-5 text-neutral-400 dark:text-neutral-50 text-ssm"
5959
for="restart"
6060
>
6161
Restart service
6262
<p
63-
class="mt-1 text-xs font-normal text-neutral-350"
63+
class="mt-1 text-xs font-normal text-neutral-350 dark:text-neutral-50"
6464
>
6565
To restart the pods of your service.
6666
</p>

0 commit comments

Comments
 (0)