-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Datasets figure web component #886
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
263ebb6
feat(wc): add a web component for datasets figure
fgravin 2ec9618
fix(wc): don't initiate API obsevables in class declaration
fgravin 1f253f9
doc(wc): improve add a new web component section
fgravin 4f1441a
refactor: recordsCount$ should not catch the error
fgravin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
apps/webcomponents/src/app/components/gn-figure-datasets/gn-figure-datasets.component.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
@import '../../../styles.css'; |
7 changes: 7 additions & 0 deletions
7
apps/webcomponents/src/app/components/gn-figure-datasets/gn-figure-datasets.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<gn-ui-figure | ||
class="" | ||
[figure]="recordsCount$ | async" | ||
[icon]="'folder_open'" | ||
title="catalog.figures.datasets" | ||
[color]="'secondary'" | ||
></gn-ui-figure> |
39 changes: 39 additions & 0 deletions
39
apps/webcomponents/src/app/components/gn-figure-datasets/gn-figure-datasets.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { | ||
ChangeDetectionStrategy, | ||
ChangeDetectorRef, | ||
Component, | ||
Injector, | ||
ViewEncapsulation, | ||
} from '@angular/core' | ||
import { BaseComponent } from '../base.component' | ||
import { RecordsService } from '@geonetwork-ui/feature/catalog' | ||
import { startWith } from 'rxjs/operators' | ||
import { Observable } from 'rxjs' | ||
import { SearchFacade } from '@geonetwork-ui/feature/search' | ||
|
||
@Component({ | ||
selector: 'wc-gn-figure-datasets', | ||
templateUrl: './gn-figure-datasets.component.html', | ||
styleUrls: ['./gn-figure-datasets.component.css'], | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
encapsulation: ViewEncapsulation.ShadowDom, | ||
providers: [SearchFacade], | ||
}) | ||
export class GnFigureDatasetsComponent extends BaseComponent { | ||
catalogRecords: RecordsService | ||
recordsCount$: Observable<string | number> | ||
|
||
constructor(injector: Injector, private changeDetector: ChangeDetectorRef) { | ||
super(injector) | ||
this.catalogRecords = injector.get(RecordsService) | ||
this.recordsCount$ = this.catalogRecords.recordsCount$.pipe(startWith('-')) | ||
} | ||
|
||
init(): void { | ||
super.init() | ||
} | ||
|
||
changes(): void { | ||
super.changes() | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
apps/webcomponents/src/app/components/gn-figure-datasets/gn-figure-datasets.sample.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<title>Web Component Demo - Figure datasets</title> | ||
<base href="./" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
<link rel="preconnect" href="https://fonts.googleapis.com" /> | ||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin /> | ||
<link | ||
href="https://fonts.googleapis.com/css2?family=DM+Serif+Display&family=Inter:wght@200;300;400;500;600;700&display=swap" | ||
rel="stylesheet" | ||
type="text/css" | ||
/> | ||
<style> | ||
body { | ||
margin: 0; | ||
font-family: 'Inter', sans-serif; | ||
} | ||
main { | ||
margin: 5rem; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<main> | ||
<h3>Figure - Datasets</h3> | ||
<div> | ||
<script src="gn-wc.js"></script> | ||
|
||
<gn-figure-datasets | ||
api-url="https://demo.georchestra.org/geonetwork/srv/api" | ||
primary-color="#0f4395" | ||
secondary-color="#8bc832" | ||
main-color="#555" | ||
background-color="#fdfbff" | ||
main-font="'Inter', sans-serif" | ||
title-font="'DM Serif Display', serif" | ||
></gn-figure-datasets> | ||
</div> | ||
</main> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,17 @@ | ||
import { Injectable } from '@angular/core' | ||
import { Observable, of } from 'rxjs' | ||
import { Observable, of, switchMap } from 'rxjs' | ||
import { catchError, shareReplay } from 'rxjs/operators' | ||
import { RecordsRepositoryInterface } from '@geonetwork-ui/common/domain/repository/records-repository.interface' | ||
|
||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class RecordsService { | ||
fgravin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
recordsCount$: Observable<number> = this.recordsRepository | ||
.getMatchesCount({}) | ||
.pipe( | ||
shareReplay(1), | ||
catchError(() => of(0)) | ||
) | ||
recordsCount$: Observable<number> = of(0).pipe( | ||
switchMap(() => this.recordsRepository.getMatchesCount({})), | ||
shareReplay(1), | ||
catchError(() => of(0)) | ||
) | ||
|
||
constructor(private recordsRepository: RecordsRepositoryInterface) {} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would add a
catchError(()=> of('-'))
to stay consistent with the way you built it.I like the way that you start with an '-'.
Since you put :
catchError(() => of(0))
on therecordsCount$
in the service, in case of error it will display to the user 0 wich is wrong (could be 14 or 392).What do you think about this ?