Skip to content

Commit

Permalink
Also search Google People API
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffdaley committed Mar 25, 2024
1 parent 42c6d51 commit 4229ba6
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 10 deletions.
13 changes: 7 additions & 6 deletions web/app/components/header/toolbar.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -54,28 +54,29 @@
</div>
</:anchor>
<:item as |dd|>
{{log " d d d d" dd}}
<dd.LinkTo
@query={{get-facet-query-hash
"owners"
dd.attrs.value
(is-active-filter dd.attrs.value)
dd.attrs
(is-active-filter dd.attrs)
}}
class="block"
>
<div class="flex items-center gap-2 overflow-hidden">
<Person::Avatar @email={{dd.attrs.value}} />
<Person::Avatar @email={{dd.attrs}} />
<div class="w-full min-w-0">
<div class="truncate text-body-200 leading-tight">
{{#let
(get-model-attr "person.name" dd.attrs.value)
(get-model-attr "person.name" dd.attrs)
as |name|
}}
{{or name dd.attrs.value}}
{{or name dd.attrs}}
{{#if name}}
<span
class="ml-0.5 text-body-100 text-color-foreground-disabled"
>
{{dd.attrs.value}}
{{dd.attrs}}
</span>
{{/if}}
{{/let}}
Expand Down
35 changes: 31 additions & 4 deletions web/app/components/header/toolbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import ConfigService from "hermes/services/config";
import { SearchForFacetValuesResponse } from "instantsearch.js";
import Ember from "ember";
import { ProjectStatus } from "hermes/types/project-status";
import StoreService from "hermes/services/_store";
import PersonModel from "hermes/models/person";

export enum SortByValue {
DateDesc = "dateDesc",
Expand Down Expand Up @@ -68,6 +70,7 @@ export default class ToolbarComponent extends Component<ToolbarComponentSignatur
@service declare activeFilters: ActiveFiltersService;
@service declare documentTypes: DocumentTypesService;
@service declare productAreas: ProductAreasService;
@service declare store: StoreService;
/**
* Whether there has been a search during this session.
* Used to determine whether to search a query on focus.
Expand All @@ -92,8 +95,7 @@ export default class ToolbarComponent extends Component<ToolbarComponentSignatur
* The results of an ownerSearch, if any.
* Looped through by the DropdownList component.
*/
@tracked protected ownerResults: SearchForFacetValuesResponse | undefined =
undefined;
@tracked protected ownerResults: string[] | undefined = undefined;

protected get ownerFacetIsShown() {
return this.args.scope !== SearchScope.Projects;
Expand Down Expand Up @@ -265,7 +267,7 @@ export default class ToolbarComponent extends Component<ToolbarComponentSignatur
if (this.ownerQuery.length) {
this.searchInputIsEmpty = false;
try {
await this.algolia.searchForFacetValues
const algoliaResultsPromise = this.algolia.searchForFacetValues
.perform(
this.configSvc.config.algolia_docs_index_name,
"owners",
Expand All @@ -278,8 +280,33 @@ export default class ToolbarComponent extends Component<ToolbarComponentSignatur
)
.then((results) => {
assert("facetHits must exist", results && "facetHits" in results);
this.ownerResults = results.facetHits;
return results.facetHits;
});

const peoplePromise = this.store.query("person", {
query: this.ownerQuery,
});

const [algoliaResults, peopleResults] = await Promise.all([
algoliaResultsPromise,
peoplePromise,
]);

let people: string[] = [];

if (peopleResults.length) {
people = peopleResults
.map((p: PersonModel) => p.email)
.filter((email: string) => {
return (
!this.activeFilters.index[FacetName.Owners].includes(email) &&
!algoliaResults.some((result) => result.value === email)
);
});
}
this.ownerResults = algoliaResults
.map((result) => result.value)
.concat(people);
} catch (e) {
console.error(e);
}
Expand Down
32 changes: 32 additions & 0 deletions web/tests/integration/components/header/toolbar-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,36 @@ module("Integration | Component | header/toolbar", function (hooks) {
.dom(OWNER_MATCH)
.containsText(TEST_USER_NAME, "the owner's name is displayed");
});

test("owners are searched in algolia and the google people api", async function (this: ToolbarTestContext, assert) {
this.server.create("google/person", {
names: [{ displayName: "Mishra" }],
emailAddresses: [{ value: "[email protected]" }],
});

this.server.create("google/person", {
names: [{ displayName: "Michelle" }],
emailAddresses: [{ value: "[email protected]" }],
});

this.server.create("document", {
status: "Approved",
owners: ["[email protected]"],
});

this.set("facets", FACETS);

await render<ToolbarTestContext>(hbs`
<Header::Toolbar @facets={{this.facets}} />
`);

await fillIn(OWNERS_INPUT, "mi");

assert
.dom(OWNER_MATCH)
.exists(
{ count: 2 },
"both people are displayed even though only one is a doc owner; the duplicate entry is filtered out",
);
});
});

0 comments on commit 4229ba6

Please sign in to comment.