Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

2.5 KB
Raw Blame
import { t } from "ttag";

import EmptyDashboardBot from "assets/img/dashboard-empty.svg";
import { EmptyState } from "metabase/common/components/EmptyState";
import { MonitorMain } from "metabase/monitor/components/MonitorLayout";
import { Outlet } from "metabase/router";
import { useSetting } from "metabase/settings";
import { Flex } from "metabase/ui";
import * as Urls from "metabase/urls";

type UnavailablePageProps = {
  title: string;
  message: string;
  action: string;
  link: string;
};

function UnavailablePage({
  title,
  message,
  action,
  link,
}: UnavailablePageProps) {
  return (
    <MonitorMain align="center" h="100%">
      <Flex flex={1} align="center" justify="center">
        <EmptyState
          illustrationElement={
            <img src={EmptyDashboardBot} alt="" width={100} height={100} />
          }
          title={title}
          message={message}
          action={action}
          link={link}
          actionVariant="default"
        />
      </Flex>
    </MonitorMain>
  );
}

export function MetabotAnalyticsAvailabilityLayout() {
  const aiFeaturesEnabled = !!useSetting("ai-features-enabled?");
  const isConfigured = !!useSetting("llm-metabot-configured?");

  if (!aiFeaturesEnabled) {
    return (
      <UnavailablePage
        title={t`AI features are disabled`}
        message={t`Enable AI features in Admin settings to view AI usage and conversations.`}
        action={t`Go to AI Settings`}
        link={Urls.adminAiSettings()}
      />
    );
  }

  if (!isConfigured) {
    return (
      <UnavailablePage
        title={t`Set up AI to view analytics`}
        message={t`Configure an AI provider in Admin settings to view AI usage and conversations.`}
        action={t`Go to AI Settings`}
        link={Urls.adminAiSettings()}
      />
    );
  }

  return <Outlet />;
}

export function McpAnalyticsAvailabilityLayout() {
  const aiFeaturesEnabled = !!useSetting("ai-features-enabled?");
  const mcpEnabled = !!useSetting("mcp-enabled?");

  if (!aiFeaturesEnabled) {
    return (
      <UnavailablePage
        title={t`AI features are disabled`}
        message={t`Enable AI features in Admin settings to view MCP analytics.`}
        action={t`Go to AI Settings`}
        link={Urls.adminAiSettings()}
      />
    );
  }

  if (!mcpEnabled) {
    return (
      <UnavailablePage
        title={t`MCP is disabled`}
        message={t`Enable MCP in Admin settings to view MCP analytics.`}
        action={t`Go to MCP settings`}
        link={Urls.adminMcpSettings()}
      />
    );
  }

  return <Outlet />;
}