Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ <h2>{{filterLabel+'.filters.head' | translate}}</h2>
}

@if ((filters | async)?.hasSucceeded) {
<div [class.visually-hidden]="filtersWithComputedVisibility !== (filters | async)?.payload?.length">
<div [class.visually-hidden]="getFinalFiltersComputed(this.currentConfiguration) !== (filters | async)?.payload?.length">
@for (filter of (filters | async)?.payload; track filter.name) {
<ds-search-filter (isVisibilityComputed)="countFiltersWithComputedVisibility($event)" [scope]="currentScope" [filter]="filter" [inPlaceSearch]="inPlaceSearch" [refreshFilters]="refreshFilters"></ds-search-filter>
}
</div>
}

@if(filtersWithComputedVisibility !== (filters | async)?.payload?.length) {
@if(getFinalFiltersComputed(this.currentConfiguration) !== (filters | async)?.payload?.length) {
<ngx-skeleton-loader [count]="defaultFilterCount"/>
}

Expand Down
134 changes: 130 additions & 4 deletions src/app/shared/search/search-filters/search-filters.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
BehaviorSubject,
Observable,
} from 'rxjs';
import { map } from 'rxjs/operators';
import {
filter,
map,
take,
} from 'rxjs/operators';

import {
APP_CONFIG,
Expand Down Expand Up @@ -82,9 +86,16 @@
searchLink: string;

/**
* Filters for which visibility has been computed
* Keeps track of the filters computed for each configuration during the current rendering cycle
* This array stores objects with configuration identifier and number of computed filters
*/
private currentFiltersComputed = [];

/**
* Stores the final count of computed filters for each configuration
* Used to determine when all filters for a configuration have been processed
*/
filtersWithComputedVisibility = 0;
private finalFiltersComputed = [];

subs = [];
filterLabel = 'search';
Expand Down Expand Up @@ -136,7 +147,122 @@

countFiltersWithComputedVisibility(computed: boolean) {
if (computed) {
this.filtersWithComputedVisibility += 1;
this.filters.pipe(

Check warning on line 150 in src/app/shared/search/search-filters/search-filters.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/shared/search/search-filters/search-filters.component.ts#L150

Added line #L150 was not covered by tests
// Get filter data and check if we need to increment the counter
map(filtersData => {
if (filtersData && filtersData.hasSucceeded && filtersData.payload) {
const totalFilters = filtersData.payload.length;
const currentComputed = this.getCurrentFiltersComputed(this.currentConfiguration);

Check warning on line 155 in src/app/shared/search/search-filters/search-filters.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/shared/search/search-filters/search-filters.component.ts#L154-L155

Added lines #L154 - L155 were not covered by tests

// If we've already computed all filters for this configuration
if (currentComputed >= totalFilters) {
// Register in finalFiltersComputed if not already registered
if (!this.findConfigInFinalFilters(this.currentConfiguration)) {
this.updateFinalFiltersComputed(this.currentConfiguration, totalFilters);

Check warning on line 161 in src/app/shared/search/search-filters/search-filters.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/shared/search/search-filters/search-filters.component.ts#L161

Added line #L161 was not covered by tests
}
return { shouldIncrement: false };

Check warning on line 163 in src/app/shared/search/search-filters/search-filters.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/shared/search/search-filters/search-filters.component.ts#L163

Added line #L163 was not covered by tests
}

// We haven't reached the total yet, proceed with increment
return {

Check warning on line 167 in src/app/shared/search/search-filters/search-filters.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/shared/search/search-filters/search-filters.component.ts#L167

Added line #L167 was not covered by tests
shouldIncrement: true,
totalFilters,
};
}
return { shouldIncrement: false };

Check warning on line 172 in src/app/shared/search/search-filters/search-filters.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/shared/search/search-filters/search-filters.component.ts#L172

Added line #L172 was not covered by tests
}),
// Only continue if we need to increment the counter
filter(result => result.shouldIncrement),

Check warning on line 175 in src/app/shared/search/search-filters/search-filters.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/shared/search/search-filters/search-filters.component.ts#L175

Added line #L175 was not covered by tests
// Increment the counter for the current configuration
map(result => {
const filterConfig = this.findConfigInCurrentFilters(this.currentConfiguration);

Check warning on line 178 in src/app/shared/search/search-filters/search-filters.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/shared/search/search-filters/search-filters.component.ts#L178

Added line #L178 was not covered by tests

if (filterConfig) {
// Update existing counter
filterConfig.filtersComputed += 1;

Check warning on line 182 in src/app/shared/search/search-filters/search-filters.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/shared/search/search-filters/search-filters.component.ts#L182

Added line #L182 was not covered by tests
} else {
// Create new counter entry
this.currentFiltersComputed.push({

Check warning on line 185 in src/app/shared/search/search-filters/search-filters.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/shared/search/search-filters/search-filters.component.ts#L185

Added line #L185 was not covered by tests
configuration: this.currentConfiguration,
filtersComputed: 1,
});
}

// Pass along the total and updated count
return {

Check warning on line 192 in src/app/shared/search/search-filters/search-filters.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/shared/search/search-filters/search-filters.component.ts#L192

Added line #L192 was not covered by tests
totalFilters: result.totalFilters,
currentComputed: this.getCurrentFiltersComputed(this.currentConfiguration),
};
}),
// Check if we've reached the total after incrementing
map(result => {
if (result.currentComputed === result.totalFilters) {
// If we've reached the total, update final filters count
this.updateFinalFiltersComputed(this.currentConfiguration, result.currentComputed);

Check warning on line 201 in src/app/shared/search/search-filters/search-filters.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/shared/search/search-filters/search-filters.component.ts#L201

Added line #L201 was not covered by tests
}
return result;

Check warning on line 203 in src/app/shared/search/search-filters/search-filters.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/shared/search/search-filters/search-filters.component.ts#L203

Added line #L203 was not covered by tests
}),
).pipe(take(1)).subscribe(); // Execute the pipeline and immediately unsubscribe
}
}

/**
* Finds a configuration entry in the currentFiltersComputed array
* @param configuration The configuration identifier to search for
* @returns The filter configuration object if found, otherwise undefined
*/
private findConfigInCurrentFilters(configuration: string) {
return this.currentFiltersComputed.find(
(configFilter) => configFilter.configuration === configuration,

Check warning on line 216 in src/app/shared/search/search-filters/search-filters.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/shared/search/search-filters/search-filters.component.ts#L215-L216

Added lines #L215 - L216 were not covered by tests
);
}

/**
* Finds a configuration entry in the finalFiltersComputed array
* @param configuration The configuration identifier to search for
* @returns The filter configuration object if found, otherwise undefined
*/
private findConfigInFinalFilters(configuration: string) {
return this.finalFiltersComputed.find(
(configFilter) => configFilter.configuration === configuration,

Check warning on line 227 in src/app/shared/search/search-filters/search-filters.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/shared/search/search-filters/search-filters.component.ts#L227

Added line #L227 was not covered by tests
);
}

/**
* Updates or adds a new entry in the finalFiltersComputed array
* @param configuration The configuration identifier to update
* @param count The number of computed filters to set for this configuration
*/
private updateFinalFiltersComputed(configuration: string, count: number) {
const filterConfig = this.findConfigInFinalFilters(configuration);

Check warning on line 237 in src/app/shared/search/search-filters/search-filters.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/shared/search/search-filters/search-filters.component.ts#L237

Added line #L237 was not covered by tests

if (filterConfig) {
filterConfig.filtersComputed = count;

Check warning on line 240 in src/app/shared/search/search-filters/search-filters.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/shared/search/search-filters/search-filters.component.ts#L240

Added line #L240 was not covered by tests
} else {
this.finalFiltersComputed.push({

Check warning on line 242 in src/app/shared/search/search-filters/search-filters.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/shared/search/search-filters/search-filters.component.ts#L242

Added line #L242 was not covered by tests
configuration,
filtersComputed: count,
});
}
}

/**
* Gets the current number of computed filters for a specific configuration
* @param configuration The configuration identifier to get the count for
* @returns The number of computed filters, or 0 if none found
*/
private getCurrentFiltersComputed(configuration: string) {
const configFilter = this.findConfigInCurrentFilters(configuration);

Check warning on line 255 in src/app/shared/search/search-filters/search-filters.component.ts

View check run for this annotation

Codecov / codecov/patch

src/app/shared/search/search-filters/search-filters.component.ts#L255

Added line #L255 was not covered by tests
return configFilter?.filtersComputed || 0;
}

/**
* Gets the final number of computed filters for a specific configuration
* @param configuration The configuration identifier to get the count for
* @returns The number of computed filters in the final state, or 0 if none found
*/
getFinalFiltersComputed(configuration: string): number {
const configFilter = this.findConfigInFinalFilters(configuration);
return configFilter?.filtersComputed || 0;
}
}
Loading