Skip to content

Commit

Permalink
[Console] Add a function to filter terms
Browse files Browse the repository at this point in the history
  • Loading branch information
yuliacech committed Jun 4, 2024
1 parent c4db1de commit 706f242
Showing 1 changed file with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ export const getDocumentationLinkFromAutocomplete = (
}
return null;
};
/*
* Helper function that filters out suggestions without a name.
*/
const filterTermsWithoutName = (terms: ResultTerm[]): ResultTerm[] =>
terms.filter((term) => term.name !== undefined);

/*
* This function returns an array of completion items for the request method
Expand Down Expand Up @@ -140,9 +145,7 @@ export const getUrlPathCompletionItems = (
};
if (autoCompleteSet && autoCompleteSet.length > 0) {
return (
autoCompleteSet
// filter autocomplete items without a name
.filter(({ name }) => Boolean(name))
filterTermsWithoutName(autoCompleteSet)
// map autocomplete items to completion items
.map((item) => {
return {
Expand Down Expand Up @@ -202,9 +205,7 @@ export const getUrlParamsCompletionItems = (
endColumn: position.column,
};
return (
context.autoCompleteSet
// filter autocomplete items without a name
.filter(({ name }) => Boolean(name))
filterTermsWithoutName(context.autoCompleteSet)
// map autocomplete items to completion items
.map((item) => {
return {
Expand Down Expand Up @@ -310,9 +311,7 @@ const getSuggestions = (
endColumn,
};
return (
autocompleteSet
// filter out items that don't have name
.filter(({ name }) => name !== undefined)
filterTermsWithoutName(autocompleteSet)
// map autocomplete items to completion items
.map((item) => {
const suggestion = {
Expand Down

0 comments on commit 706f242

Please sign in to comment.