Skip to content

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

Fix: #50011 Hides "Here are some explorations of" when there are no explorations (#63839)

Brad Anderson23cb8b11c0e3
diff --git a/frontend/src/metabase/home/components/HomeContent/HomeContent.unit.spec.tsx b/frontend/src/metabase/home/components/HomeContent/HomeContent.unit.spec.tsx
index cfbd4f20d05..d7040f169a7 100644
--- a/frontend/src/metabase/home/components/HomeContent/HomeContent.unit.spec.tsx
+++ b/frontend/src/metabase/home/components/HomeContent/HomeContent.unit.spec.tsx
@@ -11,6 +11,7 @@ import {
} from "__support__/ui";
import type {
Database,
+ DatabaseXray,
PopularItem,
RecentItem,
Settings,
@@ -18,8 +19,11 @@ import type {
} from "metabase-types/api";
import {
createMockDatabase,
+ createMockDatabaseCandidate,
createMockPopularTableItem,
createMockRecentTableItem,
+ createMockTable,
+ createMockTableCandidate,
createMockUser,
} from "metabase-types/api/mocks";
import {
@@ -36,6 +40,7 @@ interface SetupOpts {
popularItems?: PopularItem[];
isXrayEnabled?: boolean;
settings?: Partial<Settings>;
+ candidates?: Record<number, DatabaseXray[]>;
}
const setup = async ({
@@ -45,6 +50,7 @@ const setup = async ({
popularItems = [],
isXrayEnabled = true,
settings = {},
+ candidates = {},
}: SetupOpts) => {
const state = createMockState({
currentUser: user,
@@ -57,7 +63,9 @@ const setup = async ({
setupDatabasesEndpoints(databases);
setupRecentViewsEndpoints(recentItems);
setupPopularItemsEndpoints(popularItems);
- databases.forEach(({ id }) => setupDatabaseCandidatesEndpoint(id, []));
+ databases.forEach(({ id }) =>
+ setupDatabaseCandidatesEndpoint(id, candidates[id] || []),
+ );
renderWithProviders(<HomeContent />, { storeInitialState: state });
@@ -126,26 +134,44 @@ describe("HomeContent", () => {
});
it("should render x-rays for an installer after the setup", async () => {
+ const database = createMockDatabase({ tables: [createMockTable()] });
+
await setup({
user: createMockUser({
is_installer: true,
has_question_and_dashboard: false,
first_login: "2020-01-10T00:00:00Z",
}),
- databases: [createMockDatabase()],
+ databases: [database],
+ candidates: {
+ [database.id]: [
+ createMockDatabaseCandidate({
+ tables: [createMockTableCandidate()],
+ }),
+ ],
+ },
});
expect(screen.getByText(/Here are some explorations/)).toBeInTheDocument();
});
it("should render x-rays for the installer when there is no question and dashboard", async () => {
+ const database = createMockDatabase({ tables: [createMockTable()] });
+
await setup({
user: createMockUser({
is_installer: true,
has_question_and_dashboard: false,
first_login: "2020-01-10T00:00:00Z",
}),
- databases: [createMockDatabase()],
+ databases: [database],
+ candidates: {
+ [database.id]: [
+ createMockDatabaseCandidate({
+ tables: [createMockTableCandidate()],
+ }),
+ ],
+ },
recentItems: [createMockRecentTableItem()],
});
diff --git a/frontend/src/metabase/home/components/HomeXraySection/HomeXraySection.tsx b/frontend/src/metabase/home/components/HomeXraySection/HomeXraySection.tsx
index dca4427de03..913c6a4e5fd 100644
--- a/frontend/src/metabase/home/components/HomeXraySection/HomeXraySection.tsx
+++ b/frontend/src/metabase/home/components/HomeXraySection/HomeXraySection.tsx
@@ -72,6 +72,7 @@ const HomeXrayView = ({ database, candidates = [] }: HomeXrayViewProps) => {
const tableMessages = useMemo(() => getMessages(tableCount), [tableCount]);
const canSelectSchema = schemas.length > 1 && schema !== null;
const applicationName = useSelector(getApplicationName);
+ const hasTables = (candidate?.tables.length ?? 0) > 0;
return (
<div>
@@ -90,12 +91,12 @@ const HomeXrayView = ({ database, candidates = [] }: HomeXrayViewProps) => {
{t`schema in`}
<DatabaseInfo database={database} />
</HomeCaption>
- ) : (
+ ) : hasTables ? (
<HomeCaption primary>
{t`Here are some explorations of`}
<DatabaseInfo database={database} />
</HomeCaption>
- )}
+ ) : null}
<SectionBody>
{candidate?.tables.map((table, index) => (
<HomeXrayCard
diff --git a/frontend/src/metabase/home/components/HomeXraySection/HomeXraySection.unit.spec.tsx b/frontend/src/metabase/home/components/HomeXraySection/HomeXraySection.unit.spec.tsx
index 33d98966c8c..59ff90108f6 100644
--- a/frontend/src/metabase/home/components/HomeXraySection/HomeXraySection.unit.spec.tsx
+++ b/frontend/src/metabase/home/components/HomeXraySection/HomeXraySection.unit.spec.tsx
@@ -97,4 +97,15 @@ describe("HomeXraySection", () => {
expect(screen.getByTestId("xray-schema-name")).toHaveTextContent("public");
});
+
+ it("should not render a caption when there are no x-rays", async () => {
+ await setup({
+ database: createMockDatabase(),
+ candidates: [],
+ });
+
+ expect(
+ screen.queryByText(/Here are some explorations/),
+ ).not.toBeInTheDocument();
+ });
});