From d0244ff2100d592b9d3cb969a5835969b4875f51 Mon Sep 17 00:00:00 2001 From: Sylvain Brunato Date: Thu, 18 Jan 2024 17:00:04 +0100 Subject: [PATCH 01/19] feat: providers list handler --- eodag_labextension/handlers.py | 44 ++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/eodag_labextension/handlers.py b/eodag_labextension/handlers.py index e0fa6b6..49489e3 100644 --- a/eodag_labextension/handlers.py +++ b/eodag_labextension/handlers.py @@ -16,17 +16,51 @@ class ProductTypeHandler(APIHandler): - """Product type listing handler + """Product type listing handlerd""" - .. note:: + @tornado.web.authenticated + def get(self): + """Get endpoint""" + + get_product_types_kwargs = {} + query_dict = parse_qs(self.request.query) + if "provider" in query_dict and isinstance(query_dict["provider"], list) and len(query_dict["provider"]) > 0: + get_product_types_kwargs["provider"] = query_dict["provider"][0] + product_types = get_product_types(**get_product_types_kwargs) + + self.write(json.dumps(product_types)) - Product types endpoint filtered by provider not implemented""" + +class ProvidersHandler(APIHandler): + """Providers listing handler""" @tornado.web.authenticated def get(self): """Get endpoint""" - self.write(json.dumps(get_product_types())) + available_providers_kwargs = {} + query_dict = parse_qs(self.request.query) + if ( + "product_type" in query_dict + and isinstance(query_dict["product_type"], list) + and len(query_dict["product_type"]) > 0 + ): + available_providers_kwargs["product_type"] = query_dict["product_type"][0] + available_providers = eodag_api.available_providers(**available_providers_kwargs) + + providers_list = [ + dict( + provider=provider, + priority=conf.priority, + description=getattr(conf, "description", None), + url=getattr(conf, "url", None), + ) + for provider, conf in eodag_api.providers_config.items() + if provider in available_providers + ] + providers_list.sort(key=lambda x: (x["priority"] * -1, x["provider"])) + + self.write(json.dumps(providers_list)) class GuessProductTypeHandler(APIHandler): @@ -121,12 +155,14 @@ def setup_handlers(web_app, url_path): # matching patterns host_pattern = ".*$" product_types_pattern = url_path_join(base_url, url_path, "product-types") + providers_pattern = url_path_join(base_url, url_path, "providers") guess_product_types_pattern = url_path_join(base_url, url_path, "guess-product-type") search_pattern = url_path_join(base_url, url_path, r"(?P[\w-]+)") # handlers added for each pattern handlers = [ (product_types_pattern, ProductTypeHandler), + (providers_pattern, ProvidersHandler), (guess_product_types_pattern, GuessProductTypeHandler), (MethodAndPathMatch("POST", search_pattern), SearchHandler), ] From cacbb7302a087803994adc41c9b52925a94066d8 Mon Sep 17 00:00:00 2001 From: PUECH Fabien Date: Fri, 19 Jan 2024 17:28:11 +0100 Subject: [PATCH 02/19] feat: add provider select --- src/Autocomplete.tsx | 35 +++++++++++++-------- src/FormComponent.tsx | 73 +++++++++++++++++++++++++++++++++++++++++-- src/types.ts | 1 + 3 files changed, 94 insertions(+), 15 deletions(-) diff --git a/src/Autocomplete.tsx b/src/Autocomplete.tsx index 9b62b7d..0398674 100644 --- a/src/Autocomplete.tsx +++ b/src/Autocomplete.tsx @@ -92,11 +92,13 @@ interface IProps { suggestions: OptionTypeBase[]; value: string; handleChange: any; + url: string; + label: string; } class IntegrationReactSelect extends React.Component { render() { - const { suggestions, value, handleChange } = this.props; + const { label, url, suggestions, value, handleChange } = this.props; const currentValue: OptionTypeBase = value ? suggestions.find(e => e.value === value) : undefined; @@ -108,12 +110,9 @@ class IntegrationReactSelect extends React.Component { `${EODAG_SERVER_ADRESS}` ); - return fetch( - URLExt.join(_eodag_server, `guess-product-type?keywords=${inputValue}`), - { - credentials: 'same-origin' - } - ) + return fetch(URLExt.join(_eodag_server, `${url}=${inputValue}`), { + credentials: 'same-origin' + }) .then(response => { if (response.status >= 400) { showErrorMessage( @@ -125,11 +124,21 @@ class IntegrationReactSelect extends React.Component { return response.json(); }) .then(products => { - const guessProductTypes = map(products, product => ({ - value: product.ID, - label: product.ID, - description: product.abstract - })); + const guessProductTypes = map(products, product => { + if ('provider' in product) { + return { + value: product.provider, + label: product.provider, + description: product.description + }; + } else { + return { + value: product.ID, + label: product.ID, + description: product.abstract + }; + } + }); return guessProductTypes; }); }; @@ -142,7 +151,7 @@ class IntegrationReactSelect extends React.Component { return (