Skip to content

Commit f10000d

Browse files
committed
feat(explorers): enhance shared wiki, modal-link, and popover-link components
- Make wikiParams a required input on wiki, popover-link, and modal-link components - Switch wiki component from effect-based to OnInit lifecycle for data fetching - Add isPlatformBrowser guard to wiki and terms-of-service components - Improve wiki/wiki-hero layout with flexbox for better loading state display - Convert wiki isLoading to signal for reactive state management - Add className input to wiki and wiki-hero components for external styling - Add heroBackgroundImagePath input to wiki-hero for customizable backgrounds - Fix logger service to not log undefined when optional data/error params are omitted - Add non-null assertion for optional headerTitleWikiParams in comparison-tool-header
1 parent 74eb9fe commit f10000d

File tree

17 files changed

+142
-105
lines changed

17 files changed

+142
-105
lines changed

libs/explorers/comparison-tool/src/lib/comparison-tool-header/comparison-tool-header.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<div class="comparison-tool-header-title">
77
<h1>{{ viewConfig().headerTitle }}</h1>
88
@if (viewConfig().headerTitleWikiParams) {
9-
<explorers-popover-link [wikiParams]="viewConfig().headerTitleWikiParams" />
9+
<explorers-popover-link [wikiParams]="viewConfig().headerTitleWikiParams!" />
1010
}
1111
</div>
1212
<explorers-comparison-tool-share-url-button />

