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
1 change: 1 addition & 0 deletions src/app/core/components/nav-menu/nav-menu.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export class NavMenuComponent {
isCollections: this.isCollectionsRoute() || false,
currentUrl: this.router.url,
isViewOnly: !!getViewOnlyParam(this.router),
permissions: this.currentResource()?.permissions,
};

const items = updateMenuItems(filtered, routeContext);
Expand Down
38 changes: 27 additions & 11 deletions src/app/core/helpers/nav-menu.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,21 @@ function updateProjectMenuItem(item: MenuItem, ctx: RouteContext): MenuItem {
}

menuItems = menuItems.map((menuItem) => {
if (menuItem.id !== 'project-wiki') {
return menuItem;
if (menuItem.id === 'project-wiki') {
return {
...menuItem,
visible: ctx.wikiPageVisible,
};
}

return {
...menuItem,
visible: ctx.wikiPageVisible,
};
if (menuItem.id === 'project-contributors' || menuItem.id === 'project-settings') {
return {
...menuItem,
visible: !!ctx.permissions?.length,
};
}

return menuItem;
});

return {
Expand Down Expand Up @@ -139,11 +146,20 @@ function updateRegistryMenuItem(item: MenuItem, ctx: RouteContext): MenuItem {
...subItem,
visible: true,
expanded: true,
items: menuItems.map((menuItem) => ({
...menuItem,
routerLink: [ctx.resourceId as string, menuItem.routerLink],
queryParams: ctx.isViewOnly ? { view_only: getViewOnlyParamFromUrl(ctx.currentUrl) } : undefined,
})),
items: menuItems.map((menuItem) => {
if (menuItem.id === 'registration-contributors') {
return {
...menuItem,
visible: !!ctx.permissions?.length,
};
}

return {
...menuItem,
routerLink: [ctx.resourceId as string, menuItem.routerLink],
queryParams: ctx.isViewOnly ? { view_only: getViewOnlyParamFromUrl(ctx.currentUrl) } : undefined,
};
}),
};
}
return { ...subItem, visible: false, expanded: false };
Expand Down
3 changes: 3 additions & 0 deletions src/app/core/models/route-context.model.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { UserPermissions } from '@osf/shared/enums';

export interface RouteContext {
resourceId: string | undefined;
providerId?: string;
Expand All @@ -11,4 +13,5 @@ export interface RouteContext {
isCollections: boolean;
currentUrl?: string;
isViewOnly?: boolean;
permissions?: UserPermissions[];
}
3 changes: 3 additions & 0 deletions src/app/shared/models/current-resource.model.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { UserPermissions } from '../enums';

export interface CurrentResource {
id: string;
type: string;
parentId?: string;
parentType?: string;
wikiEnabled?: boolean;
permissions: UserPermissions[];
}
3 changes: 3 additions & 0 deletions src/app/shared/models/guid-response-json-api.model.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { UserPermissions } from '../enums';

import { JsonApiResponse } from './common';

export type GuidedResponseJsonApi = JsonApiResponse<GuidDataJsonApi, null>;
Expand All @@ -8,6 +10,7 @@ interface GuidDataJsonApi {
attributes: {
guid: string;
wiki_enabled: boolean;
permissions: UserPermissions[];
};
relationships: {
target?: {
Expand Down
1 change: 1 addition & 0 deletions src/app/shared/services/resource.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export class ResourceGuidService {
? res.data.relationships.provider?.data.type
: res.data.relationships.target?.data.type,
wikiEnabled: res.data.attributes.wiki_enabled,
permissions: res.data.attributes.permissions,
}) as CurrentResource
),
finalize(() => this.loaderService.hide())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class CurrentResourceState {
private resourceService = inject(ResourceGuidService);

@Action(GetResource)
getResourceType(ctx: StateContext<CurrentResourceStateModel>, action: GetResource) {
getResource(ctx: StateContext<CurrentResourceStateModel>, action: GetResource) {
const state = ctx.getState();

if (state.currentResource.data?.id === action.resourceId && !action.refresh) {
Expand Down
Loading