1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-10 21:33:27 +00:00
Files
browser/bitwarden_license/bit-web/src/app/secrets-manager/projects/project/project.component.ts
Oscar Hinton c67fc1ff82 Add edit project button to project page (#4982)
* Add edit project button to project page

* Ensure write permission

* Refresh secret list if project is edited
2023-03-17 18:32:42 +01:00

67 lines
1.9 KiB
TypeScript

import { Component, OnDestroy, OnInit } from "@angular/core";
import { ActivatedRoute } from "@angular/router";
import { combineLatest, filter, Observable, startWith, Subject, switchMap, takeUntil } from "rxjs";
import { DialogService } from "@bitwarden/components";
import { ProjectPermissionDetailsView } from "../../models/view/project.view";
import {
OperationType,
ProjectDialogComponent,
ProjectOperation,
} from "../dialog/project-dialog.component";
import { ProjectService } from "../project.service";
@Component({
selector: "sm-project",
templateUrl: "./project.component.html",
})
export class ProjectComponent implements OnInit, OnDestroy {
protected project$: Observable<ProjectPermissionDetailsView>;
private organizationId: string;
private projectId: string;
private destroy$ = new Subject<void>();
constructor(
private route: ActivatedRoute,
private projectService: ProjectService,
private dialogService: DialogService
) {}
ngOnInit(): void {
// Update project if it is edited
const currentProjectEdited = this.projectService.project$.pipe(
filter((p) => p?.id === this.projectId),
startWith(null)
);
this.project$ = combineLatest([this.route.params, currentProjectEdited]).pipe(
switchMap(([params, _]) => {
return this.projectService.getByProjectId(params.projectId);
})
);
this.route.params.pipe(takeUntil(this.destroy$)).subscribe((params) => {
this.organizationId = params.organizationId;
this.projectId = params.projectId;
});
}
ngOnDestroy(): void {
this.destroy$.next();
this.destroy$.complete();
}
async openEditDialog() {
this.dialogService.open<unknown, ProjectOperation>(ProjectDialogComponent, {
data: {
organizationId: this.organizationId,
operation: OperationType.Edit,
projectId: this.projectId,
},
});
}
}