mirror of
https://github.com/langgenius/dify.git
synced 2026-05-13 08:57:28 +08:00
67 lines
2.1 KiB
TypeScript
67 lines
2.1 KiB
TypeScript
import type { DeployedToSummary, EnvironmentDeploymentRow, ReleaseHistoryRow } from '@/features/deployments/types'
|
|
import {
|
|
activeRelease,
|
|
deploymentStatus,
|
|
environmentId,
|
|
environmentName,
|
|
} from '../../utils'
|
|
|
|
export type ReleaseDeploymentState = 'active' | 'deploying' | 'failed'
|
|
|
|
export type ReleaseDeployment = {
|
|
environmentId: string
|
|
environmentName: string
|
|
state: ReleaseDeploymentState
|
|
}
|
|
|
|
function releaseDeploymentState(status?: string): ReleaseDeploymentState {
|
|
const normalized = status?.toLowerCase() ?? ''
|
|
if (normalized.includes('deploying') || normalized.includes('pending'))
|
|
return 'deploying'
|
|
if (normalized.includes('fail') || normalized.includes('error'))
|
|
return 'failed'
|
|
return 'active'
|
|
}
|
|
|
|
function fromDeployedTo(item: DeployedToSummary): ReleaseDeployment | undefined {
|
|
if (!item.environmentId)
|
|
return undefined
|
|
|
|
return {
|
|
environmentId: item.environmentId,
|
|
environmentName: item.environmentName || item.environmentId,
|
|
state: releaseDeploymentState(item.instanceStatus),
|
|
}
|
|
}
|
|
|
|
function dedupeReleaseDeployments(items: ReleaseDeployment[]) {
|
|
return items.filter((item, index) => {
|
|
return items.findIndex(candidate => candidate.environmentId === item.environmentId) === index
|
|
})
|
|
}
|
|
|
|
export function getReleaseDeployments(row: ReleaseHistoryRow, deploymentRows: EnvironmentDeploymentRow[]) {
|
|
const releaseId = (row.release ?? row).id
|
|
if (!releaseId)
|
|
return []
|
|
|
|
const historyItems = row.deployedTo?.map(fromDeployedTo).filter((item): item is ReleaseDeployment => !!item) ?? []
|
|
const runtimeItems = deploymentRows.flatMap((deployment) => {
|
|
const envId = environmentId(deployment.environment)
|
|
if (!envId)
|
|
return []
|
|
|
|
const items: ReleaseDeployment[] = []
|
|
if (activeRelease(deployment)?.id === releaseId) {
|
|
items.push({
|
|
environmentId: envId,
|
|
environmentName: environmentName(deployment.environment),
|
|
state: releaseDeploymentState(deploymentStatus(deployment)),
|
|
})
|
|
}
|
|
return items
|
|
})
|
|
|
|
return dedupeReleaseDeployments([...runtimeItems, ...historyItems])
|
|
}
|