Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

1.3 KB
Raw Blame
import { ActionButton } from "@/src/components/ActionButton";
import { useHasProjectAccess } from "@/src/features/rbac/utils/checkProjectAccess";
import { Zap } from "@langfuse/icons";
import { api } from "@/src/utils/api";
import { Spinner } from "@/src/components/design-system/Spinner/Spinner";

type AutomationButtonProps = {
  projectId: string;
};

export const AutomationButton = ({ projectId }: AutomationButtonProps) => {
  const hasAccess = useHasProjectAccess({
    projectId,
    scope: "automations:read",
  });

  const numberOfAutomations = api.automations.count.useQuery({
    projectId,
  });

  const numberIndicator = numberOfAutomations.isLoading ? (
    <span className="ml-1.5 inline-flex w-6 items-center justify-center rounded-sm bg-transparent px-1 text-xs">
      <Spinner size="xxs" />
    </span>
  ) : (
    <span className="bg-input ml-1.5 inline-flex w-6 items-center justify-center rounded-sm px-1 text-xs shadow-xs @6xl:inline">
      {numberOfAutomations.data}
    </span>
  );

  return (
    <ActionButton
      href={`/project/${projectId}/automations`}
      icon={<Zap size="base" aria-hidden="true" />}
      hasAccess={hasAccess}
      title="Automations"
      variant="outline"
    >
      <span className="hidden md:ml-1 md:inline">
        Automations
        {numberIndicator}
      </span>
    </ActionButton>
  );
};