From 659024f6728392f7049ee7c8ea87d640cefcfef7 Mon Sep 17 00:00:00 2001 From: mikkancso Date: Thu, 13 Apr 2023 09:53:18 +0200 Subject: [PATCH] EditDataSources: Add EditDataSourceActions to EditDataSourcePages (#64487) * add EditDataSourceActions to EditDataSourcePages * fix tests * EditDSPage: do not show buttons in header if topnav is off * remove delete button from the header * EditDSPage: hide buttons from footer when topnav is on * update tests * rename ActionProps to Props * wrap setting of feature toggle in act in jest test * fix jest test by using waitFor --- .../connections/pages/EditDataSourcePage.tsx | 8 +- .../datasources/components/ButtonRow.tsx | 29 ++++--- .../components/EditDataSourceActions.tsx | 80 +++++++++++++++++++ .../pages/EditDataSourcePage.test.tsx | 25 +++++- .../datasources/pages/EditDataSourcePage.tsx | 8 +- 5 files changed, 134 insertions(+), 16 deletions(-) create mode 100644 public/app/features/datasources/components/EditDataSourceActions.tsx diff --git a/public/app/features/connections/pages/EditDataSourcePage.tsx b/public/app/features/connections/pages/EditDataSourcePage.tsx index d72a168518c..2f66e87f6db 100644 --- a/public/app/features/connections/pages/EditDataSourcePage.tsx +++ b/public/app/features/connections/pages/EditDataSourcePage.tsx @@ -1,8 +1,10 @@ import * as React from 'react'; import { useLocation, useParams } from 'react-router-dom'; +import { config } from '@grafana/runtime'; import { Page } from 'app/core/components/Page/Page'; import { EditDataSource } from 'app/features/datasources/components/EditDataSource'; +import { EditDataSourceActions } from 'app/features/datasources/components/EditDataSourceActions'; import { useDataSourceSettingsNav } from '../hooks/useDataSourceSettingsNav'; @@ -14,7 +16,11 @@ export function EditDataSourcePage() { const { navId, pageNav } = useDataSourceSettingsNav(); return ( - + : undefined} + > diff --git a/public/app/features/datasources/components/ButtonRow.tsx b/public/app/features/datasources/components/ButtonRow.tsx index 773d81d7697..d1c40f885be 100644 --- a/public/app/features/datasources/components/ButtonRow.tsx +++ b/public/app/features/datasources/components/ButtonRow.tsx @@ -1,6 +1,7 @@ import React from 'react'; import { selectors } from '@grafana/e2e-selectors'; +import { config } from '@grafana/runtime'; import { Button, LinkButton } from '@grafana/ui'; import { contextSrv } from 'app/core/core'; import { AccessControlAction } from 'app/types'; @@ -19,21 +20,25 @@ export function ButtonRow({ canSave, canDelete, onDelete, onSubmit, onTest, expl return (
- + {!config.featureToggles.topnav && ( + + )} Explore - + {!config.featureToggles.topnav && ( + + )} {canSave && ( + + ); +} diff --git a/public/app/features/datasources/pages/EditDataSourcePage.test.tsx b/public/app/features/datasources/pages/EditDataSourcePage.test.tsx index 54c2cd9ec9c..149ef0f29b5 100644 --- a/public/app/features/datasources/pages/EditDataSourcePage.test.tsx +++ b/public/app/features/datasources/pages/EditDataSourcePage.test.tsx @@ -1,10 +1,11 @@ -import { screen, render } from '@testing-library/react'; +import { screen, render, waitFor } from '@testing-library/react'; import React from 'react'; import { Store } from 'redux'; import { TestProvider } from 'test/helpers/TestProvider'; import { LayoutModes } from '@grafana/data'; import { setAngularLoader } from '@grafana/runtime'; +import config from 'app/core/config'; import { getRouteComponentProps } from 'app/core/navigation/__mocks__/routeProps'; import { configureStore } from 'app/store/configureStore'; @@ -57,6 +58,7 @@ describe('', () => { const dataSourceMeta = getMockDataSourceMeta(); const dataSourceSettings = getMockDataSourceSettingsState(); let store: Store; + const topnavValue = config.featureToggles.topnav; beforeAll(() => { setAngularLoader({ @@ -94,7 +96,12 @@ describe('', () => { }); }); + afterAll(() => { + config.featureToggles.topnav = topnavValue; + }); + it('should render the edit page without an issue', async () => { + config.featureToggles.topnav = false; setup(uid, store); expect(screen.queryByText('Loading ...')).not.toBeInTheDocument(); @@ -106,9 +113,23 @@ describe('', () => { expect(screen.queryByRole('button', { name: /Back/i })).toBeVisible(); expect(screen.queryByRole('button', { name: /Delete/i })).toBeVisible(); expect(screen.queryByRole('button', { name: /Save (.*) test/i })).toBeVisible(); - expect(screen.queryByText('Explore')).toBeVisible(); + expect(screen.queryByRole('link', { name: /Explore/i })).toBeVisible(); // wait for the rest of the async processes to finish expect(await screen.findByText(name)).toBeVisible(); }); + + it('should show updated action buttons when topnav is on', async () => { + config.featureToggles.topnav = true; + setup(uid, store); + + await waitFor(() => { + // Buttons + expect(screen.queryAllByRole('button', { name: /Back/i })).toHaveLength(0); + expect(screen.queryByRole('button', { name: /Delete/i })).toBeVisible(); + expect(screen.queryByRole('button', { name: /Save (.*) test/i })).toBeVisible(); + expect(screen.queryByRole('link', { name: /Build a dashboard/i })).toBeVisible(); + expect(screen.queryAllByRole('link', { name: /Explore/i })).toHaveLength(2); + }); + }); }); diff --git a/public/app/features/datasources/pages/EditDataSourcePage.tsx b/public/app/features/datasources/pages/EditDataSourcePage.tsx index 22f959c5a4a..b9804fc970d 100644 --- a/public/app/features/datasources/pages/EditDataSourcePage.tsx +++ b/public/app/features/datasources/pages/EditDataSourcePage.tsx @@ -1,9 +1,11 @@ import React from 'react'; +import { config } from '@grafana/runtime'; import { Page } from 'app/core/components/Page/Page'; import { GrafanaRouteComponentProps } from 'app/core/navigation/types'; import { EditDataSource } from '../components/EditDataSource'; +import { EditDataSourceActions } from '../components/EditDataSourceActions'; import { useDataSourceSettingsNav } from '../state'; export interface Props extends GrafanaRouteComponentProps<{ uid: string }> {} @@ -15,7 +17,11 @@ export function EditDataSourcePage(props: Props) { const nav = useDataSourceSettingsNav(uid, pageId); return ( - + : undefined} + >