Skip to content

Commit

Permalink
refactor(datahub): renamed search-results-error component to error co…
Browse files Browse the repository at this point in the history
…mponent.
  • Loading branch information
Romuald Caplier committed May 27, 2024
1 parent e86e2d2 commit d0775d4
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,10 @@
</div>
</div>
<ng-container *ngIf="displayDatasetHasNoLinkBlock$ | async">
<gn-ui-search-results-error
<gn-ui-error
data-test="dataset-has-no-link-block"
[type]="errorTypes.DATASET_HAS_NO_LINK"
></gn-ui-search-results-error>
></gn-ui-error>
</ng-container>
<div id="related-records" *ngIf="displayRelated$ | async">
<div>
Expand Down Expand Up @@ -166,14 +166,14 @@
class="mt-12 p-4 max-w-[600px] m-auto text-[13px]"
*ngIf="metadataViewFacade.error$ | async as error"
>
<gn-ui-search-results-error
<gn-ui-error
*ngIf="error.notFound"
[type]="errorTypes.RECORD_NOT_FOUND"
[recordId]="(metadataViewFacade.metadata$ | async).uniqueIdentifier"
></gn-ui-search-results-error>
<gn-ui-search-results-error
></gn-ui-error>
<gn-ui-error
*ngIf="error.otherError"
[type]="errorTypes.RECEIVED_ERROR"
[error]="error.otherError"
></gn-ui-search-results-error>
></gn-ui-error>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,9 @@ import { By } from '@angular/platform-browser'
import { SourcesService } from '@geonetwork-ui/feature/catalog'
import { MapManagerService } from '@geonetwork-ui/feature/map'
import { SearchService } from '@geonetwork-ui/feature/search'
import {
ErrorType,
SearchResultsErrorComponent,
} from '@geonetwork-ui/ui/elements'
import { ErrorComponent, ErrorType } from '@geonetwork-ui/ui/elements'
import { TranslateModule } from '@ngx-translate/core'
import { BehaviorSubject, of, tap } from 'rxjs'
import { BehaviorSubject, of } from 'rxjs'
import { RecordMetadataComponent } from './record-metadata.component'
import { OrganizationsServiceInterface } from '@geonetwork-ui/common/domain/organizations.service.interface'
import { DATASET_RECORDS } from '@geonetwork-ui/common/fixtures'
Expand Down Expand Up @@ -177,7 +174,7 @@ describe('RecordMetadataComponent', () => {
MockDataOtherlinksComponent,
MockDataApisComponent,
MockRelatedComponent,
SearchResultsErrorComponent,
ErrorComponent,
MockMetadataInfoComponent,
MockMetadataCatalogComponent,
MockMetadataContactComponent,
Expand Down Expand Up @@ -625,9 +622,7 @@ describe('RecordMetadataComponent', () => {
it('does not show errors', () => {
facade.otherLinks$.next([''])
fixture.detectChanges()
const result = fixture.debugElement.query(
By.directive(SearchResultsErrorComponent)
)
const result = fixture.debugElement.query(By.directive(ErrorComponent))
expect(result).toBeFalsy()
})
})
Expand All @@ -637,9 +632,7 @@ describe('RecordMetadataComponent', () => {
fixture.detectChanges()
})
it('shows error', () => {
const result = fixture.debugElement.query(
By.directive(SearchResultsErrorComponent)
)
const result = fixture.debugElement.query(By.directive(ErrorComponent))

expect(result).toBeTruthy()
expect(result.componentInstance.type).toBe(ErrorType.RECORD_NOT_FOUND)
Expand All @@ -655,9 +648,7 @@ describe('RecordMetadataComponent', () => {
fixture.detectChanges()
})
it('shows error', () => {
const result = fixture.debugElement.query(
By.directive(SearchResultsErrorComponent)
)
const result = fixture.debugElement.query(By.directive(ErrorComponent))

expect(result).toBeTruthy()
expect(result.componentInstance.type).toBe(ErrorType.RECEIVED_ERROR)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@
</div>

<div class="p-4 max-w-[600px] m-auto text-[13px]">
<gn-ui-search-results-error
<gn-ui-error
*ngIf="(errorCode$ | async) === 0"
[type]="errorTypes.COULD_NOT_REACH_API"
>
</gn-ui-search-results-error>
<gn-ui-search-results-error
</gn-ui-error>
<gn-ui-error
*ngIf="(error$ | async) !== null && (errorCode$ | async) !== 0"
[type]="errorTypes.RECEIVED_ERROR"
[error]="errorMessage$ | async"
></gn-ui-search-results-error>
></gn-ui-error>
</div>

<ng-template #favoriteToggle let-record>
Expand Down
2 changes: 1 addition & 1 deletion libs/ui/elements/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export * from './lib/pagination-buttons/pagination-buttons.component'
export * from './lib/pagination/pagination.component'
export * from './lib/record-api-form/record-api-form.component'
export * from './lib/related-record-card/related-record-card.component'
export * from './lib/search-results-error/search-results-error.component'
export * from './lib/error/error.component'
export * from './lib/thumbnail/thumbnail.component'
export * from './lib/ui-elements.module'
export * from './lib/user-preview/user-preview.component'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing'

import {
ErrorType,
SearchResultsErrorComponent,
} from './search-results-error.component'
import { ErrorComponent, ErrorType } from './error.component'
import { DebugElement, NO_ERRORS_SCHEMA } from '@angular/core'
import { By } from '@angular/platform-browser'

describe('SearchResultsErrorComponent', () => {
let component: SearchResultsErrorComponent
let fixture: ComponentFixture<SearchResultsErrorComponent>
describe('ErrorComponent', () => {
let component: ErrorComponent
let fixture: ComponentFixture<ErrorComponent>
let compiled: DebugElement

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [SearchResultsErrorComponent],
declarations: [ErrorComponent],
schemas: [NO_ERRORS_SCHEMA],
}).compileComponents()
})

beforeEach(() => {
fixture = TestBed.createComponent(SearchResultsErrorComponent)
fixture = TestBed.createComponent(ErrorComponent)
component = fixture.componentInstance
compiled = fixture.debugElement
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import {
ErrorType,
SearchResultsErrorComponent,
} from './search-results-error.component'
import { ErrorComponent, ErrorType } from './error.component'
import {
applicationConfig,
componentWrapperDecorator,
Expand All @@ -19,8 +16,8 @@ import { importProvidersFrom } from '@angular/core'
import { MatIcon } from '@angular/material/icon'

export default {
title: 'Elements/SearchResultsErrorComponent',
component: SearchResultsErrorComponent,
title: 'Elements/ErrorComponent',
component: ErrorComponent,
decorators: [
moduleMetadata({
declarations: [MatIcon],
Expand All @@ -36,9 +33,9 @@ export default {
(story) => `<div style="max-width: 800px">${story}</div>`
),
],
} as Meta<SearchResultsErrorComponent>
} as Meta<ErrorComponent>

export const Primary: StoryObj<SearchResultsErrorComponent> = {
export const Primary: StoryObj<ErrorComponent> = {
args: {
type: ErrorType.RECEIVED_ERROR,
error: 'something wrong happened',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ export enum ErrorType {
}

@Component({
selector: 'gn-ui-search-results-error',
templateUrl: './search-results-error.component.html',
styleUrls: ['./search-results-error.component.css'],
selector: 'gn-ui-error',
templateUrl: './error.component.html',
styleUrls: ['./error.component.css'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class SearchResultsErrorComponent {
export class ErrorComponent {
@Input() type!: ErrorType
@Input() error?: string
@Input() recordId?: string
Expand Down
7 changes: 3 additions & 4 deletions libs/ui/elements/src/lib/ui-elements.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@ import { ApiCardComponent } from './api-card/api-card.component'
import { UiWidgetsModule } from '@geonetwork-ui/ui/widgets'
import { UiLayoutModule } from '@geonetwork-ui/ui/layout'
import { TranslateModule } from '@ngx-translate/core'
import { LinkCardComponent } from './link-card/link-card.component'
import { RelatedRecordCardComponent } from './related-record-card/related-record-card.component'
import { MetadataContactComponent } from './metadata-contact/metadata-contact.component'
import { MetadataCatalogComponent } from './metadata-catalog/metadata-catalog.component'
import { MetadataQualityComponent } from './metadata-quality/metadata-quality.component'
import { MetadataQualityItemComponent } from './metadata-quality-item/metadata-quality-item.component'
import { SearchResultsErrorComponent } from './search-results-error/search-results-error.component'
import { ErrorComponent } from './error/error.component'
import { PaginationComponent } from './pagination/pagination.component'
import { ThumbnailComponent } from './thumbnail/thumbnail.component'
import { UiInputsModule } from '@geonetwork-ui/ui/inputs'
Expand Down Expand Up @@ -62,7 +61,7 @@ import { TimeSincePipe } from './user-feedback-item/time-since.pipe'
MetadataCatalogComponent,
MetadataQualityComponent,
MetadataQualityItemComponent,
SearchResultsErrorComponent,
ErrorComponent,
PaginationComponent,
AvatarComponent,
UserPreviewComponent,
Expand All @@ -84,7 +83,7 @@ import { TimeSincePipe } from './user-feedback-item/time-since.pipe'
MetadataCatalogComponent,
MetadataQualityComponent,
MetadataQualityItemComponent,
SearchResultsErrorComponent,
ErrorComponent,
PaginationComponent,
ThumbnailComponent,
AvatarComponent,
Expand Down

0 comments on commit d0775d4

Please sign in to comment.