All files / pages/collections/tabs RulesTabPage.tsx

55.55% Statements 5/9
50% Branches 6/12
33.33% Functions 1/3
55.55% Lines 5/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48                      5x   5x   5x               5x                     5x                          
/**
 * Rules tab — first-class access rules editor (Phase 3).
 */
 
import { RefreshCw } from 'lucide-react';
import { Button } from '@/components/ui/button';
import CollectionRulesTab from '@/components/collections/CollectionRulesTab';
import { useCollectionDetail } from '../CollectionDetailContext';
import { useCollectionsWorkspace } from '../CollectionsWorkspaceContext';
 
export default function RulesTabPage() {
  const { collection, listItem, loading, error, refreshDetail } =
    useCollectionDetail();
  const { isSuperadmin, refreshCollections } = useCollectionsWorkspace();
 
  Iif (loading && !collection) {
    return (
      <div className="flex items-center justify-center py-16">
        <RefreshCw className="h-6 w-6 animate-spin text-muted-foreground" />
      </div>
    );
  }
 
  Iif (error || !collection) {
    return (
      <div className="space-y-2 py-8 text-center">
        <p className="text-destructive">{error ?? 'Collection not found'}</p>
        <Button size="sm" variant="outline" onClick={() => void refreshDetail()}>
          Retry
        </Button>
      </div>
    );
  }
 
  return (
    <div data-testid="rules-tab">
      <CollectionRulesTab
        collection={collection}
        readOnly={!isSuperadmin}
        hasPublicAccess={listItem?.has_public_access ?? false}
        onRulesSaved={() => {
          void refreshCollections();
        }}
      />
    </div>
  );
}