-
Notifications
You must be signed in to change notification settings - Fork 532
Fix CMS metadata editor language field saving #5412
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -10,6 +10,7 @@ import { provideNoopAnimations } from '@angular/platform-browser/animations'; | |||||
| import { NotificationsService } from '@dspace/core/notification-system/notifications.service'; | ||||||
| import { NotificationsServiceStub } from '@dspace/core/testing/notifications-service.stub'; | ||||||
| import { TranslateLoaderMock } from '@dspace/core/testing/translate-loader.mock'; | ||||||
| import { createSuccessfulRemoteDataObject$ } from '@dspace/core/utilities/remote-data.utils'; | ||||||
| import { | ||||||
| TranslateLoader, | ||||||
| TranslateModule, | ||||||
|
|
@@ -26,11 +27,12 @@ describe('AdminEditCmsMetadataComponent', () => { | |||||
| let component: AdminEditCmsMetadataComponent; | ||||||
| let fixture: ComponentFixture<AdminEditCmsMetadataComponent>; | ||||||
| const site = Object.assign(new Site(), { | ||||||
| metadata: { }, | ||||||
| metadata: {}, | ||||||
| }); | ||||||
|
|
||||||
| const siteServiceStub = jasmine.createSpyObj('SiteDataService', { | ||||||
| find: jasmine.createSpy('find'), | ||||||
| findByHref: jasmine.createSpy('findByHref'), | ||||||
| patch: jasmine.createSpy('patch'), | ||||||
| }); | ||||||
|
Comment on lines
33
to
37
|
||||||
|
|
||||||
|
|
@@ -70,6 +72,7 @@ describe('AdminEditCmsMetadataComponent', () => { | |||||
| fixture = TestBed.createComponent(AdminEditCmsMetadataComponent); | ||||||
| component = fixture.componentInstance; | ||||||
| siteServiceStub.find.and.returnValue(of(site)); | ||||||
| siteServiceStub.findByHref.and.returnValue(createSuccessfulRemoteDataObject$(site)); | ||||||
| siteServiceStub.patch.and.returnValue(of(site)); | ||||||
|
||||||
| siteServiceStub.patch.and.returnValue(of(site)); | |
| siteServiceStub.patch.and.returnValue(createSuccessfulRemoteDataObject$(site)); |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -84,9 +84,7 @@ export class AdminEditCmsMetadataComponent implements OnInit { | |||||||||||||||||
| } | ||||||||||||||||||
| this.metadataList.push(md); | ||||||||||||||||||
| }); | ||||||||||||||||||
| this.siteService.find().subscribe((site) => { | ||||||||||||||||||
| this.site = site; | ||||||||||||||||||
| }); | ||||||||||||||||||
| this.refreshSiteWithAllLanguages(); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| /** | ||||||||||||||||||
|
|
@@ -106,12 +104,25 @@ export class AdminEditCmsMetadataComponent implements OnInit { | |||||||||||||||||
| this.notificationsService.error(this.translateService.get('admin.edit-cms-metadata.error')); | ||||||||||||||||||
| } | ||||||||||||||||||
| this.siteService.setStale(); | ||||||||||||||||||
| this.siteService.find().subscribe((site) => { | ||||||||||||||||||
| this.site = site; | ||||||||||||||||||
| }); | ||||||||||||||||||
| this.refreshSiteWithAllLanguages(); | ||||||||||||||||||
| }); | ||||||||||||||||||
|
Comment on lines
104
to
108
|
||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| /** | ||||||||||||||||||
| * Reload site metadata including all language variants. | ||||||||||||||||||
| */ | ||||||||||||||||||
| private refreshSiteWithAllLanguages() { | ||||||||||||||||||
| this.siteService.find().subscribe((site) => { | ||||||||||||||||||
| this.siteService.findByHref(`${site.self}?projection=allLanguages`, false, true).pipe( | ||||||||||||||||||
| getFirstCompletedRemoteData(), | ||||||||||||||||||
| ).subscribe((response) => { | ||||||||||||||||||
| if (response?.hasSucceeded) { | ||||||||||||||||||
| this.site = response.payload; | ||||||||||||||||||
| } | ||||||||||||||||||
| }); | ||||||||||||||||||
| }); | ||||||||||||||||||
|
Comment on lines
+114
to
+123
|
||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| /** | ||||||||||||||||||
| * Reset metadata selection and go back to the select options | ||||||||||||||||||
| */ | ||||||||||||||||||
|
|
@@ -147,16 +158,38 @@ export class AdminEditCmsMetadataComponent implements OnInit { | |||||||||||||||||
| * @returns List of operations to send to backend to edit selected metadata | ||||||||||||||||||
| */ | ||||||||||||||||||
| private getOperationsToEditText(): Operation[] { | ||||||||||||||||||
| const entries = Array.from(this.selectedMetadataValues.entries()); | ||||||||||||||||||
| const operations: Operation[] = []; | ||||||||||||||||||
| const nonEmptyValues = Array.from(this.selectedMetadataValues.entries()) | ||||||||||||||||||
| .filter(([, text]) => text && text.trim().length > 0); | ||||||||||||||||||
|
|
||||||||||||||||||
| if (nonEmptyValues.length === 0) { | ||||||||||||||||||
| if (this.site.hasMetadata(this.selectedMetadata)) { | ||||||||||||||||||
| operations.push({ | ||||||||||||||||||
| op: 'remove', | ||||||||||||||||||
| path: `/metadata/${this.selectedMetadata}`, | ||||||||||||||||||
| }); | ||||||||||||||||||
| } | ||||||||||||||||||
| return operations; | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| if (this.site.hasMetadata(this.selectedMetadata)) { | ||||||||||||||||||
| operations.push({ | ||||||||||||||||||
| op: 'remove', | ||||||||||||||||||
| path: `/metadata/${this.selectedMetadata}`, | ||||||||||||||||||
| }); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| nonEmptyValues.forEach(([language, text]) => { | ||||||||||||||||||
| operations.push({ | ||||||||||||||||||
| op: 'add', | ||||||||||||||||||
| path: `/metadata/${this.selectedMetadata}/-`, | ||||||||||||||||||
| value: { | ||||||||||||||||||
| value: text, | ||||||||||||||||||
| language, | ||||||||||||||||||
| }, | ||||||||||||||||||
|
Comment on lines
+186
to
+189
|
||||||||||||||||||
| value: { | |
| value: text, | |
| language, | |
| }, | |
| value: [{ | |
| value: text, | |
| language, | |
| }], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The component now builds the
findByHrefURL fromsite.self, but this spec’ssitetest object doesn’t define_links.self.href(or set theselfsetter). With the new code,site.selfwill throw duringngOnInit. Update the test fixture to setsite.self(or_links.self.href) to a dummy value so initialization doesn’t crash and theprojection=allLanguagesURL can be asserted.