Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

2.1 KB
Raw Blame
import type { DeviceGitPullRequestCheck } from '@lobechat/types';
import { Icon } from '@lobehub/ui';
import { cssVar } from '@lobehub/ui/stylex/cssVar.stylex';
import * as stylex from '@stylexjs/stylex';
import { ExternalLinkIcon } from 'lucide-react';
import { memo } from 'react';
import { useTranslation } from 'react-i18next';

import { openTrustedExternalUrl } from '@/utils/openTrustedExternalUrl';

import { OverviewRow } from '../Overview/OverviewRow';
import { formatCheckDuration, getCheckVisual, TONE_COLOR } from './prVisual';

const styles = stylex.create({
  duration: { fontFamily: cssVar.fontFamilyCode },
  list: { display: 'flex', flexDirection: 'column', gap: '1px' },
});

interface ChecksListProps {
  checks: DeviceGitPullRequestCheck[];
}

const ChecksList = memo<ChecksListProps>(({ checks }) => {
  const { t } = useTranslation('chat');
  const hasRequiredCheck = checks.some((check) => check.required);
  return (
    <div {...stylex.props(styles.list)}>
      {checks.map((check, index) => {
        const { detailsUrl } = check;
        const visual = getCheckVisual(check.status);
        const duration =
          check.status === 'pending' && !check.startedAt
            ? t('workingPanel.pr.check.queued')
            : formatCheckDuration(check);
        return (
          <OverviewRow
            icon={visual.icon}
            iconColor={TONE_COLOR[visual.tone]}
            key={`${check.name}:${index}`}
            spin={visual.spin}
            title={check.name}
            value={check.name}
            trailing={
              <>
                {hasRequiredCheck && !check.required && (
                  <span>{t('workingPanel.pr.check.optional')}</span>
                )}
                {duration && <span {...stylex.props(styles.duration)}>{duration}</span>}
                {detailsUrl && <Icon icon={ExternalLinkIcon} size={12} />}
              </>
            }
            onClick={detailsUrl ? () => openTrustedExternalUrl(detailsUrl) : undefined}
          />
        );
      })}
    </div>
  );
});

ChecksList.displayName = 'PullRequestChecksList';

export default ChecksList;