Skip to content

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

Tree Filter should not be case sensitive (#66792)

Nick Fitzpatrick6c903ded78bb
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/common/components/Table/useTreeFilter.ts b/enterprise/frontend/src/metabase-enterprise/data-studio/common/components/Table/useTreeFilter.ts
index eb23b357909..7daef066be5 100644
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/common/components/Table/useTreeFilter.ts
+++ b/enterprise/frontend/src/metabase-enterprise/data-studio/common/components/Table/useTreeFilter.ts
@@ -29,11 +29,15 @@ export const useTreeFilter = <
if (
searchProps.some((s) => {
- if (typeof node[s] !== "string") {
- return false;
+ if (
+ typeof node[s] === "string" &&
+ typeof searchQuery === "string"
+ ) {
+ return node[s]
+ .toLowerCase()
+ .includes(searchQuery.toLowerCase());
}
-
- return !!node[s].includes(searchQuery);
+ return false;
})
) {
return node;
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/common/components/Table/useTreeFilter.unit.spec.tsx b/enterprise/frontend/src/metabase-enterprise/data-studio/common/components/Table/useTreeFilter.unit.spec.tsx
new file mode 100644
index 00000000000..ed5c0dbbc26
--- /dev/null
+++ b/enterprise/frontend/src/metabase-enterprise/data-studio/common/components/Table/useTreeFilter.unit.spec.tsx
@@ -0,0 +1,96 @@
+import { renderHook } from "__support__/ui";
+
+import { useTreeFilter } from "./useTreeFilter";
+
+type Node = {
+ name: string;
+ category: string;
+ children?: Node[];
+};
+
+const TEST_TREE: Node[] = [
+ {
+ name: "FOO",
+ category: "Doohickey",
+ children: [
+ {
+ name: "Hudson Borer",
+ category: "Doohickey",
+ },
+ {
+ name: "Domenica Williamson",
+ category: "Doohickey",
+ },
+ {
+ name: "Lina Heaney",
+ category: "Gadget",
+ },
+ {
+ name: "Arnold Adams",
+ category: "Doohickey",
+ },
+ ],
+ },
+ {
+ name: "BAR",
+ category: "Gadget",
+ children: [
+ {
+ name: "Rene Muller",
+ category: "Gadget",
+ },
+ {
+ name: "Roselyn Bosco",
+ category: "Gadget",
+ children: [
+ {
+ name: "Lavonne Senger",
+ category: "Doohickey",
+ },
+ ],
+ },
+ {
+ name: "Aracely Jenkins",
+ category: "Gadget",
+ },
+ {
+ name: "Anais Ward",
+ category: "Doohickey",
+ },
+ ],
+ },
+];
+
+describe("useTreeFilter", () => {
+ it("should filter child nodes using specified props", () => {
+ const {
+ result: { current: tree },
+ } = renderHook(() =>
+ useTreeFilter({
+ data: TEST_TREE,
+ searchProps: ["category"],
+ searchQuery: "gadg",
+ }),
+ );
+
+ // This is actually asserting many things
+ // - Only leaf nodes are considered in search,
+ // - parent nodes with no filtered children should not be returned. this is why Roselyn was filtered out
+ // - We shouldn't change the order that of returned values
+ // - That search is not case sensitive
+
+ expect(tree).toMatchObject([
+ {
+ name: "FOO",
+ children: [expect.objectContaining({ name: "Lina Heaney" })],
+ },
+ {
+ name: "BAR",
+ children: [
+ expect.objectContaining({ name: "Rene Muller" }),
+ expect.objectContaining({ name: "Aracely Jenkins" }),
+ ],
+ },
+ ]);
+ });
+});