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

feat: providers list handler #127

Merged
merged 19 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
feat: change url useFetchSuggestions
  • Loading branch information
PUECH Fabien committed Feb 6, 2024
commit b331bbb6a0c1eeabad94729994416c9bcf95ece6
3 changes: 1 addition & 2 deletions src/FormComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ export const FormComponent: FC<IProps> = ({
queryParams: providersValue
? `product-types?provider=${providersValue}`
: 'product-types',

onSuccess: (products: IProduct[]) => {
const productTypeList: IOptionTypeBase[] = map(products, product => ({
value: product.ID,
Expand Down Expand Up @@ -209,7 +208,7 @@ export const FormComponent: FC<IProps> = ({
placeholder="S2_..."
value={value}
loadSuggestions={(inputValue: string) =>
loadProductTypesSuggestions(inputValue)
loadProductTypesSuggestions(providersValue, inputValue)
}
handleChange={(e: IOptionTypeBase | null) => {
onChange(e?.value);
Expand Down
25 changes: 19 additions & 6 deletions src/hooks/useFetchSuggestions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,21 @@ import { IOptionTypeBase } from './../FormComponent';
import { EODAG_SERVER_ADRESS } from './../config';

const useFetchSuggestions = () => {
const guessProductTypes = async (inputValue: string) => {
const guessProductTypes = async (
providerValue: string,
inputValue: string
) => {
const _serverSettings = ServerConnection.makeSettings();
const _eodag_server = URLExt.join(
_serverSettings.baseUrl,
`${EODAG_SERVER_ADRESS}`
);

return fetch(
URLExt.join(_eodag_server, `guess-product-type?keywords=${inputValue}`),
URLExt.join(
_eodag_server,
`guess-product-type?provider=${providerValue}&keywords=${inputValue}`
),
{
credentials: 'same-origin'
}
Expand All @@ -39,10 +45,17 @@ const useFetchSuggestions = () => {
});
};

const loadSuggestions = (inputValue: string) =>
new Promise<IOptionTypeBase[]>(resolve => {
resolve(guessProductTypes(inputValue));
});
// const loadSuggestions = (providerValue: string, inputValue: string) =>
// new Promise<IOptionTypeBase[]>(resolve => {
// resolve(guessProductTypes(providerValue, inputValue));
// });

const loadSuggestions = async (
providerValue: string,
inputValue: string
): Promise<IOptionTypeBase[]> => {
return await guessProductTypes(providerValue, inputValue);
};
return loadSuggestions;
};

Expand Down