Skip to content

Commit

Permalink
Actually add traits to search
Browse files Browse the repository at this point in the history
  • Loading branch information
gunnarvelle committed Jan 2, 2025
1 parent 48fd82d commit 7c5ccb0
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/containers/SearchPage/SearchInnerPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
getTypeFilter,
mapSearchDataToGroups,
convertSearchParam,
converSearchStringToObject,
convertSearchStringToObject,
getTypeParams,
TypeFilter,
mapSubjectDataToGroup,
Expand Down Expand Up @@ -76,7 +76,7 @@ const SearchInnerPage = ({
setTypeFilter(getTypeFilter(resourceTypes, selectedFilters, activeSubFilters, t));
}, [resourceTypes, selectedFilters, activeSubFilters, t]);

const searchParams = converSearchStringToObject(location, i18n.language);
const searchParams = convertSearchStringToObject(location, i18n.language);
const stateSearchParams = isLti
? {
query: !query ? undefined : query,
Expand Down
4 changes: 2 additions & 2 deletions src/containers/SearchPage/SearchPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { useLocation, useNavigate } from "react-router-dom";
import { useQuery } from "@apollo/client";
import { HelmetWithTracker, useTracker } from "@ndla/tracker";
import { constants } from "@ndla/ui";
import { converSearchStringToObject } from "./searchHelpers";
import { convertSearchStringToObject } from "./searchHelpers";
import SearchInnerPage, { getStateSearchParams } from "./SearchInnerPage";
import { AuthContext } from "../../components/AuthenticationContext";
import { ContentPlaceholder } from "../../components/ContentPlaceholder";
Expand All @@ -30,7 +30,7 @@ const SearchPage = () => {
const { user, authContextLoaded } = useContext(AuthContext);
const location = useLocation();
const navigate = useNavigate();
const searchParams = converSearchStringToObject(location, i18n.language);
const searchParams = convertSearchStringToObject(location, i18n.language);

const { data, loading } = useQuery<GQLSearchPageQuery>(searchPageQuery);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`searchHelpers converSearchStringToObject converts search string 1`] = `
exports[`searchHelpers convertSearchStringToObject converts search string 1`] = `
{
"contextTypes": [],
"fallback": "true",
Expand All @@ -21,10 +21,11 @@ exports[`searchHelpers converSearchStringToObject converts search string 1`] = `
"urn:test:1",
"urn:test:2",
],
"traits": [],
}
`;

exports[`searchHelpers converSearchStringToObject with no location 1`] = `
exports[`searchHelpers convertSearchStringToObject with no location 1`] = `
{
"contextTypes": [],
"fallback": "true",
Expand All @@ -35,6 +36,7 @@ exports[`searchHelpers converSearchStringToObject with no location 1`] = `
"relevance": [],
"resourceTypes": [],
"subjects": [],
"traits": [],
}
`;

Expand Down
10 changes: 5 additions & 5 deletions src/containers/SearchPage/__tests__/searchHelpers-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*
*/
import { searchResultToLinkProps, converSearchStringToObject, convertSearchParam } from "../searchHelpers";
import { searchResultToLinkProps, convertSearchStringToObject, convertSearchParam } from "../searchHelpers";

test("searchHelpers searchResultToLinkProps learningpath", () => {
const result = {
Expand All @@ -27,16 +27,16 @@ test("searchHelpers searchResultToLinkProps article", () => {
expect(searchResultToLinkProps(result)).toMatchSnapshot();
});

test("searchHelpers converSearchStringToObject converts search string", () => {
test("searchHelpers convertSearchStringToObject converts search string", () => {
const locationWithSearch = {
search: "?query=test&page=3&languageFilter=1,2,3&subjects=urn:test:3,urn:test:1,urn:test:2",
};

expect(converSearchStringToObject(locationWithSearch)).toMatchSnapshot();
expect(convertSearchStringToObject(locationWithSearch)).toMatchSnapshot();
});

test("searchHelpers converSearchStringToObject with no location", () => {
expect(converSearchStringToObject()).toMatchSnapshot();
test("searchHelpers convertSearchStringToObject with no location", () => {
expect(convertSearchStringToObject()).toMatchSnapshot();
});

test("searchHelpers convertSearchParam", () => {
Expand Down
2 changes: 1 addition & 1 deletion src/containers/SearchPage/searchHelpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const arrayFields = [
"traits",
];

export const converSearchStringToObject = (
export const convertSearchStringToObject = (
location?: Pick<Location, "search">,
locale?: LocaleType,
): Record<string, any> => {
Expand Down
1 change: 0 additions & 1 deletion src/graphqlTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2048,7 +2048,6 @@ export type GQLQuerySearchArgs = {
};

export type GQLQuerySearchWithoutPaginationArgs = {
contextFilters?: InputMaybe<Scalars["String"]["input"]>;
contextTypes?: InputMaybe<Scalars["String"]["input"]>;
fallback?: InputMaybe<Scalars["String"]["input"]>;
ids?: InputMaybe<Array<Scalars["Int"]["input"]>>;
Expand Down
4 changes: 2 additions & 2 deletions src/lti/LtiProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { PageLayout } from "../components/Layout/PageContainer";
import { useLtiData } from "../components/LtiContext";
import { RESOURCE_TYPE_LEARNING_PATH, STORED_LANGUAGE_COOKIE_KEY } from "../constants";
import { PageErrorBoundary } from "../containers/ErrorPage/ErrorBoundary";
import { converSearchStringToObject } from "../containers/SearchPage/searchHelpers";
import { convertSearchStringToObject } from "../containers/SearchPage/searchHelpers";
import SearchInnerPage, { getStateSearchParams } from "../containers/SearchPage/SearchInnerPage";
import { GQLSearchPageQuery } from "../graphqlTypes";
import { getLangAttributeValue } from "../i18n";
Expand All @@ -43,7 +43,7 @@ const LtiProvider = () => {
const ltiContext = useLtiData();
const location = useLocation();
const navigate = useNavigate();
const searchParams = converSearchStringToObject(location);
const searchParams = convertSearchStringToObject(location);

const { t, i18n } = useTranslation();

Expand Down
1 change: 1 addition & 0 deletions src/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ export const searchQuery = gql`
languageFilter: $languageFilter
relevance: $relevance
grepCodes: $grepCodes
traits: $traits
aggregatePaths: $aggregatePaths
filterInactive: $filterInactive
) {
Expand Down
1 change: 0 additions & 1 deletion src/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -1411,7 +1411,6 @@ type Query {
traits: [String!]
): Search
searchWithoutPagination(
contextFilters: String
contextTypes: String
fallback: String
ids: [Int!]
Expand Down

0 comments on commit 7c5ccb0

Please sign in to comment.