Skip to content

Commit

Permalink
Merge pull request #1524 from musicEnfanthen/develop
Browse files Browse the repository at this point in the history
fix(core): simplify conversion of full text search response
  • Loading branch information
musicEnfanthen authored May 28, 2024
2 parents 1b2d7ac + f8c7a5d commit b0ccf3d
Show file tree
Hide file tree
Showing 10 changed files with 310 additions and 90 deletions.
6 changes: 6 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@
"modifiers": ["readonly"],
"format": ["UPPER_CASE"],
"trailingUnderscore": "allow"
},
{
"selector": "objectLiteralProperty",
"format": ["camelCase", "UPPER_CASE", "snake_case"],
"leadingUnderscore": "allow",
"trailingUnderscore": "allow"
}
],
"@typescript-eslint/no-empty-function": "off",
Expand Down
5 changes: 2 additions & 3 deletions src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
import { Location } from '@angular/common';
import { Component, DebugElement } from '@angular/core';
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { Router, Routes } from '@angular/router';
import { RouterTestingModule } from '@angular/router/testing';
import { Router, RouterModule, Routes } from '@angular/router';

import Spy = jasmine.Spy;

Expand Down Expand Up @@ -60,7 +59,7 @@ describe('AppComponent (DONE)', () => {
};

TestBed.configureTestingModule({
imports: [RouterTestingModule.withRoutes(MOCK_ROUTES)],
imports: [RouterModule.forRoot(MOCK_ROUTES)],
declarations: [
AppComponent,
FooterStubComponent,
Expand Down
306 changes: 264 additions & 42 deletions src/app/core/services/conversion-service/conversion.service.spec.ts

Large diffs are not rendered by default.

57 changes: 26 additions & 31 deletions src/app/core/services/conversion-service/conversion.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,17 +120,17 @@ export class ConversionService extends ApiService {
return searchResults;
}

searchResults.subjects = searchResults.subjects.reduce((acc, subject) => {
subject = this._cleanSubjectValueLabels(subject);
subject = this._cleanSubjectValues(subject);
// Clean up labels and values of result subjects
const cleanedSubjects = searchResults.subjects.map(subject => {
subject = this._cleanSubjectValueLabels({ ...subject });
subject = this._cleanSubjectValues({ ...subject });
return subject;
});

acc.push(subject);
return acc;
}, []);
// Remove duplicates from result subjects
const distinctSubjects = this._distinctSubjects(cleanedSubjects);

// Remove duplicates from response
searchResults.subjects = this._distinctSubjects(searchResults.subjects);
return searchResults;
return { ...searchResults, subjects: distinctSubjects };
}

/**
Expand Down Expand Up @@ -531,16 +531,14 @@ export class ConversionService extends ApiService {
*
* @returns {SubjectItemJson} The cleaned subject.
*/
_cleanSubjectValueLabels(subject: SubjectItemJson): SubjectItemJson {
let { valuelabel, obj_id } = subject;
private _cleanSubjectValueLabels(subject: SubjectItemJson): SubjectItemJson {
const { valuelabel, obj_id: objId } = subject;
const firstValueLabel = valuelabel?.[0];

if (valuelabel?.[0]) {
valuelabel[0] = valuelabel[0].replace(' (Richtext)', '');
}
if (obj_id) {
obj_id = obj_id.replace('_-_local', '');
}
return { ...subject, valuelabel, obj_id };
const modifiedValuelabel = firstValueLabel ? [firstValueLabel.replace(' (Richtext)', '')] : valuelabel;
const modifiedObjId = objId ? objId?.replace('_-_local', '') : '';

return { ...subject, valuelabel: modifiedValuelabel, obj_id: modifiedObjId };
}

/**
Expand All @@ -553,12 +551,12 @@ export class ConversionService extends ApiService {
*
* @returns {SubjectItemJson} The cleaned subject.
*/
_cleanSubjectValues(subject: SubjectItemJson): SubjectItemJson {
let tmpSubject = { ...subject };
const { valuetype_id, value } = tmpSubject;
private _cleanSubjectValues(subject: SubjectItemJson): SubjectItemJson {
const tmpSubject = { ...subject };
const { valuetype_id: valueTypeId, value } = tmpSubject;
const firstValue = value?.[0];

if (valuetype_id?.[0] === '14' && firstValue) {
if (valueTypeId?.[0] === '14' && firstValue) {
const { utf8str, textattr } = firstValue;
if (utf8str && textattr) {
const htmlstr = this._convertRichtextValue(utf8str, textattr);
Expand Down Expand Up @@ -693,14 +691,11 @@ export class ConversionService extends ApiService {
*/
private _convertLinkValue(prop: any, index: number): string {
// Add <a>-tag with click-directive; linktext is stored in "$&"
const firstValue = prop.value_firstprops[index];
const replaceValue =
'<a (click)="ref.navigateToResource(\'' +
prop.values[index] +
'\')">$& (' +
prop.value_restype[index] +
')</a>';
return firstValue.replace(firstValue, replaceValue);
const originalValue = prop.value_firstprops[index];
const linkTemplate = `<a (click)="ref.navigateToResource('${prop.values[index]}')">$& (${prop.value_restype[index]})</a>`;
const linkedValue = originalValue.replace(originalValue, linkTemplate);

return linkedValue;
}

/**
Expand Down Expand Up @@ -869,7 +864,7 @@ export class ConversionService extends ApiService {
private _getNodeIdFromAttributes(attributes: string): string {
// Identify node id from prop.attributes
// E.g. "hlist=17" or "selection=77"
return attributes.split('=')[1].toString();
return attributes?.split('=')[1]?.toString();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { Component, EventEmitter, Input, Output } from '@angular/core';
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { ReactiveFormsModule, UntypedFormBuilder } from '@angular/forms';
import { RouterTestingModule } from '@angular/router/testing';
import { RouterModule } from '@angular/router';

import { Observable, of as observableOf } from 'rxjs';
import Spy = jasmine.Spy;
Expand Down Expand Up @@ -67,7 +67,7 @@ describe('SearchResultListComponent', () => {
};

TestBed.configureTestingModule({
imports: [FontAwesomeTestingModule, NgbPaginationModule, ReactiveFormsModule, RouterTestingModule],
imports: [FontAwesomeTestingModule, NgbPaginationModule, ReactiveFormsModule, RouterModule],
declarations: [SearchResultListComponent, CompileHtmlComponent, TableStubComponent],
providers: [
{ provide: DataStreamerService, useValue: mockDataStreamerService },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { DebugElement } from '@angular/core';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ActivatedRoute } from '@angular/router';
import { RouterTestingModule } from '@angular/router/testing';
import { ActivatedRoute, RouterModule } from '@angular/router';

import { Observable, ReplaySubject } from 'rxjs';
import Spy = jasmine.Spy;
Expand Down Expand Up @@ -55,7 +54,7 @@ describe('EditionComplexComponent (DONE)', () => {
mockActivatedRoute = new ActivatedRouteStub();

await TestBed.configureTestingModule({
imports: [RouterTestingModule],
imports: [RouterModule],
declarations: [EditionComplexComponent],
providers: [
{ provide: ActivatedRoute, useValue: mockActivatedRoute },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ describe('SelectResultsComponent (DONE)', () => {
compDe = fixture.debugElement;

// Test data
const varKeys = ['Test', 'success'];
const varKeys = ['test', 'success'];
const b = [
{
Test: { type: 'test type', value: 'test value' },
test: { type: 'test type', value: 'test value' },
success: { type: 'success type', value: 'sucess value' },
},
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ describe('SparqlTableComponent (DONE)', () => {
compDe = fixture.debugElement;

// Test data
const varKeys = ['Test', 'success'];
const varKeys = ['test', 'success'];
const b = [
{
Test: { type: 'test type', value: 'test value' },
test: { type: 'test type', value: 'test value' },
success: { type: 'success type', value: 'sucess value' },
},
];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DebugElement } from '@angular/core';
import { ComponentFixture, fakeAsync, TestBed, waitForAsync } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { RouterModule } from '@angular/router';

import Spy = jasmine.Spy;

Expand Down Expand Up @@ -30,7 +30,7 @@ describe('SourceListComponent (DONE)', () => {

beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
imports: [RouterTestingModule],
imports: [RouterModule],
declarations: [SourceListComponent, CompileHtmlComponent, RouterLinkStubDirective],
}).compileComponents();
}));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { DebugElement } from '@angular/core';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ActivatedRoute } from '@angular/router';
import { RouterTestingModule } from '@angular/router/testing';
import { ActivatedRoute, RouterModule } from '@angular/router';

import { ActivatedRouteStub } from '@testing/router-stubs';

Expand Down Expand Up @@ -30,7 +29,7 @@ describe('EditionSeriesDetailComponent', () => {
const mockActivatedRoute: ActivatedRouteStub = new ActivatedRouteStub();

await TestBed.configureTestingModule({
imports: [RouterTestingModule],
imports: [RouterModule],
declarations: [EditionSeriesDetailComponent],
providers: [
{ provide: ActivatedRoute, useValue: mockActivatedRoute },
Expand Down

0 comments on commit b0ccf3d

Please sign in to comment.