Skip to content

Commit

Permalink
move search function into async
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffibm committed May 7, 2024
1 parent e9398aa commit 4b0692c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const FilterNamespace = ({ domains, onSearch }) => {
id="search-method"
labelText={__('Search')}
placeholder={__('Search with Name or Relative path')}
onClear={() => onSearch('')}
onClear={() => onSearch({ searchText: noSelect })}
onChange={(event) => onSearch({ searchText: event.target.value || noSelect })}
/>
</div>
Expand Down
23 changes: 17 additions & 6 deletions app/javascript/components/AeInlineMethod/NamespaceSelector.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,29 @@ const NamespaceSelector = ({ onSelectMethod, selectedIds }) => {
.then(([{ domains }, { methods }]) => updateData({ loading: false, domains, methods: formatMethods(methods) }));
}, []);

const retrieveMethods = async(url) => {
const response = await http.get(url);
return response.methods;
};

/** Function to handle search text and drop-down item onchange events. */
const onSearch = (filterData) => {
const onSearch = async(filterData) => {
updateData({ loading: true });
const searchText = filterData.searchText ? filterData.searchText : data.searchText;
const selectedDomain = filterData.selectedDomain ? filterData.selectedDomain : data.selectedDomain;
const url = searchUrl(selectedDomain, searchText);
http.get(url)
.then(({ methods }) => {
updateData({
loading: false, selectedDomain, searchText, methods: formatMethods(methods),
});
try {
const methods = await retrieveMethods(url);
updateData({
loading: false,
selectedDomain,
searchText,
methods: formatMethods(methods),
});
} catch (error) {
console.error('Error retrieving methods:', error);
updateData({ loading: false }); // Update loading state even if there's an error
}
};

/** Function to handle the click events for the list. */
Expand Down

0 comments on commit 4b0692c

Please sign in to comment.