Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

3.0 KB
Raw Blame
import { FolderPlusIcon, GlobeIcon, LayersIcon, PlusIcon, SearchIcon, XIcon } from "lucide-react";

import { ProjectPermissionCan } from "@app/components/permissions";
import {
  Button,
  Empty,
  EmptyContent,
  EmptyDescription,
  EmptyHeader,
  EmptyMedia,
  EmptyTitle
} from "@app/components/v3";
import { ProjectPermissionActions, ProjectPermissionSub } from "@app/context";

type Props = {
  isFiltered?: boolean;
  variant?: "secrets" | "no-environments";
  onAddEnvironment?: () => void;
  hasSearch?: boolean;
  onSearchAllFolders?: () => void;
  onClearSearch?: () => void;
  isTableRow?: boolean;
};

export function EmptyResourceDisplay({
  isFiltered,
  variant = "secrets",
  onAddEnvironment,
  hasSearch,
  onSearchAllFolders,
  onClearSearch,
  isTableRow
}: Props) {
  if (variant === "no-environments") {
    return (
      <Empty className="border">
        <EmptyHeader>
          <EmptyMedia variant="icon">
            <LayersIcon />
          </EmptyMedia>
          <EmptyTitle>No environments yet</EmptyTitle>
          <EmptyDescription>
            Environments isolate secrets by stage. Add one to start managing secrets for this
            project.
          </EmptyDescription>
        </EmptyHeader>
        <EmptyContent>
          <ProjectPermissionCan
            I={ProjectPermissionActions.Create}
            a={ProjectPermissionSub.Environments}
          >
            {(isAllowed) => (
              <Button size="xs" isDisabled={!isAllowed} onClick={onAddEnvironment}>
                <PlusIcon />
                Add Environment
              </Button>
            )}
          </ProjectPermissionCan>
        </EmptyContent>
      </Empty>
    );
  }

  let title = "This project doesn't have any secrets";
  let description = "Add some secrets to get started";

  if (isFiltered && hasSearch) {
    title = "No matches in this folder";
    description = "Try another search, or look across every folder in this project.";
  } else if (isFiltered) {
    title = "No resources match these filters";
    description = "Adjust or clear your filters and try again.";
  }

  return (
    <Empty
      variant={isTableRow ? "unstyled" : "default"}
      className={isTableRow ? "h-full" : "border"}
    >
      <EmptyHeader>
        <EmptyMedia variant="icon">{isFiltered ? <SearchIcon /> : <FolderPlusIcon />}</EmptyMedia>
        <EmptyTitle>{title}</EmptyTitle>
        <EmptyDescription>{description}</EmptyDescription>
      </EmptyHeader>
      {hasSearch && (onSearchAllFolders || onClearSearch) && (
        <EmptyContent>
          <div className="flex gap-2">
            {onClearSearch && (
              <Button variant="outline" size="xs" onClick={onClearSearch}>
                <XIcon />
                Clear Search
              </Button>
            )}
            {onSearchAllFolders && (
              <Button variant="outline" size="xs" onClick={onSearchAllFolders}>
                <GlobeIcon />
                Search All Folders
              </Button>
            )}
          </div>
        </EmptyContent>
      )}
    </Empty>
  );
}