Skip to content

Commit 6dfd8de

Browse files
authored
refactor(Navigation): move DocSearch configuration to config file (#8028)
1 parent ca07e71 commit 6dfd8de

3 files changed

Lines changed: 45 additions & 4 deletions

File tree

cypress/e2e/search.cy.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,30 @@
11
"use strict";
22

33
describe("Search", () => {
4+
beforeEach(() => {
5+
cy.intercept("POST", "https://*.algolia.net/**", {
6+
statusCode: 200,
7+
body: {
8+
results: [
9+
{
10+
hits: [
11+
{
12+
url: "http://localhost:3000/concepts/",
13+
hierarchy: { lvl0: "Concepts" },
14+
objectID: "1",
15+
},
16+
],
17+
},
18+
],
19+
},
20+
}).as("algoliaSearch");
21+
});
22+
423
it("should visit entry page", () => {
524
cy.visit("/concepts/");
625
cy.get(".DocSearch").click();
726
cy.get("#docsearch-input").type("roadmap");
8-
cy.get(".DocSearch-Hits").should("be.visible");
27+
28+
cy.get(".DocSearch-Modal").should("be.visible");
929
});
1030
});

src/components/Navigation/Navigation.jsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ import PropTypes from "prop-types";
44
import { useEffect, useRef, useState } from "react";
55
import { Link as ReactDOMLink, NavLink, useLocation } from "react-router-dom";
66

7+
// Import Internal Config
8+
import {
9+
DOCSEARCH_API_KEY,
10+
DOCSEARCH_APP_ID,
11+
DOCSEARCH_INDEX_NAME,
12+
} from "../../config/docsearch.js";
13+
714
// Import Components
815
import DiscordIcon from "../../styles/icons/discord.svg";
916
import GithubIcon from "../../styles/icons/github.svg";
@@ -202,9 +209,9 @@ function Navigation({ links, pathname, hash = "", toggleSidebar }) {
202209
<HelloDarkness />
203210
{mounted && (
204211
<DocSearch
205-
appId="BH4D9OD16A"
206-
apiKey={"fac401d1a5f68bc41f01fb6261661490"}
207-
indexName="webpack-js-org"
212+
appId={DOCSEARCH_APP_ID}
213+
apiKey={DOCSEARCH_API_KEY}
214+
indexName={DOCSEARCH_INDEX_NAME}
208215
disableUserPersonalization={true}
209216
placeholder="Search webpack documentation"
210217
transformItems={(items) =>

src/config/docsearch.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"use strict";
2+
3+
// DocSearch configuration
4+
// Set DOCSEARCH_API_KEY in your environment (e.g., .env file or build system)
5+
6+
const DOCSEARCH_API_KEY = "fac401d1a5f68bc41f01fb6261661490";
7+
const DOCSEARCH_APP_ID = "BH4D90D16A";
8+
const DOCSEARCH_INDEX_NAME = "webpack-js-org";
9+
10+
module.exports = {
11+
DOCSEARCH_API_KEY,
12+
DOCSEARCH_APP_ID,
13+
DOCSEARCH_INDEX_NAME,
14+
};

0 commit comments

Comments
 (0)