The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
Hide the filter button when there are no parameters (#62295)
Alexander Polyankinc1762bf78718
diff --git a/frontend/src/metabase/nav/components/AppBar/AppBar.unit.spec.tsx b/frontend/src/metabase/nav/components/AppBar/AppBar.unit.spec.tsxindex 84c37886529..207559a9b61 100644--- a/frontend/src/metabase/nav/components/AppBar/AppBar.unit.spec.tsx+++ b/frontend/src/metabase/nav/components/AppBar/AppBar.unit.spec.tsx@@ -1,4 +1,8 @@-import { renderWithProviders, screen } from "__support__/ui";+import {+ createMockMediaQueryList,+ renderWithProviders,+ screen,+} from "__support__/ui";import { createMockUser } from "metabase-types/api/mocks";import type { AppBarProps } from "./AppBar";@@ -31,7 +35,9 @@ describe("AppBar", () => {describe("large screens", () => {beforeEach(() => {- matchMediaSpy.mockReturnValue(getMediaQuery({ matches: false }));+ matchMediaSpy.mockReturnValue(+ createMockMediaQueryList({ matches: false }),+ );});it("should render the desktop app bar", () => {@@ -93,7 +99,9 @@ describe("AppBar", () => {describe("small screens", () => {beforeEach(() => {- matchMediaSpy.mockReturnValue(getMediaQuery({ matches: true }));+ matchMediaSpy.mockReturnValue(+ createMockMediaQueryList({ matches: true }),+ );});it("should render the mobile app bar", () => {@@ -161,15 +169,3 @@ const getProps = (opts?: Partial<AppBarProps>): AppBarProps => ({onLogout: jest.fn(),...opts,});--const getMediaQuery = (opts?: Partial<MediaQueryList>): MediaQueryList => ({- media: "",- matches: false,- onchange: jest.fn(),- dispatchEvent: jest.fn(),- addListener: jest.fn(),- addEventListener: jest.fn(),- removeListener: jest.fn(),- removeEventListener: jest.fn(),- ...opts,-});diff --git a/frontend/src/metabase/query_builder/components/ResponsiveParameterList.unit.spec.tsx b/frontend/src/metabase/query_builder/components/ResponsiveParameterList.unit.spec.tsxnew file mode 100644index 00000000000..3bbc4bdebaf--- /dev/null+++ b/frontend/src/metabase/query_builder/components/ResponsiveParameterList.unit.spec.tsx@@ -0,0 +1,89 @@+import {+ createMockMediaQueryList,+ renderWithProviders,+ screen,+} from "__support__/ui";+import { SAMPLE_METADATA } from "metabase-lib/test-helpers";+import Question from "metabase-lib/v1/Question";+import type { Parameter } from "metabase-types/api";+import {+ createMockNativeDatasetQuery,+ createMockParameter,+} from "metabase-types/api/mocks";++import { ResponsiveParametersList } from "./ResponsiveParametersList";++type SetupOpts = {+ question?: Question;+ parameters?: Parameter[];+ enableParameterRequiredBehavior?: boolean;+};++function setup({+ question = Question.create({+ dataset_query: createMockNativeDatasetQuery(),+ metadata: SAMPLE_METADATA,+ }),+ parameters = [],+ enableParameterRequiredBehavior = false,+}: SetupOpts) {+ const setParameterValue = jest.fn();+ const setParameterIndex = jest.fn();++ renderWithProviders(+ <ResponsiveParametersList+ question={question}+ parameters={parameters}+ enableParameterRequiredBehavior={enableParameterRequiredBehavior}+ setParameterValue={setParameterValue}+ setParameterIndex={setParameterIndex}+ />,+ );++ return { setParameterValue, setParameterIndex };+}++describe("ResponsiveParametersList", () => {+ const matchMediaSpy = jest.spyOn(window, "matchMedia");++ afterEach(() => {+ matchMediaSpy.mockRestore();+ });++ describe("small screens", () => {+ beforeEach(() => {+ matchMediaSpy.mockReturnValue(+ createMockMediaQueryList({ matches: true }),+ );+ });++ it("should show the filter button when there are parameters", () => {+ setup({ parameters: [createMockParameter()] });+ expect(+ screen.getByRole("button", { name: /Filters/ }),+ ).toBeInTheDocument();+ });++ it("should not show the filter button when there are no parameters", () => {+ setup({ parameters: [] });+ expect(+ screen.queryByRole("button", { name: /Filters/ }),+ ).not.toBeInTheDocument();+ });+ });++ describe("large screens", () => {+ beforeEach(() => {+ matchMediaSpy.mockReturnValue(+ createMockMediaQueryList({ matches: false }),+ );+ });++ it("should not show the filter button for small screens when there are parameters", () => {+ setup({ parameters: [createMockParameter()] });+ expect(+ screen.queryByRole("button", { name: /Filters/ }),+ ).not.toBeInTheDocument();+ });+ });+});diff --git a/frontend/src/metabase/query_builder/components/ResponsiveParametersList.tsx b/frontend/src/metabase/query_builder/components/ResponsiveParametersList.tsxindex 402b6eefaf3..a3bac08af54 100644--- a/frontend/src/metabase/query_builder/components/ResponsiveParametersList.tsx+++ b/frontend/src/metabase/query_builder/components/ResponsiveParametersList.tsx@@ -42,7 +42,7 @@ export const ResponsiveParametersList = ({w={isSmallScreen && mobileShowParameterList ? "100%" : undefined}style={{ alignSelf: "center" }}>- {isSmallScreen && (+ {parameters.length > 0 && isSmallScreen && (<ButtonclassName={ResponsiveParametersListS.filterButton}borderless@@ -66,7 +66,7 @@ export const ResponsiveParametersList = ({[ResponsiveParametersListS.isShowingMobile]: mobileShowParameterList,})}>- {isSmallScreen && (+ {parameters.length > 0 && isSmallScreen && (<Flex p="0.75rem 1rem" align="center" justify="space-between"><h3>{t`Filters`}</h3><Buttondiff --git a/frontend/test/__support__/ui.tsx b/frontend/test/__support__/ui.tsxindex 14526e0548b..27f6e17e517 100644--- a/frontend/test/__support__/ui.tsx+++ b/frontend/test/__support__/ui.tsx@@ -413,6 +413,23 @@ export function createMockClipboardData(return clipboardData as unknown as DataTransfer;}+/**+ * jsdom doesn't have MediaQueryList+ */+export const createMockMediaQueryList = (+ opts?: Partial<MediaQueryList>,+): MediaQueryList => ({+ media: "",+ matches: false,+ onchange: jest.fn(),+ dispatchEvent: jest.fn(),+ addListener: jest.fn(),+ addEventListener: jest.fn(),+ removeListener: jest.fn(),+ removeEventListener: jest.fn(),+ ...opts,+});+const ThemeProviderWrapper = ({children,...props