import { User, Clock, Edit, ChevronRight, ChevronUp } from 'lucide-react'; import moment from 'moment'; import { useEffect, useState } from 'react'; import { Pod } from 'kubernetes-types/core/v1'; import { useCurrentStateAndParams } from '@uirouter/react'; import { Authorized } from '@/react/hooks/useUser'; import { notifyError, notifySuccess } from '@/portainer/services/notifications'; import { DetailsTable } from '@@/DetailsTable'; import { Badge } from '@@/Badge'; import { Link } from '@@/Link'; import { Button, LoadingButton } from '@@/buttons'; import { isSystemNamespace } from '../../namespaces/utils'; import { appStackNameLabel, appKindToDeploymentTypeMap, appOwnerLabel, appDeployMethodLabel, appNoteAnnotation, } from '../constants'; import { applicationIsKind, bytesToReadableFormat, getResourceRequests, getRunningPods, getTotalPods, isExternalApplication, } from '../utils'; import { useApplication, usePatchApplicationMutation, } from '../application.queries'; import { Application, ApplicationPatch } from '../types'; export function ApplicationSummaryWidget() { const stateAndParams = useCurrentStateAndParams(); const { params: { namespace, name, 'resource-type': resourceType, endpointId: environmentId, }, } = stateAndParams; const applicationQuery = useApplication( environmentId, namespace, name, resourceType ); const application = applicationQuery.data; const systemNamespace = isSystemNamespace(namespace); const externalApplication = application && isExternalApplication(application); const applicationRequests = application && getResourceRequests(application); const applicationOwner = application?.metadata?.labels?.[appOwnerLabel]; const applicationDeployMethod = getApplicationDeployMethod(application); const applicationNote = application?.metadata?.annotations?.[appNoteAnnotation]; const [isNoteOpen, setIsNoteOpen] = useState(true); const [applicationNoteFormValues, setApplicationNoteFormValues] = useState(''); useEffect(() => { setApplicationNoteFormValues(applicationNote || ''); }, [applicationNote]); const patchApplicationMutation = usePatchApplicationMutation( environmentId, namespace, name ); return (
Name
{name} {externalApplication && !systemNamespace && ( external )}
Stack {application?.metadata?.labels?.[appStackNameLabel] || '-'} Namespace
{namespace} {systemNamespace && system}
Application type {application?.kind || '-'} {application?.kind && ( Status {applicationIsKind('Pod', application) && ( {application?.status?.phase} )} {!applicationIsKind('Pod', application) && ( {appKindToDeploymentTypeMap[application.kind]} {getRunningPods(application)} / {getTotalPods(application)} )} )} {(!!applicationRequests?.cpu || !!applicationRequests?.memoryBytes) && ( Resource reservations {!applicationIsKind('Pod', application) && (
per instance
)} {!!applicationRequests?.cpu && (
CPU {applicationRequests.cpu}
)} {!!applicationRequests?.memoryBytes && (
Memory{' '} {bytesToReadableFormat(applicationRequests.memoryBytes)}
)} )} Creation
{applicationOwner && ( {applicationOwner} )} {moment(application?.metadata?.creationTimestamp).format( 'YYYY-MM-DD HH:mm:ss' )} {(!externalApplication || systemNamespace) && ( Deployed from {applicationDeployMethod} )}
{isNoteOpen && ( <>