Skip to content

Commit

Permalink
fix: hierarchy filters errors (#91)
Browse files Browse the repository at this point in the history
Co-authored-by: Julien Corny <[email protected]>
Co-authored-by: Etienne Delclaux <[email protected]>
  • Loading branch information
3 people authored Dec 12, 2024
1 parent bd4432b commit 20a5e41
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 14 deletions.
2 changes: 1 addition & 1 deletion backend/gn_module_zh/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def main_search(query, json):
# --- Hierarchy search
hierarchy = json.get("hierarchy")
if hierarchy is not None and basin is not None:
query = filter_hierarchy(query, json=hierarchy, basin=basin[0].get("name"))
query = filter_hierarchy(query, json=hierarchy, basin=basin["name"])

return query

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ <h5>Rubrique</h5>
<option
class="option-title"
[value]="field.name"
disabled
>
{{ field.name | uppercase }}
</option>
Expand All @@ -36,6 +37,7 @@ <h5>Rubrique</h5>
<option
*ngIf="cat?.name"
[value]="cat.name"
[disabled]="cat.subcategory.length !== 1"
>
<span>&nbsp;{{ cat.name | capitalize }}</span>
</option>
Expand All @@ -60,7 +62,6 @@ <h5>Attribut</h5>
[parentFormControl]="localForm.controls.attributes"
keyLabel="attribut"
(onChange)="attributesChanged($event)"
[multiple]="knowledges.length"
/>
</div>
<div class="pr-0 col-lg-3 col-6">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { HierarchyField, HierarchyFields, Note, RiverBasin } from '../../models/
import { TableColumn } from '../../commonComponents/table/table-interface';

type Data = {
kownledges: string[];
knowledges: string[];
field: string;
attributes: string;
};
Expand Down Expand Up @@ -87,7 +87,9 @@ export class ZhHierarchySearchTableComponent implements OnInit {
this.fields = [];
this.notes = [];
})
.finally(() => {});
.finally(() => {
this.updateAttributesAndKnowledgeForm();
});
}
}

Expand All @@ -110,9 +112,6 @@ export class ZhHierarchySearchTableComponent implements OnInit {
}

fieldChanged(event) {
this.localForm.controls['attributes'].reset();
this.localForm.controls['knowledges'].reset();

const filteredNotes = this.notes.filter(
(item) =>
(item.volet == event && item.rubrique == null && item.sousrubrique == null) ||
Expand All @@ -131,11 +130,29 @@ export class ZhHierarchySearchTableComponent implements OnInit {
this.knowledges = this.getKnowledge(this.attributes[0]);
}

if (this.attributes.length > 0) {
this.localForm.controls['attributes'].setValue([this.attributes[0]]);
// Update the form
this.updateAttributesAndKnowledgeForm();
}

updateAttributesAndKnowledgeForm() {
const knowledgeControl = this.localForm.controls['knowledges'];
const attributesControl = this.localForm.controls['attributes'];

attributesControl.reset();
knowledgeControl.reset();

if (this.attributes.length) {
attributesControl.enable();
attributesControl.setValue([this.attributes[0]]);
} else {
attributesControl.disable();
}

if (this.knowledges.length > 0) {
this.localForm.controls['knowledges'].setValue([this.knowledges[0]]);
knowledgeControl.enable();
knowledgeControl.setValue(this.knowledges[0]);
} else {
knowledgeControl.disable();
}
}

Expand Down Expand Up @@ -170,9 +187,17 @@ export class ZhHierarchySearchTableComponent implements OnInit {
const form = this.initialForm();
form.patchValue(this.localForm.value);
this.data.push(form);
// Reset all form data
this.reset();
let knowledges_array = [];
this.data.value.forEach((element) => {
if (element['knowledges'] !== null && !Array.isArray(element['knowledges'])) {
// avoid object object in 'connaissance' column of the frontend table
knowledges_array.push(element['knowledges']);
element['knowledges'] = knowledges_array;
knowledges_array = [];
}
});
}
this.reset();
}

onDeleteFilter(event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ <h4>Recherche hiérarchisation</h4>
<div class="card-body">
<div
class="row"
*ngIf="riverBasin?.value?.length > 0; else noZone"
*ngIf="riverBasin?.value?.code; else noZone"
>
<div class="col-12">
<zh-hierarchy-search-table
[form]="form"
[riverBasin]="riverBasin?.value[0]"
[riverBasin]="riverBasin?.value"
></zh-hierarchy-search-table>
</div>
</div>
Expand Down
2 changes: 2 additions & 0 deletions frontend/app/zh-search/zh-search.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ export class ZhSearchComponent implements OnInit {
onReset() {
this._searchService.reset();
// Emit empty object to search all ZH
this.hierarchySearchToggled = false;
this.advancedSearchToggled = false;
this.onSearch.emit();
}

Expand Down

0 comments on commit 20a5e41

Please sign in to comment.