import * as React from 'react'; import { Button, ModalVariant, Popover, Spinner } from '@patternfly/react-core'; import ErrorModal from '~/components/modal/ErrorModal'; import { BackgroundStatusIconWithText } from '~/components/StatusIcon/BackgroundTaskStatusIcon'; import { LINKING_ERROR_ANNOTATION, LINKING_STATUS_ANNOTATION } from '~/consts/secrets'; import { useLinkedServiceAccounts } from '~/hooks/useLinkedServiceAccounts'; import { HttpError } from '~/k8s/error'; import { useNamespace } from '~/shared/providers/Namespace'; import { SecretKind } from '~/types'; import { getSecretRowLabels, getSecretTypetoLabel } from '~/utils/secrets/secret-utils'; import { isLinkableSecret } from '~/utils/service-account/service-account-utils'; import { BackgroundJobStatus, useTaskStore } from '~/utils/task-store'; import { RowFunctionArgs, TableData } from '../../../shared'; import ActionMenu from '../../../shared/components/action-menu/ActionMenu'; import { createModalLauncher } from '../../modal/createModalLauncher'; import { useModalLauncher } from '../../modal/ModalProvider'; import { useSecretActions } from '../secret-actions'; import { SecretLabels } from './SecretLabels'; import { secretsTableColumnClasses } from './SecretsListHeaderWithComponents'; import './SecretsListRow.scss'; type SecretsListRowProps = RowFunctionArgs< SecretKind, { expandedIds: Set; handleToggle: (id: number) => void } >; const SecretsListRowWithComponents: React.FC> = ({ obj, customData, index, }) => { const showModal = useModalLauncher(); const actions = useSecretActions(obj); const namespace = useNamespace(); const { expandedIds, handleToggle } = customData; const { secretLabels } = getSecretRowLabels(obj); const labels = secretLabels !== '-' ? secretLabels.split(', ') : [secretLabels]; const task = useTaskStore((state) => state.tasks[obj.metadata.name]); const taskError = task?.error ?? obj.metadata?.annotations?.[LINKING_ERROR_ANNOTATION]; const taskStatus = task?.status ?? obj.metadata?.annotations?.[LINKING_STATUS_ANNOTATION] ?? BackgroundJobStatus.Succeeded; const { linkedServiceAccounts, isLoading, error } = useLinkedServiceAccounts( obj.metadata?.namespace || namespace, obj, true, ); return ( <> {getSecretTypetoLabel(obj) ?? '-'} {obj.metadata?.name} {isLoading ? ( ) : error ? ( Error ) : !isLinkableSecret(obj) ? ( '-' ) : ( // The linkedServiceAccounts returns [] or [sa1, sa2...]. {linkedServiceAccounts.length} )} {taskStatus === BackgroundJobStatus.Failed && taskError && ( )} ); }; export default SecretsListRowWithComponents;