Skip to content
This repository was archived by the owner on Aug 28, 2023. It is now read-only.

Commit 2f2653e

Browse files
authored
[21134] Connect markdown prettifier for OMZ models description (#63)
1 parent f73e7f3 commit 2f2653e

File tree

39 files changed

+179
-342
lines changed

39 files changed

+179
-342
lines changed

client/e2e/src/pages/test-utils.ts

-7
Original file line numberDiff line numberDiff line change
@@ -801,13 +801,6 @@ export class TestUtils {
801801
}
802802
}
803803

804-
async getMessageFromErrorContainer(): Promise<string> {
805-
const detailsButton: ElementFinder = await TestUtils.getElementByDataTestId('details-button');
806-
await this.clickElement(detailsButton);
807-
const messageContainer: ElementFinder = await TestUtils.getElementByDataTestId('message-details');
808-
return messageContainer.element(by.className('markdown-text-block')).getText();
809-
}
810-
811804
async waitRowStatus() {
812805
await this.inferenceCard.waitForProgressBar();
813806
return await this.waitForProjectToBeReady();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { Injectable } from '@angular/core';
2+
import { Router } from '@angular/router';
3+
4+
import { includes, isNil, isString, startsWith } from 'lodash';
5+
import { filter } from 'rxjs/operators';
6+
7+
import { DialogService } from '@core/services/common/dialog.service';
8+
9+
import { linkRegExp } from '@shared/pipes';
10+
11+
@Injectable({
12+
providedIn: 'root',
13+
})
14+
export class LinkNavigationService {
15+
private readonly _externalLinkMessage = this._dialogService.dialogMessages.externalLinkMessage;
16+
17+
private static _isInternalURL(url: string): boolean {
18+
return includes(url, location.hostname) || startsWith(url, '/');
19+
}
20+
21+
constructor(private _dialogService: DialogService, private _router: Router) {}
22+
23+
navigate(url: string): void {
24+
const isValidURL = linkRegExp.test(url);
25+
// as we use global regex it is needed to reset the state
26+
// (https://stackoverflow.com/questions/2630418/javascript-regex-returning-true-then-false-then-true-etc)
27+
linkRegExp.lastIndex = 0;
28+
if (isNil(url) || !isString(url) || !isValidURL) {
29+
return;
30+
}
31+
if (LinkNavigationService._isInternalURL(url)) {
32+
this._router.navigateByUrl(url);
33+
return;
34+
}
35+
this._dialogService
36+
.openConfirmationDialog({ message: this._externalLinkMessage })
37+
.afterClosed()
38+
.pipe(filter((res) => !!res))
39+
.subscribe(() => {
40+
window.open(url, '_blank');
41+
});
42+
}
43+
}

client/src/app/modules/accuracy/components/advanced-accuracy-configuration/advanced-accuracy-configuration.component.scss

-4
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@
77

88
:host ::ng-deep {
99
@import 'node_modules/monaco-editor/min/vs/editor/editor.main';
10-
11-
.hint-container .markdown-text-block {
12-
white-space: pre-wrap;
13-
}
1410
}
1511

1612
.model-type-selection {

client/src/app/modules/dashboard/components/deployment-manager/deployment-manager.component.scss

-5
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,6 @@ mat-radio-group.wb-radio-group .mat-radio-button {
6363
}
6464
}
6565

66-
// FIXME: replace txt class in hint component
67-
.hint ::ng-deep .markdown-text-block {
68-
@include wb-label();
69-
}
70-
7166
.tip ::ng-deep .ui-tip {
7267
max-width: none;
7368
}

client/src/app/modules/dataset-manager/components/create-dataset/create-dataset.component.spec.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ComponentFixture, TestBed } from '@angular/core/testing';
22
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
3+
import { RouterTestingModule } from '@angular/router/testing';
34

45
import { SharedModule } from '@shared/shared.module';
56

