From 0f60701995cc9c18bc527e0b57788faa9056721c Mon Sep 17 00:00:00 2001 From: Vitor Avila <96086495+Vitor-Avila@users.noreply.github.com> Date: Fri, 5 Jul 2024 16:57:25 -0300 Subject: [PATCH] chore(Home): Avoid firing API requests when a custom Home is used (#29493) --- .../src/pages/Home/Home.test.tsx | 25 +++++++++++++++++++ superset-frontend/src/pages/Home/index.tsx | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/superset-frontend/src/pages/Home/Home.test.tsx b/superset-frontend/src/pages/Home/Home.test.tsx index 6be4dc186ed79..f470e9ea7380d 100644 --- a/superset-frontend/src/pages/Home/Home.test.tsx +++ b/superset-frontend/src/pages/Home/Home.test.tsx @@ -228,3 +228,28 @@ test('Should render a submenu extension component if one is supplied', async () expect(screen.getByText('submenu extension')).toBeInTheDocument(); }); + +test('Should not make data fetch calls if `welcome.main.replacement` is defined', async () => { + const extensionsRegistry = getExtensionsRegistry(); + + // Clean up + extensionsRegistry.set('welcome.banner', () => null); + + // Set up + extensionsRegistry.set('welcome.main.replacement', () => ( + <>welcome.main.replacement extension component + )); + + setupExtensions(); + + await renderWelcome(); + + expect( + screen.getByText('welcome.main.replacement extension component'), + ).toBeInTheDocument(); + + expect(fetchMock.calls(chartsEndpoint)).toHaveLength(0); + expect(fetchMock.calls(dashboardsEndpoint)).toHaveLength(0); + expect(fetchMock.calls(recentActivityEndpoint)).toHaveLength(0); + expect(fetchMock.calls(savedQueryEndpoint)).toHaveLength(0); +}); diff --git a/superset-frontend/src/pages/Home/index.tsx b/superset-frontend/src/pages/Home/index.tsx index 5661451a42df9..b92e84f486dc5 100644 --- a/superset-frontend/src/pages/Home/index.tsx +++ b/superset-frontend/src/pages/Home/index.tsx @@ -218,7 +218,7 @@ function Welcome({ user, addDangerToast }: WelcomeProps) { }, []); useEffect(() => { - if (!otherTabFilters) { + if (!otherTabFilters || WelcomeMainExtension) { return; } const activeTab = getItem(LocalStorageKeys.HomepageActivityFilter, null);