Skip to content

Commit

Permalink
refactor: correct linter issues
Browse files Browse the repository at this point in the history
  • Loading branch information
alambare committed Mar 4, 2025
1 parent a54ccf7 commit 1f47dfc
Show file tree
Hide file tree
Showing 14 changed files with 1,013 additions and 893 deletions.
3 changes: 1 addition & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ module.exports = {
custom: {
regex: '^I[A-Z]',
match: true
},
'prettier/prettier': ['error', { endOfLine: 'auto' }]
}
}
],
'@typescript-eslint/no-unused-vars': ['warn', { args: 'none' }],
Expand Down
70 changes: 16 additions & 54 deletions eodag_labextension/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,7 @@ def get(self):
query_dict = parse_qs(self.request.query)

provider = None
if (
"provider" in query_dict
and isinstance(query_dict["provider"], list)
and len(query_dict["provider"]) > 0
):
if "provider" in query_dict and isinstance(query_dict["provider"], list) and len(query_dict["provider"]) > 0:
provider = query_dict.pop("provider")[0]
provider = None if not provider or provider == "null" else provider

Expand Down Expand Up @@ -81,9 +77,7 @@ def get(self):
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
)
available_providers = eodag_api.available_providers(**available_providers_kwargs)

all_providers_list = [
dict(
Expand All @@ -98,35 +92,25 @@ def get(self):
all_providers_list.sort(key=lambda x: (x["priority"] * -1, x["provider"]))

returned_providers = []
if (
"keywords" in query_dict
and isinstance(query_dict["keywords"], list)
and len(query_dict["keywords"]) > 0
):
if "keywords" in query_dict and isinstance(query_dict["keywords"], list) and len(query_dict["keywords"]) > 0:
# 1. List providers starting with given keyword
first_keyword = query_dict["keywords"][0].lower()
returned_providers = [
p
for p in all_providers_list
if p["provider"].lower().startswith(first_keyword)
]
returned_providers = [p for p in all_providers_list if p["provider"].lower().startswith(first_keyword)]
providers_ids = [p["provider"] for p in returned_providers]

# 2. List providers containing given keyword
returned_providers += [
p
for p in all_providers_list
if first_keyword in p["provider"].lower()
and p["provider"] not in providers_ids
if first_keyword in p["provider"].lower() and p["provider"] not in providers_ids
]
providers_ids = [p["provider"] for p in returned_providers]

# 3. List providers containing given keyword in decription
returned_providers += [
p
for p in all_providers_list
if first_keyword in (p["description"] or "").lower()
and p["provider"] not in providers_ids
if first_keyword in (p["description"] or "").lower() and p["provider"] not in providers_ids
]
else:
returned_providers = all_providers_list
Expand All @@ -144,11 +128,7 @@ def get(self):
query_dict = parse_qs(self.request.query)

provider = None
if (
"provider" in query_dict
and isinstance(query_dict["provider"], list)
and len(query_dict["provider"]) > 0
):
if "provider" in query_dict and isinstance(query_dict["provider"], list) and len(query_dict["provider"]) > 0:
provider = query_dict.pop("provider")[0]
provider = None if not provider or provider == "null" else provider

Expand All @@ -164,40 +144,30 @@ def get(self):
):
# 1. List product types starting with given keywords
first_keyword = query_dict["keywords"][0].lower()
returned_product_types = [
pt
for pt in all_product_types
if pt["ID"].lower().startswith(first_keyword)
]
returned_product_types = [pt for pt in all_product_types if pt["ID"].lower().startswith(first_keyword)]
returned_product_types_ids = [pt["ID"] for pt in returned_product_types]

# 2. List product types containing keyword
returned_product_types += [
pt
for pt in all_product_types
if first_keyword in pt["ID"].lower()
and pt["ID"] not in returned_product_types_ids
]
returned_product_types_ids += [
pt["ID"] for pt in returned_product_types
if first_keyword in pt["ID"].lower() and pt["ID"] not in returned_product_types_ids
]
returned_product_types_ids += [pt["ID"] for pt in returned_product_types]

# 3. Append guessed product types
guess_kwargs = {}
# ["aa bb", "cc-dd_ee"] to "*aa* AND *bb* AND *cc-dd_ee*"
for k, v in query_dict.items():
guess_kwargs[k] = " AND ".join(
re.sub(r"(\S+)", r"*\1*", " ".join(v)).split(" ")
)
guess_kwargs[k] = " AND ".join(re.sub(r"(\S+)", r"*\1*", " ".join(v)).split(" "))

# guessed product types ids
guessed_ids_list = eodag_api.guess_product_type(**guess_kwargs)
# product types with full associated metadata
returned_product_types += [
pt
for pt in all_product_types
if pt["ID"] in guessed_ids_list
and pt["ID"] not in returned_product_types_ids
if pt["ID"] in guessed_ids_list and pt["ID"] not in returned_product_types_ids
]
else:
returned_product_types = all_product_types
Expand Down Expand Up @@ -246,9 +216,7 @@ def post(self, product_type):
arguments = dict((k, v) for k, v in arguments.items() if v is not None)

try:
products = eodag_api.search(
productType=product_type, count=True, **arguments
)
products = eodag_api.search(productType=product_type, count=True, **arguments)
except ValidationError as e:
self.set_status(400)
self.finish({"error": e.message})
Expand All @@ -263,9 +231,7 @@ def post(self, product_type):
return
except AuthenticationError as e:
self.set_status(403)
self.finish(
{"error": f"AuthenticationError: Please check your credentials ({e})"}
)
self.finish({"error": f"AuthenticationError: Please check your credentials ({e})"})
return
except Exception as e:
self.set_status(502)
Expand Down Expand Up @@ -332,9 +298,7 @@ def get(self):
}
logger.error(queryables_kwargs)
try:
queryables_dict = eodag_api.list_queryables(
fetch_providers=False, **queryables_kwargs
)
queryables_dict = eodag_api.list_queryables(fetch_providers=False, **queryables_kwargs)
json_schema = queryables_dict.get_model().model_json_schema()
self._remove_null_defaults(json_schema)
json_schema["additionalProperties"] = queryables_dict.additional_properties
Expand All @@ -360,9 +324,7 @@ def setup_handlers(web_app, url_path):
product_types_pattern = url_path_join(base_url, url_path, "product-types")
reload_pattern = url_path_join(base_url, url_path, "reload")
providers_pattern = url_path_join(base_url, url_path, "providers")
guess_product_types_pattern = url_path_join(
base_url, url_path, "guess-product-type"
)
guess_product_types_pattern = url_path_join(base_url, url_path, "guess-product-type")
queryables_pattern = url_path_join(base_url, url_path, "queryables")
search_pattern = url_path_join(base_url, url_path, r"(?P<product_type>[\w\-\.]+)")
default_pattern = url_path_join(base_url, url_path, r".*")
Expand Down
42 changes: 28 additions & 14 deletions src/CodeGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,34 +66,48 @@ search_results = dag.search(`;
}
const filteredParameters = additionnalParameters.filter(
({ name, value }) => name && value && name !== '' && value !== ''
)
);

const extraParamEntries = Object.entries(extraParams).filter(([_, value]) => value !== undefined);
const extraParamEntries = Object.entries(extraParams).filter(
([_, value]) => value !== undefined
);

if (filteredParameters.length > 0 || extraParamEntries.length > 0) {
code += '\n' + tab + '**{\n';

// Map additionnalParameters
code += filteredParameters.map(({ name, value }) => {
const processedValue = Array.isArray(value)
? `[${value.map((item: any) => (typeof item === 'string' ? `"${item.trim()}"` : item)).join(', ')}]`
: typeof value === 'string'
code += filteredParameters
.map(({ name, value }) => {
const processedValue = Array.isArray(value)
? `[${value
.map((item: any) =>
typeof item === 'string' ? `"${item.trim()}"` : item
)
.join(', ')}]`
: typeof value === 'string'
? `"${value.trim()}"`
: value;
return `${tab + tab}"${name}": ${processedValue},`;
}).join('\n');
return `${tab + tab}"${name}": ${processedValue},`;
})
.join('\n');

// Map extra parameters dynamically
if (extraParamEntries.length > 0) {
if (filteredParameters.length > 0) code += '\n'; // Separate sections
code += extraParamEntries.map(([key, value]) => {
const processedValue = Array.isArray(value)
? `[${value.map((item: any) => (typeof item === 'string' ? `"${item.trim()}"` : item)).join(', ')}]`
: typeof value === 'string'
code += extraParamEntries
.map(([key, value]) => {
const processedValue = Array.isArray(value)
? `[${value
.map((item: any) =>
typeof item === 'string' ? `"${item.trim()}"` : item
)
.join(', ')}]`
: typeof value === 'string'
? `"${value.trim()}"`
: value;
return `${tab + tab}"${key}": ${processedValue},`;
}).join('\n');
return `${tab + tab}"${key}": ${processedValue},`;
})
.join('\n');
}

code += '\n' + `${tab}}`; // Close dictionary
Expand Down
12 changes: 6 additions & 6 deletions src/SearchService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ class SearchService {

// Map any extra dynamic properties (excluding already handled ones)
const excludedKeys = new Set([
"startDate",
"endDate",
"productType",
"geometry",
"provider",
"additionnalParameters"
'startDate',
'endDate',
'productType',
'geometry',
'provider',
'additionnalParameters'
]);

Object.keys(formValues).forEach(key => {
Expand Down
2 changes: 1 addition & 1 deletion src/browser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export class EodagBrowser extends React.Component<IProps, IState> {
const searchString = '# Code generated by eodag-labextension,';
const isReplaceCellExist =
cells.filter(cell => cell.node.innerText.includes(searchString)).length >
0
0
? true
: false;

Expand Down
Loading

0 comments on commit 1f47dfc

Please sign in to comment.