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
2 changes: 1 addition & 1 deletion .husky/pre-push
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ npm run test:check-coverage-thresholds || {
printf "\n\nYou are seeing this error because test coverage increased without updating the jest.config.js thresholds."
#printf "\n\nPlease address them before proceeding.\n\n\n\n"
# exit 1
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export enum SubmissionReviewStatus {
Pending = 'pending',
InProgress = 'in_progress',
Accepted = 'accepted',
Rejected = 'rejected',
Withdrawn = 'withdrawn',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
[value]="relatedCounts()?.forksCount"
[showButton]="true"
[buttonLabel]="'project.analytics.kpi.viewForks'"
(buttonClick)="navigateToDuplicates()"
></osf-analytics-kpi>

<osf-analytics-kpi
Expand Down
28 changes: 24 additions & 4 deletions src/app/features/project/analytics/analytics.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import { SelectModule } from 'primeng/select';
import { map, of } from 'rxjs';

import { CommonModule, DatePipe } from '@angular/common';
import { ChangeDetectionStrategy, Component, inject, OnInit, Signal, signal } from '@angular/core';
import { ChangeDetectionStrategy, Component, DestroyRef, inject, OnInit, Signal, signal } from '@angular/core';
import { toSignal } from '@angular/core/rxjs-interop';
import { FormsModule } from '@angular/forms';
import { ActivatedRoute } from '@angular/router';
import { ActivatedRoute, Router } from '@angular/router';

import { BarChartComponent, LineChartComponent, PieChartComponent, SubHeaderComponent } from '@osf/shared/components';
import { ResourceType } from '@osf/shared/enums';
Expand All @@ -20,7 +20,7 @@ import { DatasetInput } from '@osf/shared/models';
import { AnalyticsKpiComponent } from './components';
import { DATE_RANGE_OPTIONS } from './constants';
import { DateRangeOption } from './models';
import { AnalyticsSelectors, GetMetrics, GetRelatedCounts } from './store';
import { AnalyticsSelectors, ClearAnalytics, GetMetrics, GetRelatedCounts } from './store';
import { analyticsData } from './test-data';

@Component({
Expand Down Expand Up @@ -49,6 +49,8 @@ export class AnalyticsComponent implements OnInit {

private readonly datePipe = inject(DatePipe);
private readonly route = inject(ActivatedRoute);
private readonly router = inject(Router);
private readonly destroyRef = inject(DestroyRef);

readonly resourceId = toSignal(this.route.parent?.params.pipe(map((params) => params['id'])) ?? of(undefined));
readonly resourceType: Signal<ResourceType | undefined> = toSignal(
Expand All @@ -63,7 +65,11 @@ export class AnalyticsComponent implements OnInit {

protected isMetricsError = select(AnalyticsSelectors.isMetricsError);

protected actions = createDispatchMap({ getMetrics: GetMetrics, getRelatedCounts: GetRelatedCounts });
protected actions = createDispatchMap({
getMetrics: GetMetrics,
getRelatedCounts: GetRelatedCounts,
clearAnalytics: ClearAnalytics,
});

protected visitsLabels: string[] = [];
protected visitsDataset: DatasetInput[] = [];
Expand All @@ -83,6 +89,16 @@ export class AnalyticsComponent implements OnInit {
this.setData();
}

constructor() {
this.setupCleanup();
}

setupCleanup(): void {
this.destroyRef.onDestroy(() => {
this.actions.clearAnalytics();
});
}

onRangeChange(range: DateRangeOption) {
this.selectedRange.set(range);
this.actions.getMetrics(this.resourceId(), range.value);
Expand All @@ -107,4 +123,8 @@ export class AnalyticsComponent implements OnInit {
this.popularPagesLabels = analytics.popularPages.map((item) => item.title);
this.popularPagesDataset = [{ label: 'Popular pages', data: analytics.popularPages.map((item) => item.count) }];
}

protected navigateToDuplicates() {
this.router.navigate(['duplicates'], { relativeTo: this.route });
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

@if (showButton()) {
<div>
<p-button severity="secondary" [label]="buttonLabel() | translate"> </p-button>
<p-button severity="secondary" [label]="buttonLabel() | translate" (onClick)="buttonClick.emit()"> </p-button>
</div>
}
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { TranslatePipe } from '@ngx-translate/core';
import { Button } from 'primeng/button';
import { Skeleton } from 'primeng/skeleton';

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

@Component({
selector: 'osf-analytics-kpi',
Expand All @@ -18,4 +18,5 @@ export class AnalyticsKpiComponent {
buttonLabel = input<string>('');
title = input<string>('');
value = input<number | undefined>(0);
buttonClick = output<void>();
}
1 change: 1 addition & 0 deletions src/app/features/project/analytics/components/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { AnalyticsKpiComponent } from './analytics-kpi/analytics-kpi.component';
export { ViewDuplicatesComponent } from './view-duplicates/view-duplicates.component';
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<osf-sub-header
[title]="'project.analytics.kpi.forks' | translate"
[showButton]="true"
[buttonLabel]="'project.overview.actions.forkProjectLabel' | translate"
(buttonClick)="handleForkResource()"
/>

<div class="flex flex-column flex-1 bg-white gap-5 p-3 sm:p-4">
@if (!isDuplicatesLoading() && currentResource()) {
@if (!duplicates().length) {
<h3 class="mt-5 text-center">{{ 'project.overview.dialog.fork.noForksMessage' | translate }}</h3>
} @else {
<p>{{ 'project.overview.dialog.fork.forksMessage' | translate }}</p>

@for (duplicate of duplicates(); track duplicate.id) {
@if (duplicate.currentUserPermissions.includes(UserPermissions.Read)) {
<div class="duplicate-wrapper flex flex-column gap-3 p-3 sm:p-4">
<div class="flex justify-content-between align-items-center">
<h2 class="flex gap-2">
<i [ngClass]="duplicate.public ? 'osf-icon-padlock-unlock' : 'osf-icon-padlock'"></i>
{{ duplicate.title }}
</h2>
<div>
@if (duplicate.currentUserPermissions.includes(UserPermissions.Write)) {
<p-button
severity="contrast"
icon="fas fa-ellipsis-vertical"
raised
variant="outlined"
(click)="componentActionMenu.toggle($event)"
>
</p-button>
}

<p-menu appendTo="body" #componentActionMenu [model]="forkActionItems(duplicate.id)" popup>
<ng-template #item let-item>
<a class="p-menu-item-link">{{ item.label | translate }}</a>
</ng-template>
</p-menu>
</div>
</div>

<div class="component-name flex flex-column gap-2">
<div class="flex flex-wrap align-items-center gap-1">
<span class="font-bold">{{ 'common.labels.forked' | translate }}:</span>
<p>{{ duplicate.dateCreated | date: 'MMM d, y, h:mm a' }}</p>
</div>

<div class="flex flex-wrap align-items-center gap-1">
<span class="font-bold">{{ 'common.labels.lastUpdated' | translate }}:</span>
<p>{{ duplicate.dateModified | date: 'MMM d, y, h:mm a' }}</p>
</div>

<div class="flex flex-wrap align-items-center gap-1">
<span class="font-bold">{{ 'common.labels.contributors' | translate }}:</span>
@for (contributor of duplicate.contributors; track contributor.id) {
<div>
<a [href]="contributor.id" target="_blank" class="font-bold"> {{ contributor.fullName }}</a>
<span>{{ $last ? '' : ',' }}</span>
</div>
}
</div>

<div class="component-description">
<div class="flex flex-wrap align-items-center gap-1">
<span class="font-bold">{{ 'common.labels.description' | translate }}:</span>
<osf-truncated-text [text]="duplicate.description" />
</div>
</div>
</div>
<p-button
[label]="'common.buttons.view' | translate"
severity="secondary"
[routerLink]="'/project/' + duplicate.id"
/>
</div>
}
}

@if (totalDuplicates() > pageSize) {
<osf-custom-paginator
[totalCount]="totalDuplicates()"
[rows]="pageSize"
[first]="firstIndex()"
(pageChanged)="onPageChange($event)"
/>
}
}
} @else {
<osf-loading-spinner></osf-loading-spinner>
}
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@use "assets/styles/variables" as var;
@use "assets/styles/mixins" as mix;

:host {
display: flex;
flex-direction: column;
flex: 1;
}

.duplicate-wrapper {
border: 1px solid var.$grey-2;
border-radius: mix.rem(12px);
color: var.$dark-blue-1;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { ViewDuplicatesComponent } from './view-duplicates.component';

describe.skip('ViewForksComponent', () => {
let component: ViewDuplicatesComponent;
let fixture: ComponentFixture<ViewDuplicatesComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [ViewDuplicatesComponent],
}).compileComponents();

fixture = TestBed.createComponent(ViewDuplicatesComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Loading