Skip to content
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

Tweak search results header; improve /results types; prep for project results #611

Merged
merged 3 commits into from
Feb 28, 2024
Merged
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
2 changes: 1 addition & 1 deletion web/app/components/doc/tile-medium.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface DocTileMediumComponentSignature {
* The search query associated with the current view.
* Used to highlight search terms in the document title.
*/
query?: string;
query?: string | null;
};
Blocks: {
default: [];
Expand Down
2 changes: 1 addition & 1 deletion web/app/components/pagination.hbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div data-test-pagination class="pagination flex justify-center">
<div data-test-pagination class="pagination mt-8 flex justify-center">
{{#if (eq @nbPages 1)}}
{{! There is only one page of results }}
<Pagination::Link @icon="chevron-left" @disabled={{true}} />
Expand Down
22 changes: 7 additions & 15 deletions web/app/components/results/index.hbs
Original file line number Diff line number Diff line change
@@ -1,24 +1,16 @@
<h1
data-test-results-header-text
class="mb-4 text-display-300 font-semibold"
>{{@results.nbHits}}
{{if (eq 1 @results.nbHits) "document" "documents"}}
{{#if @query}}
matching
<mark>
{{@query}}
</mark>
{{/if}}
</h1>
<h2 data-test-results-subhead class="mb-6 text-display-300 font-semibold">
{{@docResults.nbHits}}
{{if (eq @docResults.nbHits 1) "match" "matches"}}
</h2>
<ol class="divided-list">
{{#each @results.hits as |doc|}}
{{#each @docResults.hits as |doc|}}
<li data-test-doc-search-result class="group relative">
<Doc::TileMedium @doc={{doc}} @query={{@query}} />
</li>
{{/each}}
</ol>

<Pagination
@currentPage={{(add @results.page 1)}}
@nbPages={{@results.nbPages}}
@currentPage={{(add (or @docResults.page 0) 1)}}
@nbPages={{@docResults.nbPages}}
/>
23 changes: 6 additions & 17 deletions web/app/components/results/index.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,18 @@
import Component from "@glimmer/component";
import { SearchResponse } from "@algolia/client-search";
import { HermesDocument } from "hermes/types/document";
import { capitalize } from "@ember/string";

interface ResultsIndexComponentSignature {
Args: {
results: SearchResponse<HermesDocument>;
query: string;
docResults?: SearchResponse<HermesDocument>;
query: string | null;
};
}

export default class ResultsIndexComponent extends Component<ResultsIndexComponentSignature> {
get lowercasedQuery(): string {
return this.args.query?.toLowerCase();
}

get capitalizedQuery(): string {
return capitalize(this.lowercasedQuery);
}
export default class ResultsIndexComponent extends Component<ResultsIndexComponentSignature> {}

get queryIsProductName(): boolean {
let hits = this.args.results?.hits as HermesDocument[];
// Assume at least one of the first 12 hits is a product match for the query.
return hits.some(
(hit) => hit.product?.toLowerCase() === this.lowercasedQuery,
);
declare module "@glint/environment-ember-loose/registry" {
export default interface Registry {
Results: typeof ResultsIndexComponent;
}
}
2 changes: 1 addition & 1 deletion web/app/controllers/authenticated/results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ModelFrom } from "hermes/types/route-models";
export default class AuthenticatedResultsController extends Controller {
queryParams = ["docType", "owners", "page", "product", "q", "status"];

q = null;
q: string | null = null;
page = 1;
docType = [];
owners = [];
Expand Down
14 changes: 8 additions & 6 deletions web/app/routes/authenticated/results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,16 @@ export default class AuthenticatedResultsRoute extends Route {
};

async model(params: ResultsRouteParams) {
const searchIndex = this.configSvc.config.algolia_docs_index_name;
const docsIndex = this.configSvc.config.algolia_docs_index_name;

const [facets, results] = await Promise.all([
this.algolia.getFacets.perform(searchIndex, params),
this.algolia.getDocResults.perform(searchIndex, params),
const [docFacets, docResults] = await Promise.all([
this.algolia.getFacets.perform(docsIndex, params),
this.algolia.getDocResults.perform(docsIndex, params),
]);

const hits = (results as { hits?: HermesDocument[] }).hits;
const typedDocResults = docResults as SearchResponse<HermesDocument>;

const hits = typedDocResults.hits;

if (hits) {
// Load owner information
Expand All @@ -52,7 +54,7 @@ export default class AuthenticatedResultsRoute extends Route {

this.activeFilters.update(params);

return { facets, results };
return { docFacets, docResults: typedDocResults };
}

/**
Expand Down
8 changes: 4 additions & 4 deletions web/app/styles/components/header/active-filter-list.scss
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
.active-filter-list {
@apply pt-6 flex items-start;
@apply flex items-start pt-6;

h3 {
@apply h-[30px] flex items-center mr-4 font-semibold shrink-0;
@apply mr-4 flex h-[30px] shrink-0 items-center font-semibold text-color-foreground-strong;
}

.active-filter-list-container {
@apply min-h-[30px] flex items-center flex-wrap;
@apply flex min-h-[30px] flex-wrap items-center;
}

.clear-all-link {
@apply no-underline text-color-foreground-faint flex items-center h-[30px] ml-2 shrink-0;
@apply ml-2 flex h-[30px] shrink-0 items-center text-color-foreground-faint no-underline;

&:hover {
@apply text-color-foreground-strong;
Expand Down
14 changes: 12 additions & 2 deletions web/app/templates/authenticated/results.hbs
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
{{page-title this.pageTitle}}

<Header::Toolbar @facets={{this.model.facets}} />
<div class="mb-6">
<h1 data-test-results-headline class="w-full text-display-500">
Results
{{#if this.q}}
for
<mark>{{this.q}}</mark>
{{/if}}
</h1>
</div>

<Results @results={{this.model.results}} @query={{this.q}} />
<Header::Toolbar @facets={{this.model.docFacets}} />

<Results @docResults={{this.model.docResults}} @query={{this.q}} />
28 changes: 14 additions & 14 deletions web/tests/acceptance/authenticated/results-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ const VIEW_ALL_DOCS_LINK = "[data-test-view-all-docs-link]";

// Header
const DOC_SEARCH_RESULT = "[data-test-doc-search-result]";
const RESULTS_HEADER_TEXT = "[data-test-results-header-text]";
const RESULTS_HEADLINE = "[data-test-results-headline]";
const RESULTS_SUBHEAD = "[data-test-results-subhead]";
const ACTIVE_FILTER_LIST = "[data-test-active-filter-list]";
const ACTIVE_FILTER_LINK = "[data-test-active-filter-link]";
const CLEAR_ALL_FILTERS_LINK = "[data-test-clear-all-filters-link]";
Expand Down Expand Up @@ -69,24 +70,23 @@ module("Acceptance | authenticated/results", function (hooks) {

assert.dom(DOC_SEARCH_RESULT).exists({ count: totalDocCount });

assert.dom(RESULTS_HEADLINE).hasText("Results");
assert
.dom(RESULTS_HEADER_TEXT)
.dom(RESULTS_SUBHEAD)
.hasText(
`${totalDocCount} documents`,
"the correct header text is shown (plural, no query)",
`${totalDocCount} matches`,
"the correct header text is shown (plural)",
);

// search for title
await visit(`/results?q=${uniqueTitle.replace(" ", "+")}`);

assert.dom(DOC_SEARCH_RESULT).exists({ count: 1 });

assert.dom(RESULTS_HEADLINE).hasText(`Results for ${uniqueTitle}`);
assert
.dom(RESULTS_HEADER_TEXT)
.hasText(
`1 document matching ${uniqueTitle}`,
"the correct header text is shown (singular, with query)",
);
.dom(RESULTS_SUBHEAD)
.hasText("1 match", "the correct header text is shown (singular)");
});

test("you can filter results", async function (this: Context, assert) {
Expand Down Expand Up @@ -144,7 +144,7 @@ module("Acceptance | authenticated/results", function (hooks) {

await visit("/results");

assert.dom(RESULTS_HEADER_TEXT).containsText(`${totalDocCount}`);
assert.dom(RESULTS_SUBHEAD).containsText(`${totalDocCount}`);
assert.dom(DOC_SEARCH_RESULT).exists({ count: totalDocCount });

assert
Expand All @@ -168,7 +168,7 @@ module("Acceptance | authenticated/results", function (hooks) {

await click(secondFacet as unknown as Element);

assert.dom(RESULTS_HEADER_TEXT).containsText(`${frdCount}`);
assert.dom(RESULTS_SUBHEAD).containsText(`${frdCount}`);
assert.dom(DOC_SEARCH_RESULT).exists({ count: frdCount });

assert
Expand Down Expand Up @@ -201,7 +201,7 @@ module("Acceptance | authenticated/results", function (hooks) {

await click(secondFacet as unknown as Element);

assert.dom(RESULTS_HEADER_TEXT).containsText("1");
assert.dom(RESULTS_SUBHEAD).containsText("1");
assert.dom(DOC_SEARCH_RESULT).exists({ count: 1 });

assert
Expand Down Expand Up @@ -234,7 +234,7 @@ module("Acceptance | authenticated/results", function (hooks) {

await click(ACTIVE_FILTER_LINK);

assert.dom(RESULTS_HEADER_TEXT).containsText(`${terraformDocCount}`);
assert.dom(RESULTS_SUBHEAD).containsText(`${terraformDocCount}`);
assert.dom(DOC_SEARCH_RESULT).exists({ count: terraformDocCount });

assert
Expand All @@ -246,7 +246,7 @@ module("Acceptance | authenticated/results", function (hooks) {

await click(CLEAR_ALL_FILTERS_LINK);

assert.dom(RESULTS_HEADER_TEXT).containsText(`${totalDocCount}`);
assert.dom(RESULTS_SUBHEAD).containsText(`${totalDocCount}`);

assert.dom(DOC_SEARCH_RESULT).exists({ count: totalDocCount });

Expand Down
Loading