Skip to content
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
12 changes: 10 additions & 2 deletions src/app/core/components/nav-menu/nav-menu.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ import { toSignal } from '@angular/core/rxjs-interop';
import { ActivatedRoute, NavigationEnd, Router, RouterLink, RouterLinkActive } from '@angular/router';

import { MENU_ITEMS } from '@core/constants';
import { ProviderSelectors } from '@core/store/provider';
import { filterMenuItems, updateMenuItems } from '@osf/core/helpers';
import { RouteContext } from '@osf/core/models';
import { AuthService } from '@osf/core/services';
import { UserSelectors } from '@osf/core/store/user';
import { IconComponent } from '@osf/shared/components';
import { CurrentResourceType } from '@osf/shared/enums';
import { CurrentResourceType, ReviewPermissions } from '@osf/shared/enums';
import { getViewOnlyParam } from '@osf/shared/helpers';
import { WrapFnPipe } from '@osf/shared/pipes';
import { CurrentResourceSelectors } from '@osf/shared/stores';
Expand All @@ -37,14 +38,15 @@ export class NavMenuComponent {

private readonly isAuthenticated = select(UserSelectors.isAuthenticated);
private readonly currentResource = select(CurrentResourceSelectors.getCurrentResource);
private readonly provider = select(ProviderSelectors.getCurrentProvider);

readonly mainMenuItems = computed(() => {
const isAuthenticated = this.isAuthenticated();
const filtered = filterMenuItems(MENU_ITEMS, isAuthenticated);

const routeContext: RouteContext = {
resourceId: this.currentResourceId(),
providerId: this.currentProviderId(),
providerId: this.provider()?.id,
isProject:
this.currentResource()?.type === CurrentResourceType.Projects &&
this.currentResourceId() === this.currentResource()?.id,
Expand All @@ -53,6 +55,12 @@ export class NavMenuComponent {
this.currentResourceId() === this.currentResource()?.id,
isPreprint: this.isPreprintRoute(),
preprintReviewsPageVisible: this.canUserViewReviews(),
registrationModerationPageVisible:
this.provider()?.type === CurrentResourceType.Registrations &&
this.provider()?.permissions?.includes(ReviewPermissions.ViewSubmissions),
collectionModerationPageVisible:
this.provider()?.type === CurrentResourceType.Collections &&
this.provider()?.permissions?.includes(ReviewPermissions.ViewSubmissions),
isCollections: this.isCollectionsRoute() || false,
currentUrl: this.router.url,
isViewOnly: !!getViewOnlyParam(this.router),
Expand Down
2 changes: 1 addition & 1 deletion src/app/core/constants/nav-items.constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ export const MENU_ITEMS: MenuItem[] = [
routerLink: 'moderation',
label: 'navigation.moderation',
visible: false,
routerLinkActiveOptions: { exact: true },
routerLinkActiveOptions: { exact: false },
},
],
},
Expand Down
28 changes: 27 additions & 1 deletion src/app/core/helpers/nav-menu.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export function updateMenuItems(menuItems: MenuItem[], ctx: RouteContext): MenuI
}

if (item.id === 'collections') {
return { ...item, visible: ctx.isCollections };
return updateCollectionMenuItem(item, ctx);
}

return item;
Expand Down Expand Up @@ -137,6 +137,15 @@ function updateRegistryMenuItem(item: MenuItem, ctx: RouteContext): MenuItem {
}
return { ...subItem, visible: false, expanded: false };
}

if (subItem.id === 'registries-moderation') {
return {
...subItem,
visible: ctx.registrationModerationPageVisible,
routerLink: ['/registries', ctx.providerId, 'moderation'],
};
}

return subItem;
});

Expand Down Expand Up @@ -169,3 +178,20 @@ function updatePreprintMenuItem(item: MenuItem, ctx: RouteContext): MenuItem {

return { ...item, expanded: ctx.isPreprint, items };
}

