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

fix: fix facets association bug #176

Closed
wants to merge 1 commit into from
Closed
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
3 changes: 2 additions & 1 deletion frontend/src/mixins/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
removeParenthesis,
} from '../utils/url';
import {isNullOrUndefined} from '../utils';
import {DEFAULT_SEARCH_NAME} from '../utils/constants';
import {BuildParamsOutput} from './search-ctl';
import {property} from 'lit/decorators.js';
import {QueryOperator} from '../utils/enums';
Expand Down Expand Up @@ -117,7 +118,7 @@ export const SearchaliciousHistoryMixin = <T extends Constructor<LitElement>>(
@property({attribute: false})
query = '';
@property()
name = 'searchalicious';
name = DEFAULT_SEARCH_NAME;

// stub methods defined in search-ctl
_sortElement = (): SearchaliciousSort | null => {
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/mixins/search-action.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {LitElement} from 'lit';
import {Constructor} from './utils';
import {BaseSearchDetail, LaunchSearchEvent} from '../events';
import {DEFAULT_SEARCH_NAME} from '../utils/constants';
import {SearchaliciousEvents} from '../utils/enums';
import {property} from 'lit/decorators.js';

Expand All @@ -21,7 +22,7 @@ export const SearchActionMixin = <T extends Constructor<LitElement>>(
): Constructor<SearchActionMixinInterface> & T => {
class SearchActionMixinClass extends superClass {
@property({attribute: 'search-name'})
searchName = 'searchalicious';
searchName = DEFAULT_SEARCH_NAME;

/**
* Launches a search event.
Expand Down
17 changes: 12 additions & 5 deletions frontend/src/mixins/search-ctl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {Constructor} from './utils';
import {SearchaliciousSort} from '../search-sort';
import {SearchaliciousFacets} from '../search-facets';
import {setCurrentURLHistory} from '../utils/url';
import {FACETS_DIVIDER} from '../utils/constants';
import {DEFAULT_SEARCH_NAME, FACETS_DIVIDER} from '../utils/constants';
import {
HistorySearchParams,
SearchaliciousHistoryInterface,
Expand Down Expand Up @@ -67,7 +67,7 @@ export const SearchaliciousSearchMixin = <T extends Constructor<LitElement>>(
* The name of this search
*/
@property()
override name = 'searchalicious';
override name = DEFAULT_SEARCH_NAME;

/**
* The base api url
Expand Down Expand Up @@ -119,9 +119,16 @@ export const SearchaliciousSearchMixin = <T extends Constructor<LitElement>>(

/** list of facets containers */
_facetsParentNode() {
return document.querySelectorAll(
`searchalicious-facets[search-name=${this.name}]`
);
if (this.name === DEFAULT_SEARCH_NAME) {
// manually filtering, as it may be implicit
return Array.from(
document.querySelectorAll('searchalicious-facets')
).filter((facets) => facets.searchName === this.name);
} else {
return document.querySelectorAll(
`searchalicious-facets[search-name=${this.name}]`
);
}
}

/**
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/mixins/search-results-ctl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
EventRegistrationInterface,
EventRegistrationMixin,
} from '../event-listener-setup';
import {DEFAULT_SEARCH_NAME} from '../utils/constants';
import {SearchaliciousEvents} from '../utils/enums';
import {SearchResultEvent} from '../events';
import {Constructor} from './utils';
Expand Down Expand Up @@ -38,7 +39,7 @@ export const SearchaliciousResultCtlMixin = <T extends Constructor<LitElement>>(
* this corresponds to `name` attribute of corresponding search-bar
*/
@property({attribute: 'search-name'})
searchName = 'searchalicious';
searchName = DEFAULT_SEARCH_NAME;

/**
* this will be true if we already launched a search
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/test/search-pages_test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {SearchaliciousPages} from '../search-pages';
import {DEFAULT_SEARCH_NAME} from '../utils/constants';
import {SearchaliciousEvents} from '../utils/enums';
import {SearchResultDetail, SearchResultEvent} from '../events';

Expand All @@ -13,7 +14,7 @@ suite('searchalicious-pages', () => {
pageCount: number
) => {
const detail: SearchResultDetail = {
searchName: 'searchalicious',
searchName: DEFAULT_SEARCH_NAME,
results: [], // we don't really care
count: Math.ceil(pageCount / 10),
pageCount: pageCount,
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/test/search-results_test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {SearchaliciousResults} from '../search-results';
import {DEFAULT_SEARCH_NAME} from '../utils/constants';
import {SearchaliciousEvents} from '../utils/enums';
import {SearchResultDetail} from '../events';

Expand All @@ -16,7 +17,7 @@ suite('searchalicious-results', () => {
results: Array<Record<string, unknown>>
) => {
const detail: SearchResultDetail = {
searchName: 'searchalicious',
searchName: DEFAULT_SEARCH_NAME,
results: results,
count: 3,
pageCount: 1,
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/utils/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export const FACET_TERM_OTHER = '--other--';

export const FACETS_DIVIDER = ',';

export const DEFAULT_SEARCH_NAME = 'searchalicious';