Skip to content

Commit

Permalink
Display the tag name when clicking on a tag in the search results
Browse files Browse the repository at this point in the history
  • Loading branch information
crisnicandrei committed Jan 16, 2025
1 parent eb42280 commit 298c354
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ describe('ArchiveSearchComponent', () => {

component.onTagClick([new TagVO({ name: 'Tag1', tagId: 1 })]);

expect(component.searchByTag.emit).toHaveBeenCalledWith(1);
expect(component.searchByTag.emit).toHaveBeenCalledWith({
tagId: 1,
tagName: 'Tag1',
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ import {
})
export class ArchiveSearchComponent implements OnInit {
@Output() search = new EventEmitter<string>();
@Output() searchByTag = new EventEmitter<number>();
@Output() searchByTag = new EventEmitter<{
tagId: number;
tagName: string;
}>();

public archive: ArchiveVO;
private valueChangesSubscription: Subscription;
Expand Down Expand Up @@ -127,7 +130,7 @@ export class ArchiveSearchComponent implements OnInit {

public onTagClick(tag: TagVO[]): void {
this.tag = tag;
this.searchByTag.emit(tag[0].tagId);
this.searchByTag.emit({ tagId: tag[0].tagId, tagName: tag[0].name });

this.valueChangesSubscription.unsubscribe();
this.searchForm.patchValue({ query: `tag:"${tag[0].name}"` });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { of } from 'rxjs';
import { PublicProfileService } from '@public/services/public-profile/public-profile.service';
import { Router } from '@angular/router';
import { PublicArchiveComponent } from './public-archive.component';
import { ArchiveVO } from '@models/index';

Check failure on line 9 in src/app/public/components/public-archive/public-archive.component.spec.ts

View workflow job for this annotation

GitHub Actions / lint

`@models/index` import should occur before import of `./public-archive.component`

const publicProfileServiceMock = {
publicRoot$: () => of({}),
Expand Down Expand Up @@ -76,12 +77,12 @@ describe('PublicArchiveComponent', () => {
const router = inject(Router);
spyOn(router, 'navigate');

instance.archive = { archiveId: '123' } as any;
instance.archive = new ArchiveVO({ archiveId: '123' });

instance.onTagClick('example-tag');
instance.onTagClick({ tagId: 'example-tag-id', tagName: 'tag-name' });

expect(router.navigate).toHaveBeenCalledWith(
['search-tag', '123', 'example-tag'],
['search-tag', '123', 'example-tag-id', 'tag-name'],
{ relativeTo: instance.route },
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,15 @@ export class PublicArchiveComponent implements OnInit, OnDestroy {
this.showProfileInformation = !this.showProfileInformation;
}

public onTagClick(tagName: string): void {
public onTagClick(tag): void {
try {
this.router.navigate(
['search-tag', this.archive.archiveId, `${tagName}`],
[
'search-tag',
this.archive.archiveId,
`${tag.tagId}`,
`${tag.tagName}`,
],
{
relativeTo: this.route,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<ng-container *ngTemplateOutlet="backToArchive"></ng-container>
<br />
<span class="search-results">Search results for </span>
<span class="search-results search-results-param">{{ query }}</span>
<span class="search-results search-results-param">{{ searchString }}</span>
</div>
<div class="search-results-view">
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export class PublicSearchResultsComponent implements OnInit, OnDestroy {
public waiting = false;
public query = '';
public tags = [];
public searchString = '';

public archivePath = ['..', '..', '..'];

Expand All @@ -31,10 +32,14 @@ export class PublicSearchResultsComponent implements OnInit, OnDestroy {
if (this.route.params) {
this.paramsSubscription = this.route.params.subscribe((params) => {
this.archivePath = ['/p/archive', params.publicArchiveNbr];

this.query = params.query ? params.query : '';
this.tags = params.tagId ? [new TagVO({ tagId: params.tagId })] : [];

this.searchString = this.query
? this.query
: `Keyword: ${params.tagName}`;

this.searchSubscription = this.searchService
.getResultsInPublicArchive(this.query, this.tags, params.archiveId)
.subscribe((response) => {
Expand Down
2 changes: 1 addition & 1 deletion src/app/public/public.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const routes: RoutesWithData = [
component: PublicSearchResultsComponent,
},
{
path: 'search-tag/:archiveId/:tagId',
path: 'search-tag/:archiveId/:tagId/:tagName',
component: PublicSearchResultsComponent,
},
{
Expand Down

0 comments on commit 298c354

Please sign in to comment.