function updateCollectionMenuItem(item: MenuItem, ctx: RouteContext): MenuItem {
const isCollections = ctx.isCollections;

const items = (item.items || []).map((subItem) => {
if (subItem.id === 'collections-moderation') {
return {
...subItem,
visible: isCollections && ctx.collectionModerationPageVisible,
routerLink: ['/collections', ctx.providerId, 'moderation'],
};
}
return subItem;
});

return { ...item, items, visible: ctx.isCollections };
}
2 changes: 2 additions & 0 deletions src/app/core/models/route-context.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ export interface RouteContext {
isRegistry: boolean;
isPreprint: boolean;
preprintReviewsPageVisible?: boolean;
registrationModerationPageVisible?: boolean;
collectionModerationPageVisible?: boolean;
isCollections: boolean;
currentUrl?: string;
isViewOnly?: boolean;
Expand Down
8 changes: 6 additions & 2 deletions src/app/core/store/provider/provider.actions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { ProviderModel } from '@osf/shared/models';
import { ProviderShortInfoModel } from '@osf/shared/models';

export class SetCurrentProvider {
static readonly type = '[Provider] Set Current Provider';
constructor(public provider: ProviderModel) {}
constructor(public provider: ProviderShortInfoModel) {}
}

export class ClearCurrentProvider {
static readonly type = '[Provider] Clear Current Provider';
}
4 changes: 2 additions & 2 deletions src/app/core/store/provider/provider.model.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ProviderModel } from '@osf/shared/models';
import { ProviderShortInfoModel } from '@osf/shared/models';

export interface ProviderStateModel {
currentProvider: ProviderModel | null;
currentProvider: ProviderShortInfoModel | null;
}

export const PROVIDER_STATE_INITIAL: ProviderStateModel = {
Expand Down
4 changes: 2 additions & 2 deletions src/app/core/store/provider/provider.selectors.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Selector } from '@ngxs/store';

import { ProviderModel } from '@osf/shared/models';
import { ProviderShortInfoModel } from '@osf/shared/models';

import { ProviderStateModel } from './provider.model';
import { ProviderState } from './provider.state';

export class ProviderSelectors {
@Selector([ProviderState])
static getCurrentProvider(state: ProviderStateModel): ProviderModel | null {
static getCurrentProvider(state: ProviderStateModel): ProviderShortInfoModel | null {
return state.currentProvider;
}
}
11 changes: 7 additions & 4 deletions src/app/core/store/provider/provider.state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Action, State, StateContext } from '@ngxs/store';

import { Injectable } from '@angular/core';

import { SetCurrentProvider } from './provider.actions';
import { ClearCurrentProvider, SetCurrentProvider } from './provider.actions';
import { PROVIDER_STATE_INITIAL, ProviderStateModel } from './provider.model';

