mirror of
https://dev.azure.com/hugendubel/ISA/_git/ISA-Frontend
synced 2025-12-28 22:42:11 +01:00
hotfix(catalog): correct regex pattern matching for Reihe line detection
Centralized the Reihe prefix pattern into a shared constant to ensure consistent matching across LineTypePipe and ReiheRoutePipe. The pattern now correctly matches "Reihe:", "Reihe/Set:", and "Set/Reihe:" prefixes. Additionally enhanced the ReiheRoutePipe to strip trailing numbers from series names (e.g., "Harry Potter 1" -> "Harry Potter") to improve search query accuracy when navigating to article search results. Changes: - Created REIHE_PREFIX_PATTERN constant for shared regex pattern - Updated LineTypePipe to use centralized pattern (fixed capture group index) - Updated ReiheRoutePipe to use centralized pattern and strip trailing numbers Ref: #5421
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { Pipe, PipeTransform } from '@angular/core';
|
||||
import { REIHE_PREFIX_PATTERN } from './reihe.constants';
|
||||
|
||||
@Pipe({
|
||||
name: 'lineType',
|
||||
@@ -7,8 +8,8 @@ import { Pipe, PipeTransform } from '@angular/core';
|
||||
})
|
||||
export class LineTypePipe implements PipeTransform {
|
||||
transform(value: string, ...args: any[]): 'text' | 'reihe' {
|
||||
const REIHE_REGEX = /^Reihe:\s*"(.+)\"$/g;
|
||||
const reihe = REIHE_REGEX.exec(value)?.[1];
|
||||
const REIHE_REGEX = new RegExp(`^${REIHE_PREFIX_PATTERN}:\\s*"(.+)"$`, 'g');
|
||||
const reihe = REIHE_REGEX.exec(value)?.[2];
|
||||
return reihe ? 'reihe' : 'text';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
import { ChangeDetectorRef, OnDestroy, Pipe, PipeTransform } from '@angular/core';
|
||||
import {
|
||||
ChangeDetectorRef,
|
||||
OnDestroy,
|
||||
Pipe,
|
||||
PipeTransform,
|
||||
} from '@angular/core';
|
||||
import { ApplicationService } from '@core/application';
|
||||
import { ProductCatalogNavigationService } from '@shared/services/navigation';
|
||||
import { isEqual } from 'lodash';
|
||||
import { Subscription, combineLatest, BehaviorSubject } from 'rxjs';
|
||||
import { distinctUntilChanged } from 'rxjs/operators';
|
||||
import { REIHE_PREFIX_PATTERN } from './reihe.constants';
|
||||
|
||||
@Pipe({
|
||||
name: 'reiheRoute',
|
||||
@@ -22,10 +28,13 @@ export class ReiheRoutePipe implements PipeTransform, OnDestroy {
|
||||
private application: ApplicationService,
|
||||
private cdr: ChangeDetectorRef,
|
||||
) {
|
||||
this.subscription = combineLatest([this.application.activatedProcessId$, this.value$])
|
||||
this.subscription = combineLatest([
|
||||
this.application.activatedProcessId$,
|
||||
this.value$,
|
||||
])
|
||||
.pipe(distinctUntilChanged(isEqual))
|
||||
.subscribe(([processId, value]) => {
|
||||
const REIHE_REGEX = /[";]|Reihe:/g; // Entferne jedes Semikolon, Anführungszeichen und den String Reihe:
|
||||
const REIHE_REGEX = new RegExp(`[";]|${REIHE_PREFIX_PATTERN}:`, 'g'); // Entferne jedes Semikolon, Anführungszeichen und den String Reihe:/Reihe/Set:/Set/Reihe:
|
||||
const reihe = value?.replace(REIHE_REGEX, '')?.trim();
|
||||
|
||||
if (!reihe) {
|
||||
@@ -33,9 +42,15 @@ export class ReiheRoutePipe implements PipeTransform, OnDestroy {
|
||||
return;
|
||||
}
|
||||
|
||||
const main_qs = reihe.split('/')[0];
|
||||
// Entferne Zahlen am Ende, die mit Leerzeichen, Komma, Slash oder Semikolon getrennt sind
|
||||
// Beispiele: "Harry Potter 1" -> "Harry Potter", "Harry Potter,1" -> "Harry Potter", "Harry Potter/2" -> "Harry Potter"
|
||||
const main_qs = reihe
|
||||
.split('/')[0]
|
||||
.replace(/[\s,;]+\d+$/g, '')
|
||||
.trim();
|
||||
|
||||
const path = this.navigation.getArticleSearchResultsPath(processId).path;
|
||||
const path =
|
||||
this.navigation.getArticleSearchResultsPath(processId).path;
|
||||
|
||||
this.result = {
|
||||
path,
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
/**
|
||||
* Shared regex pattern for matching Reihe line prefixes.
|
||||
* Matches: "Reihe:", "Reihe/Set:", or "Set/Reihe:"
|
||||
*/
|
||||
export const REIHE_PREFIX_PATTERN = '(Reihe|Reihe\\/Set|Set\\/Reihe)';
|
||||
Reference in New Issue
Block a user