@@ -11,7 +12,7 @@ describe('CreateDatasetComponent', () => {
1112

1213
beforeEach(async () => {
1314
await TestBed.configureTestingModule({
14-
imports: [BrowserAnimationsModule, SharedModule],
15+
imports: [RouterTestingModule, BrowserAnimationsModule, SharedModule],
1516
declarations: [CreateDatasetComponent],
1617
}).compileComponents();
1718
});

client/src/app/modules/dataset-manager/components/dataset-upload/dataset-upload.component.scss

-4
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,6 @@ $footer-height: 40px;
135135
&:not(:last-child) {
136136
margin-bottom: 20px;
137137
}
138-
139-
::ng-deep .markdown-text-block {
140-
white-space: pre-wrap;
141-
}
142138
}
143139
.feedback-info {
144140
margin: 0 $container-padding $container-padding;

client/src/app/modules/dataset-manager/pages/import-text-dataset-page/text-dataset-data/text-dataset-data.component.spec.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ComponentFixture, TestBed } from '@angular/core/testing';
22
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
3+
import { RouterTestingModule } from '@angular/router/testing';
34

45
import { SharedModule } from '@shared/shared.module';
56

@@ -12,7 +13,7 @@ describe('TextDatasetDataComponent', () => {
1213

1314
beforeEach(async () => {
1415
await TestBed.configureTestingModule({
15-
imports: [SharedModule, NoopAnimationsModule, DatasetManagerModule],
16+
imports: [RouterTestingModule, SharedModule, NoopAnimationsModule, DatasetManagerModule],
1617
declarations: [TextDatasetDataComponent],
1718
}).compileComponents();
1819
});

client/src/app/modules/dataset-manager/pages/import-text-dataset-page/text-dataset-info/text-dataset-info.component.scss

-4
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,6 @@ mat-expansion-panel.wb-panel {
4444
background: $faded-bgr;
4545
}
4646

47-
::ng-deep .markdown-text-block {
48-
white-space: pre-wrap;
49-
}
50-
5147
.dataset-info-content-divider {
5248
margin-left: -20px;
5349
margin-right: -20px;

client/src/app/modules/login/pages/login/login.component.scss

-4
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@
2222
::ng-deep .hint-container {
2323
align-items: flex-start;
2424
}
25-
26-
::ng-deep .markdown-text-block {
27-
line-height: 20px;
28-
}
2925
}
3026
}
3127

client/src/app/modules/model-manager/components/hugging-face-import-ribbon-content/hugging-face-import-ribbon-content.component.spec.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ComponentFixture, TestBed } from '@angular/core/testing';
22
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
3+
import { RouterTestingModule } from '@angular/router/testing';
34

45
import { StoreModule } from '@ngrx/store';
56

@@ -23,6 +24,7 @@ describe('HuggingFaceImportRibbonContentComponent', () => {
2324
imports: [
2425
SharedModule,
2526
NoopAnimationsModule,
27+
RouterTestingModule,
2628
StoreModule.forRoot({
2729
...RootStoreState.reducers,
2830
}),

client/src/app/modules/model-manager/components/hugging-face-import-ribbon-content/huggingface-model-details/huggingface-model-details.component.html

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
</wb-model-zoo-details-parameters>
1010

1111
<wb-model-zoo-details-description>
12-
<div
13-
class="readme markdown-body"
12+
<wb-markdown-text
13+
class="readme"
1414
*wbSkeleton="loading$ | async; repeat: 10; width: 'rand'; gap: '20px'"
15-
[innerHTML]="markdownHTML$ | async"
15+
[text]="markdownHTML$ | async"
1616
data-test-id="model-description"
17-
></div>
17+
></wb-markdown-text>
1818
<div class="readme-not-found wb-text-8" *ngIf="error$ | async">No readme found.</div>
1919
</wb-model-zoo-details-description>
2020

client/src/app/modules/model-manager/components/hugging-face-import-ribbon-content/huggingface-model-details/huggingface-model-details.component.scss

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@import 'colors';
2+
@import 'fonts';
23

34
:host {
45
display: flex;
@@ -8,7 +9,7 @@
89
}
910

1011
.readme ::ng-deep {
11-
font-family: Roboto, sans-serif;
12+
@include wb-text-8();
1213

1314
table {
1415
border-spacing: 0;

client/src/app/modules/model-manager/components/hugging-face-import-ribbon-content/huggingface-model-details/huggingface-model-details.component.spec.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { ComponentFixture, TestBed } from '@angular/core/testing';
2+
import { RouterTestingModule } from '@angular/router/testing';
23

34
import { StoreModule } from '@ngrx/store';
45

@@ -9,7 +10,6 @@ import { RootStoreState } from '@store';
910
import { SharedModule } from '@shared/shared.module';
1011

1112
import { HuggingfaceModelDetailsComponent } from './huggingface-model-details.component';
12-
import { MarkdownService } from './markdown/markdown.service';
1313

1414
describe('HuggingfaceModelDetailsComponent', () => {
1515
let component: HuggingfaceModelDetailsComponent;
@@ -19,11 +19,12 @@ describe('HuggingfaceModelDetailsComponent', () => {
1919
await TestBed.configureTestingModule({
2020
imports: [
2121
SharedModule,
22+
RouterTestingModule,
2223
StoreModule.forRoot({
2324
...RootStoreState.reducers,
2425
}),
2526
],
26-
providers: [HuggingfaceService, MarkdownService],
27+
providers: [HuggingfaceService],
2728
declarations: [HuggingfaceModelDetailsComponent],
2829
}).compileComponents();
2930
});

client/src/app/modules/model-manager/components/hugging-face-import-ribbon-content/huggingface-model-details/huggingface-model-details.component.ts

+1-7
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import {
1111
import { DatePipe } from '@angular/common';
1212

1313
import { Store } from '@ngrx/store';
14-
import { switchMap } from 'rxjs/operators';
15-
import { of, from } from 'rxjs';
1614

1715
import { ModelDomain, modelDomainNames } from '@store/model-store/model.model';
1816
import { RootStoreState } from '@store';
@@ -22,7 +20,6 @@ import { IHuggingfaceModel } from '@shared/models/huggingface/huggingface-model'
2220
import { IParameter } from '@shared/components/model-details/parameter-details/parameter-details.component';
2321
import { shortenNumber } from '@shared/pipes/format-number.pipe';
2422

25-
import { MarkdownService } from './markdown/markdown.service';
2623
import { IHuggingfaceTagsSets } from '../hugging-face-import-ribbon-content.component';
2724

2825
@Component({
@@ -53,9 +50,7 @@ export class HuggingfaceModelDetailsComponent {
5350
@Output() import = new EventEmitter<void>();
5451
@Output() hide = new EventEmitter<void>();
5552

56-
readonly markdownHTML$ = this._store$
57-
.select(HuggingfaceModelStoreSelectors.selectModelReadme)
58-
.pipe(switchMap((readme) => (readme ? from(this._mdService.parse(readme)) : of(null))));
53+
readonly markdownHTML$ = this._store$.select(HuggingfaceModelStoreSelectors.selectModelReadme);
5954

6055
readonly loading$ = this._store$.select(HuggingfaceModelStoreSelectors.selectModelReadmeLoading);
6156
readonly error$ = this._store$.select(HuggingfaceModelStoreSelectors.selectModelReadmeError);
@@ -66,7 +61,6 @@ export class HuggingfaceModelDetailsComponent {
6661

6762
constructor(
6863
private readonly _cdr: ChangeDetectorRef,
69-
private readonly _mdService: MarkdownService,
7064
private readonly _store$: Store<RootStoreState.State>,
7165
@Inject(LOCALE_ID) private readonly _localeId: string
7266
) {}

client/src/app/modules/model-manager/components/hugging-face-import-ribbon-content/huggingface-model-details/markdown/index.ts

-7
This file was deleted.

client/src/app/modules/model-manager/components/hugging-face-import-ribbon-content/huggingface-model-details/markdown/markdown.service.spec.ts

-16
This file was deleted.

client/src/app/modules/model-manager/components/hugging-face-import-ribbon-content/huggingface-model-details/markdown/markdown.service.ts

-25
This file was deleted.

client/src/app/modules/model-manager/components/model-manager-convert/model-manager-convert.component.spec.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { ComponentFixture, TestBed } from '@angular/core/testing';
2+
import { RouterTestingModule } from '@angular/router/testing';
23

34
import { StoreModule } from '@ngrx/store';
45

@@ -18,6 +19,7 @@ describe('ModelManagerConvertComponent', () => {
1819
declarations: [ModelManagerConvertComponent],
1920
imports: [
2021
SharedModule,
22+
RouterTestingModule,
2123
StoreModule.forRoot({
2224
...RootStoreState.reducers,
2325
}),

client/src/app/modules/model-manager/components/model-manager-convert/transformations-config-field/transformations-config-field.component.spec.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ComponentFixture, TestBed } from '@angular/core/testing';
22
import { FormControl, FormGroup } from '@angular/forms';
3+
import { RouterTestingModule } from '@angular/router/testing';
34

45
import { SharedModule } from '@shared/shared.module';
56

@@ -19,7 +20,7 @@ describe('TransformationsConfigFieldComponent', () => {
1920

2021
beforeEach(async () => {
2122
await TestBed.configureTestingModule({
22-
imports: [SharedModule],
23+
imports: [RouterTestingModule, SharedModule],
2324
}).compileComponents();
2425
});
2526

client/src/app/modules/model-manager/components/omz-import-ribbon-content/omz-model-details/omz-model-details.component.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<wb-model-zoo-details-description>
1414
<div class="title">Description</div>
1515
<div class="description" data-test-id="model-description">
16-
<wb-markdown-text [text]="model?.description | linkify"></wb-markdown-text>
16+
<wb-markdown-text [text]="model?.description"></wb-markdown-text>
1717
</div>
1818
<div class="title">Licence</div>
1919
<div class="description" data-test-id="model-license">

client/src/app/modules/model-manager/components/omz-model-info/omz-model-info.component.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<div class="content" data-test-id="omz-model-info">
66
<div class="title">Description</div>
77
<div class="description">
8-
<wb-markdown-text [text]="modelInfo?.description | linkify" class="wb-label"></wb-markdown-text>
8+
<wb-markdown-text [text]="modelInfo?.description" class="wb-label"></wb-markdown-text>
99
</div>
1010
<div class="title title-license">Licence</div>
1111
<div class="content-license">

client/src/app/modules/model-manager/components/omz-model-info/omz-model-info.component.spec.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
2+
import { RouterTestingModule } from '@angular/router/testing';
23

34
import { SharedModule } from '@shared/shared.module';
45

@@ -11,7 +12,7 @@ describe('OmzModelInfoComponent', () => {
1112
beforeEach(
1213
waitForAsync(() => {
1314
TestBed.configureTestingModule({
14-
imports: [SharedModule],
15+
imports: [RouterTestingModule, SharedModule],
1516
declarations: [OmzModelInfoComponent],
1617
}).compileComponents();
1718
})

client/src/app/modules/target-machines/components/pipeline-stages/pipeline-stages.component.spec.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
22
import { CommonModule } from '@angular/common';
3+
import { RouterTestingModule } from '@angular/router/testing';
34

45
import { SharedModule } from '@shared/shared.module';
56

@@ -15,7 +16,7 @@ describe('PipelineStagesComponent', () => {
1516
beforeEach(
1617
waitForAsync(() => {
1718
TestBed.configureTestingModule({
18-
imports: [CommonModule, SharedModule],
19+
imports: [CommonModule, RouterTestingModule, SharedModule],
1920
declarations: [
2021
PipelineStagesComponent,
2122
PipelineStageStatusComponent,

0 commit comments

Comments
 (0)