Skip to content

Commit 074b80b

Browse files
committed
fix: TT-178 Make URI clickable when possible
1 parent 29cc62d commit 074b80b

File tree

4 files changed

+36
-20
lines changed

4 files changed

+36
-20
lines changed

src/app/modules/reports/components/time-entries-table/time-entries-table.component.html

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
<div class="row scroll-table mt-5 ml-0">
2-
<table class="table table-striped mb-0" datatable [dtTrigger]="dtTrigger" [dtOptions]="dtOptions"
2+
<table
3+
class="table table-striped mb-0"
4+
datatable
5+
[dtTrigger]="dtTrigger"
6+
[dtOptions]="dtOptions"
37
*ngIf="reportDataSource$ | async as dataSource">
48
<thead class="thead-blue">
59
<tr class="d-flex">
@@ -39,7 +43,7 @@
3943
<td class="col md-col">{{ entry.activity_name }}</td>
4044
<td class="col lg-col">
4145
<ng-container *ngIf="entry.uri !== null">
42-
<a [class.is-url]="isValidUri(entry.uri)" (click)="isLinkExternal(entry.uri)">
46+
<a [class.is-url]="isURL(entry.uri)" (click)="openURLInNewTab(entry.uri)">
4347
{{ entry.uri }}
4448
</a>
4549
</ng-container>

src/app/modules/reports/components/time-entries-table/time-entries-table.component.scss

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@import '../../../../../styles/colors.scss';
12
.col{
23
white-space: nowrap;
34
overflow: hidden;
@@ -33,24 +34,24 @@
3334
display: grid;
3435
}
3536

36-
$base-color: #00BAEE;
37-
$hover-color: darken($base-color, 20);
37+
$url-base-color: $primary;
38+
$url-hover-color: darken($url-base-color, 20);
3839

3940
.is-url {
4041
cursor: pointer;
41-
color: $base-color;
42+
color: $url-base-color;
4243
text-decoration: underline;
4344

4445
&:visited {
45-
color: green;
46+
color: $dark;
4647
}
4748

4849
&:hover {
49-
color: $hover-color;
50+
color: $url-hover-color;
5051
}
5152

5253
&:active {
53-
color: $base-color;
54+
color: $url-base-color;
5455
}
5556
}
5657

src/app/modules/reports/components/time-entries-table/time-entries-table.component.spec.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,21 +80,31 @@ describe('Reports Page', () => {
8080
});
8181

8282
it('when the uri starts with http or https it should return true and open the url in a new tab', () => {
83-
const uriExpected = 'http://customuri.com';
84-
spyOn(component, 'isValidUri').and.returnValue(true);
83+
const url = 'http://customuri.com';
84+
spyOn(component, 'isURL').and.returnValue(true);
8585
spyOn(window, 'open');
8686

87-
expect(component.isLinkExternal(uriExpected)).not.toEqual('');
88-
expect(window.open).toHaveBeenCalledWith(uriExpected, '_blank');
89-
expect(component.isValidUri).toHaveBeenCalled();
87+
expect(component.openURLInNewTab(url)).not.toEqual('');
88+
expect(window.open).toHaveBeenCalledWith(url, '_blank');
9089
});
9190

9291
it('when the uri starts without http or https it should return false and not navigate or open a new tab', () => {
9392
const uriExpected = timeEntry.uri;
94-
spyOn(component, 'isValidUri').and.returnValue(false);
93+
spyOn(component, 'isURL').and.returnValue(false);
9594

96-
expect(component.isLinkExternal(uriExpected)).toEqual('');
97-
expect(component.isValidUri).toHaveBeenCalled();
95+
expect(component.openURLInNewTab(uriExpected)).toEqual('');
96+
});
97+
98+
const params = [
99+
{url: 'http://example.com', expected_value: true, with: 'with'},
100+
{url: 'https://example.com', expected_value: true, with: 'with'},
101+
{url: 'no-url-example', expected_value: false, with: 'without'}
102+
];
103+
params.map((param) => {
104+
it(`when the url starts ${param.with} http or https it should return ${param.expected_value}`, () => {
105+
106+
expect(component.isURL(param.url)).toEqual(param.expected_value);
107+
});
98108
});
99109

100110
afterEach(() => {

src/app/modules/reports/components/time-entries-table/time-entries-table.component.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,12 @@ export class TimeEntriesTableComponent implements OnInit, OnDestroy, AfterViewIn
8686
}
8787
}
8888

89-
isLinkExternal(uri: string): WindowProxy | string {
90-
return this.isValidUri(uri) ? window.open(uri, '_blank') : '';
89+
openURLInNewTab(uri: string): WindowProxy | string {
90+
return this.isURL(uri) ? window.open(uri, '_blank') : '';
9191
}
9292

93-
isValidUri(uri: string) {
94-
return uri.startsWith('http' || 'https');
93+
isURL(uri: string) {
94+
const regex = new RegExp('http*', 'g');
95+
return regex.test(uri) ? true : false;
9596
}
9697
}

0 commit comments

Comments
 (0)