From 9d08cac56603dda7d0271f9af826c12082d85e35 Mon Sep 17 00:00:00 2001 From: Nona Luypaert Date: Fri, 2 Jun 2023 13:31:53 +0200 Subject: [PATCH] 101623: Reset in Treeview also resets selectedItems + Provide TreeviewService in root --- src/app/browse-by/browse-by-page.module.ts | 2 +- .../vocabularies/vocabulary.service.ts | 6 ++++-- src/app/shared/form/form.module.ts | 2 -- .../vocabulary-treeview.component.html | 2 ++ .../vocabulary-treeview.component.spec.ts | 10 ++++++++++ .../vocabulary-treeview.component.ts | 17 +++++++++++++++-- .../vocabulary-treeview.service.ts | 4 +++- src/modules/app/browser-app.module.ts | 5 ----- 8 files changed, 35 insertions(+), 13 deletions(-) diff --git a/src/app/browse-by/browse-by-page.module.ts b/src/app/browse-by/browse-by-page.module.ts index fea6668b3c..2f4ae433c9 100644 --- a/src/app/browse-by/browse-by-page.module.ts +++ b/src/app/browse-by/browse-by-page.module.ts @@ -13,7 +13,7 @@ import { BrowseByGuard } from './browse-by-guard'; providers: [ ItemDataService, BrowseService, - BrowseByGuard + BrowseByGuard, ] }) export class BrowseByPageModule { diff --git a/src/app/core/submission/vocabularies/vocabulary.service.ts b/src/app/core/submission/vocabularies/vocabulary.service.ts index f2c1747658..1ff5b30ee0 100644 --- a/src/app/core/submission/vocabularies/vocabulary.service.ts +++ b/src/app/core/submission/vocabularies/vocabulary.service.ts @@ -223,13 +223,15 @@ export class VocabularyService { * no valid cached version. Defaults to true * @param reRequestOnStale Whether or not the request should automatically be re- * requested after the response becomes stale + * @param constructId Whether constructing the full vocabularyDetail ID + * ({vocabularyName}:{detailName}) is still necessary * @param linksToFollow List of {@link FollowLinkConfig} that indicate which * {@link HALLink}s should be automatically resolved * @return {Observable>} * Return an observable that emits VocabularyEntryDetail object */ - findEntryDetailById(id: string, name: string, useCachedVersionIfAvailable = true, reRequestOnStale = true, ...linksToFollow: FollowLinkConfig[]): Observable> { - const findId = `${name}:${id}`; + findEntryDetailById(id: string, name: string, useCachedVersionIfAvailable = true, reRequestOnStale = true, constructId: boolean = true, ...linksToFollow: FollowLinkConfig[]): Observable> { + const findId: string = (constructId ? `${name}:${id}` : id); return this.vocabularyEntryDetailDataService.findById(findId, useCachedVersionIfAvailable, reRequestOnStale, ...linksToFollow); } diff --git a/src/app/shared/form/form.module.ts b/src/app/shared/form/form.module.ts index 6e3fc33832..c2fc4c855e 100644 --- a/src/app/shared/form/form.module.ts +++ b/src/app/shared/form/form.module.ts @@ -32,7 +32,6 @@ import { NumberPickerComponent } from './number-picker/number-picker.component'; import { AuthorityConfidenceStateDirective } from './directives/authority-confidence-state.directive'; import { SortablejsModule } from 'ngx-sortablejs'; import { VocabularyTreeviewComponent } from './vocabulary-treeview/vocabulary-treeview.component'; -import { VocabularyTreeviewService } from './vocabulary-treeview/vocabulary-treeview.service'; import { VocabularyTreeviewModalComponent } from './vocabulary-treeview-modal/vocabulary-treeview-modal.component'; import { FormBuilderService } from './builder/form-builder.service'; import { DsDynamicTypeBindRelationService } from './builder/ds-dynamic-form-ui/ds-dynamic-type-bind-relation.service'; @@ -104,7 +103,6 @@ const DIRECTIVES = [ useValue: dsDynamicFormControlMapFn }, ...DYNAMIC_MATCHER_PROVIDERS, - VocabularyTreeviewService, DynamicFormLayoutService, DynamicFormService, DynamicFormValidationService, diff --git a/src/app/shared/form/vocabulary-treeview/vocabulary-treeview.component.html b/src/app/shared/form/vocabulary-treeview/vocabulary-treeview.component.html index 9cbc0146a1..fb7d162008 100644 --- a/src/app/shared/form/vocabulary-treeview/vocabulary-treeview.component.html +++ b/src/app/shared/form/vocabulary-treeview/vocabulary-treeview.component.html @@ -33,6 +33,7 @@ > @@ -65,6 +66,7 @@ container="body"> diff --git a/src/app/shared/form/vocabulary-treeview/vocabulary-treeview.component.spec.ts b/src/app/shared/form/vocabulary-treeview/vocabulary-treeview.component.spec.ts index 9ca8d7ab8b..97a21b724b 100644 --- a/src/app/shared/form/vocabulary-treeview/vocabulary-treeview.component.spec.ts +++ b/src/app/shared/form/vocabulary-treeview/vocabulary-treeview.component.spec.ts @@ -21,6 +21,7 @@ import { AuthTokenInfo } from '../../../core/auth/models/auth-token-info.model'; import { authReducer } from '../../../core/auth/auth.reducer'; import { storeModuleConfig } from '../../../app.reducer'; import { By } from '@angular/platform-browser'; +import { VocabularyService } from '../../../core/submission/vocabularies/vocabulary.service'; describe('VocabularyTreeviewComponent test suite', () => { @@ -49,6 +50,14 @@ describe('VocabularyTreeviewComponent test suite', () => { restoreNodes: jasmine.createSpy('restoreNodes'), cleanTree: jasmine.createSpy('cleanTree'), }); + const vocabularyServiceStub = jasmine.createSpyObj('VocabularyService', { + getVocabularyEntriesByValue: jasmine.createSpy('getVocabularyEntriesByValue'), + getEntryDetailParent: jasmine.createSpy('getEntryDetailParent'), + findEntryDetailById: jasmine.createSpy('findEntryDetailById'), + searchTopEntries: jasmine.createSpy('searchTopEntries'), + getEntryDetailChildren: jasmine.createSpy('getEntryDetailChildren'), + clearSearchTopRequests: jasmine.createSpy('clearSearchTopRequests') + }); initialState = { core: { @@ -77,6 +86,7 @@ describe('VocabularyTreeviewComponent test suite', () => { ], providers: [ { provide: VocabularyTreeviewService, useValue: vocabularyTreeviewServiceStub }, + { provide: VocabularyService, useValue: vocabularyServiceStub }, { provide: NgbActiveModal, useValue: modalStub }, provideMockStore({ initialState }), ChangeDetectorRef, diff --git a/src/app/shared/form/vocabulary-treeview/vocabulary-treeview.component.ts b/src/app/shared/form/vocabulary-treeview/vocabulary-treeview.component.ts index 891a825745..017416e8c2 100644 --- a/src/app/shared/form/vocabulary-treeview/vocabulary-treeview.component.ts +++ b/src/app/shared/form/vocabulary-treeview/vocabulary-treeview.component.ts @@ -17,6 +17,8 @@ import { VocabularyTreeFlattener } from './vocabulary-tree-flattener'; import { VocabularyTreeFlatDataSource } from './vocabulary-tree-flat-data-source'; import { CoreState } from '../../../core/core-state.model'; import { lowerCase } from 'lodash/string'; +import { VocabularyService } from '../../../core/submission/vocabularies/vocabulary.service'; +import { getFirstSucceededRemoteDataPayload } from '../../../core/shared/operators'; /** * Component that shows a hierarchical vocabulary in a tree view @@ -114,11 +116,13 @@ export class VocabularyTreeviewComponent implements OnDestroy, OnInit { * Initialize instance variables * * @param {VocabularyTreeviewService} vocabularyTreeviewService + * @param {vocabularyService} vocabularyService * @param {Store} store * @param {TranslateService} translate */ constructor( private vocabularyTreeviewService: VocabularyTreeviewService, + private vocabularyService: VocabularyService, private store: Store, private translate: TranslateService ) { @@ -284,13 +288,22 @@ export class VocabularyTreeviewComponent implements OnDestroy, OnInit { * Reset tree resulting from a previous search */ reset() { + this.searchText = ''; + for (const item of this.selectedItems) { + this.subs.push(this.vocabularyService.findEntryDetailById(item, this.vocabularyOptions.name, true, true, false).pipe( + getFirstSucceededRemoteDataPayload(), + ).subscribe((detail: VocabularyEntryDetail) => { + this.deselect.emit(detail); + })); + this.nodeMap.get(item).isSelected = false; + } + this.selectedItems = []; + if (isNotEmpty(this.storedNodeMap)) { this.nodeMap = this.storedNodeMap; this.storedNodeMap = new Map(); this.vocabularyTreeviewService.restoreNodes(); } - - this.searchText = ''; } /** diff --git a/src/app/shared/form/vocabulary-treeview/vocabulary-treeview.service.ts b/src/app/shared/form/vocabulary-treeview/vocabulary-treeview.service.ts index d400615f1e..f524af4c0e 100644 --- a/src/app/shared/form/vocabulary-treeview/vocabulary-treeview.service.ts +++ b/src/app/shared/form/vocabulary-treeview/vocabulary-treeview.service.ts @@ -25,7 +25,9 @@ import { VocabularyEntryDetail } from '../../../core/submission/vocabularies/mod /** * A service that provides methods to deal with vocabulary tree */ -@Injectable() +@Injectable({ + providedIn: 'root' +}) export class VocabularyTreeviewService { /** diff --git a/src/modules/app/browser-app.module.ts b/src/modules/app/browser-app.module.ts index 4cdf7fbe2f..68e328a8d5 100644 --- a/src/modules/app/browser-app.module.ts +++ b/src/modules/app/browser-app.module.ts @@ -31,7 +31,6 @@ import { GoogleAnalyticsService } from '../../app/statistics/google-analytics.se import { AuthRequestService } from '../../app/core/auth/auth-request.service'; import { BrowserAuthRequestService } from '../../app/core/auth/browser-auth-request.service'; import { BrowserInitService } from './browser-init.service'; -import { VocabularyTreeviewService } from 'src/app/shared/form/vocabulary-treeview/vocabulary-treeview.service'; export const REQ_KEY = makeStateKey('req'); @@ -111,10 +110,6 @@ export function getRequest(transferState: TransferState): any { { provide: LocationToken, useFactory: locationProvider, - }, - { - provide: VocabularyTreeviewService, - useClass: VocabularyTreeviewService, } ] })