@State<ProviderStateModel>({
Expand All @@ -13,8 +13,11 @@ import { PROVIDER_STATE_INITIAL, ProviderStateModel } from './provider.model';
export class ProviderState {
@Action(SetCurrentProvider)
setCurrentProvider(ctx: StateContext<ProviderStateModel>, action: SetCurrentProvider) {
ctx.patchState({
currentProvider: action.provider,
});
ctx.patchState({ currentProvider: action.provider });
}

@Action(ClearCurrentProvider)
clearCurrentProvider(ctx: StateContext<ProviderStateModel>) {
ctx.setState(PROVIDER_STATE_INITIAL);
}
}
4 changes: 0 additions & 4 deletions src/app/core/store/user/user.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ export class UpdateProfileSettingsUser {
constructor(public payload: Partial<User>) {}
}

export class SetUserAsModerator {
static readonly type = '[User] Set User As Moderator';
}

export class AcceptTermsOfServiceByUser {
static readonly type = '[User] Accept Terms Of Service';
}
Expand Down
5 changes: 0 additions & 5 deletions src/app/core/store/user/user.selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,6 @@ export class UserSelectors {
return state.currentUser.data?.social;
}

@Selector([UserState])
static isCurrentUserModerator(state: UserStateModel): boolean {
return !!state.currentUser.data?.isModerator;
}

@Selector([UserState])
static getCanViewReviews(state: UserStateModel): boolean {
return state.currentUser.data?.canViewReviews || false;
Expand Down
21 changes: 0 additions & 21 deletions src/app/core/store/user/user.state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
GetCurrentUser,
GetCurrentUserSettings,
SetCurrentUser,
SetUserAsModerator,
UpdateProfileSettingsEducation,
UpdateProfileSettingsEmployment,
UpdateProfileSettingsSocialLinks,
Expand Down Expand Up @@ -234,26 +233,6 @@ export class UserState {
);
}

@Action(SetUserAsModerator)
setUserAsModerator(ctx: StateContext<UserStateModel>) {
const state = ctx.getState();
const currentUser = state.currentUser.data;

if (!currentUser) {
return;
}

ctx.patchState({
currentUser: {
...state.currentUser,
data: {
...currentUser,
isModerator: true,
},
},
});
}

@Action(AcceptTermsOfServiceByUser)
acceptTermsOfServiceByUser(ctx: StateContext<UserStateModel>) {
const state = ctx.getState();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export class InstitutionsProjectsComponent implements OnInit, OnDestroy {
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe(() => this.toastService.showSuccess('adminInstitutions.institutionUsers.messageSent'));
} else {
const projectId = (userRowData['title'] as TableCellLink).url.split('/').pop() || '';
const projectId = (userRowData['link'] as TableCellLink).url.split('/').pop() || '';

this.actions
.requestProjectAccess({
Expand Down
18 changes: 16 additions & 2 deletions src/app/features/collections/collections.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ import { authGuard } from '@osf/core/guards';
import { AddToCollectionState } from '@osf/features/collections/store/add-to-collection';
import { CollectionsModerationState } from '@osf/features/moderation/store/collections-moderation';
import { ConfirmLeavingGuard } from '@shared/guards';
import { BookmarksState, CitationsState, ContributorsState, NodeLinksState, ProjectsState } from '@shared/stores';
import {
BookmarksState,
CitationsState,
ContributorsState,
NodeLinksState,
ProjectsState,
SubjectsState,
} from '@shared/stores';
import { CollectionsState } from '@shared/stores/collections';

export const collectionsRoutes: Routes = [
Expand Down Expand Up @@ -58,7 +65,14 @@ export const collectionsRoutes: Routes = [
'@osf/features/moderation/components/collection-submission-overview/collection-submission-overview.component'
).then((mod) => mod.CollectionSubmissionOverviewComponent),
providers: [
provideStates([NodeLinksState, CitationsState, CollectionsModerationState, CollectionsState, BookmarksState]),
provideStates([
NodeLinksState,
CitationsState,
CollectionsModerationState,
CollectionsState,
BookmarksState,
SubjectsState,
]),
],
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import { TagsInputComponent, TextInputComponent, TruncatedTextComponent } from '
import { InputLimits } from '@shared/constants';
import { ResourceType } from '@shared/enums';
import { LicenseModel } from '@shared/models';
import { Project } from '@shared/models/projects';
import { ProjectModel } from '@shared/models/projects';
import { InterpolatePipe } from '@shared/pipes';
import { ToastService } from '@shared/services';
import { ClearProjects, GetAllContributors, UpdateProjectMetadata } from '@shared/stores';
Expand Down Expand Up @@ -189,7 +189,7 @@ export class ProjectMetadataStepComponent {
this.metadataSaved.emit();
}

private updateProjectMetadata(selectedProject: Project): void {
private updateProjectMetadata(selectedProject: ProjectModel): void {
const metadata = this.formService.buildMetadataPayload(this.projectMetadataForm, selectedProject);

this.actions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { ChangeDetectionStrategy, Component, computed, input, output, signal } f
import { AddToCollectionSteps } from '@osf/features/collections/enums';
import { SetSelectedProject } from '@osf/shared/stores';
import { ProjectSelectorComponent } from '@shared/components';
import { Project } from '@shared/models/projects';
import { ProjectModel } from '@shared/models/projects';
import { CollectionsSelectors, GetUserCollectionSubmissions } from '@shared/stores/collections';
import { ProjectsSelectors } from '@shared/stores/projects/projects.selectors';

Expand All @@ -32,7 +32,7 @@ export class SelectProjectStepComponent {
stepChange = output<number>();
projectSelected = output<void>();

currentSelectedProject = signal<Project | null>(null);
currentSelectedProject = signal<ProjectModel | null>(null);

excludedProjectIds = computed(() => {
const submissions = this.currentUserSubmissions();
Expand All @@ -44,7 +44,7 @@ export class SelectProjectStepComponent {
getUserCollectionSubmissions: GetUserCollectionSubmissions,
});

handleProjectChange(project: Project | null): void {
handleProjectChange(project: ProjectModel | null): void {
if (project) {
this.currentSelectedProject.set(project);
this.actions.setSelectedProject(project);
Expand All @@ -53,7 +53,7 @@ export class SelectProjectStepComponent {
}
}

handleProjectsLoaded(projects: Project[]): void {
handleProjectsLoaded(projects: ProjectModel[]): void {
const collectionId = this.collectionId();
if (collectionId && projects.length) {
const projectIds = projects.map((project) => project.id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { FormControl } from '@angular/forms';
import { ActivatedRoute, Router, RouterLink } from '@angular/router';

import { CollectionsHelpDialogComponent, CollectionsMainContentComponent } from '@osf/features/collections/components';
import { CollectionsQuerySyncService } from '@osf/features/collections/services';
import { LoadingSpinnerComponent, SearchInputComponent } from '@shared/components';
import { HeaderStyleHelper } from '@shared/helpers';
import { CollectionsFilters } from '@shared/models';
import { BrandService } from '@shared/services';
import { ClearCurrentProvider } from '@core/store/provider';
import { LoadingSpinnerComponent, SearchInputComponent } from '@osf/shared/components';
import { HeaderStyleHelper } from '@osf/shared/helpers';
import { CollectionsFilters } from '@osf/shared/models';
import { BrandService } from '@osf/shared/services';
import {
ClearCollections,
ClearCollectionSubmissions,
Expand All @@ -27,7 +26,11 @@ import {
SearchCollectionSubmissions,
SetPageNumber,
SetSearchValue,
} from '@shared/stores/collections';
} from '@osf/shared/stores';

import { CollectionsQuerySyncService } from '../../services';
import { CollectionsHelpDialogComponent } from '../collections-help-dialog/collections-help-dialog.component';
import { CollectionsMainContentComponent } from '../collections-main-content';

@Component({
selector: 'osf-collections-discover',
Expand Down Expand Up @@ -72,6 +75,7 @@ export class CollectionsDiscoverComponent {
setPageNumber: SetPageNumber,
clearCollections: ClearCollections,
clearCollectionsSubmissions: ClearCollectionSubmissions,
clearCurrentProvider: ClearCurrentProvider,
});

constructor() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import { Chip } from 'primeng/chip';

import { ChangeDetectionStrategy, Component, computed } from '@angular/core';

import { collectionFilterTypes } from '@osf/features/collections/constants/filter-types.const';
import { CollectionFilterType } from '@osf/features/collections/enums';
import {
CollectionsSelectors,
SetCollectedTypeFilters,
Expand All @@ -20,6 +18,9 @@ import {
SetVolumeFilters,
} from '@shared/stores/collections';

import { collectionFilterTypes } from '../../constants';
import { CollectionFilterType } from '../../enums';

@Component({
selector: 'osf-collections-filter-chips',
imports: [Chip],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
@use "styles/variables" as var;
@use "styles/mixins" as mix;

.filters {
border: 1px solid var.$grey-2;
border: 1px solid var(--grey-2);
border-radius: mix.rem(12px);
padding: 0 mix.rem(20px);
display: flex;
Expand Down
Loading
Loading