Skip to content

Commit

Permalink
wc - Minor code clean
Browse files Browse the repository at this point in the history
Signed-off-by: gpveronica <[email protected]>
  • Loading branch information
gpveronica committed Oct 26, 2023
1 parent 8e79953 commit 538fd27
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/webcomponents/commons/filters/cellbase-search-autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,10 @@ export default class CellbaseSearchAutocomplete extends LitElement {
maxItems: 0, // No limit set
minimumInputLength: 3, // Only start searching when the user has input 3 or more characters
placeholder: this.RESOURCES[this.resource].placeholder,
fields: this.RESOURCES[this.resource].fields,
filterResults: this.#filterResults,
viewResultStyle: this.#viewResultStyle,
viewResult: this.#viewResult,
viewSelection: result => result[this.searchField],
// TODO Vero: change name to fetch
source: async (params, success, failure) => {
const page = params?.data?.page || 1;
Expand All @@ -238,33 +241,29 @@ export default class CellbaseSearchAutocomplete extends LitElement {
...this.RESOURCES[this.resource].queryParams,
skip: (page - 1) * this._config.limit,
};
const options = {};
if (params?.data?.term) {
const currentSearchField = this.RESOURCES[this.resource].getSearchField(params.data.term);
this.searchField = currentSearchField;
// Get the query param field. It will vary with the text typed by the user according to a regex
this.searchField = this.RESOURCES[this.resource].getSearchField(params.data.term);
// Set the query params
const queryParamsField = {
[`${currentSearchField}`]: `~/${params?.data?.term}/i`,
[this.searchField]: `~/${params?.data?.term}/i`,
...queryParams,
};
// Query cellbase with the appropriate resource params
try {
const response = await this.cellbaseClient.get(
this.RESOURCES[this.resource].category,
this.RESOURCES[this.resource].subcategory,
"",
this.RESOURCES[this.resource].operation,
queryParamsField,
options);
queryParamsField);
success(response);
} catch (error) {
// TODO Vero 20230928: manage failure
console.log(error);
}
}
},
filterResults: results => this.#filterResults(results),
viewResult: result => this.#viewResult(result),
viewResultStyle: () => this.#viewResultStyle(),
viewSelection: result => result[this.searchField],
};
}

Expand Down

0 comments on commit 538fd27

Please sign in to comment.