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
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ export class CreateViewLinkDialogComponent implements OnInit {

ngOnInit(): void {
const currentResource = this.config.data as ResourceInfoModel;
const { id, type } = currentResource;
const { id, type, rootParentId } = currentResource;

if (id) {
this.actions.getComponents(id, type);
this.actions.getComponents(rootParentId ?? '', id, type);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ export class ContributorsComponent implements OnInit {
id: this.resourceDetails().id,
title: this.resourceDetails().title,
type: this.resourceType(),
rootParentId: this.resourceDetails().rootParentId,
};

this.dialogService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export interface ResourceInfoModel {
id: string;
title: string;
type: ResourceType;
rootParentId?: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export class FilesWidgetComponent {

readonly options = computed(() => {
const components = this.components().filter((component) => this.rootOption().value !== component.id);
return [this.rootOption(), ...this.buildOptions(components).reverse()];
return [this.rootOption(), ...this.buildOptions(components)];
});

readonly storageAddons = computed(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export class ProjectOverviewMapper {
rootFolder: response.relationships?.files?.links?.related?.href,
iri: response.links?.iri,
},
rootParentId: response.relationships?.root?.data?.id,
} as ProjectOverview;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export interface ProjectOverview {
rootFolder: string;
iri: string;
};
rootParentId?: string;
}

export interface ProjectOverviewSubject {
Expand Down Expand Up @@ -206,6 +207,12 @@ export interface ProjectOverviewGetResponseJsonApi {
};
};
};
root?: {
data: {
id: string;
type: string;
};
};
};
links: {
iri: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,14 @@ export class ProjectOverviewComponent extends DataciteTrackerComponent implement
super();
this.setupCollectionsEffects();
this.setupCleanup();

effect(() => {
const currentProject = this.currentProject();
if (currentProject) {
const rootParentId = currentProject.rootParentId ?? currentProject.id;
this.actions.getComponentsTree(rootParentId, currentProject.id, ResourceType.Project);
}
});
}

getDoi(): Observable<string | null> {
Expand All @@ -244,7 +252,6 @@ export class ProjectOverviewComponent extends DataciteTrackerComponent implement
this.actions.getBookmarksId();
this.actions.getHomeWiki(ResourceType.Project, projectId);
this.actions.getComponents(projectId);
this.actions.getComponentsTree(projectId, ResourceType.Project);
this.actions.getLinkedProjects(projectId);
this.actions.getActivityLogs(projectId, this.activityDefaultPage.toString(), this.activityPageSize.toString());
this.setupDataciteViewTrackerEffect().subscribe();
Expand Down
16 changes: 14 additions & 2 deletions src/app/shared/mappers/nodes/base-node.mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ export class BaseNodeMapper {
return data.map((item) => this.getNodeData(item));
}

static getNodesWithChildren(data: BaseNodeDataJsonApi[]): NodeShortInfoModel[] {
return data.map((item) => ({
static getNodesWithChildren(data: BaseNodeDataJsonApi[], parentId: string): NodeShortInfoModel[] {
return this.getAllDescendants(data, parentId).map((item) => ({
id: item.id,
title: item.attributes.title,
parentId: item.relationships.parent?.data?.id,
Expand Down Expand Up @@ -36,6 +36,18 @@ export class BaseNodeMapper {
currentUserIsContributor: data.attributes.current_user_is_contributor,
wikiEnabled: data.attributes.wiki_enabled,
customCitation: data.attributes.custom_citation || undefined,
rootParentId: data.relationships.root?.data?.id,
};
}

static getAllDescendants(allNodes: BaseNodeDataJsonApi[], parentId: string): BaseNodeDataJsonApi[] {
const parent = allNodes.find((n) => n.id === parentId);
if (!parent) return [];

const directChildren = allNodes.filter((node) => node.relationships.parent?.data?.id === parentId);

const descendants = directChildren.flatMap((child) => this.getAllDescendants(allNodes, child.id));

return [parent, ...descendants];
}
}
1 change: 1 addition & 0 deletions src/app/shared/models/nodes/base-node.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ export interface BaseNodeModel {
currentUserPermissions: string[];
currentUserIsContributor: boolean;
wikiEnabled: boolean;
rootParentId?: string;
}
10 changes: 7 additions & 3 deletions src/app/shared/services/resource.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,15 @@ export class ResourceGuidService {
.pipe(map((response) => BaseNodeMapper.getNodeData(response.data)));
}

getResourceWithChildren(resourceId: string, resourceType: ResourceType): Observable<NodeShortInfoModel[]> {
getResourceWithChildren(
rootParentId: string,
resourceId: string,
resourceType: ResourceType
): Observable<NodeShortInfoModel[]> {
const resourcePath = this.urlMap.get(resourceType);

return this.jsonApiService
.get<ResponseJsonApi<BaseNodeDataJsonApi[]>>(`${this.apiUrl}/${resourcePath}/?filter[root]=${resourceId}`)
.pipe(map((response) => BaseNodeMapper.getNodesWithChildren(response.data.reverse())));
.get<ResponseJsonApi<BaseNodeDataJsonApi[]>>(`${this.apiUrl}/${resourcePath}/?filter[root]=${rootParentId}`)
.pipe(map((response) => BaseNodeMapper.getNodesWithChildren(response.data, resourceId)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export class GetResourceDetails {
export class GetResourceWithChildren {
static readonly type = '[Current Resource] Get Resource With Children';
constructor(
public rootParentId: string,
public resourceId: string,
public resourceType: ResourceType
) {}
Expand Down
26 changes: 14 additions & 12 deletions src/app/shared/stores/current-resource/current-resource.state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,19 @@ export class CurrentResourceState {
},
});

return this.resourceService.getResourceWithChildren(action.resourceId, action.resourceType).pipe(
tap((children) => {
ctx.patchState({
resourceChildren: {
data: children,
isLoading: false,
error: null,
},
});
}),
catchError((error) => handleSectionError(ctx, 'resourceChildren', error))
);
return this.resourceService
.getResourceWithChildren(action.rootParentId, action.resourceId, action.resourceType)
.pipe(
tap((children) => {
ctx.patchState({
resourceChildren: {
data: children,
isLoading: false,
error: null,
},
});
}),
catchError((error) => handleSectionError(ctx, 'resourceChildren', error))
);
}
}
Loading