diff --git a/frontend/src/app/corpus-definitions/form/field-form/field-form.component.html b/frontend/src/app/corpus-definitions/form/field-form/field-form.component.html index 8c8da2d99..da5c74c38 100644 --- a/frontend/src/app/corpus-definitions/form/field-form/field-form.component.html +++ b/frontend/src/app/corpus-definitions/form/field-form/field-form.component.html @@ -108,7 +108,7 @@

Fields

[class.is-disabled]="corpus.active"> - {{languageLabel(field)}} + {{languageLabel(field.get('language').value)}}
diff --git a/frontend/src/app/corpus-definitions/form/field-form/field-form.component.ts b/frontend/src/app/corpus-definitions/form/field-form/field-form.component.ts index 122144611..ba68b0cbb 100644 --- a/frontend/src/app/corpus-definitions/form/field-form/field-form.component.ts +++ b/frontend/src/app/corpus-definitions/form/field-form/field-form.component.ts @@ -198,9 +198,8 @@ export class FieldFormComponent implements OnChanges { this.dialogService.showManualPage('types-of-fields'); } - languageLabel(field: FormGroup): string { - const value = field.controls.language.value; - return this.languageOptions.find(o => o.code == value).displayName; + languageLabel(code: string): string { + return this.languageOptions.find(o => o.code == code)?.displayName || 'Unknown'; } addField(name: string) { diff --git a/frontend/src/app/corpus-definitions/form/index-form/index-form.component.html b/frontend/src/app/corpus-definitions/form/index-form/index-form.component.html index adfd14c19..c20ca00cf 100644 --- a/frontend/src/app/corpus-definitions/form/index-form/index-form.component.html +++ b/frontend/src/app/corpus-definitions/form/index-form/index-form.component.html @@ -98,13 +98,15 @@

Index data

+ [routerLink]="['/search', corpus.definition.name]" + [class.is-loading]="loading$ | async"> Search corpus diff --git a/frontend/src/app/corpus-definitions/form/index-form/index-form.component.ts b/frontend/src/app/corpus-definitions/form/index-form/index-form.component.ts index 08d4befa7..733afa348 100644 --- a/frontend/src/app/corpus-definitions/form/index-form/index-form.component.ts +++ b/frontend/src/app/corpus-definitions/form/index-form/index-form.component.ts @@ -4,7 +4,7 @@ import { APIIndexHealth, isComplete, JobStatus } from '@models/indexing'; import { ApiService, CorpusService } from '@services'; import { actionIcons } from '@shared/icons'; import * as _ from 'lodash'; -import { map, Subject, switchMap, merge, filter } from 'rxjs'; +import { map, Subject, switchMap, merge, filter, BehaviorSubject } from 'rxjs'; /** Possible states for the interface of this component */ type DisplayState = { @@ -85,9 +85,11 @@ export class IndexFormComponent implements OnChanges, OnDestroy { state$ = new Subject; destroy$ = new Subject(); + loading$ = new BehaviorSubject(false); actionIcons = actionIcons; + private jobID: number; private stopping$ = new Subject(); @@ -138,7 +140,8 @@ export class IndexFormComponent implements OnChanges, OnDestroy { toggleCorpusActive() { this.corpus.active = !this.corpus.active; - this.corpus.save(); + this.loading$.next(true); + this.corpus.save().subscribe(() => this.loading$.next(false)); } stateClass(state: DisplayState) { diff --git a/frontend/src/app/models/corpus-definition.ts b/frontend/src/app/models/corpus-definition.ts index 01b578e8b..4bb4ef45e 100644 --- a/frontend/src/app/models/corpus-definition.ts +++ b/frontend/src/app/models/corpus-definition.ts @@ -1,7 +1,7 @@ import * as _ from 'lodash'; import { ApiService, CorpusService } from '@services'; -import { BehaviorSubject, Observable } from 'rxjs'; -import { filter, share, switchMap, tap } from 'rxjs/operators'; +import { BehaviorSubject, from, Observable } from 'rxjs'; +import { delayWhen, filter, shareReplay, tap } from 'rxjs/operators'; import { findByName } from '@app/utils/utils'; export type Delimiter = ',' | ';' | '\t'; @@ -153,15 +153,13 @@ export class CorpusDefinition { const request$ = this.id ? this.apiService.updateCorpus(this.id, data) : this.apiService.createCorpus(data); - const result$ = request$.pipe(share()); - - result$.subscribe((result) => this.setFromAPIData(result)); - // refresh corpus data if applicable - result$.pipe( - switchMap(() => this.requireCorpusRefresh()), - filter(_.identity) - ).subscribe(() => this.corpusService.get(true)); + const result$ = request$.pipe( + tap(result => this.setFromAPIData(result)), + delayWhen(() => this.refreshCorpora()), + shareReplay(1), + ); + result$.subscribe(); // subscribe to execute request(s) return result$; } @@ -200,6 +198,13 @@ export class CorpusDefinition { } return Promise.resolve(false); } + + /** refresh searchable corpora if needed */ + private refreshCorpora(): Observable { + return from(this.requireCorpusRefresh().then( + refresh => refresh ? this.corpusService.get(refresh) : Promise.resolve(undefined) + )); + } }; export const FIELD_TYPE_OPTIONS: {