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
Can't use regex filter with \b on non-ascii names (#70838)
Nathan Voxland13bc69335722
diff --git a/enterprise/frontend/src/metabase-enterprise/tenants/components/TenantsListing/TenantsListing.tsx b/enterprise/frontend/src/metabase-enterprise/tenants/components/TenantsListing/TenantsListing.tsxindex ca535450242..56ae25caba5 100644--- a/enterprise/frontend/src/metabase-enterprise/tenants/components/TenantsListing/TenantsListing.tsx+++ b/enterprise/frontend/src/metabase-enterprise/tenants/components/TenantsListing/TenantsListing.tsx@@ -12,7 +12,6 @@ import { ForwardRefLink } from "metabase/common/components/Link";import { UserAvatar } from "metabase/common/components/UserAvatar";import CS from "metabase/css/core/index.css";import { useDispatch } from "metabase/lib/redux";-import { regexpEscape } from "metabase/lib/string";import {Box,Button,@@ -57,8 +56,11 @@ export const TenantsListing = ({};const filteredTenants = useMemo(() => {- const filter = new RegExp(`\\b${regexpEscape(searchInputValue)}`, "i");- return tenants.filter((g) => filter.test(g.name));+ if (!searchInputValue) {+ return tenants;+ }+ const lowerSearch = searchInputValue.toLowerCase();+ return tenants.filter((g) => g.name.toLowerCase().includes(lowerSearch));}, [searchInputValue, tenants]);if (hasNoTenants) {diff --git a/enterprise/frontend/src/metabase-enterprise/tenants/components/TenantsListing/TenantsListing.unit.spec.tsx b/enterprise/frontend/src/metabase-enterprise/tenants/components/TenantsListing/TenantsListing.unit.spec.tsxnew file mode 100644index 00000000000..3bfb7375882--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/tenants/components/TenantsListing/TenantsListing.unit.spec.tsx@@ -0,0 +1,75 @@+import userEvent from "@testing-library/user-event";+import { useState } from "react";++import { renderWithProviders, screen } from "__support__/ui";+import { ACTIVE_STATUS } from "metabase/admin/people/constants";+import { createMockTenant } from "metabase-types/api/mocks";++import { TenantsListing } from "./TenantsListing";++const TenantsListingWrapper = ({+ tenants = [createMockTenant()],+}: {+ tenants?: ReturnType<typeof createMockTenant>[];+} = {}) => {+ const [searchInputValue, setSearchInputValue] = useState("");++ return (+ <TenantsListing+ tenants={tenants}+ isAdmin={true}+ searchInputValue={searchInputValue}+ setSearchInputValue={setSearchInputValue}+ status={ACTIVE_STATUS.active}+ hasNoTenants={tenants.length === 0}+ />+ );+};++const setup = (tenants = [createMockTenant()]) => {+ renderWithProviders(<TenantsListingWrapper tenants={tenants} />);+};++describe("TenantsListing", () => {+ it("shows tenants with non-Latin names", () => {+ setup([createMockTenant({ id: 10, name: "здравей", slug: "zdravey" })]);++ expect(screen.getByText("здравей")).toBeInTheDocument();+ });++ it("shows tenants with non-Latin names alongside Latin-named tenants", () => {+ setup([+ createMockTenant({ id: 10, name: "здравей", slug: "zdravey" }),+ createMockTenant({ id: 11, name: "Acme Corp", slug: "acme-corp" }),+ ]);++ expect(screen.getByText("здравей")).toBeInTheDocument();+ expect(screen.getByText("Acme Corp")).toBeInTheDocument();+ });++ it("filters non-Latin tenants by search text", async () => {+ setup([+ createMockTenant({ id: 10, name: "здравей", slug: "zdravey" }),+ createMockTenant({ id: 11, name: "Acme Corp", slug: "acme-corp" }),+ ]);++ const searchInput = screen.getByPlaceholderText("Find a tenant");+ await userEvent.type(searchInput, "здрав");++ expect(screen.getByText("здравей")).toBeInTheDocument();+ expect(screen.queryByText("Acme Corp")).not.toBeInTheDocument();+ });++ it("excludes non-matching non-Latin tenants when searching", async () => {+ setup([+ createMockTenant({ id: 10, name: "здравей", slug: "zdravey" }),+ createMockTenant({ id: 11, name: "Acme Corp", slug: "acme-corp" }),+ ]);++ const searchInput = screen.getByPlaceholderText("Find a tenant");+ await userEvent.type(searchInput, "Acme");++ expect(screen.queryByText("здравей")).not.toBeInTheDocument();+ expect(screen.getByText("Acme Corp")).toBeInTheDocument();+ });+});diff --git a/frontend/src/metabase/admin/people/components/GroupsListing.tsx b/frontend/src/metabase/admin/people/components/GroupsListing.tsxindex d9786173d93..691afcad27c 100644--- a/frontend/src/metabase/admin/people/components/GroupsListing.tsx+++ b/frontend/src/metabase/admin/people/components/GroupsListing.tsx@@ -18,7 +18,6 @@ import {isDefaultGroup,} from "metabase/lib/groups";import { KEYCODE_ENTER } from "metabase/lib/keyboard";-import { regexpEscape } from "metabase/lib/string";import { PLUGIN_TENANTS } from "metabase/plugins";import {Box,@@ -497,8 +496,11 @@ export const GroupsListing = (props: GroupsListingProps) => {const { groups, isAdmin } = props;- const groupNameFilter = new RegExp(`\\b${regexpEscape(searchText)}`, "i");- const filteredGroups = groups.filter((g) => groupNameFilter.test(g.name));+ const filteredGroups = searchText+ ? groups.filter((g) =>+ g.name.toLowerCase().includes(searchText.toLowerCase()),+ )+ : groups;return (<AdminPaneLayoutdiff --git a/frontend/src/metabase/admin/people/components/GroupsListing.unit.spec.tsx b/frontend/src/metabase/admin/people/components/GroupsListing.unit.spec.tsxnew file mode 100644index 00000000000..b1cc0d3f4fd--- /dev/null+++ b/frontend/src/metabase/admin/people/components/GroupsListing.unit.spec.tsx@@ -0,0 +1,69 @@+import userEvent from "@testing-library/user-event";++import { setupApiKeyEndpoints } from "__support__/server-mocks";+import { renderWithProviders, screen } from "__support__/ui";+import { createMockGroup } from "metabase-types/api/mocks";++import { GroupsListing } from "./GroupsListing";++const setup = (groups = [createMockGroup()]) => {+ setupApiKeyEndpoints([]);++ const props = {+ groups: groups.map((g) => ({ ...g, members: [] })),+ isAdmin: true,+ create: jest.fn().mockResolvedValue(undefined),+ update: jest.fn().mockResolvedValue(undefined),+ delete: jest.fn().mockResolvedValue(undefined),+ };++ renderWithProviders(<GroupsListing {...props} />);+};++describe("GroupsListing", () => {+ it("shows groups with non-Latin names", async () => {+ setup([+ createMockGroup({ id: 10, name: "здравей", magic_group_type: null }),+ ]);++ expect(await screen.findByText("здравей")).toBeInTheDocument();+ });++ it("shows groups with non-Latin names alongside Latin-named groups", async () => {+ setup([+ createMockGroup({ id: 10, name: "здравей", magic_group_type: null }),+ createMockGroup({ id: 11, name: "Engineering", magic_group_type: null }),+ ]);++ expect(await screen.findByText("здравей")).toBeInTheDocument();+ expect(await screen.findByText("Engineering")).toBeInTheDocument();+ });++ it("filters non-Latin groups by search text", async () => {+ setup([+ createMockGroup({ id: 10, name: "здравей", magic_group_type: null }),+ createMockGroup({ id: 11, name: "Engineering", magic_group_type: null }),+ ]);++ await screen.findByText("здравей");+ const searchInput = screen.getByPlaceholderText("Find a group");+ await userEvent.type(searchInput, "здрав");++ expect(screen.getByText("здравей")).toBeInTheDocument();+ expect(screen.queryByText("Engineering")).not.toBeInTheDocument();+ });++ it("excludes non-matching non-Latin groups when searching", async () => {+ setup([+ createMockGroup({ id: 10, name: "здравей", magic_group_type: null }),+ createMockGroup({ id: 11, name: "Engineering", magic_group_type: null }),+ ]);++ await screen.findByText("здравей");+ const searchInput = screen.getByPlaceholderText("Find a group");+ await userEvent.type(searchInput, "Eng");++ expect(screen.queryByText("здравей")).not.toBeInTheDocument();+ expect(screen.getByText("Engineering")).toBeInTheDocument();+ });+});