Skip to content

Commit a010864

Browse files
permissions: move Add policy to the actions footer and scroll dialog to the button on Add policy click
1 parent 2bbd28a commit a010864

4 files changed

Lines changed: 25 additions & 7 deletions

File tree

frontend/src/app/components/users/cedar-policy-editor-dialog/cedar-policy-editor-dialog.component.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
flex-shrink: 0;
3434
}
3535

36+
.dialog-actions-spacer {
37+
flex: 1;
38+
}
39+
3640
.code-editor-box {
3741
height: 300px;
3842
border: 1px solid var(--mdc-outlined-text-field-outline-color, rgba(0, 0, 0, 0.38));

frontend/src/app/components/users/cedar-policy-editor-dialog/cedar-policy-editor-dialog.component.html

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<h1 mat-dialog-title>Policy — {{ data.groupTitle }}</h1>
22
<form (ngSubmit)="savePolicy()">
3-
<mat-dialog-content>
3+
<mat-dialog-content #dialogContent>
44
<div class="editor-mode-toggle">
55
<mat-button-toggle-group [value]="editorMode" (change)="onEditorModeChange($event.value)">
66
<mat-button-toggle value="form">Form</mat-button-toggle>
@@ -35,7 +35,13 @@ <h1 mat-dialog-title>Policy — {{ data.groupTitle }}</h1>
3535
</div>
3636
</div>
3737
</mat-dialog-content>
38-
<mat-dialog-actions align="end">
38+
<mat-dialog-actions>
39+
<button *ngIf="editorMode === 'form' && !formParseError && !loading && !policyList?.showAddForm"
40+
type="button" mat-button color="primary"
41+
(click)="onAddPolicyClick()">
42+
<mat-icon>add</mat-icon> Add policy
43+
</button>
44+
<span class="dialog-actions-spacer"></span>
3945
<button type="button" mat-flat-button (click)="confirmClose()">Cancel</button>
4046
<button type="submit" mat-flat-button color="primary"
4147
[disabled]="submitting">

frontend/src/app/components/users/cedar-policy-editor-dialog/cedar-policy-editor-dialog.component.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { NgIf } from '@angular/common';
2-
import { Component, DestroyRef, Inject, inject, OnInit, ViewChild } from '@angular/core';
2+
import { Component, DestroyRef, ElementRef, Inject, inject, OnInit, ViewChild } from '@angular/core';
33
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
44
import { FormsModule } from '@angular/forms';
55
import { MatButtonModule } from '@angular/material/button';
@@ -60,6 +60,7 @@ export class CedarPolicyEditorDialogComponent implements OnInit {
6060
public formParseError: boolean = false;
6161

6262
@ViewChild(CedarPolicyListComponent) policyList?: CedarPolicyListComponent;
63+
@ViewChild('dialogContent', { read: ElementRef }) dialogContent?: ElementRef<HTMLElement>;
6364

6465
public cedarPolicyModel: object;
6566
public codeEditorOptions = {
@@ -211,6 +212,17 @@ export class CedarPolicyEditorDialogComponent implements OnInit {
211212
});
212213
}
213214

215+
onAddPolicyClick() {
216+
if (!this.policyList) return;
217+
this.policyList.showAddForm = true;
218+
setTimeout(() => {
219+
const el = this.dialogContent?.nativeElement;
220+
if (el) {
221+
el.scrollTop = el.scrollHeight;
222+
}
223+
});
224+
}
225+
214226
private _parseCedarToPolicyItems(): CedarPolicyItem[] {
215227
const parsed = parseCedarPolicy(this.cedarPolicy, this.connectionID, this.data.groupId, this.allTables);
216228
const dashboardItems = parseCedarDashboardItems(this.cedarPolicy, this.connectionID);

frontend/src/app/components/users/cedar-policy-list/cedar-policy-list.component.html

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,4 @@
138138
</div>
139139
</div>
140140

141-
<button *ngIf="!showAddForm && !loading" mat-button color="primary" type="button"
142-
(click)="showAddForm = true" class="add-policy-button">
143-
<mat-icon>add</mat-icon> Add policy
144-
</button>
145141
</div>

0 commit comments

Comments
 (0)