Skip to content

Commit

Permalink
Merge pull request #2280 from NDLANO/add-traits-to-searchresult
Browse files Browse the repository at this point in the history
Add traits to searchresult
  • Loading branch information
gunnarvelle authored Jan 2, 2025
2 parents 1774068 + 7c5ccb0 commit d5aa751
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 24 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,8 +1,7 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`searchHelpers converSearchStringToObject converts search string 1`] = `
exports[`searchHelpers convertSearchStringToObject converts search string 1`] = `
{
"contextFilters": [],
"contextTypes": [],
"fallback": "true",
"grepCodes": [],
Expand All @@ -22,12 +21,12 @@ 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`] = `
{
"contextFilters": [],
"contextTypes": [],
"fallback": "true",
"grepCodes": [],
Expand All @@ -37,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
4 changes: 2 additions & 2 deletions src/containers/SearchPage/searchHelpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ const arrayFields = [
"relevance",
"resourceTypes",
"contextTypes",
"contextFilters",
"grepCodes",
"traits",
];

export const converSearchStringToObject = (
export const convertSearchStringToObject = (
location?: Pick<Location, "search">,
locale?: LocaleType,
): Record<string, any> => {
Expand Down
5 changes: 2 additions & 3 deletions src/graphqlTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2029,7 +2029,6 @@ export type GQLQueryResourceEmbedsArgs = {

export type GQLQuerySearchArgs = {
aggregatePaths?: InputMaybe<Array<Scalars["String"]["input"]>>;
contextFilters?: InputMaybe<Scalars["String"]["input"]>;
contextTypes?: InputMaybe<Scalars["String"]["input"]>;
fallback?: InputMaybe<Scalars["String"]["input"]>;
filterInactive?: InputMaybe<Scalars["Boolean"]["input"]>;
Expand All @@ -2045,10 +2044,10 @@ export type GQLQuerySearchArgs = {
resourceTypes?: InputMaybe<Scalars["String"]["input"]>;
sort?: InputMaybe<Scalars["String"]["input"]>;
subjects?: InputMaybe<Scalars["String"]["input"]>;
traits?: InputMaybe<Array<Scalars["String"]["input"]>>;
};

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 Expand Up @@ -5190,14 +5189,14 @@ export type GQLSearchQueryVariables = Exact<{
language?: InputMaybe<Scalars["String"]["input"]>;
ids?: InputMaybe<Array<Scalars["Int"]["input"]> | Scalars["Int"]["input"]>;
resourceTypes?: InputMaybe<Scalars["String"]["input"]>;
contextFilters?: InputMaybe<Scalars["String"]["input"]>;
levels?: InputMaybe<Scalars["String"]["input"]>;
sort?: InputMaybe<Scalars["String"]["input"]>;
fallback?: InputMaybe<Scalars["String"]["input"]>;
subjects?: InputMaybe<Scalars["String"]["input"]>;
languageFilter?: InputMaybe<Scalars["String"]["input"]>;
relevance?: InputMaybe<Scalars["String"]["input"]>;
grepCodes?: InputMaybe<Scalars["String"]["input"]>;
traits?: InputMaybe<Array<Scalars["String"]["input"]> | Scalars["String"]["input"]>;
aggregatePaths?: InputMaybe<Array<Scalars["String"]["input"]> | Scalars["String"]["input"]>;
filterInactive?: InputMaybe<Scalars["Boolean"]["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
4 changes: 2 additions & 2 deletions src/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,14 @@ export const searchQuery = gql`
$language: String
$ids: [Int!]
$resourceTypes: String
$contextFilters: String
$levels: String
$sort: String
$fallback: String
$subjects: String
$languageFilter: String
$relevance: String
$grepCodes: String
$traits: [String!]
$aggregatePaths: [String!]
$filterInactive: Boolean
) {
Expand All @@ -116,14 +116,14 @@ export const searchQuery = gql`
language: $language
ids: $ids
resourceTypes: $resourceTypes
contextFilters: $contextFilters
levels: $levels
sort: $sort
fallback: $fallback
subjects: $subjects
languageFilter: $languageFilter
relevance: $relevance
grepCodes: $grepCodes
traits: $traits
aggregatePaths: $aggregatePaths
filterInactive: $filterInactive
) {
Expand Down
3 changes: 1 addition & 2 deletions src/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -1393,7 +1393,6 @@ type Query {
resourceTypes: [ResourceTypeDefinition!]
search(
aggregatePaths: [String!]
contextFilters: String
contextTypes: String
fallback: String
filterInactive: Boolean
Expand All @@ -1409,9 +1408,9 @@ type Query {
resourceTypes: String
sort: String
subjects: String
traits: [String!]
): Search
searchWithoutPagination(
contextFilters: String
contextTypes: String
fallback: String
ids: [Int!]
Expand Down

0 comments on commit d5aa751

Please sign in to comment.