Skip to content

Commit

Permalink
Merge pull request #319 from hubmapconsortium/href-2
Browse files Browse the repository at this point in the history
Href 2
  • Loading branch information
edlu77 authored Dec 11, 2023
2 parents 9e3a0ba + 3b89694 commit 5999297
Show file tree
Hide file tree
Showing 41 changed files with 2,527 additions and 1,966 deletions.
21 changes: 17 additions & 4 deletions apps/ftu-ui-small-wc/src/app/app.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { TestBed } from '@angular/core/testing';
import { BrowserAnimationsModule, NoopAnimationsModule } from '@angular/platform-browser/animations';
import { Router } from '@angular/router';
import { dispatch, dispatch$, dispatchAction$, select$, selectSnapshot } from '@hra-ui/cdk/injectors';
import { of } from 'rxjs';
import { LinkRegistryActions } from '@hra-ui/cdk/state';
import { FTU_DATA_IMPL_ENDPOINTS, FtuDataImplEndpoints } from '@hra-ui/services';
import { ActiveFtuActions, TissueLibraryActions } from '@hra-ui/state';
import { mock } from 'jest-mock-extended';
import { of, ReplaySubject } from 'rxjs';
import { Shallow } from 'shallow-render';

import { AppComponent } from './app.component';
import { initFactory } from './app.init';
import { NavigationLessRouter } from './routing/simple-router.service';
import { FTU_DATA_IMPL_ENDPOINTS } from '@hra-ui/services';
import { LinkRegistryActions } from '@hra-ui/cdk/state';
import { ActiveFtuActions, TissueLibraryActions } from '@hra-ui/state';

jest.mock('@hra-ui/cdk/injectors');

Expand All @@ -18,10 +21,20 @@ describe('AppComponent', () => {
beforeEach(() => {
jest.clearAllMocks();

TestBed.configureTestingModule({
providers: [
{
provide: FTU_DATA_IMPL_ENDPOINTS,
useValue: mock<ReplaySubject<FtuDataImplEndpoints>>({ next: () => undefined }),
},
],
});

jest.mocked(selectSnapshot).mockReturnValue(jest.fn());
jest.mocked(dispatch).mockReturnValue(jest.fn());
jest.mocked(select$).mockReturnValue(of());
jest.mocked(dispatch$).mockReturnValue(jest.fn(() => of({})));

shallow = new Shallow(AppComponent)
.provideMock(Router, NavigationLessRouter)
.provide([
Expand Down
37 changes: 16 additions & 21 deletions apps/ftu-ui-small-wc/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
ChangeDetectionStrategy,
Component,
inject,
Injector,
Input,
OnChanges,
OnInit,
Expand All @@ -11,7 +10,7 @@ import {
ViewEncapsulation,
} from '@angular/core';
import { dispatch, dispatch$, select$, selectSnapshot } from '@hra-ui/cdk/injectors';
import { createLinkId, LinkRegistryActions, ResourceRegistryActions } from '@hra-ui/cdk/state';
import { BaseHrefActions, createLinkId, LinkRegistryActions, ResourceRegistryActions } from '@hra-ui/cdk/state';
import {
BiomarkerDetailsWcComponent,
FooterBehaviorComponent,
Expand All @@ -20,7 +19,7 @@ import {
TissueLibraryBehaviorComponent,
} from '@hra-ui/components/behavioral';
import { FullscreenContainerComponent, FullscreenContentComponent } from '@hra-ui/components/molecules';
import { FTU_DATA_IMPL_ENDPOINTS, FtuDataImplEndpoints, Iri } from '@hra-ui/services';
import { FTU_DATA_IMPL_ENDPOINTS, FtuDataImplEndpoints, setUrl, Url } from '@hra-ui/services';
import {
ActiveFtuActions,
ActiveFtuSelectors,
Expand All @@ -30,7 +29,7 @@ import {
TissueLibraryActions,
TissueLibrarySelectors,
} from '@hra-ui/state';
import { tap } from 'rxjs';
import { ReplaySubject, tap } from 'rxjs';

@Component({
selector: 'hra-root',
Expand Down Expand Up @@ -77,7 +76,9 @@ export class AppComponent implements OnInit, OnChanges {

@Output() readonly nodeClicked = select$(IllustratorSelectors.selectedOnClicked);

private readonly setBaseHref = dispatch(BaseHrefActions.Set);
private readonly loadLinks = dispatch(LinkRegistryActions.LoadFromYaml);
private readonly addMany = dispatch(LinkRegistryActions.AddMany);
private readonly loadResources = dispatch(ResourceRegistryActions.LoadFromYaml);
private readonly navigateToOrgan = dispatch(LinkRegistryActions.Navigate);
private readonly setScreenSmall = dispatch(ScreenModeAction.SetSize);
Expand All @@ -86,17 +87,19 @@ export class AppComponent implements OnInit, OnChanges {

private readonly reset = dispatch$(ActiveFtuActions.Reset);

private readonly injector = inject(Injector);
private endpoints?: FtuDataImplEndpoints;
private readonly endpoints = inject(FTU_DATA_IMPL_ENDPOINTS) as ReplaySubject<FtuDataImplEndpoints>;

ngOnInit() {
this.endpoints = this.injector.get(FTU_DATA_IMPL_ENDPOINTS);
this.loadLinks(this.setUrl(this.linksYamlUrl));
this.loadResources(this.setUrl(this.resourcesYamlUrl));
this.endpoints.illustrations = this.setUrl(this.illustrationsUrl);
this.endpoints.datasets = this.setUrl(this.datasetUrl);
this.endpoints.summaries = this.setUrl(this.summariesUrl);
this.endpoints.baseHref = this.baseHref as Iri;
const { baseHref } = this;
this.setBaseHref(this.baseHref);
this.loadLinks(setUrl(this.linksYamlUrl, baseHref));
this.loadResources(setUrl(this.resourcesYamlUrl, baseHref));
this.endpoints.next({
illustrations: setUrl(this.illustrationsUrl, baseHref),
datasets: setUrl(this.datasetUrl, baseHref),
summaries: setUrl(this.summariesUrl, baseHref),
baseHref: this.baseHref as Url,
});
}

ngOnChanges(changes: SimpleChanges) {
Expand All @@ -110,14 +113,6 @@ export class AppComponent implements OnInit, OnChanges {
.subscribe();
}

private setUrl(url: string): Iri {
if (url.slice(0, 4) === 'http') {
return url as Iri;
} else {
return (this.baseHref + url) as Iri;
}
}

showDefaultIri() {
this.tissues
.pipe(
Expand Down
12 changes: 6 additions & 6 deletions apps/ftu-ui-small-wc/src/app/app.init.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { dispatchAction$ } from '@hra-ui/cdk/injectors';
import { LinkRegistryActions, LinkType, ResourceRegistryActions } from '@hra-ui/cdk/state';
import { LinkIds, TissueLibraryActions } from '@hra-ui/state';
import { LinkRegistryActions, LinkType, createLinkId } from '@hra-ui/cdk/state';
import { LinkIds } from '@hra-ui/state';
import { Observable } from 'rxjs';

/**
Expand All @@ -16,10 +16,10 @@ export function initFactory(): () => Observable<unknown> {
type: LinkType.Internal,
commands: ['/'],
},
[createLinkId('FTU')]: {
type: LinkType.Internal,
commands: ['ftu/'],
},
}),

new LinkRegistryActions.LoadFromYaml('assets/links.yml'),
new ResourceRegistryActions.LoadFromYaml('assets/resources.yml'),
new TissueLibraryActions.Load(),
]);
}
Loading

0 comments on commit 5999297

Please sign in to comment.