Skip to content

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

feat: ui to display data complexity color coding (#74363)

Maksym Yakubych6bc738d93e63
diff --git a/.loki/reference/chrome_laptop_Design_System_Colors_Default.png b/.loki/reference/chrome_laptop_Design_System_Colors_Default.png
index 21a104f276f..092a5aab387 100644
Binary files a/.loki/reference/chrome_laptop_Design_System_Colors_Default.png and b/.loki/reference/chrome_laptop_Design_System_Colors_Default.png differ
diff --git a/enterprise/frontend/src/metabase-enterprise/audit_app/metabot-analytics/components/ConversationStatsPage/DataComplexityCards.module.css b/enterprise/frontend/src/metabase-enterprise/audit_app/metabot-analytics/components/ConversationStatsPage/DataComplexityCards.module.css
new file mode 100644
index 00000000000..5d3239a03ef
--- /dev/null
+++ b/enterprise/frontend/src/metabase-enterprise/audit_app/metabot-analytics/components/ConversationStatsPage/DataComplexityCards.module.css
@@ -0,0 +1,36 @@
+.accordionRoot {
+ display: flex;
+ flex-direction: column;
+ gap: 0.25rem;
+ width: 100%;
+}
+
+.accordionItem {
+ border: 0;
+ border-radius: 0.5rem;
+ overflow: hidden;
+}
+
+.accordionControl {
+ background-color: var(--mb-color-background-secondary);
+ border-radius: 0.5rem;
+ padding: 0.625rem 1rem;
+}
+
+.accordionContent {
+ background-color: var(--mb-color-background-secondary);
+ border-top: 1px solid var(--mb-color-border-subtle);
+ padding: 0.5rem 1rem 0.75rem;
+}
+
+.accordionChevron {
+ border: 0;
+ color: var(--mb-color-text-primary);
+ height: 0.75rem;
+ margin-left: 1rem;
+ width: 0.75rem;
+}
+
+.accordionLabel {
+ padding: 0;
+}
diff --git a/enterprise/frontend/src/metabase-enterprise/audit_app/metabot-analytics/components/ConversationStatsPage/DataComplexityCards.tsx b/enterprise/frontend/src/metabase-enterprise/audit_app/metabot-analytics/components/ConversationStatsPage/DataComplexityCards.tsx
index 9306b608f9d..dd672bd8115 100644
--- a/enterprise/frontend/src/metabase-enterprise/audit_app/metabot-analytics/components/ConversationStatsPage/DataComplexityCards.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/audit_app/metabot-analytics/components/ConversationStatsPage/DataComplexityCards.tsx
@@ -4,67 +4,65 @@ import { msgid, ngettext, t } from "ttag";
import { getErrorMessage } from "metabase/api/utils";
import {
+ Accordion,
Alert,
Box,
- Button,
Card,
Flex,
- Group,
Icon,
+ type MantineStyleProps,
Modal,
SimpleGrid,
Skeleton,
Stack,
Text,
+ Tooltip,
UnstyledButton,
} from "metabase/ui";
+import type { MetabaseColorKey } from "metabase/ui/colors/types";
import { formatNumber } from "metabase/utils/formatting";
+import { getObjectEntries } from "metabase/utils/objects";
import { hasPremiumFeature } from "metabase-enterprise/settings";
import { useGetDataComplexityScoresQuery } from "../../api";
-import type {
- DataComplexityCatalog,
- DataComplexityCatalogId,
- DataComplexityComponentId,
- DataComplexityGroup,
- DataComplexityGroupId,
- DataComplexitySubScore,
+import {
+ DATA_COMPLEXITY_CATALOG_IDS,
+ DATA_COMPLEXITY_GROUP_IDS,
+ type DataComplexityCatalog,
+ type DataComplexityCatalogId,
+ type DataComplexityComponentId,
+ type DataComplexityFailure,
+ type DataComplexityGroupId,
+ type DataComplexityRating,
+ type DataComplexitySubScore,
+ type ScoreAndRating,
+ type ScoreAndRatingError,
} from "../../types";
-// Each group only carries its own component IDs (size: entity_count/field_count;
-// ambiguity: name_collisions/synonym_pairs/repeated_measures). The data-driven
-// iteration over COMPONENT_GROUPS uses the wide union, so cast to a permissive
-// view for the lookup — missing keys yield undefined.
-function getSubScore(
- group: DataComplexityGroup,
- componentId: DataComplexityComponentId,
-): DataComplexitySubScore | undefined {
- return (
- group.components as Partial<
- Record<DataComplexityComponentId, DataComplexitySubScore>
- >
- )[componentId];
-}
+import S from "./DataComplexityCards.module.css";
+
+type RatingColorKey = DataComplexityRating | "default";
-const CATALOG_IDS: DataComplexityCatalogId[] = [
- "library",
- "universe",
- "metabot",
-];
+const RATING_BADGE_BACKGROUND_COLORS = {
+ low: "background-success-secondary",
+ medium: "background-warning-secondary",
+ high: "background-error",
+ default: "background-tertiary",
+} satisfies Record<RatingColorKey, MetabaseColorKey>;
-const COMPONENT_GROUPS: {
- groupId: DataComplexityGroupId;
- componentIds: DataComplexityComponentId[];
-}[] = [
- {
- groupId: "size",
- componentIds: ["entity_count", "field_count"],
- },
- {
- groupId: "ambiguity",
- componentIds: ["name_collisions", "synonym_pairs", "repeated_measures"],
- },
-];
+const RATING_BADGE_TEXT_COLORS = {
+ low: "success-secondary",
+ medium: "text-primary",
+ high: "error",
+ default: "text-secondary",
+} satisfies Record<RatingColorKey, MetabaseColorKey>;
+
+const RATING_TEXT_COLORS = {
+ low: "success",
+ medium: "warning",
+ high: "error",
+ default: "text-secondary",
+} satisfies Record<RatingColorKey, MetabaseColorKey>;
function DataComplexityCardSkeleton() {
return (
@@ -90,10 +88,10 @@ function DataComplexityCard({
catalog: DataComplexityCatalog;
}) {
const [isModalOpen, { close, open }] = useDisclosure();
- const { title, subtitle } = match(catalogId)
+ const { subtitle, title } = match(catalogId)
.with("library", () => ({
title: t`Curated semantic layer`,
- subtitle: t`Models and metrics from the curated Library subset.`,
+ subtitle: t`Metrics and published tables within your Library.`,
}))
.with("universe", () => ({
title: t`Full semantic layer`,
@@ -110,36 +108,43 @@ function DataComplexityCard({
<UnstyledButton onClick={open}>
<Flex align="center" justify="space-between" gap="sm">
<Text fw={700}>{title}</Text>
- <Icon name="chevronright" size={12} c="text-tertiary" />
+ <Icon name="expand" c="text-tertiary" />
</Flex>
<Text c="text-secondary">{subtitle}</Text>
- {match(catalog.score)
- .with(P.number, (score) => (
- <Stack align="center" gap="sm" my="sm">
- <Text size="4rem" fw={700}>
- {formatNumber(score, { maximumFractionDigits: 0 })}
- </Text>
- <Text c="text-secondary">{t`Lower is better`}</Text>
- </Stack>
- ))
- .otherwise(() => (
- <Stack gap={4} my="sm">
- <Text c="error" fw={700}>{t`Score unavailable`}</Text>
- <Text c="text-secondary">{t`Open for component details.`}</Text>
- </Stack>
- ))}
+ {catalog.score !== null ? (
+ <Stack align="center" gap="sm" my="sm">
+ <Text
+ size="4rem"
+ fw={700}
+ c={RATING_TEXT_COLORS[catalog.rating ?? "default"]}
+ >
+ {formatNumber(catalog.score, { maximumFractionDigits: 0 })}
+ </Text>
+ <Text c="text-secondary">{catalog.rating_label}</Text>
+ </Stack>
+ ) : (
+ <Stack gap={4} my="sm">
+ <Text c="error" fw={700}>{t`Score unavailable`}</Text>
+ <Text c="text-secondary">{t`Open for component details.`}</Text>
+ </Stack>
+ )}
</UnstyledButton>
- <Modal opened={isModalOpen} onClose={close} title={title} size="lg">
- <Stack gap="lg">
- <Text size="sm" c="text-secondary">
- {subtitle}
- </Text>
- <DataComplexityBreakdown catalog={catalog} />
- <Group justify="flex-end">
- <Button variant="default" onClick={close}>{t`Close`}</Button>
- </Group>
- </Stack>
+ <Modal
+ opened={isModalOpen}
+ onClose={close}
+ title={
+ <Stack gap={4} align="flex-start">
+ <Text fw={700} size="xl" lh="1.5rem">
+ {title}
+ </Text>
+ <Text size="sm" lh="1rem" c="text-secondary">
+ {subtitle}
+ </Text>
+ </Stack>
+ }
+ >
+ <DataComplexityBreakdown catalog={catalog} />
</Modal>
</Card>
);
@@ -153,55 +158,64 @@ function DataComplexityBreakdown({
const hasError = catalog.score == null;
return (
- <Stack gap="lg">
+ <Stack gap="lg" mt="md">
{hasError && (
<Alert color="warning" icon={<Icon name="warning" />}>
{t`Some component scores could not be computed.`}
</Alert>
)}
- {COMPONENT_GROUPS.map(({ groupId, componentIds }) => {
- const { title, description } = match(groupId)
- .with("size", () => ({
- title: t`Size`,
- description: t`How much surface area this layer exposes.`,
- }))
- .with("ambiguity", () => ({
- title: t`Ambiguity`,
- description: t`Signals that similar or repeated names could make answers harder to trust.`,
- }))
+ {DATA_COMPLEXITY_GROUP_IDS.map((groupId) => {
+ const title = match(groupId)
+ .with("size", () => t`Size of this layer`)
+ .with("ambiguity", () => t`Areas of ambiguity`)
.exhaustive();
const group = catalog.components[groupId];
return (
- <Box key={groupId}>
- <Text fw={700}>{title}</Text>
- <Text size="sm" c="text-secondary">
- {description}
- </Text>
+ <Stack key={groupId} gap="md" w="100%">
+ <Flex align="center" justify="space-between" gap="lg">
+ <Text fw={700} lh="1rem">
+ {title}
+ </Text>
+ <ScoreDisplayInline withTitle score={group} mr="2.75rem" />
+ </Flex>
- <Stack gap="sm" mt="md">
- {componentIds.map((componentId) => {
- const component = getSubScore(group, componentId);
- if (!component) {
- return null;
- }
- return (
+ <Accordion
+ chevron={<Icon name="chevrondown" size={12} />}
+ classNames={{
+ chevron: S.accordionChevron,
+ content: S.accordionContent,
+ control: S.accordionControl,
+ item: S.accordionItem,
+ label: S.accordionLabel,
+ root: S.accordionRoot,
+ }}
+ >
+ {getGroupComponentEntries(catalog, groupId).map(
+ ([componentId, component]) => (
<DataComplexityComponentItem
key={componentId}
componentId={componentId}
component={component}
/>
- );
- })}
- </Stack>
- </Box>
+ ),
+ )}
+ </Accordion>
+ </Stack>
);
})}
</Stack>
);
}
+const getGroupComponentEntries = <G extends DataComplexityGroupId>(
+ catalog: DataComplexityCatalog,
+ groupId: G,
+) => {
+ return getObjectEntries(catalog.components[groupId].components);
+};
+
function DataComplexityComponentItem({
componentId,
component,
@@ -210,112 +224,95 @@ function DataComplexityComponentItem({
component: DataComplexitySubScore;
}) {
const measurement = "measurement" in component ? component.measurement : null;
-
- const { title, description, count } = match(componentId)
+ const { count, description } = match(componentId)
.with("entity_count", () => ({
- title: t`Entity count`,
- description: t`How many tables, models, and metrics are included in this layer.`,
count:
- measurement !== null &&
- ngettext(
- msgid`${measurement} entity`,
- `${measurement} entities`,
- measurement,
- ),
+ measurement === null
+ ? t`Entities`
+ : ngettext(
+ msgid`${measurement} entity`,
+ `${measurement} entities`,
+ measurement,
+ ),
+ description: t`How many tables, models, and metrics are included in this layer.`,
}))
.with("name_collisions", () => ({
- title: t`Name collisions`,
- description: t`Exact duplicate names after normalization, which can make entities harder to distinguish.`,
count:
- measurement !== null &&
- ngettext(
- msgid`${measurement} collision`,
- `${measurement} collisions`,
- measurement,
- ),
+ measurement === null
+ ? t`Duplicate names`
+ : ngettext(
+ msgid`${measurement} duplicate name`,
+ `${measurement} duplicate names`,
+ measurement,
+ ),
+ description: t`Exact duplicate names after normalization, which can make entities harder to distinguish.`,
}))
.with("synonym_pairs", () => ({
- title: t`Synonym pairs`,
- description: t`Pairs of entity names that are semantically similar enough to be treated as possible synonyms.`,
count:
- measurement !== null &&
- ngettext(
- msgid`${measurement} similar pair`,
- `${measurement} similar pairs`,
- measurement,
- ),
+ measurement === null
+ ? t`Semantically similar pairs`
+ : ngettext(
+ msgid`${measurement} semantically similar pair`,
+ `${measurement} semantically similar pairs`,
+ measurement,
+ ),
+ description: t`Pairs of entity names that are semantically similar enough to be treated as possible synonyms.`,
}))
.with("field_count", () => ({
- title: t`Field count`,
- description: t`Active physical-table fields exposed through this layer.`,
count:
- measurement !== null &&
- ngettext(
- msgid`${measurement} field`,
- `${measurement} fields`,
- measurement,
- ),
+ measurement === null
+ ? t`Fields`
+ : ngettext(
+ msgid`${measurement} field`,
+ `${measurement} fields`,
+ measurement,
+ ),
+ description: t`Active physical-table fields exposed through this layer.`,
}))
.with("repeated_measures", () => ({
- title: t`Repeated measures`,
- description: t`Duplicate measure names across included tables.`,
count:
- measurement !== null &&
- ngettext(
- msgid`${measurement} repeated name`,
- `${measurement} repeated names`,
- measurement,
- ),
+ measurement === null
+ ? t`Duplicate measure names`
+ : ngettext(
+ msgid`${measurement} duplicate measure name`,
+ `${measurement} duplicate measure names`,
+ measurement,
+ ),
+ description: t`Duplicate measure names across included tables.`,
}))
.exhaustive();
return (
- <Box
- p="md"
- bdrs="md"
- bg="background-secondary"
- style={{
- border: "1px solid var(--mb-color-border)",
- }}
- >
- <Flex gap="md" justify="space-between" align="flex-start">
- <Group gap="sm" align="flex-start" wrap="nowrap" flex={1}>
- <Box>
- <Text fw={700}>{title}</Text>
- <Text size="sm" c="text-secondary">
- {description}
+ <Accordion.Item value={componentId} bg="background-secondary" bd="0" mt={0}>
+ <Accordion.Control>
+ <Flex align="center" gap="sm" w="100%">
+ <Text c="text-primary" fw={500} truncate>
+ {count}
+ </Text>
+ <Tooltip label={description}>
+ <Icon name="info" c="text-tertiary" size={14} />
+ </Tooltip>
+ <ScoreDisplayInline score={component} />
+ </Flex>
+ </Accordion.Control>
+ <Accordion.Panel>
+ <Text size="sm" c="text-secondary">
+ {description}
+ </Text>
+ {match(component)
+ .with({ error: P.nonNullable }, ({ error }) => (
+ <Text c="error" size="sm" role="alert">
+ {error}
</Text>
- {"error" in component && (
- <Text mt="sm" size="sm" c="error" role="alert">
- {component.error}
- </Text>
- )}
- </Box>
- </Group>
-
- {count !== false && (
- <Box
- px="sm"
- py={4}
- bdrs="sm"
- bg="background-primary"
- style={{
- border: "1px solid var(--mb-color-border)",
- flexShrink: 0,
- }}
- >
- <Text
- size="sm"
- fw={700}
- c="text-secondary"
- style={{ whiteSpace: "nowrap" }}
- >
- {count}
+ ))
+ .with({ rating_label: P.nonNullable }, ({ rating_label }) => (
+ <Text size="sm" c="text-secondary">
+ {rating_label}
</Text>
- </Box>
- )}
- </Flex>
- </Box>
+ ))
+ .otherwise(() => null)}
+ </Accordion.Panel>
+ </Accordion.Item>
);
}
@@ -337,7 +334,7 @@ export function DataComplexityCards() {
<SimpleGrid cols={{ base: 1, md: 3 }} spacing="lg">
{match({ isLoading, queryError, data })
.with({ isLoading: true }, () =>
- CATALOG_IDS.map((catalogId) => (
+ DATA_COMPLEXITY_CATALOG_IDS.map((catalogId) => (
<DataComplexityCardSkeleton key={catalogId} />
)),
)
@@ -362,7 +359,7 @@ export function DataComplexityCards() {
),
)
.with({ data: P.nonNullable }, ({ data }) =>
- CATALOG_IDS.map((key) => (
+ DATA_COMPLEXITY_CATALOG_IDS.map((key) => (
<DataComplexityCard key={key} catalogId={key} catalog={data[key]} />
)),
)
@@ -370,3 +367,45 @@ export function DataComplexityCards() {
</SimpleGrid>
);
}
+
+function ScoreDisplayInline({
+ withTitle,
+ score,
+ ...rest
+}: {
+ withTitle?: boolean;
+ score: ScoreAndRating | ScoreAndRatingError | DataComplexityFailure;
+} & MantineStyleProps) {
+ return match(score)
+ .with({ score: P.nullish }, { error: P.nonNullable }, () => (
+ <Text c="error" fw={700} lh="1rem" ml="auto" {...rest}>
+ {withTitle ? t`Complexity score unavailable` : t`Unavailable`}
+ </Text>
+ ))
+ .with({ score: P.nonNullable }, ({ score, rating }) => {
+ const ratingColorKey = rating ?? "default";
+
+ return (
+ <Flex
+ ml="auto"
+ px={8}
+ py={4}
+ bdrs="sm"
+ bg={RATING_BADGE_BACKGROUND_COLORS[ratingColorKey]}
+ {...rest}
+ gap="sm"
+ >
+ {withTitle && (
+ <Text
+ lh="1rem"
+ c={RATING_BADGE_TEXT_COLORS[ratingColorKey]}
+ >{t`Complexity score`}</Text>
+ )}
+ <Text fw={700} lh="1rem" c={RATING_BADGE_TEXT_COLORS[ratingColorKey]}>
+ {formatNumber(score, { maximumFractionDigits: 0 })}
+ </Text>
+ </Flex>
+ );
+ })
+ .exhaustive();
+}
diff --git a/enterprise/frontend/src/metabase-enterprise/audit_app/metabot-analytics/components/ConversationStatsPage/DataComplexityCards.unit.spec.tsx b/enterprise/frontend/src/metabase-enterprise/audit_app/metabot-analytics/components/ConversationStatsPage/DataComplexityCards.unit.spec.tsx
index f982f78cd77..284289b8128 100644
--- a/enterprise/frontend/src/metabase-enterprise/audit_app/metabot-analytics/components/ConversationStatsPage/DataComplexityCards.unit.spec.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/audit_app/metabot-analytics/components/ConversationStatsPage/DataComplexityCards.unit.spec.tsx
@@ -6,10 +6,19 @@ import { renderWithProviders, screen, within } from "__support__/ui";
import type { TokenFeatures } from "metabase-types/api";
import { createMockTokenFeatures } from "metabase-types/api/mocks";
-import type { DataComplexityScoresResponse } from "../../types";
+import type {
+ DataComplexityRating,
+ DataComplexityScoresResponse,
+} from "../../types";
import { DataComplexityCards } from "./DataComplexityCards";
+const mockScore = (
+ score: number,
+ rating: DataComplexityRating = "low",
+ rating_label = "Low complexity",
+) => ({ rating, rating_label, score });
+
/* eslint-disable testing-library/no-node-access -- Snapshot cleanup is applied to a cloned DOM tree. */
const cleanForSnapshot = (element: Element) => {
const clone = element.cloneNode(true) as Element;
@@ -18,6 +27,7 @@ const cleanForSnapshot = (element: Element) => {
node.removeAttribute("class");
node.removeAttribute("style");
node.removeAttribute("id");
+ node.removeAttribute("aria-controls");
node.removeAttribute("aria-describedby");
node.removeAttribute("aria-labelledby");
});
@@ -26,63 +36,70 @@ const cleanForSnapshot = (element: Element) => {
};
/* eslint-enable testing-library/no-node-access */
+const mockComponentScore = (
+ measurement: number,
+ score: number,
+ rating: DataComplexityRating = "low",
+ rating_label = "Low complexity",
+) => ({ measurement, rating, rating_label, score });
+
const mockScores: DataComplexityScoresResponse = {
library: {
- score: 18,
+ ...mockScore(18),
components: {
size: {
- score: 18,
+ ...mockScore(18),
components: {
- entity_count: { measurement: 1, score: 10 },
- field_count: { measurement: 8, score: 8 },
+ entity_count: mockComponentScore(1, 10),
+ field_count: mockComponentScore(8, 8),
},
},
ambiguity: {
- score: 0,
+ ...mockScore(0),
components: {
- name_collisions: { measurement: 0, score: 0 },
- synonym_pairs: { measurement: 0, score: 0 },
- repeated_measures: { measurement: 0, score: 0 },
+ name_collisions: mockComponentScore(0, 0),
+ synonym_pairs: mockComponentScore(0, 0),
+ repeated_measures: mockComponentScore(0, 0),
},
},
},
},
universe: {
- score: 54,
+ ...mockScore(54),
components: {
size: {
- score: 44,
+ ...mockScore(44),
components: {
- entity_count: { measurement: 2, score: 20 },
- field_count: { measurement: 24, score: 24 },
+ entity_count: mockComponentScore(2, 20),
+ field_count: mockComponentScore(24, 24),
},
},
ambiguity: {
- score: 10,
+ ...mockScore(10),
components: {
- name_collisions: { measurement: 0, score: 0 },
- synonym_pairs: { measurement: 0, score: 0 },
- repeated_measures: { measurement: 5, score: 10 },
+ name_collisions: mockComponentScore(0, 0),
+ synonym_pairs: mockComponentScore(0, 0),
+ repeated_measures: mockComponentScore(5, 10),
},
},
},
},
metabot: {
- score: 30,
+ ...mockScore(30),
components: {
size: {
- score: 30,
+ ...mockScore(30),
components: {
- entity_count: { measurement: 1, score: 10 },
- field_count: { measurement: 20, score: 20 },
+ entity_count: mockComponentScore(1, 10),
+ field_count: mockComponentScore(20, 20),
},
},
ambiguity: {
- score: 0,
+ ...mockScore(0),
components: {
- name_collisions: { measurement: 0, score: 0 },
- synonym_pairs: { measurement: 0, score: 0 },
- repeated_measures: { measurement: 0, score: 0 },
+ name_collisions: mockComponentScore(0, 0),
+ synonym_pairs: mockComponentScore(0, 0),
+ repeated_measures: mockComponentScore(0, 0),
},
},
},
@@ -98,10 +115,14 @@ const mockScoresWithError: DataComplexityScoresResponse = {
...mockScores,
metabot: {
score: null,
+ rating: null,
+ rating_label: null,
components: {
...mockScores.metabot.components,
ambiguity: {
score: null,
+ rating: null,
+ rating_label: null,
components: {
...mockScores.metabot.components.ambiguity.components,
synonym_pairs: {
diff --git a/enterprise/frontend/src/metabase-enterprise/audit_app/metabot-analytics/components/ConversationStatsPage/DataComplexitySection.unit.spec.tsx b/enterprise/frontend/src/metabase-enterprise/audit_app/metabot-analytics/components/ConversationStatsPage/DataComplexitySection.unit.spec.tsx
index 5854bf2c7bf..8f756537257 100644
--- a/enterprise/frontend/src/metabase-enterprise/audit_app/metabot-analytics/components/ConversationStatsPage/DataComplexitySection.unit.spec.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/audit_app/metabot-analytics/components/ConversationStatsPage/DataComplexitySection.unit.spec.tsx
@@ -5,67 +5,83 @@ import { renderWithProviders, screen } from "__support__/ui";
import type { TokenFeatures } from "metabase-types/api";
import { createMockTokenFeatures } from "metabase-types/api/mocks";
-import type { DataComplexityScoresResponse } from "../../types";
+import type {
+ DataComplexityRating,
+ DataComplexityScoresResponse,
+} from "../../types";
import { DataComplexitySection } from "./ConversationStatsPage";
+const mockScore = (
+ score: number,
+ rating: DataComplexityRating = "low",
+ rating_label = "Low complexity",
+) => ({ rating, rating_label, score });
+
+const mockComponentScore = (
+ measurement: number,
+ score: number,
+ rating: DataComplexityRating = "low",
+ rating_label = "Low complexity",
+) => ({ measurement, rating, rating_label, score });
+
const mockScores: DataComplexityScoresResponse = {
library: {
- score: 18,
+ ...mockScore(18),
components: {
size: {
- score: 18,
+ ...mockScore(18),
components: {
- entity_count: { measurement: 1, score: 10 },
- field_count: { measurement: 8, score: 8 },
+ entity_count: mockComponentScore(1, 10),
+ field_count: mockComponentScore(8, 8),
},
},
ambiguity: {
- score: 0,
+ ...mockScore(0),
components: {
- name_collisions: { measurement: 0, score: 0 },
- synonym_pairs: { measurement: 0, score: 0 },
- repeated_measures: { measurement: 0, score: 0 },
+ name_collisions: mockComponentScore(0, 0),
+ synonym_pairs: mockComponentScore(0, 0),
+ repeated_measures: mockComponentScore(0, 0),
},
},
},
},
universe: {
- score: 54,
+ ...mockScore(54),
components: {
size: {
- score: 44,
+ ...mockScore(44),
components: {
- entity_count: { measurement: 2, score: 20 },
- field_count: { measurement: 24, score: 24 },
+ entity_count: mockComponentScore(2, 20),
+ field_count: mockComponentScore(24, 24),
},
},
ambiguity: {
- score: 10,
+ ...mockScore(10),
components: {
- name_collisions: { measurement: 0, score: 0 },
- synonym_pairs: { measurement: 0, score: 0 },
- repeated_measures: { measurement: 5, score: 10 },
+ name_collisions: mockComponentScore(0, 0),
+ synonym_pairs: mockComponentScore(0, 0),
+ repeated_measures: mockComponentScore(5, 10),
},
},
},
},
metabot: {
- score: 30,
+ ...mockScore(30),
components: {
size: {
- score: 30,
+ ...mockScore(30),
components: {
- entity_count: { measurement: 1, score: 10 },
- field_count: { measurement: 20, score: 20 },
+ entity_count: mockComponentScore(1, 10),
+ field_count: mockComponentScore(20, 20),
},
},
ambiguity: {
- score: 0,
+ ...mockScore(0),
components: {
- name_collisions: { measurement: 0, score: 0 },
- synonym_pairs: { measurement: 0, score: 0 },
- repeated_measures: { measurement: 0, score: 0 },
+ name_collisions: mockComponentScore(0, 0),
+ synonym_pairs: mockComponentScore(0, 0),
+ repeated_measures: mockComponentScore(0, 0),
},
},
},
diff --git a/enterprise/frontend/src/metabase-enterprise/audit_app/metabot-analytics/components/ConversationStatsPage/__snapshots__/DataComplexityCards.unit.spec.tsx.snap b/enterprise/frontend/src/metabase-enterprise/audit_app/metabot-analytics/components/ConversationStatsPage/__snapshots__/DataComplexityCards.unit.spec.tsx.snap
index dc73ee92aff..24d6935fc80 100644
--- a/enterprise/frontend/src/metabase-enterprise/audit_app/metabot-analytics/components/ConversationStatsPage/__snapshots__/DataComplexityCards.unit.spec.tsx.snap
+++ b/enterprise/frontend/src/metabase-enterprise/audit_app/metabot-analytics/components/ConversationStatsPage/__snapshots__/DataComplexityCards.unit.spec.tsx.snap
@@ -17,17 +17,17 @@ exports[`DataComplexityCards renders the data complexity cards 1`] = `
Curated semantic layer
</div>
<svg
- aria-label="chevronright icon"
- height="12"
+ aria-label="expand icon"
+ height="16"
role="img"
- width="12"
+ width="16"
/>
</div>
<div
color="text-primary"
data-size="md"
>
- Models and metrics from the curated Library subset.
+ Metrics and published tables within your Library.
</div>
<div>
<div
@@ -39,7 +39,7 @@ exports[`DataComplexityCards renders the data complexity cards 1`] = `
color="text-primary"
data-size="md"
>
- Lower is better
+ Low complexity
</div>
</div>
</button>
@@ -58,10 +58,10 @@ exports[`DataComplexityCards renders the data complexity cards 1`] = `
Full semantic layer
</div>
<svg
- aria-label="chevronright icon"
- height="12"
+ aria-label="expand icon"
+ height="16"
role="img"
- width="12"
+ width="16"
/>
</div>
<div
@@ -80,7 +80,7 @@ exports[`DataComplexityCards renders the data complexity cards 1`] = `
color="text-primary"
data-size="md"
>
- Lower is better
+ Low complexity
</div>
</div>
</button>
@@ -99,10 +99,10 @@ exports[`DataComplexityCards renders the data complexity cards 1`] = `
Metabot-visible layer
</div>
<svg
- aria-label="chevronright icon"
- height="12"
+ aria-label="expand icon"
+ height="16"
role="img"
- width="12"
+ width="16"
/>
</div>
<div
@@ -121,7 +121,7 @@ exports[`DataComplexityCards renders the data complexity cards 1`] = `
color="text-primary"
data-size="md"
>
- Lower is better
+ Low complexity
</div>
</div>
</button>
@@ -139,7 +139,20 @@ exports[`DataComplexityCards renders the data complexity cards 2`] = `
>
<header>
<h2>
- Curated semantic layer
+ <div>
+ <div
+ color="text-primary"
+ data-size="xl"
+ >
+ Curated semantic layer
+ </div>
+ <div
+ color="text-primary"
+ data-size="sm"
+ >
+ Metrics and published tables within your Library.
+ </div>
+ </div>
</h2>
<button
aria-label="Close"
@@ -162,199 +175,384 @@ exports[`DataComplexityCards renders the data complexity cards 2`] = `
</header>
<div>
<div>
- <div
- color="text-primary"
- data-size="sm"
- >
- Models and metrics from the curated Library subset.
- </div>
<div>
<div>
<div
color="text-primary"
data-size="md"
>
- Size
+ Size of this layer
</div>
- <div
- color="text-primary"
- data-size="sm"
- >
- How much surface area this layer exposes.
+ <div>
+ <div
+ color="text-primary"
+ data-size="md"
+ >
+ Complexity score
+ </div>
+ <div
+ color="text-primary"
+ data-size="md"
+ >
+ 18
+ </div>
</div>
+ </div>
+ <div
+ data-accordion="true"
+ data-variant="default"
+ >
<div>
- <div>
- <div>
+ <button
+ aria-expanded="false"
+ data-accordion-control="true"
+ data-chevron-position="right"
+ type="button"
+ >
+ <span
+ data-position="right"
+ >
+ <svg
+ aria-label="chevrondown icon"
+ height="12"
+ role="img"
+ width="12"
+ />
+ </span>
+ <span>
<div>
+ <div
+ color="text-primary"
+ data-size="md"
+ data-truncate="end"
+ >
+ 1 entity
+ </div>
+ <svg
+ aria-label="info icon"
+ height="14"
+ role="img"
+ width="14"
+ />
<div>
<div
color="text-primary"
data-size="md"
>
- Entity count
- </div>
- <div
- color="text-primary"
- data-size="sm"
- >
- How many tables, models, and metrics are included in this layer.
+ 10
</div>
</div>
</div>
+ </span>
+ </button>
+ <div
+ aria-hidden="true"
+ inert=""
+ role="region"
+ >
+ <div>
+ <div
+ color="text-primary"
+ data-size="sm"
+ >
+ How many tables, models, and metrics are included in this layer.
+ </div>
+ <div
+ color="text-primary"
+ data-size="sm"
+ >
+ Low complexity
+ </div>
+ </div>
+ </div>
+ </div>
+ <div>
+ <button
+ aria-expanded="false"
+ data-accordion-control="true"
+ data-chevron-position="right"
+ type="button"
+ >
+ <span
+ data-position="right"
+ >
+ <svg
+ aria-label="chevrondown icon"
+ height="12"
+ role="img"
+ width="12"
+ />
+ </span>
+ <span>
<div>
<div
color="text-primary"
- data-size="sm"
+ data-size="md"
+ data-truncate="end"
>
- 1 entity
+ 8 fields
</div>
- </div>
- </div>
- </div>
- <div>
- <div>
- <div>
+ <svg
+ aria-label="info icon"
+ height="14"
+ role="img"
+ width="14"
+ />
<div>
<div
color="text-primary"
data-size="md"
>
- Field count
- </div>
- <div
- color="text-primary"
- data-size="sm"
- >
- Active physical-table fields exposed through this layer.
+ 8
</div>
</div>
</div>
- <div>
- <div
- color="text-primary"
- data-size="sm"
- >
- 8 fields
- </div>
+ </span>
+ </button>
+ <div
+ aria-hidden="true"
+ inert=""
+ role="region"
+ >
+ <div>
+ <div
+ color="text-primary"
+ data-size="sm"
+ >
+ Active physical-table fields exposed through this layer.
+ </div>
+ <div
+ color="text-primary"
+ data-size="sm"
+ >
+ Low complexity
</div>
</div>
</div>
</div>
</div>
+ </div>
+ <div>
<div>
<div
color="text-primary"
data-size="md"
>
- Ambiguity
+ Areas of ambiguity
</div>
- <div
- color="text-primary"
- data-size="sm"
- >
- Signals that similar or repeated names could make answers harder to trust.
+ <div>
+ <div
+ color="text-primary"
+ data-size="md"
+ >
+ Complexity score
+ </div>
+ <div
+ color="text-primary"
+ data-size="md"
+ >
+ 0
+ </div>
</div>
+ </div>
+ <div
+ data-accordion="true"
+ data-variant="default"
+ >
<div>
- <div>
- <div>
+ <button
+ aria-expanded="false"
+ data-accordion-control="true"
+ data-chevron-position="right"
+ type="button"
+ >
+ <span
+ data-position="right"
+ >
+ <svg
+ aria-label="chevrondown icon"
+ height="12"
+ role="img"
+ width="12"
+ />
+ </span>
+ <span>
<div>
+ <div
+ color="text-primary"
+ data-size="md"
+ data-truncate="end"
+ >
+ 0 duplicate names
+ </div>
+ <svg
+ aria-label="info icon"
+ height="14"
+ role="img"
+ width="14"
+ />
<div>
<div
color="text-primary"
data-size="md"
>
- Name collisions
- </div>
- <div
- color="text-primary"
- data-size="sm"
- >
- Exact duplicate names after normalization, which can make entities harder to distinguish.
+ 0
</div>
</div>
</div>
+ </span>
+ </button>
+ <div
+ aria-hidden="true"
+ inert=""
+ role="region"
+ >
+ <div>
+ <div
+ color="text-primary"
+ data-size="sm"
+ >
+ Exact duplicate names after normalization, which can make entities harder to distinguish.
+ </div>
+ <div
+ color="text-primary"
+ data-size="sm"
+ >
+ Low complexity
+ </div>
+ </div>
+ </div>
+ </div>
+ <div>
+ <button
+ aria-expanded="false"
+ data-accordion-control="true"
+ data-chevron-position="right"
+ type="button"
+ >
+ <span
+ data-position="right"
+ >
+ <svg
+ aria-label="chevrondown icon"
+ height="12"
+ role="img"
+ width="12"
+ />
+ </span>
+ <span>
<div>
<div
color="text-primary"
- data-size="sm"
+ data-size="md"
+ data-truncate="end"
>
- 0 collisions
+ 0 semantically similar pairs
</div>
- </div>
- </div>
- </div>
- <div>
- <div>
- <div>
+ <svg
+ aria-label="info icon"
+ height="14"
+ role="img"
+ width="14"
+ />
<div>
<div
color="text-primary"
data-size="md"
>
- Synonym pairs
- </div>
- <div
- color="text-primary"
- data-size="sm"
- >
- Pairs of entity names that are semantically similar enough to be treated as possible synonyms.
+ 0
</div>
</div>
</div>
+ </span>
+ </button>
+ <div
+ aria-hidden="true"
+ inert=""
+ role="region"
+ >
+ <div>
+ <div
+ color="text-primary"
+ data-size="sm"
+ >
+ Pairs of entity names that are semantically similar enough to be treated as possible synonyms.
+ </div>
+ <div
+ color="text-primary"
+ data-size="sm"
+ >
+ Low complexity
+ </div>
+ </div>
+ </div>
+ </div>
+ <div>
+ <button
+ aria-expanded="false"
+ data-accordion-control="true"
+ data-chevron-position="right"
+ type="button"
+ >
+ <span
+ data-position="right"
+ >
+ <svg
+ aria-label="chevrondown icon"
+ height="12"
+ role="img"
+ width="12"
+ />
+ </span>
+ <span>
<div>
<div
color="text-primary"
- data-size="sm"
+ data-size="md"
+ data-truncate="end"
>
- 0 similar pairs
+ 0 duplicate measure names
</div>
- </div>
- </div>
- </div>
- <div>
- <div>
- <div>
+ <svg
+ aria-label="info icon"
+ height="14"
+ role="img"
+ width="14"
+ />
<div>
<div
color="text-primary"
data-size="md"
>
- Repeated measures
- </div>
- <div
- color="text-primary"
- data-size="sm"
- >
- Duplicate measure names across included tables.
+ 0
</div>
</div>
</div>
- <div>
- <div
- color="text-primary"
- data-size="sm"
- >
- 0 repeated names
- </div>
+ </span>
+ </button>
+ <div
+ aria-hidden="true"
+ inert=""
+ role="region"
+ >
+ <div>
+ <div
+ color="text-primary"
+ data-size="sm"
+ >
+ Duplicate measure names across included tables.
+ </div>
+ <div
+ color="text-primary"
+ data-size="sm"
+ >
+ Low complexity
</div>
</div>
</div>
</div>
</div>
</div>
- <div>
- <button
- data-size="md"
- data-variant="default"
- type="button"
- >
- <span>
- <span>
- Close
- </span>
- </span>
- </button>
- </div>
</div>
</div>
</section>
diff --git a/enterprise/frontend/src/metabase-enterprise/audit_app/metabot-analytics/types.ts b/enterprise/frontend/src/metabase-enterprise/audit_app/metabot-analytics/types.ts
index 959a617cd92..e48c04326a5 100644
--- a/enterprise/frontend/src/metabase-enterprise/audit_app/metabot-analytics/types.ts
+++ b/enterprise/frontend/src/metabase-enterprise/audit_app/metabot-analytics/types.ts
@@ -105,8 +105,18 @@ export type ConversationDetail = {
feedback: ConversationFeedback[];
};
-export type DataComplexityCatalogId = "library" | "universe" | "metabot";
-export type DataComplexityGroupId = "size" | "ambiguity";
+export const DATA_COMPLEXITY_CATALOG_IDS = [
+ "library",
+ "universe",
+ "metabot",
+] as const;
+
+export const DATA_COMPLEXITY_GROUP_IDS = ["size", "ambiguity"] as const;
+
+export type DataComplexityRating = "low" | "medium" | "high";
+export type DataComplexityCatalogId =
+ (typeof DATA_COMPLEXITY_CATALOG_IDS)[number];
+export type DataComplexityGroupId = (typeof DATA_COMPLEXITY_GROUP_IDS)[number];
export type DataComplexitySizeComponentId = "entity_count" | "field_count";
export type DataComplexityAmbiguityComponentId =
@@ -116,33 +126,36 @@ export type DataComplexityAmbiguityComponentId =
export type DataComplexityComponentId =
| DataComplexitySizeComponentId
| DataComplexityAmbiguityComponentId;
+type DataComplexityGroupComponents = {
+ size: DataComplexitySizeComponentId;
+ ambiguity: DataComplexityAmbiguityComponentId;
+};
-export type DataComplexitySubScore =
- | { error: string }
- | { measurement: number; score: number };
-
-export type DataComplexitySizeGroup = {
- score: number | null;
- components: Record<DataComplexitySizeComponentId, DataComplexitySubScore>;
+export type DataComplexityFailure = { error: string };
+export type ScoreAndRating = {
+ score: number;
+ rating: DataComplexityRating | null;
+ rating_label: string | null;
};
-export type DataComplexityAmbiguityGroup = {
- score: number | null;
- components: Record<
- DataComplexityAmbiguityComponentId,
- DataComplexitySubScore
- >;
+export type ScoreAndRatingError = {
+ [K in keyof ScoreAndRating]: null;
};
-export type DataComplexityGroup =
- | DataComplexitySizeGroup
- | DataComplexityAmbiguityGroup;
+export type DataComplexityLeaf = {
+ measurement: number;
+} & ScoreAndRating;
+
+export type DataComplexitySubScore = DataComplexityFailure | DataComplexityLeaf;
-export type DataComplexityCatalog = {
- score: number | null;
+export type DataComplexityCatalog = (ScoreAndRating | ScoreAndRatingError) & {
components: {
- size: DataComplexitySizeGroup;
- ambiguity: DataComplexityAmbiguityGroup;
+ [G in DataComplexityGroupId]: (ScoreAndRating | ScoreAndRatingError) & {
+ components: Record<
+ DataComplexityGroupComponents[G],
+ DataComplexitySubScore
+ >;
+ };
};
};
diff --git a/frontend/src/metabase/ui/colors/constants/themes/dark.ts b/frontend/src/metabase/ui/colors/constants/themes/dark.ts
index 5ed585866f3..1390d231bf6 100644
--- a/frontend/src/metabase/ui/colors/constants/themes/dark.ts
+++ b/frontend/src/metabase/ui/colors/constants/themes/dark.ts
@@ -35,6 +35,7 @@ export const METABASE_DARK_THEME: MetabaseThemeV2 = {
overlay: baseColors.orionAlpha[70],
"background-error": baseColors.lobster[90],
"background-success": baseColors.palm[90],
+ "background-success-secondary": baseColors.palm[70],
brand: baseColors.blue[40],
"brand-hover": baseColors.brand[30],
danger: baseColors.lobster[50],
diff --git a/frontend/src/metabase/ui/colors/constants/themes/light.ts b/frontend/src/metabase/ui/colors/constants/themes/light.ts
index cad17198f2b..01a6bf89260 100644
--- a/frontend/src/metabase/ui/colors/constants/themes/light.ts
+++ b/frontend/src/metabase/ui/colors/constants/themes/light.ts
@@ -35,6 +35,7 @@ export const METABASE_LIGHT_THEME: MetabaseThemeV2 = {
overlay: baseColors.orionAlpha[60],
"background-error": baseColors.lobster[10],
"background-success": baseColors.palm[5],
+ "background-success-secondary": baseColors.palm[20],
brand: baseColors.blue[40],
"brand-hover": baseColors.brand[50],
danger: baseColors.lobster[50],
diff --git a/frontend/src/metabase/ui/colors/types/color-keys.ts b/frontend/src/metabase/ui/colors/types/color-keys.ts
index 870df6ec720..9ecc784fb9b 100644
--- a/frontend/src/metabase/ui/colors/types/color-keys.ts
+++ b/frontend/src/metabase/ui/colors/types/color-keys.ts
@@ -29,6 +29,7 @@ export type MetabaseColorKey =
| "background-secondary-inverse"
| "background-selected"
| "background-success"
+ | "background-success-secondary"
| "background-tertiary"
| "background-tertiary-inverse"
| "background-warning"