Skip to content
Open
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 @@ -8,6 +8,7 @@
[hasPMOAccess]="canEdit()"
[loading]="loading()"
[totalRecords]="votes().length"
[editQueryParams]="editVoteQueryParams()"
(viewResults)="viewVoteResults($event)"
(viewVote)="viewVoteResults($event)">
@if (canEdit()) {
Expand All @@ -17,8 +18,7 @@
icon="fa-light fa-check-to-slot"
severity="info"
size="small"
[routerLink]="['/votes', 'create']"
[queryParams]="createVoteQueryParams()"
(click)="onCreateVote()"
data-testid="committee-votes-create-btn"></lfx-button>
}
</lfx-votes-table>
Expand All @@ -30,8 +30,7 @@
icon="fa-light fa-check-to-slot"
severity="info"
size="small"
[routerLink]="['/votes', 'create']"
[queryParams]="createVoteQueryParams()"
(click)="onCreateVote()"
data-testid="committee-votes-empty-create-btn"></lfx-button>
</div>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@

import { ChangeDetectionStrategy, Component, computed, inject, input, model, signal, Signal } from '@angular/core';
import { toObservable, toSignal } from '@angular/core/rxjs-interop';
import { Router } from '@angular/router';
import { ButtonComponent } from '@components/button/button.component';
import { CardComponent } from '@components/card/card.component';
import { Committee, Vote } from '@lfx-one/shared/interfaces';
import { buildCommitteeCreateQueryParams } from '@lfx-one/shared/utils';
import { VotesTableComponent } from '@app/modules/votes/components/votes-table/votes-table.component';
import { VoteResultsDrawerComponent } from '@app/modules/votes/components/vote-results-drawer/vote-results-drawer.component';
import { CommitteeService } from '@services/committee.service';
import { LensService } from '@services/lens.service';
import { VoteService } from '@services/vote.service';
import { MessageService } from 'primeng/api';
import { catchError, filter, finalize, of, switchMap } from 'rxjs';
Expand All @@ -21,8 +24,11 @@ import { catchError, filter, finalize, of, switchMap } from 'rxjs';
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class CommitteeVotesComponent {
private readonly committeeService = inject(CommitteeService);
private readonly lensService = inject(LensService);
private readonly voteService = inject(VoteService);
private readonly messageService = inject(MessageService);
private readonly router = inject(Router);

// Inputs
public committee = input.required<Committee>();
Expand All @@ -37,6 +43,31 @@ export class CommitteeVotesComponent {
// Data
public votes: Signal<Vote[]> = this.initVotes();
public createVoteQueryParams: Signal<Record<string, string>> = this.initCreateVoteQueryParams();
public editVoteQueryParams: Signal<Record<string, string>> = this.createVoteQueryParams;

/** Checks committee write permission fresh before navigating to the create-vote route.
* Redirects to project overview with _notice=votes if permission has been revoked
* since the page loaded — consistent with the writerGuard denial flow. */
protected onCreateVote(): void {
const committee = this.committee();
const overviewPath = this.lensService.activeLens() === 'foundation' ? '/foundation/overview' : '/project/overview';
const denyParams: Record<string, string> = { _notice: 'votes' };
if (committee.project_slug) denyParams['project'] = committee.project_slug;
const deny = () => void this.router.navigate([overviewPath], { queryParams: denyParams });

this.committeeService
.fetchCommittee(committee.uid)
.subscribe({
Comment thread
MRashad26 marked this conversation as resolved.
next: (fresh) => {
if (fresh?.writer !== true) {
deny();
return;
}
void this.router.navigate(['/votes', 'create'], { queryParams: this.createVoteQueryParams() });
},
error: () => deny(),
Comment thread
MRashad26 marked this conversation as resolved.
});
}

/** Opens the vote results drawer for the selected vote. */
public viewVoteResults(voteUid: string): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,16 @@
<div class="flex items-center justify-end gap-1">
@if (hasPMOAccess()) {
@if (vote.status === PollStatus.DISABLED) {
<a [routerLink]="['/votes', vote.uid, 'edit']">
<lfx-button label="Edit" severity="primary" size="small" [text]="true" [attr.data-testid]="'votes-edit-' + vote.uid"> </lfx-button>
</a>
<lfx-button
label="Edit"
severity="primary"
size="small"
[text]="true"
[routerLink]="['/votes', vote.uid, 'edit']"
[queryParams]="editQueryParams()"
(onClick)="$event.stopPropagation()"
[attr.data-testid]="'votes-edit-' + vote.uid">
</lfx-button>
<lfx-button
label="Delete"
severity="danger"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { DatePipe } from '@angular/common';
import { Component, computed, DestroyRef, effect, inject, input, output, signal, Signal, untracked } from '@angular/core';
import { takeUntilDestroyed, toObservable } from '@angular/core/rxjs-interop';
import { FormControl, FormGroup, ReactiveFormsModule } from '@angular/forms';
import { RouterLink } from '@angular/router';
import { ButtonComponent } from '@components/button/button.component';
import { CardTabsBarComponent } from '@components/card-tabs-bar/card-tabs-bar.component';
import { CardComponent } from '@components/card/card.component';
Expand Down Expand Up @@ -36,7 +35,6 @@ import { combineLatest, debounceTime, distinctUntilChanged, map, startWith, take
ButtonComponent,
DatePipe,
ReactiveFormsModule,
RouterLink,
InputTextComponent,
SelectComponent,
PollStatusLabelPipe,
Expand Down Expand Up @@ -77,6 +75,7 @@ export class VotesTableComponent {
public readonly showProjectFilter = input<boolean>(false);
// Draft tab is only meaningful in management contexts (project/committee lens); hide it in the Me lens.
public readonly showDraftTab = input<boolean>(true);
public readonly editQueryParams = input<Record<string, string>>({});
Comment thread
MRashad26 marked this conversation as resolved.

// === Outputs ===
public readonly viewVote = output<string>();
Expand Down
Loading