Skip to content

Commit

Permalink
Fix URL encoding issue for links (#446)
Browse files Browse the repository at this point in the history
* Use [routerLink] with array instead of routerLink with interpolated string

* switch navigateByUrl to navigate with array format

* add some quick tests
  • Loading branch information
jean-the-coder authored Mar 7, 2024
1 parent c487c9f commit 43579df
Show file tree
Hide file tree
Showing 26 changed files with 67 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<fhir-coding *ngFor="let coding of rowItem.data" [coding]="coding"></fhir-coding>
</ng-template>
<ng-template #dataTypeReference>
<a routerLink="/explore/{{displayModel.source_id}}/resource/{{rowItem.data.reference}}">{{rowItem.data.display}}</a>
<a [routerLink]="['/explore', displayModel.source_id, 'resource', rowItem.data.reference]">{{rowItem.data.display}}</a>
</ng-template>
<ng-template #dataTypeString>{{rowItem.data}}</ng-template>
</td>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,49 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { TableComponent } from './table.component';
import { TableRowItemDataType } from './table-row-item';
import { RouterTestingModule } from '@angular/router/testing';
import { FastenDisplayModel } from 'src/lib/models/fasten/fasten-display-model';

describe('TableComponent', () => {
let component: TableComponent;
let fixture: ComponentFixture<TableComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [ TableComponent ]
imports: [ TableComponent, RouterTestingModule ]
})
.compileComponents();

fixture = TestBed.createComponent(TableComponent);
component = fixture.componentInstance;
component.displayModel = {
source_id: '123-456-789=',
} as FastenDisplayModel,
component.tableData = [
{
enabled: true,
label: 'hello',
data_type: TableRowItemDataType.Reference,
data: {
reference: 'aHR0cHM6Ly93d3cubWVyY3kubmV0L3NpdGVzL2RlZmF1bHQvZmlsZXMvZG9jdG9yX2ltYWdlcy9kZXNrdG9wLzE2NTk4ODYwNTktbS5qcGc=',
display: 'binary'
}
}
]
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});

it('encodes urls properly', () => {
spyOn(console, 'log').and.callThrough();
const link = fixture.debugElement.nativeElement.querySelector('a');
console.log(link);
expect(link.href).toContain(
'/explore/123-456-789%3D/resource/aHR0cHM6Ly93d3cubWVyY3kubmV0L3NpdGVzL2RlZmF1bHQvZmlsZXMvZG9jdG9yX2ltYWdlcy9kZXNrdG9wLzE2NTk4ODYwNTktbS5qcGc%3D'
);
});
});
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import type { Meta, StoryObj } from '@storybook/angular';
import { moduleMetadata, type Meta, type StoryObj } from '@storybook/angular';
import {TableComponent} from "./table.component";
import {TableRowItem} from "./table-row-item";
import {FastenDisplayModel} from "../../../../../lib/models/fasten/fasten-display-model";
import { RouterTestingModule } from '@angular/router/testing';

