Skip to content

⭐️⭐️⭐️ Open-source, self-hosted alternative to Linear and Plane. Project management and issue tracking where teams and AI agents work side by side to plan and ship products.

3.6 KB
Raw Blame
import { useRef, useState } from 'react';
import { Maximize2, X } from 'lucide-react';
import type { ProjectDetail } from '@/lib/api/endpoints/projects';
import type { IssueDetail as IssueDetailRow } from '@/lib/api/endpoints/issues';
import IssueDetailContent from './IssueDetailContent';
import IssueActionsBar from '../actions/IssueActionsBar';
import { useExitOnEscape } from '@/hooks/useExitOnEscape';
import { useExitOnClickOutside } from '../../hooks/useExitOnClickOutside';
import { useIssueTitle } from '../../hooks/useIssueTitle';
import { Button } from '@/components/ui/button';
import { useTranslations } from 'next-intl';

// The issue detail as a side panel over the project, at the end edge. Expand opens the
// same issue as a full page; the shared body lives in IssueDetailContent.
export default function IssueDetail({
  project,
  issueId,
  onClose,
  onExpand,
}: {
  project: ProjectDetail;
  issueId: number;
  onClose: () => void;
  // Passed the issue's project-scoped number so the host can open the page URL
  // (/acme/issue/MKT-42); null while the issue is still loading.
  onExpand: (sequenceNumber: number | null) => void;
}) {
  const t = useTranslations('issue');
  const tCommon = useTranslations('common');
  const [issue, setIssue] = useState<IssueDetailRow | null>(null);
  const panelRef = useRef<HTMLDivElement>(null);

  useExitOnEscape(onClose);
  useExitOnClickOutside(panelRef, onClose);
  useIssueTitle(issueId, 'panel');

  return (
    <div
      // Above the floating chat button (z-40), which sits in the corner the panel's
      // last-comment bubble uses.
      className="pointer-events-none fixed inset-0 z-50 flex"
    >
      {/* No padding at the top: the sticky header carries it, so it can sit flush
          against the panel edge with nothing showing above it. */}
      <div
        ref={panelRef}
        className="pointer-events-auto ms-auto flex h-full w-full flex-col overflow-y-auto border-s bg-card px-5 pt-0 pb-5 sm:w-[720px] sm:max-w-[92vw] sm:px-8"
      >
        {/* The header stays at the top while the body scrolls under it. Negative
            margins cancel the panel padding so its translucent, blurred backdrop
            spans the full panel width. */}
        <div className="sticky top-0 z-10 -mx-5 mb-3 flex items-center justify-between gap-2 bg-card/85 px-5 pt-5 pb-3 backdrop-blur-md sm:-mx-8 sm:px-8">
          <span className="text-xs text-muted-foreground">{issue?.identifier ?? ''}</span>
          <div className="flex items-center gap-1">
            {issue && (
              <>
                <IssueActionsBar
                  project={project}
                  issue={issue}
                  variant="header"
                  onDeleted={onClose}
                />
                <div className="mx-1 h-5 w-px bg-border" />
              </>
            )}
            <Button
              variant="ghost"
              size="icon"
              className="size-7 text-muted-foreground hover:text-foreground"
              onClick={() => onExpand(issue?.sequenceNumber ?? null)}
              title={t('openAsPage')}
            >
              <Maximize2 />
            </Button>
            <Button
              variant="ghost"
              size="icon"
              className="size-7"
              onClick={onClose}
              title={tCommon('close')}
            >
              <X />
            </Button>
          </div>
        </div>

        <IssueDetailContent
          project={project}
          issueId={issueId}
          onIssueLoaded={setIssue}
          onDeleted={onClose}
        />
      </div>
    </div>
  );
}