Skip to content
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

Fix issues with meta tags #1228

Merged
merged 21 commits into from
Jul 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions src/app/+collection-page/collection-page.component.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { BehaviorSubject, combineLatest as observableCombineLatest, Observable, Subject } from 'rxjs';
import {
BehaviorSubject,
combineLatest as observableCombineLatest,
Observable,
Subject
} from 'rxjs';
import { filter, map, mergeMap, startWith, switchMap, take } from 'rxjs/operators';
import { PaginatedSearchOptions } from '../shared/search/paginated-search-options.model';
import { SearchService } from '../core/shared/search/search.service';
import { SortDirection, SortOptions } from '../core/cache/models/sort-options.model';
import { CollectionDataService } from '../core/data/collection-data.service';
import { PaginatedList } from '../core/data/paginated-list.model';
import { RemoteData } from '../core/data/remote-data';

import { MetadataService } from '../core/metadata/metadata.service';
import { Bitstream } from '../core/shared/bitstream.model';

import { Collection } from '../core/shared/collection.model';
Expand Down Expand Up @@ -65,7 +68,6 @@ export class CollectionPageComponent implements OnInit {
constructor(
private collectionDataService: CollectionDataService,
private searchService: SearchService,
private metadata: MetadataService,
private route: ActivatedRoute,
private router: Router,
private authService: AuthService,
Expand Down Expand Up @@ -122,10 +124,6 @@ export class CollectionPageComponent implements OnInit {
getAllSucceededRemoteDataPayload(),
map((collection) => getCollectionPageRoute(collection.id))
);

this.route.queryParams.pipe(take(1)).subscribe((params) => {
this.metadata.processRemoteData(this.collectionRD$);
});
}

isNotEmpty(object: any) {
Expand Down
10 changes: 4 additions & 6 deletions src/app/+item-page/full/full-item-page.component.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {filter, map} from 'rxjs/operators';
import { filter, map } from 'rxjs/operators';
import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';

import { Observable , BehaviorSubject } from 'rxjs';
import { Observable, BehaviorSubject } from 'rxjs';

import { ItemPageComponent } from '../simple/item-page.component';
import { MetadataMap } from '../../core/shared/metadata.models';
Expand All @@ -11,8 +11,6 @@ import { ItemDataService } from '../../core/data/item-data.service';
import { RemoteData } from '../../core/data/remote-data';
import { Item } from '../../core/shared/item.model';

import { MetadataService } from '../../core/metadata/metadata.service';

import { fadeInOut } from '../../shared/animations/fade';
import { hasValue } from '../../shared/empty.util';
import { AuthService } from '../../core/auth/auth.service';
Expand All @@ -35,8 +33,8 @@ export class FullItemPageComponent extends ItemPageComponent implements OnInit {

metadata$: Observable<MetadataMap>;

constructor(route: ActivatedRoute, router: Router, items: ItemDataService, metadataService: MetadataService, authService: AuthService) {
super(route, router, items, metadataService, authService);
constructor(route: ActivatedRoute, router: Router, items: ItemDataService, authService: AuthService) {
super(route, router, items, authService);
}

/*** AoT inheritance fix, will hopefully be resolved in the near future **/
Expand Down
4 changes: 0 additions & 4 deletions src/app/+item-page/simple/item-page.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import { RemoteData } from '../../core/data/remote-data';

import { Item } from '../../core/shared/item.model';

import { MetadataService } from '../../core/metadata/metadata.service';

import { fadeInOut } from '../../shared/animations/fade';
import { getAllSucceededRemoteDataPayload, redirectOn4xx } from '../../core/shared/operators';
import { ViewMode } from '../../core/shared/view-mode.model';
Expand Down Expand Up @@ -54,7 +52,6 @@ export class ItemPageComponent implements OnInit {
private route: ActivatedRoute,
private router: Router,
private items: ItemDataService,
private metadataService: MetadataService,
private authService: AuthService,
) { }

Expand All @@ -66,7 +63,6 @@ export class ItemPageComponent implements OnInit {
map((data) => data.dso as RemoteData<Item>),
redirectOn4xx(this.router, this.authService)
);
this.metadataService.processRemoteData(this.itemRD$);
this.itemPageRoute$ = this.itemRD$.pipe(
getAllSucceededRemoteDataPayload(),
map((item) => getItemPageRoute(item))
Expand Down
3 changes: 3 additions & 0 deletions src/app/core/core.reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
BitstreamFormatRegistryState
} from '../+admin/admin-registries/bitstream-formats/bitstream-format.reducers';
import { historyReducer, HistoryState } from './history/history.reducer';
import { metaTagReducer, MetaTagState } from './metadata/meta-tag.reducer';

export interface CoreState {
'bitstreamFormats': BitstreamFormatRegistryState;
Expand All @@ -24,6 +25,7 @@ export interface CoreState {
'index': MetaIndexState;
'auth': AuthState;
'json/patch': JsonPatchOperationsState;
'metaTag': MetaTagState;
'route': RouteState;
}

Expand All @@ -37,5 +39,6 @@ export const coreReducers: ActionReducerMap<CoreState> = {
'index': indexReducer,
'auth': authReducer,
'json/patch': jsonPatchOperationsReducer,
'metaTag': metaTagReducer,
'route': routeReducer
};
23 changes: 23 additions & 0 deletions src/app/core/metadata/meta-tag.actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { type } from '../../shared/ngrx/type';
import { Action } from '@ngrx/store';

// tslint:disable:max-classes-per-file
export const MetaTagTypes = {
ADD: type('dspace/meta-tag/ADD'),
CLEAR: type('dspace/meta-tag/CLEAR')
};

export class AddMetaTagAction implements Action {
type = MetaTagTypes.ADD;
payload: string;

constructor(property: string) {
this.payload = property;
}
}

export class ClearMetaTagAction implements Action {
type = MetaTagTypes.CLEAR;
}

export type MetaTagAction = AddMetaTagAction | ClearMetaTagAction;
50 changes: 50 additions & 0 deletions src/app/core/metadata/meta-tag.reducer.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/

import { metaTagReducer } from './meta-tag.reducer';
import { AddMetaTagAction, ClearMetaTagAction } from './meta-tag.actions';

const nullAction = { type: null };

describe('metaTagReducer', () => {
it('should start with an empty array', () => {
const state0 = metaTagReducer(undefined, nullAction);
expect(state0.tagsInUse).toEqual([]);
});

it('should return the current state on invalid action', () => {
const state0 = {
tagsInUse: ['foo', 'bar'],
};

const state1 = metaTagReducer(state0, nullAction);
expect(state1).toEqual(state0);
});

it('should add tags on AddMetaTagAction', () => {
const state0 = {
tagsInUse: ['foo'],
};

const state1 = metaTagReducer(state0, new AddMetaTagAction('bar'));
const state2 = metaTagReducer(state1, new AddMetaTagAction('baz'));

expect(state1.tagsInUse).toEqual(['foo', 'bar']);
expect(state2.tagsInUse).toEqual(['foo', 'bar', 'baz']);
});

it('should clear tags on ClearMetaTagAction', () => {
const state0 = {
tagsInUse: ['foo', 'bar'],
};

const state1 = metaTagReducer(state0, new ClearMetaTagAction());

expect(state1.tagsInUse).toEqual([]);
});
});
38 changes: 38 additions & 0 deletions src/app/core/metadata/meta-tag.reducer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import {
MetaTagAction,
MetaTagTypes,
AddMetaTagAction,
ClearMetaTagAction,
} from './meta-tag.actions';

export interface MetaTagState {
tagsInUse: string[];
}

const initialstate: MetaTagState = {
tagsInUse: []
};

export const metaTagReducer = (state: MetaTagState = initialstate, action: MetaTagAction): MetaTagState => {
switch (action.type) {
case MetaTagTypes.ADD: {
return addMetaTag(state, action as AddMetaTagAction);
}
case MetaTagTypes.CLEAR: {
return clearMetaTags(state, action as ClearMetaTagAction);
}
default: {
return state;
}
}
};

const addMetaTag = (state: MetaTagState, action: AddMetaTagAction): MetaTagState => {
return {
tagsInUse: [...state.tagsInUse, action.payload]
};
};

const clearMetaTags = (state: MetaTagState, action: ClearMetaTagAction): MetaTagState => {
return Object.assign({}, initialstate);
};
Loading