// More on how to set up stories at: https://storybook.js.org/docs/angular/writing-stories/introduction
const meta: Meta<TableComponent> = {
title: 'Fhir Card/Common/Table',
component: TableComponent,
decorators: [
// moduleMetadata({
// imports: [AppModule]
// })
// applicationConfig({
// providers: [importProvidersFrom(AppModule)],
// }),
moduleMetadata({
imports: [RouterTestingModule]
})
],
tags: ['autodocs'],
render: (args: TableComponent) => ({
Expand Down Expand Up @@ -73,7 +71,7 @@ export const Ref: Story = {
label: 'hello',
data_type: 'reference',
data: {
reference: 'Patient/123',
reference: 'Patient/123=',
display: 'John Doe'
}
},
Expand All @@ -82,8 +80,8 @@ export const Ref: Story = {
label: 'hello',
data_type: 'reference',
data: {
reference: 'Patient/123',
display: 'John Doe'
reference: 'aHR0cHM6Ly93d3cubWVyY3kubmV0L3NpdGVzL2RlZmF1bHQvZmlsZXMvZG9jdG9yX2ltYWdlcy9kZXNrdG9wLzE2NTk4ODYwNTktbS5qcGc=',
display: 'binary'
}
}
] as TableRowItem[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ <h6 class="card-title">{{displayModel?.title}}</h6>
<fhir-ui-table [displayModel]="displayModel" [tableData]="tableData"></fhir-ui-table>
</div>
<div *ngIf="showDetails" class="card-footer">
<a class="float-right" routerLink="/explore/{{displayModel?.source_id}}/resource/{{displayModel?.source_resource_id}}">details</a>
<a class="float-right" [routerLink]="['/explore', displayModel?.source_id, 'resource', displayModel?.source_resource_id]">details</a>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ <h6 class="card-title">{{displayModel?.title}}</h6>
</div>
</div>
<div *ngIf="showDetails" class="card-footer">
<a class="float-right" routerLink="/explore/{{displayModel?.source_id}}/resource/{{displayModel?.source_resource_id}}">details</a>
<a class="float-right" [routerLink]="['/explore', displayModel?.source_id, 'resource', displayModel?.source_resource_id]">details</a>
</div>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ <h6 class="card-title">{{displayModel?.category?.text}}</h6>
</div>
</div>
<div *ngIf="showDetails" class="card-footer">
<a class="float-right" routerLink="/explore/{{displayModel?.source_id}}/resource/{{displayModel?.source_resource_id}}">details</a>
<a class="float-right" [routerLink]="['/explore', displayModel?.source_id, 'resource', displayModel?.source_resource_id]">details</a>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ <h6 class="card-title">{{displayModel?.sort_title || displayModel?.code?.text}}<
<fhir-ui-table [displayModel]="displayModel" [tableData]="tableData"></fhir-ui-table>
</div>
<div *ngIf="showDetails" class="card-footer">
<a class="float-right" routerLink="/explore/{{displayModel?.source_id}}/resource/{{displayModel?.source_resource_id}}">details</a>
<a class="float-right" [routerLink]="['/explore', displayModel?.source_id, 'resource', displayModel?.source_resource_id]">details</a>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ <h6 class="card-title">{{displayModel?.title}}</h6>
<fhir-ui-table [displayModel]="displayModel" [tableData]="tableData"></fhir-ui-table>
</div>
<div *ngIf="showDetails" class="card-footer">
<a class="float-right" routerLink="/explore/{{displayModel?.source_id}}/resource/{{displayModel?.source_resource_id}}">details</a>
<a class="float-right" [routerLink]="['/explore', displayModel?.source_id, 'resource', displayModel?.source_resource_id]">details</a>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ <h6 class="card-title">{{displayModel?.name}}</h6>
<fhir-ui-table [displayModel]="displayModel" [tableData]="tableData"></fhir-ui-table>
</div>
<div *ngIf="showDetails" class="card-footer">
<a class="float-right" routerLink="/explore/{{displayModel?.source_id}}/resource/{{displayModel?.source_resource_id}}">details</a>
<a class="float-right" [routerLink]="['/explore', displayModel?.source_id, 'resource', displayModel?.source_resource_id]">details</a>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ <h6 class="card-title">{{displayModel?.sort_title}}</h6>
</div>
</div>
<div *ngIf="showDetails" class="card-footer">
<a class="float-right" routerLink="/explore/{{displayModel?.source_id}}/resource/{{displayModel?.source_resource_id}}">details</a>
<a class="float-right" [routerLink]="['/explore', displayModel?.source_id, 'resource', displayModel?.source_resource_id]">details</a>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ <h6 class="card-title">{{displayModel?.display}}</h6>
<fhir-ui-table [displayModel]="displayModel" [tableData]="tableData"></fhir-ui-table>
</div>
<div *ngIf="showDetails" class="card-footer">
<a class="float-right" routerLink="/explore/{{displayModel?.source_id}}/resource/{{displayModel?.source_resource_id}}">details</a>
<a class="float-right" [routerLink]="['/explore', displayModel?.source_id, 'resource', displayModel?.source_resource_id]">details</a>
</div>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ <h6 class="card-title">{{displayModel?.title}}</h6>
<fhir-ui-table [displayModel]="displayModel" [tableData]="tableData"></fhir-ui-table>
</div>
<div *ngIf="showDetails" class="card-footer">
<a class="float-right" routerLink="/explore/{{displayModel?.source_id}}/resource/{{displayModel?.source_resource_id}}">details</a>
<a class="float-right" [routerLink]="['/explore', displayModel?.source_id, 'resource', displayModel?.source_resource_id]">details</a>
</div>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ <h6 class="card-title">{{displayModel?.sort_title}}</h6>
></canvas>
</div>
<div *ngIf="showDetails" class="card-footer">
<a class="float-right" routerLink="/explore/{{displayModel?.source_id}}/resource/{{displayModel?.source_resource_id}}">details</a>
<a class="float-right" [routerLink]="['/explore', displayModel?.source_id, 'resource', displayModel?.source_resource_id]">details</a>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ <h6 class="card-title">{{displayModel?.name}}</h6>
<fhir-ui-table [displayModel]="displayModel" [tableData]="tableData"></fhir-ui-table>
</div>
<div *ngIf="showDetails" class="card-footer">
<a class="float-right" routerLink="/explore/{{displayModel?.source_id}}/resource/{{displayModel?.source_resource_id}}">details</a>
<a class="float-right" [routerLink]="['/explore', displayModel?.source_id, 'resource', displayModel?.source_resource_id]">details</a>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ <h6 class="card-title">{{displayModel?.sort_title || displayModel?.name?.[0]?.di
<fhir-ui-table [displayModel]="displayModel" [tableData]="tableData"></fhir-ui-table>
</div>
<div *ngIf="showDetails" class="card-footer">
<a class="float-right" routerLink="/explore/{{displayModel?.source_id}}/resource/{{displayModel?.source_resource_id}}">details</a>
<a class="float-right" [routerLink]="['/explore', displayModel?.source_id, 'resource', displayModel?.source_resource_id]">details</a>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ <h6 class="card-title">{{displayModel?.display}}</h6>
<fhir-ui-table [displayModel]="displayModel" [tableData]="tableData"></fhir-ui-table>
</div>
<div *ngIf="showDetails" class="card-footer">
<a class="float-right" routerLink="/explore/{{displayModel?.source_id}}/resource/{{displayModel?.source_resource_id}}">details</a>
<a class="float-right" [routerLink]="['/explore', displayModel?.source_id, 'resource', displayModel?.source_resource_id]">details</a>
</div>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class FhirDatatableComponent implements OnInit, OnChanges {
}

componentRef.instance.selectionChanged.subscribe((selected: FastenDisplayModel) => {
this.router.navigateByUrl(`/explore/${selected?.source_id}/resource/${selected?.source_resource_id}`);
this.router.navigate(['/explore', selected?.source_id, 'resource', selected?.source_resource_id]);
})
this.knownResourceType = (componentType != DatatableFallbackComponent)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ <h6>Fasten Health</h6>

<div class="modal-footer">

<a routerLink="/explore/{{modalSelectedSourceListItem?.source?.id}}" (click)="modal.close()" class="btn btn-indigo mr-auto">Explore</a>
<a [routerLink]="['/explore', modalSelectedSourceListItem?.source?.id]" (click)="modal.close()" class="btn btn-indigo mr-auto">Explore</a>


<div *ngIf="modalSelectedSourceListItem?.source?.platform_type != 'fasten'" class="d-inline-block" ngbDropdown>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div class="row" >
<!-- Condition Header -->
<div class="col-6">
<span routerLink="/explore/{{firstObservation?.source_id}}/resource/{{firstObservation?.source_resource_id}}">{{observationTitle}}</span>
<span [routerLink]="['/explore', firstObservation?.source_id, 'resource', firstObservation?.source_resource_id]">{{observationTitle}}</span>
</div>
<div class="col-6">
{{firstObservation | fhirPath: "Observation.effectiveDateTime": "Observation.issued" | date}}
Expand Down Expand Up @@ -36,7 +36,7 @@
<div #collapse="ngbCollapse" [ngbCollapse]="true">

<ul>
<li class="cursor-pointer tx-indigo" *ngFor="let observation of observations" routerLink="/explore/{{observation?.source_id}}/resource/{{observation?.source_resource_id}}">Observation: {{observation | fhirPath: "Observation.effectiveDateTime": "Observation.issued" | date}}</li>
<li class="cursor-pointer tx-indigo" *ngFor="let observation of observations" [routerLink]="['/explore', observation?.source_id, 'resource', observation?.source_resource_id]">Observation: {{observation | fhirPath: "Observation.effectiveDateTime": "Observation.issued" | date}}</li>
</ul>
</div>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="card card-dashboard-seven mb-3">
<div class="card-header tx-medium">
<div class="row cursor-pointer" routerLink="/explore/{{conditionDisplayModel?.source_id}}/resource/{{conditionDisplayModel?.source_resource_id}}" role="link">
<div class="row cursor-pointer" [routerLink]="['/explore', conditionDisplayModel?.source_id, 'resource', conditionDisplayModel?.source_resource_id]" role="link">
<!-- Condition Header -->
<div class="col-6">
{{conditionDisplayModel?.sort_title ? conditionDisplayModel?.sort_title : (conditionGroup | fhirPath: "Condition.code.text.first()":"Condition.code.coding.display.first()")}}
Expand Down Expand Up @@ -66,10 +66,10 @@
<div class="row">

<ng-container *ngFor="let encounter of encounters">
<div routerLink="/explore/{{encounter?.source_id}}/resource/{{encounter?.source_resource_id}}" class="col-6 mt-3 mb-2 tx-indigo" role="link">
<div [routerLink]="['/explore', encounter?.source_id, 'resource', encounter?.source_resource_id]" class="col-6 mt-3 mb-2 tx-indigo" role="link">
<strong>{{encounter.period_start | date}}</strong>
</div>
<div routerLink="/explore/{{encounter?.source_id}}/resource/{{encounter?.source_resource_id}}" class="col-6 mt-3 mb-2 tx-indigo" role="link">
<div [routerLink]="['/explore', encounter?.source_id, 'resource', encounter?.source_resource_id]" class="col-6 mt-3 mb-2 tx-indigo" role="link">
<small>{{encounter.location_display }}</small>
</div>

Expand Down Expand Up @@ -137,7 +137,7 @@
<div *ngIf="encounter?.related_resources?.Device as devices" class="col-12 mt-2 mb-2">
<strong>Device:</strong>
<ul>
<li routerLink="/explore/{{device?.source_id}}/resource/{{device?.source_resource_id}}" *ngFor="let device of devices" role="link">
<li [routerLink]="['/explore', device?.source_id, 'resource', device?.source_resource_id]" *ngFor="let device of devices" role="link">
{{device.model}}
</li>
</ul>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="card card-dashboard-seven mb-3">
<div class="card-header tx-medium">
<div class="row cursor-pointer" routerLink="/explore/{{eobDisplayModel?.source_id}}/resource/{{eobDisplayModel?.source_resource_id}}">
<div class="row cursor-pointer" [routerLink]="['/explore', eobDisplayModel?.source_id, 'resource', eobDisplayModel?.source_resource_id]">
<!-- Condition Header -->
<div class="col-6">
{{eobDisplayModel?.sort_title ? eobDisplayModel?.sort_title : condition?.display ? condition?.display : 'unknown'}}
Expand Down Expand Up @@ -139,7 +139,7 @@
<div *ngIf="eobDisplayModel?.related_resources?.Device as devices" class="col-12 mt-2 mb-2">
<strong>Device:</strong>
<ul>
<li routerLink="/explore/{{device?.source_id}}/resource/{{device?.source_resource_id}}" *ngFor="let device of devices">
<li [routerLink]="['/explore', device?.source_id, 'resource', device?.source_resource_id]" *ngFor="let device of devices">
{{device.model}}
</li>
</ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<div class="timeline-body card">
<div class="timeline-header">
<span class="username">
<a style="color:black;font-size: 1.3125rem;font-weight: 500;" routerLink="/explore/{{displayModel?.source_id}}/resource/{{displayModel?.source_resource_id}}">
<a style="color:black;font-size: 1.3125rem;font-weight: 500;" [routerLink]="['/explore', displayModel?.source_id, 'resource', displayModel?.source_resource_id]">
{{displayModel?.sort_title}}
</a>
<small></small>
Expand Down Expand Up @@ -96,7 +96,7 @@
<div *ngIf="displayModel?.related_resources?.Device as devices">
<strong>Device:</strong>
<ul>
<li routerLink="/explore/{{device?.source_id}}/resource/{{device?.source_resource_id}}" *ngFor="let device of devices" role="link">
<li [routerLink]="['/explore', device?.source_id, 'resource', device?.source_resource_id]" *ngFor="let device of devices" role="link">
{{device.model}}
</li>
</ul>
Expand All @@ -110,7 +110,7 @@
<div ngbDropdownMenu aria-labelledby="dropdownReports">
<a class="dropdown-item"
*ngFor="let documentReference of displayModel?.related_resources['DocumentReference']" ngbDropdownItem
routerLink="/explore/{{documentReference?.source_id}}/resource/{{documentReference?.source_resource_id}}"
[routerLink]="['/explore', documentReference?.source_id, 'resource', documentReference?.source_resource_id]"
>{{documentReference?.sort_title}}</a>
<a class="dropdown-item"
*ngFor="let diagnosticReport of displayModel?.related_resources['DiagnosticReport']" ngbDropdownItem
Expand All @@ -127,7 +127,7 @@
<ng-container *ngFor="let resourceEntry of displayModel?.related_resources | keyvalue">
<a class="dropdown-item"
*ngFor="let resourceListItem of resourceEntry.value" ngbDropdownItem
routerLink="/explore/{{resourceListItem?.source_id}}/resource/{{resourceListItem?.source_resource_id}}"
[routerLink]="['/explore', resourceListItem?.source_id, 'resource', resourceListItem?.source_resource_id]"
>{{resourceListItem.source_resource_type}} {{resourceListItem.sort_title ? '- '+resourceListItem.sort_title : '' }}</a>
</ng-container>

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/app/pages/dashboard/dashboard.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class DashboardComponent implements OnInit {
}

selectSource(selectedSource: Source){
this.router.navigateByUrl(`/explore/${selectedSource.id}`, {
this.router.navigate(['/explore', selectedSource.id], {
state: selectedSource
});
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/app/pages/explore/explore.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class ExploreComponent implements OnInit {
}

public exploreSource(sourceListItem: SourceListItem, ) {
this.router.navigateByUrl(`/explore/${sourceListItem.source.id}`, {
this.router.navigate(['/explore', sourceListItem.source.id], {
state: sourceListItem.source
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="container">
<div class="az-content-body">
<div class="az-content-breadcrumb">
<span class="cursor-pointer" routerLink="/explore/{{sourceId}}">{{sourceName}}</span>
<span class="cursor-pointer" [routerLink]="['/explore', sourceId]">{{sourceName}}</span>
<span>Resource</span>
<span>{{resource?.source_resource_type}}</span>
<span>{{resource?.source_resource_id}}</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<div class="patient-row row">
<div class="col-7 patient-name"><h3 class="pull-left text-primary">{{getPatientName()}}</h3></div>
<div class="col-5">
<a routerLink="/explore/{{selectedSource?.id}}/resource/{{selectedPatient?.source_resource_id}}" class="btn btn-indigo btn-icon float-right">
<a [routerLink]="['/explore', selectedSource?.id, 'resource', selectedPatient?.source_resource_id]" class="btn btn-indigo btn-icon float-right">
<i class="fas fa-info-circle"></i>
</a>
</div>
Expand Down

0 comments on commit 43579df

Please sign in to comment.