Skip to content

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

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

import { ExternalLink } from "metabase/common/components/ExternalLink";
import { Group, Icon, Stack, Text } from "metabase/ui";
import type { CustomVizPlugin } from "metabase-types/api";

import { CustomVizIcon } from "./CustomVizIcon";
import {
  SDK_CHANGELOG_URL,
  getCustomVizPluginWarningMessage,
} from "./warning-messages";

type Props = {
  plugin: CustomVizPlugin;
};

export function CustomVizPluginSummary({ plugin }: Props) {
  return (
    <Group align="flex-start" flex="1" wrap="nowrap">
      <CustomVizIcon plugin={plugin} />

      <Stack flex="1" gap="sm" py="xxs">
        <Stack flex="1" gap="xxs">
          <Text fw={700}>{plugin.display_name}</Text>

          {(plugin.bundle_hash || plugin.metabase_version) && (
            <Group gap="xxs">
              {plugin.bundle_hash && (
                <Text size="sm" c="text-secondary">
                  {t`Bundle: ${plugin.bundle_hash.slice(0, 8)}`}
                </Text>
              )}
              {plugin.bundle_hash && plugin.metabase_version && (
                <Text size="sm" c="text-secondary">
                  &bull;
                </Text>
              )}
              {plugin.metabase_version && (
                <Text size="sm" c="text-secondary">
                  {/* eslint-disable-next-line metabase/no-literal-metabase-strings -- admin-only custom-viz settings page */}
                  {t`Requires Metabase ${plugin.metabase_version}`}
                </Text>
              )}
            </Group>
          )}
        </Stack>

        {plugin.error_message && (
          <Text size="sm" c="feedback-negative">
            {plugin.error_message}
          </Text>
        )}

        {plugin.warnings.map((warning) => (
          <Group align="center" gap="xxs" key={warning.type} wrap="nowrap">
            <Icon c="feedback-warning" flex="0 0 auto" name="warning" />

            <Text c="text-secondary" size="sm">
              {getCustomVizPluginWarningMessage(warning)}

              {warning.type === "sdk-version-mismatch" && (
                <>
                  {" "}
                  <ExternalLink href={SDK_CHANGELOG_URL}>
                    {t`See the SDK changelog`}
                  </ExternalLink>
                  .
                </>
              )}
            </Text>
          </Group>
        ))}
      </Stack>
    </Group>
  );
}