From a8d5ea6437db8eafd8661a6d2a2a65664b892a60 Mon Sep 17 00:00:00 2001
From: Nick Fitzpatrick <nick@metabase.com>
Date: Thu, 13 Jun 2024 23:49:44 -0300
Subject: [PATCH] fix(command-palette): fix docs url (#44113)

---
 .../palette/components/PaletteResults.unit.spec.tsx  | 10 ++++++++++
 .../src/metabase/palette/hooks/useCommandPalette.tsx | 12 +++++++-----
 2 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/frontend/src/metabase/palette/components/PaletteResults.unit.spec.tsx b/frontend/src/metabase/palette/components/PaletteResults.unit.spec.tsx
index d96258ea0b3..da3c6d7f7e2 100644
--- a/frontend/src/metabase/palette/components/PaletteResults.unit.spec.tsx
+++ b/frontend/src/metabase/palette/components/PaletteResults.unit.spec.tsx
@@ -261,4 +261,14 @@ describe("PaletteResults", () => {
     // One call is always made to determine if the instance has models inside useCommandPaletteBasicActions
     expect(fetchMock.calls("path:/api/search").length).toBe(1);
   });
+
+  it("should provide a link to docs with the proper url param", async () => {
+    setup({ query: "model" });
+    expect(
+      await screen.findByRole("link", { name: /Search documentation/ }),
+    ).toHaveAttribute("href", expect.stringContaining("?query=model"));
+
+    // One call is always made to determine if the instance has models inside useCommandPaletteBasicActions
+    expect(fetchMock.calls("path:/api/search").length).toBe(2);
+  });
 });
diff --git a/frontend/src/metabase/palette/hooks/useCommandPalette.tsx b/frontend/src/metabase/palette/hooks/useCommandPalette.tsx
index 299f8dcbace..67a24b19d38 100644
--- a/frontend/src/metabase/palette/hooks/useCommandPalette.tsx
+++ b/frontend/src/metabase/palette/hooks/useCommandPalette.tsx
@@ -85,6 +85,9 @@ export const useCommandPalette = ({
   );
 
   const docsAction = useMemo<PaletteAction[]>(() => {
+    const link = debouncedSearchText
+      ? getDocsSearchUrl({ query: debouncedSearchText })
+      : docsUrl;
     const ret: PaletteAction[] = [
       {
         id: "search_docs",
@@ -95,11 +98,10 @@ export const useCommandPalette = ({
         keywords: debouncedSearchText, // Always match the debouncedSearchText string
         icon: "document",
         perform: () => {
-          if (debouncedSearchText) {
-            window.open(getDocsSearchUrl({ debouncedSearchText }));
-          } else {
-            window.open(docsUrl);
-          }
+          window.open(link);
+        },
+        extra: {
+          href: link,
         },
       },
     ];
-- 
GitLab