Skip to content

fix: search categories #1218

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions packages/arcgis-rest-portal/src/items/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,20 @@ import { genericSearch } from "../util/generic-search.js";
export function searchItems(
search: string | ISearchOptions | SearchQueryBuilder
): Promise<ISearchResult<IItem>> {
// For the "categories" param, we want to send each entry in the array as
// a distinct parameter. I.e. categories: ["a", "b,c"] should be sent as
// ....&categories=a&categories=b,c
// To get this behavior out of our lower-level request modules, we need to
// send category as an array of arrays.
if (
typeof search === "object" &&
!(search instanceof SearchQueryBuilder) &&
search.params?.categories
) {
search.params.categories = search.params.categories.map((x) => {
return x.split(",");
});
}

return genericSearch<IItem>(search, "item");
}
2 changes: 1 addition & 1 deletion packages/arcgis-rest-portal/test/items/search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ describe("search", () => {
expect(fetchMock.called()).toEqual(true);
const [url, options] = fetchMock.lastCall("*");
expect(url).toEqual(
"https://www.arcgis.com/sharing/rest/search?f=json&q=Washington&categories=%2FCategories%2FWater%2C%2FCategories%2FForest"
"https://www.arcgis.com/sharing/rest/search?f=json&q=Washington&categories=%2FCategories%2FWater&categories=%2FCategories%2FForest"
);
expect(options.method).toBe("GET");
done();
Expand Down
Loading