Skip to content

Commit

Permalink
feat(repository): offer a utility to define the repository url
Browse files Browse the repository at this point in the history
This is useful to avoid a direct dependency to the various openapi clients in
data-access
  • Loading branch information
jahow committed Nov 12, 2023
1 parent bd6dfbb commit 89464cc
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 73 deletions.
8 changes: 1 addition & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,7 @@ You'll need manual configuration to make the application running:
// ...
// provide API url and proxy path
providers: [
{
provide: Configuration,
useFactory: () =>
new Configuration({
basePath: getGlobalConfig().GN4_API_URL,
}),
},
provideRepositoryUrl(() => getGlobalConfig().GN4_API_URL),
{
provide: PROXY_PATH,
useFactory: () => getGlobalConfig().PROXY_PATH,
Expand Down
28 changes: 13 additions & 15 deletions apps/datahub/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@ import { importProvidersFrom, Inject, NgModule } from '@angular/core'
import { MatIconModule } from '@angular/material/icon'
import { BrowserModule } from '@angular/platform-browser'
import { Router, RouterModule } from '@angular/router'
import { Configuration } from '@geonetwork-ui/data-access/gn4'
import {
FeatureCatalogModule,
ORGANIZATION_URL_TOKEN,
} from '@geonetwork-ui/feature/catalog'
import { FeatureRecordModule } from '@geonetwork-ui/feature/record'
import {
FeatureRecordModule,
GN_UI_VERSION,
WEB_COMPONENT_EMBEDDER_URL,
} from '@geonetwork-ui/feature/record'
import {
DefaultRouterModule,
ROUTE_PARAMS,
ROUTER_ROUTE_DATASET,
ROUTER_ROUTE_SEARCH,
ROUTE_PARAMS,
RouterService,
} from '@geonetwork-ui/feature/router'
import {
Expand All @@ -36,10 +39,10 @@ import {
} from '@geonetwork-ui/util/app-config'
import { UtilI18nModule } from '@geonetwork-ui/util/i18n'
import {
getGeometryFromGeoJSON,
PROXY_PATH,
ThemeService,
UtilSharedModule,
getGeometryFromGeoJSON,
} from '@geonetwork-ui/util/shared'
import { FeatureAuthModule } from '@geonetwork-ui/feature/auth'
import { EffectsModule } from '@ngrx/effects'
Expand All @@ -64,11 +67,12 @@ import { DatahubRouterService } from './router/datahub-router.service'
import { NavigationMenuComponent } from './home/navigation-menu/navigation-menu.component'
import { FormsModule } from '@angular/forms'
import { UiDatavizModule } from '@geonetwork-ui/ui/dataviz'
import { WEB_COMPONENT_EMBEDDER_URL } from '@geonetwork-ui/feature/record'
import { LANGUAGES_LIST, UiCatalogModule } from '@geonetwork-ui/ui/catalog'
import { METADATA_LANGUAGE } from '@geonetwork-ui/api/repository'
import {
METADATA_LANGUAGE,
provideRepositoryUrl,
} from '@geonetwork-ui/api/repository'
import { BrowserAnimationsModule } from '@angular/platform-browser/animations'
import { GN_UI_VERSION } from '@geonetwork-ui/feature/record'
import { LOGIN_URL } from '@geonetwork-ui/api/repository/gn4'
import { RecordRelatedRecordsComponent } from './record/record-related-records/record-related-records.component'
import { RecordMetadataComponent } from './record/record-metadata/record-metadata.component'
Expand Down Expand Up @@ -142,16 +146,10 @@ export const metaReducers: MetaReducer[] = !environment.production ? [] : []
MatTabsModule,
],
providers: [
{ provide: RouterService, useClass: DatahubRouterService },
importProvidersFrom(FeatureAuthModule),
provideRepositoryUrl(() => getGlobalConfig().GN4_API_URL),
{ provide: RouterService, useClass: DatahubRouterService },
{ provide: GN_UI_VERSION, useValue: environment.version },
{
provide: Configuration,
useFactory: () =>
new Configuration({
basePath: getGlobalConfig().GN4_API_URL,
}),
},
{
provide: PROXY_PATH,
useFactory: () => getGlobalConfig().PROXY_PATH,
Expand Down
12 changes: 2 additions & 10 deletions apps/map-viewer/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { StoreDevtoolsModule } from '@ngrx/store-devtools'
import { EffectsModule } from '@ngrx/effects'
import { storeFreeze } from 'ngrx-store-freeze'
import { environment } from '../environments/environment'
import { Configuration } from '@geonetwork-ui/data-access/gn4'
import { provideRepositoryUrl } from '@geonetwork-ui/api/repository'

export const metaReducers: MetaReducer<any>[] = !environment.production
? [storeFreeze]
Expand All @@ -31,15 +31,7 @@ export const metaReducers: MetaReducer<any>[] = !environment.production
StoreDevtoolsModule.instrument(),
EffectsModule.forRoot(),
],
providers: [
{
provide: Configuration,
useFactory: () =>
new Configuration({
basePath: '/geonetwork/srv/api',
}),
},
],
providers: [provideRepositoryUrl('/geonetwork/srv/api')],
bootstrap: [AppComponent],
})
export class AppModule {
Expand Down
10 changes: 2 additions & 8 deletions apps/metadata-editor/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
DefaultRouterModule,
RouterService,
} from '@geonetwork-ui/feature/router'
import { Configuration } from '@geonetwork-ui/data-access/gn4'
import { getGlobalConfig, getThemeConfig } from '@geonetwork-ui/util/app-config'
import { ThemeService } from '@geonetwork-ui/util/shared'
import {
Expand All @@ -25,6 +24,7 @@ import { BrowserAnimationsModule } from '@angular/platform-browser/animations'
import { extModules } from './build-specifics'
import { DashboardPageComponent } from './dashboard/dashboard-page.component'
import { EditorRouterService } from './router.service'
import { provideRepositoryUrl } from '@geonetwork-ui/api/repository'

@NgModule({
declarations: [AppComponent],
Expand Down Expand Up @@ -56,13 +56,7 @@ import { EditorRouterService } from './router.service'
importProvidersFrom(FeatureRecordModule),
importProvidersFrom(UtilI18nModule),
importProvidersFrom(TranslateModule.forRoot(TRANSLATE_DEFAULT_CONFIG)),
{
provide: Configuration,
useFactory: () =>
new Configuration({
basePath: getGlobalConfig().GN4_API_URL,
}),
},
provideRepositoryUrl(() => getGlobalConfig().GN4_API_URL),
importProvidersFrom(EffectsModule.forRoot()),
],
bootstrap: [AppComponent],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import { StoreModule } from '@ngrx/store'
import { EffectsModule } from '@ngrx/effects'
import { TranslateModule } from '@ngx-translate/core'
import { TRANSLATE_DEFAULT_CONFIG } from '@geonetwork-ui/util/i18n'
import { Configuration } from '@geonetwork-ui/data-access/gn4'
import { OrganizationsServiceInterface } from '@geonetwork-ui/common/domain/organizations.service.interface'
import { SearchFacade, SearchService } from '@geonetwork-ui/feature/search'
import {
AuthService,
AvatarServiceInterface,
} from '@geonetwork-ui/api/repository/gn4'
import { provideRepositoryUrl } from '@geonetwork-ui/api/repository'

const user = USER_FIXTURE()
class AuthServiceMock {
Expand Down Expand Up @@ -63,15 +63,12 @@ describe('SearchHeaderComponent', () => {
],
schemas: [NO_ERRORS_SCHEMA],
providers: [
provideRepositoryUrl('/geonetwork/srv/api'),
{ provide: AuthService, useClass: AuthServiceMock },
{
provide: AvatarServiceInterface,
useClass: AvatarServiceInterfaceMock,
},
{
provide: Configuration,
useValue: new Configuration({ basePath: '/geonetwork/srv/api' }),
},
{
provide: OrganizationsServiceInterface,
useClass: OrganisationsServiceMock,
Expand Down
13 changes: 3 additions & 10 deletions apps/search/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ import { FeatureMapModule } from '@geonetwork-ui/feature/map'
import { UiLayoutModule } from '@geonetwork-ui/ui/layout'
import { UiMapModule } from '@geonetwork-ui/ui/map'
import {
UtilI18nModule,
TRANSLATE_DEFAULT_CONFIG,
UtilI18nModule,
} from '@geonetwork-ui/util/i18n'
import { Configuration } from '@geonetwork-ui/data-access/gn4'
import { FeatureSearchModule } from '@geonetwork-ui/feature/search'
import { EffectsModule } from '@ngrx/effects'
import { MetaReducer, StoreModule } from '@ngrx/store'
Expand All @@ -22,6 +21,7 @@ import { AppRoutingModule } from './app-routing.module'
import { AppComponent } from './app.component'
import { MainSearchComponent } from './main-search/main-search.component'
import { NoopAnimationsModule } from '@angular/platform-browser/animations'
import { provideRepositoryUrl } from '@geonetwork-ui/api/repository'

export const metaReducers: MetaReducer<any>[] = !environment.production
? [storeFreeze]
Expand All @@ -46,14 +46,7 @@ export const metaReducers: MetaReducer<any>[] = !environment.production
EffectsModule.forRoot(),
NoopAnimationsModule,
],
providers: [
{
provide: Configuration,
useValue: new Configuration({
basePath: environment.API_BASE_PATH,
}),
},
],
providers: [provideRepositoryUrl(environment.API_BASE_PATH)],
bootstrap: [AppComponent],
})
export class AppModule {}
1 change: 1 addition & 0 deletions libs/api/repository/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './lib/metadata-language'
export * from './lib/repository-url'
14 changes: 14 additions & 0 deletions libs/api/repository/src/lib/repository-url.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Configuration } from '@geonetwork-ui/data-access/gn4'
import { Provider } from '@angular/core'

export function provideRepositoryUrl(
urlFactory: string | (() => string)
): Provider {
return {
provide: Configuration,
useFactory: () =>
new Configuration({
basePath: typeof urlFactory === 'function' ? urlFactory() : urlFactory,
}),
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import {
DataViewPermalinkComponent,
WEB_COMPONENT_EMBEDDER_URL,
} from './data-view-permalink.component'
import { Configuration } from '@geonetwork-ui/data-access/gn4'
import { BehaviorSubject, firstValueFrom } from 'rxjs'
import { MdViewFacade } from '../state'
import { Component, Input } from '@angular/core'
import { TranslateModule } from '@ngx-translate/core'
import { GN_UI_VERSION } from '../gn-ui-version.token'
import { provideRepositoryUrl } from '@geonetwork-ui/api/repository'

const chartConfig1 = {
aggregation: 'sum',
Expand All @@ -33,9 +33,6 @@ class MdViewFacadeMock {
chartConfig$ = new BehaviorSubject(chartConfig1)
metadata$ = new BehaviorSubject(metadata)
}
class ConfigMock {
basePath: 'http://gn-api.url/'
}

const baseUrl = 'https://example.com/wc-embedder'

Expand All @@ -60,10 +57,7 @@ describe('DataViewPermalinkComponent', () => {
declarations: [DataViewPermalinkComponent, MockCopyTextButtonComponent],
imports: [TranslateModule.forRoot()],
providers: [
{
provide: Configuration,
useClass: ConfigMock,
},
provideRepositoryUrl('http://gn-api.url/'),
{
provide: MdViewFacade,
useClass: MdViewFacadeMock,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { ComponentFixture, TestBed } from '@angular/core/testing'
import { DataViewWebComponentComponent } from './data-view-web-component.component'
import { BehaviorSubject, firstValueFrom } from 'rxjs'
import { Configuration } from '@geonetwork-ui/data-access/gn4'
import { MdViewFacade } from '../state'
import { TranslateModule } from '@ngx-translate/core'
import { Component, Input } from '@angular/core'
import { GN_UI_VERSION } from '../gn-ui-version.token'
import { provideRepositoryUrl } from '@geonetwork-ui/api/repository'

const chartConfig1 = {
aggregation: 'sum',
Expand All @@ -31,9 +31,6 @@ class MdViewFacadeMock {
chartConfig$ = new BehaviorSubject(chartConfig1)
metadata$ = new BehaviorSubject(metadata)
}
class ConfigMock {
basePath: 'http://gn-api.url/'
}

@Component({
selector: 'gn-ui-copy-text-button',
Expand All @@ -58,10 +55,7 @@ describe('DataViewWebComponentComponent', () => {
],
imports: [TranslateModule.forRoot()],
providers: [
{
provide: Configuration,
useClass: ConfigMock,
},
provideRepositoryUrl('http://gn-api.url/'),
{
provide: MdViewFacade,
useClass: MdViewFacadeMock,
Expand All @@ -88,7 +82,7 @@ describe('DataViewWebComponentComponent', () => {
expect(html).toBe(
`<script src="https://cdn.jsdelivr.net/gh/geonetwork/geonetwork-ui@wc-dist-${gnUiVersion}/gn-wc.js"></script>
<gn-dataset-view-chart
api-url="http://localhost/undefined"
api-url="http://gn-api.url/"
dataset-id="${metadata.uniqueIdentifier}"
aggregation="${chartConfig1.aggregation}"
x-property="${chartConfig1.xProperty}"
Expand All @@ -113,7 +107,7 @@ describe('DataViewWebComponentComponent', () => {
expect(html).toBe(
`<script src="https://cdn.jsdelivr.net/gh/geonetwork/geonetwork-ui@wc-dist-${gnUiVersion}/gn-wc.js"></script>
<gn-dataset-view-chart
api-url="http://localhost/undefined"
api-url="http://gn-api.url/"
dataset-id="${metadata.uniqueIdentifier}"
aggregation="${chartConfig2.aggregation}"
x-property="${chartConfig2.xProperty}"
Expand Down

0 comments on commit 89464cc

Please sign in to comment.