libs/explorers/services/src/lib/logger.service.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ import * as Sentry from '@sentry/angular';
55
export class LoggerService {
66
log(message: string, data?: Record<string, unknown>) {
77
if (isDevMode()) {
8-
console.log('[LOG]', message, data);
8+
if (data) {
9+
console.log('[LOG]', message, data);
10+
} else {
11+
console.log('[LOG]', message);
12+
}
913
}
1014
Sentry.addBreadcrumb({
1115
message,
@@ -15,7 +19,11 @@ export class LoggerService {
1519
}
1620

1721
warn(message: string, data?: Record<string, unknown>) {
18-
console.warn('[WARN]', message, data);
22+
if (data) {
23+
console.warn('[WARN]', message, data);
24+
} else {
25+
console.warn('[WARN]', message);
26+
}
1927
Sentry.addBreadcrumb({
2028
message,
2129
level: 'warning',
@@ -29,7 +37,11 @@ export class LoggerService {
2937
* as a Sentry event.
3038
*/
3139
error(message: string, error?: unknown) {
32-
console.error('[ERROR]', message, error);
40+
if (error) {
41+
console.error('[ERROR]', message, error);
42+
} else {
43+
console.error('[ERROR]', message);
44+
}
3345

3446
if (error) {
3547
Sentry.captureException(error);

libs/explorers/shared/src/lib/components/terms-of-service/terms-of-service.component.html

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
[backgroundImagePath]="heroBackgroundImagePathOrDefault()"
55
/>
66
<div class="terms-of-service">
7-
@if (isLoading) {
7+
@if (isLoading()) {
88
<div class="loading-icon">
99
<explorers-loading-icon />
1010
</div>
11+
} @else {
12+
<div class="terms-of-service-content">
13+
<markdown [data]="content" />
14+
</div>
1115
}
12-
<div class="terms-of-service-content">
13-
<markdown [data]="content" />
14-
</div>
1516
</div>
1617
</div>

libs/explorers/shared/src/lib/components/terms-of-service/terms-of-service.component.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
}
2020

2121
.loading-icon {
22+
flex: 1;
2223
display: flex;
23-
justify-content: center;
2424
align-items: center;
25-
width: min(vars.$main-content-desktop-width, 100%);
25+
justify-content: center;
2626
}
2727

2828
.terms-of-service-content {

libs/explorers/shared/src/lib/components/terms-of-service/terms-of-service.component.ts

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
import { isPlatformBrowser } from '@angular/common';
12
import {
23
Component,
34
computed,
45
DestroyRef,
56
inject,
67
input,
78
OnInit,
9+
PLATFORM_ID,
10+
signal,
811
ViewEncapsulation,
912
} from '@angular/core';
1013

@@ -26,9 +29,10 @@ import { finalize } from 'rxjs/operators';
2629
export class TermsOfServiceComponent implements OnInit {
2730
synapseService = inject(SynapseApiService);
2831
private readonly destroyRef = inject(DestroyRef);
32+
private readonly platformId = inject(PLATFORM_ID);
2933

3034
content = '';
31-
isLoading = true;
35+
isLoading = signal(true);
3236
heroBackgroundImagePath = input<string | undefined>();
3337

3438
heroBackgroundImagePathOrDefault = computed(
@@ -40,21 +44,23 @@ export class TermsOfServiceComponent implements OnInit {
4044
}
4145

4246
loadTOS() {
43-
this.synapseService
44-
.getTermsOfService()
45-
.pipe(
46-
takeUntilDestroyed(this.destroyRef),
47-
finalize(() => {
48-
this.isLoading = false;
49-
}),
50-
)
51-
.subscribe({
52-
next: (markdown) => {
53-
this.content = markdown;
54-
},
55-
error: (error) => {
56-
console.error('Error loading terms of service:', error);
57-
},
58-
});
47+
if (isPlatformBrowser(this.platformId)) {
48+
this.synapseService
49+
.getTermsOfService()
50+
.pipe(
51+
takeUntilDestroyed(this.destroyRef),
52+
finalize(() => {
53+
this.isLoading.set(false);
54+
}),
55+
)
56+
.subscribe({
57+
next: (markdown) => {
58+
this.content = markdown;
59+
},
60+
error: (error) => {
61+
console.error('Error loading terms of service:', error);
62+
},
63+
});
64+
}
5965
}
6066
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<div id="wiki-hero-container">
22
<explorers-hero
33
[title]="heroTitle()"
4-
backgroundImagePath="explorers-assets/images/background.svg"
4+
[backgroundImagePath]="heroBackgroundImagePathOrDefault()"
55
/>
66
<div class="wiki-hero">
77
<div class="wiki-hero-content">
8-
<explorers-wiki [wikiParams]="wikiParams()" [className]="className" />
8+
<explorers-wiki [wikiParams]="wikiParams()" [className]="className()" />
99
</div>
1010
</div>
1111
</div>

libs/explorers/shared/src/lib/components/wiki-hero/wiki-hero.component.scss

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@
1111
display: flex;
1212
flex-direction: column;
1313
align-items: center;
14-
justify-content: start;
1514

1615
@media (width < vars.$main-content-total-width) {
1716
// adds consistent margin when the screen is smaller
1817
margin: 0 vars.$main-content-margin;
1918
}
2019

2120
.wiki-hero-content {
21+
flex: 1 1 auto;
22+
display: flex;
23+
flex-direction: column;
2224
font-size: 16px;
2325
font-weight: 400;
2426
line-height: 1.5;

libs/explorers/shared/src/lib/components/wiki-hero/wiki-hero.component.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, input } from '@angular/core';
1+
import { Component, computed, input } from '@angular/core';
22

33
import { HeroComponent } from '@sagebionetworks/explorers/ui';
44
import { WikiComponent } from '@sagebionetworks/explorers/util';
@@ -11,7 +11,12 @@ import { SynapseWikiParams } from '@sagebionetworks/explorers/models';
1111
styleUrls: ['./wiki-hero.component.scss'],
1212
})
1313
export class WikiHeroComponent {
14-
wikiParams = input<SynapseWikiParams>(); // from the route data
14+
wikiParams = input.required<SynapseWikiParams>(); // from the route data
1515
heroTitle = input('heroTitle'); // from the route data
16-
className = 'wiki-hero-page-content';
16+
heroBackgroundImagePath = input<string | undefined>(); // from the route data
17+
className = input<string>(''); // from the route data
18+
19+
heroBackgroundImagePathOrDefault = computed(
20+
() => this.heroBackgroundImagePath() ?? 'explorers-assets/images/background.svg',
21+
);
1722
}

libs/explorers/testing/src/lib/mocks/components/wiki-component-mock.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ import { SynapseWikiParams } from '@sagebionetworks/explorers/models';
77
template: '<div>wiki</div>',
88
})
99
export class MockWikiComponent {
10-
wikiParams = input<SynapseWikiParams>();
10+
wikiParams = input.required<SynapseWikiParams>();
1111
}

libs/explorers/util/src/lib/modal-link/modal-link.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
altText="info"
1010
/>
1111
@if (text()) {
12-
<span class="modal-link-text" [ngStyle]="getTextColor()">
12+
<span class="modal-link-text" [ngStyle]="textColorStyle()">
1313
{{ text() }}
1414
</span>
1515
}

0 commit comments

Comments
 (0)