diff --git a/__tests__/mocks.ts b/__tests__/mocks.ts index fb25844a6b8..c4a4e37ec08 100644 --- a/__tests__/mocks.ts +++ b/__tests__/mocks.ts @@ -1,9 +1,9 @@ -import type { ComponentType } from 'react' +import type { ComponentType, ReactNode } from 'react' import * as React from 'react' jest.mock('@auth0/auth0-react', () => ({ - Auth0Provider: ({ children }) => children, - withAuthenticationRequired: (component) => component, + Auth0Provider: ({ children }: { children: ReactNode }) => children, + withAuthenticationRequired: (component: ComponentType) => component, useAuth0: () => { return { isLoading: false, diff --git a/libs/domains/environments/data-access/src/lib/domains-environments-data-access.ts b/libs/domains/environments/data-access/src/lib/domains-environments-data-access.ts index 05db8f3f683..ae34710c448 100644 --- a/libs/domains/environments/data-access/src/lib/domains-environments-data-access.ts +++ b/libs/domains/environments/data-access/src/lib/domains-environments-data-access.ts @@ -62,15 +62,7 @@ export const environments = createQueryKeys('environments', { ) }, }), - // TODO [To update once rust-backed will be deployed]: To remove - // NOTE: Value is set by WebSocket - checkRunningStatusClosed: (clusterId: string) => ({ - queryKey: [clusterId], - queryFn() { - // eslint-disable-next-line @typescript-eslint/no-empty-function - return new Promise<{ clusterId: string; reason: string }>(() => {}) - }, - }), + details: ({ environmentId }: { environmentId: string }) => ({ queryKey: [environmentId], async queryFn() { diff --git a/libs/domains/environments/feature/src/lib/environment-state-chip/environment-state-chip.tsx b/libs/domains/environments/feature/src/lib/environment-state-chip/environment-state-chip.tsx index 130d3a95b81..9d2e7ac784b 100644 --- a/libs/domains/environments/feature/src/lib/environment-state-chip/environment-state-chip.tsx +++ b/libs/domains/environments/feature/src/lib/environment-state-chip/environment-state-chip.tsx @@ -1,7 +1,5 @@ import { Skeleton, StatusChip, type StatusChipProps } from '@qovery/shared/ui' -import { useCheckRunningStatusClosed } from '../hooks/use-check-running-status-closed/use-check-running-status-closed' import { useDeploymentStatus } from '../hooks/use-deployment-status/use-deployment-status' -import { useEnvironment } from '../hooks/use-environment/use-environment' import { useRunningStatus } from '../hooks/use-running-status/use-running-status' /** @@ -45,16 +43,7 @@ function DeploymentStateChip({ environmentId, mode, ...props }: DeploymentStateC type RunningStateChipProps = Omit function RunningStateChip({ environmentId, ...props }: RunningStateChipProps) { - const { data: environment } = useEnvironment({ environmentId }) const { data: runningStatus } = useRunningStatus({ environmentId }) - const { data: checkRunningStatusClosed } = useCheckRunningStatusClosed({ - clusterId: environment?.cluster_id ?? '', - }) - - // TODO [To update once rust-backed will be deployed]: To remove - if (checkRunningStatusClosed) { - return - } return ( diff --git a/libs/domains/environments/feature/src/lib/hooks/use-check-running-status-closed/use-check-running-status-closed.ts b/libs/domains/environments/feature/src/lib/hooks/use-check-running-status-closed/use-check-running-status-closed.ts deleted file mode 100644 index 1628578a62c..00000000000 --- a/libs/domains/environments/feature/src/lib/hooks/use-check-running-status-closed/use-check-running-status-closed.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { useQuery } from '@tanstack/react-query' -import { queries } from '@qovery/state/util-queries' - -export interface UseCheckRunningStatusClosedProps { - clusterId: string -} - -export function useCheckRunningStatusClosed({ clusterId }: UseCheckRunningStatusClosedProps) { - return useQuery({ - ...queries.environments.checkRunningStatusClosed(clusterId), - refetchOnMount: false, - refetchOnWindowFocus: false, - refetchOnReconnect: false, - staleTime: Infinity, - }) -} - -export default useCheckRunningStatusClosed diff --git a/libs/domains/services/data-access/src/lib/domains-services-data-access.ts b/libs/domains/services/data-access/src/lib/domains-services-data-access.ts index afc5f92374e..df008662721 100644 --- a/libs/domains/services/data-access/src/lib/domains-services-data-access.ts +++ b/libs/domains/services/data-access/src/lib/domains-services-data-access.ts @@ -224,15 +224,7 @@ export const services = createQueryKeys('services', { return new Promise(() => {}) }, }), - // TODO [To update once rust-backed will be deployed]: To remove - checkRunningStatusClosed: (clusterId: string, environmentId: string) => ({ - queryKey: [clusterId, environmentId], - // NOTE: Value is set by WebSocket - queryFn() { - // eslint-disable-next-line @typescript-eslint/no-empty-function - return new Promise<{ clusterId: string; environmentId: string; reason: string }>(() => {}) - }, - }), + metrics: (environmentId: string, serviceId: string) => ({ queryKey: [environmentId, serviceId], // NOTE: Value is set by WebSocket diff --git a/libs/domains/services/feature/src/lib/hooks/use-check-running-status-closed/use-check-running-status-closed.ts b/libs/domains/services/feature/src/lib/hooks/use-check-running-status-closed/use-check-running-status-closed.ts deleted file mode 100644 index 962c7be16e1..00000000000 --- a/libs/domains/services/feature/src/lib/hooks/use-check-running-status-closed/use-check-running-status-closed.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { useQuery } from '@tanstack/react-query' -import { queries } from '@qovery/state/util-queries' - -export interface UseCheckRunningStatusClosedProps { - clusterId: string - environmentId: string -} - -export function useCheckRunningStatusClosed({ clusterId, environmentId }: UseCheckRunningStatusClosedProps) { - return useQuery({ - ...queries.services.checkRunningStatusClosed(clusterId, environmentId), - refetchOnMount: false, - refetchOnWindowFocus: false, - refetchOnReconnect: false, - staleTime: Infinity, - }) -} - -export default useCheckRunningStatusClosed diff --git a/libs/domains/services/feature/src/lib/hooks/use-services/use-services.ts b/libs/domains/services/feature/src/lib/hooks/use-services/use-services.ts index e62969706a9..c5b34620840 100644 --- a/libs/domains/services/feature/src/lib/hooks/use-services/use-services.ts +++ b/libs/domains/services/feature/src/lib/hooks/use-services/use-services.ts @@ -32,67 +32,67 @@ export function useServices({ environmentId, suspense = false }: UseServicesProp })), }) - const data = useMemo( - () => - (services ?? []).map((service, index) => { - const runningStatus = runningStatusResults[index].data - const deploymentStatus = deploymentStatusResults[index].data + const data = useMemo(() => { + const nextData = (services ?? []).map((service, index) => { + const runningStatus = runningStatusResults[index].data + const deploymentStatus = deploymentStatusResults[index].data - const runningStatusLabel = upperCaseFirstLetter(runningStatus?.state.replace('_', ' ') ?? 'STOPPED') - const deploymentStatusLabel = upperCaseFirstLetter( - (deploymentStatus?.state === 'READY' ? 'NEVER_DEPLOYED' : deploymentStatus?.state)?.replace('_', ' ') ?? - 'STOPPED' - ) - const isManagedDb = service.serviceType === 'DATABASE' && service.mode === 'MANAGED' + const runningStatusLabel = upperCaseFirstLetter(runningStatus?.state.replace('_', ' ') ?? 'STOPPED') + const deploymentStatusLabel = upperCaseFirstLetter( + (deploymentStatus?.state === 'READY' ? 'NEVER_DEPLOYED' : deploymentStatus?.state)?.replace('_', ' ') ?? + 'STOPPED' + ) + const isManagedDb = service.serviceType === 'DATABASE' && service.mode === 'MANAGED' - const runningStatusOverride = match({ runningStatus, isManagedDb }) - .with({ runningStatus: P.any, isManagedDb: true }, () => ({ - triggered_action: undefined, - ...deploymentStatus, - state: match(deploymentStatus?.state) - .with('DEPLOYED', () => 'RUNNING' as const) - .otherwise(() => 'UNKNOWN' as const), - stateLabel: match(deploymentStatus?.state) - .with('DEPLOYED', () => 'Running') - .otherwise(() => 'Unknown'), - })) - .with({ runningStatus: P.nullish, isManagedDb: false }, () => ({ - state: undefined, - stateLabel: undefined, - triggered_action: undefined, - })) - .with({ runningStatus: P.not(P.nullish) }, ({ runningStatus }) => ({ - triggered_action: undefined, // will be unpacked from runningStatus if present - ...runningStatus, - stateLabel: runningStatusLabel, - })) - .exhaustive() + const runningStatusOverride = match({ runningStatus, isManagedDb }) + .with({ runningStatus: P.any, isManagedDb: true }, () => ({ + triggered_action: undefined, + ...deploymentStatus, + state: match(deploymentStatus?.state) + .with('DEPLOYED', () => 'RUNNING' as const) + .otherwise(() => 'UNKNOWN' as const), + stateLabel: match(deploymentStatus?.state) + .with('DEPLOYED', () => 'Running') + .otherwise(() => 'Unknown'), + })) + .with({ runningStatus: P.nullish, isManagedDb: false }, () => ({ + state: undefined, + stateLabel: undefined, + triggered_action: undefined, + })) + .with({ runningStatus: P.not(P.nullish) }, ({ runningStatus }) => ({ + triggered_action: undefined, // will be unpacked from runningStatus if present + ...runningStatus, + stateLabel: runningStatusLabel, + })) + .exhaustive() - return { - ...service, - runningStatus: runningStatusOverride, - ...(deploymentStatus - ? { - deploymentStatus: { - ...deploymentStatus, - stateLabel: deploymentStatusLabel, - }, - } - : {}), - } - }), - [ - services, - // https://github.com/TanStack/query/issues/5137 - // As we currently use tanstack query V4, we cannot use combine to avoid infinite renders - // So we need to use service "state" to memoize data for usage like tanstack table. - // As useMemo cannot have variable params length, we need JSON.stringify to not be bound by the services length - JSON.stringify([ - ...runningStatusResults.map(({ data }) => data?.state), - ...deploymentStatusResults.map(({ data }) => data?.state), - ]), - ] - ) + return { + ...service, + runningStatus: runningStatusOverride, + ...(deploymentStatus + ? { + deploymentStatus: { + ...deploymentStatus, + stateLabel: deploymentStatusLabel, + }, + } + : {}), + } + }) + + return nextData + }, [ + services, + // https://github.com/TanStack/query/issues/5137 + // As we currently use tanstack query V4, we cannot use combine to avoid infinite renders + // So we need to use service "state" to memoize data for usage like tanstack table. + // As useMemo cannot have variable params length, we need JSON.stringify to not be bound by the services length + JSON.stringify([ + ...runningStatusResults.map(({ data }) => data?.state), + ...deploymentStatusResults.map(({ data }) => data?.state), + ]), + ]) return { data, diff --git a/libs/domains/services/feature/src/lib/select-commit-modal/__snapshots__/select-commit-modal.spec.tsx.snap b/libs/domains/services/feature/src/lib/select-commit-modal/__snapshots__/select-commit-modal.spec.tsx.snap index 1ca0f717eb2..089fb11bbfe 100644 --- a/libs/domains/services/feature/src/lib/select-commit-modal/__snapshots__/select-commit-modal.spec.tsx.snap +++ b/libs/domains/services/feature/src/lib/select-commit-modal/__snapshots__/select-commit-modal.spec.tsx.snap @@ -60,9 +60,9 @@ exports[`SelectCommitModal should match snapshot 1`] = ` aria-hidden="true" class="fa-regular fa-code-commit absolute left-0 top-1 -translate-x-1/2 text-neutral-subtle" /> - Commit + Commits on - Jan 15, 2024 + Apr 03, 2026
committed - 2 years + 0 seconds ago
@@ -150,25 +150,6 @@ exports[`SelectCommitModal should match snapshot 1`] = ` - - -
-
-