Skip to content

[ALS-8139] Make sure facets have their references #340

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

Merged
merged 2 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion src/lib/components/explorer/FacetCategory.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
/>
{/if}
{#each facetsToDisplay as facet}
<FacetItem {facet} {facetCategory} facetParent={undefined} {textFilterValue} />
<FacetItem {facet} {facetCategory} {textFilterValue} />
{/each}
{#if facets?.length > numFacetsToShow && !textFilterValue}
<button
Expand Down
19 changes: 1 addition & 18 deletions src/lib/components/explorer/FacetItem.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,8 @@

export let facet: Facet;
export let facetCategory: DictionaryFacetResult;
export let facetParent: Facet | undefined;
export let textFilterValue: string | undefined;

if (facetParent) {
facet.parentRef = {
name: facetParent.name,
display: facetParent.display,
description: facetParent.description,
};
}

if (facetCategory) {
facet.categoryRef = {
name: facetCategory.name,
display: facetCategory.display,
description: facetCategory.description,
};
}

let open = false;

function toggleOpen() {
Expand Down Expand Up @@ -125,7 +108,7 @@
{#if open && facetsToDisplay !== undefined && facetsToDisplay?.length > 0}
<div class="flex flex-col ml-4" data-testId={`facet-${facet.name}-children`}>
{#each facetsToDisplay as child}
<svelte:self facet={child} {facetCategory} facetParent={facet} {textFilterValue} />
<svelte:self facet={child} {facetCategory} {textFilterValue} />
{/each}
</div>
{/if}
Expand Down
28 changes: 28 additions & 0 deletions src/lib/services/dictionary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,41 @@ export async function updateFacetsFromSearch(
if (facets.length === 0 && search.length === 0) {
initializeHiddenFacets(response);
}
processFacetResults(response);
return response;
} catch (error) {
console.error('Failed to update facets from search:', error);
throw error;
}
}

// Adds references to parent and category
function processFacetResults(response: DictionaryFacetResult[]) {
response.forEach((category) => {
category.facets.forEach((facet) => {
facet.categoryRef = {
name: category.name,
display: category.display,
description: category.description,
};
if (facet.children?.length) {
facet.children.forEach((child) => {
child.categoryRef = {
name: category.name,
display: category.display,
description: category.description,
};
child.parentRef = {
name: facet.name,
display: facet.display,
description: facet.description,
};
});
}
});
});
}

export async function getConceptDetails(
conceptPath: string,
dataset: string,
Expand Down
Loading