Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(orb-ui): User able to create and edit yaml policies using json … #2676

Merged
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: 2 additions & 0 deletions ui/src/app/@theme/styles/_overrides.scss
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ input {
font-size: 14px !important;
font-weight: 600 !important;
transition: background-color 0.3s ease !important;
font-family: 'Montserrat';
}
.next-button:hover {
background-color: #509afc!important;
Expand All @@ -320,6 +321,7 @@ input {
font-weight: 600 !important;
transition: background-color 0.3s ease !important;
margin-right: 0 !important;
font-family: 'Montserrat';
}
.cancel-back-button:hover {
background-color: rgba(255, 255, 255, 0.05) !important;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ <h4>{{ isEdit ? 'Edit Agent Policy' : 'Create Agent Policy'}}</h4>
YAML
</button>
</div>
<div style="display: flex; margin-top: 10px; margin-bottom: 10px; gap: 34px;">
<p class="summary-accent align">Paste or Upload your {{isJsonMode ? 'Json' : 'Yaml'}} configuration</p>
<div style="display: flex; margin-top: 10px; margin-bottom: 10px; gap: 60px;">
<span class="summary-accent align">Paste or Upload your {{isJsonMode ? 'Json' : 'Yaml'}} configuration</span>
<button class="upload-button align" (click)="fileInput.click()">
<nb-icon [icon]="uploadIconKey" pack="eva">
</nb-icon>
Expand All @@ -181,7 +181,9 @@ <h4>{{ isEdit ? 'Edit Agent Policy' : 'Create Agent Policy'}}</h4>
class="code-editor">
</ngx-monaco-editor>
</ng-container>
<span class="errorMessage">{{ errorConfigMessage }}</span>
</div>

</div>
<div class="d-flex justify-content-end">
<button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,4 +265,9 @@ ngx-tag-control, ngx-tag-display {
}
.align {
margin: 0px;
}
.errorMessage {
color: #df316f;
font-size: 14px;
font-weight: 600;
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ export class AgentPolicyAddComponent {

editorVisible = true;

errorConfigMessage: string;

@ViewChild('editorComponentYaml')
editorYaml;

Expand Down Expand Up @@ -152,6 +154,7 @@ kind: collection`;
this.agentPolicyID = this.route.snapshot.paramMap.get('id');
this.agentPolicy = this.newAgent();
this.isEdit = !!this.agentPolicyID;
this.errorConfigMessage = '';

this.readyForms();

Expand Down Expand Up @@ -339,9 +342,23 @@ kind: collection`;
}
canCreate() {
if (this.isJsonMode) {
return this.editor.isJson(this.codejson);
if (this.editor.isJson(this.codejson)) {
this.errorConfigMessage = '';
return true;
}
else {
this.errorConfigMessage = 'Invalid JSON configuration, check syntax errors';
return false;
}
} else {
return this.editor.isYaml(this.codeyaml);
if (this.editor.isYaml(this.codeyaml) && !this.editor.isJson(this.codeyaml)) {
this.errorConfigMessage = '';
return true;
}
else {
this.errorConfigMessage = 'Invalid YAML configuration, check syntax errors';
return false;
}
}
}
refreshEditor() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ export class AgentPolicyViewComponent implements OnInit, OnDestroy {

try {
if (format === 'yaml') {
if (this.editor.isJson(policyInterface)) {
throw new Error('Invalid YAML format');
}
yaml.load(policyInterface);

interfacePartial = {
Expand Down Expand Up @@ -181,6 +184,7 @@ export class AgentPolicyViewComponent implements OnInit, OnDestroy {
'Failed to edit Agent Policy',
`Error: Invalid ${format.toUpperCase()}`,
);
this.isRequesting = false;
}
}

Expand Down
1 change: 1 addition & 0 deletions ui/src/app/pages/profile/profile.component.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
button {
float: right;
font-family: 'Montserrat';
}

.card-row {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ nb-card {
min-width: 600px;
height: 200px;
max-height: 300px;
min-height: 100px;


}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@
style="color: #df316f !important;">
Discard
</button>
<button
class="upload-button"
(click)="fileInput.click()"
*ngIf="editMode">
<nb-icon icon="upload-outline" pack="eva">
</nb-icon>
Upload file
</button>
<input type="file" (change)="onFileSelected($event)" #fileInput style="display: none" class="upload-input">

</nb-card-header>
<nb-card-body>
<!-- <div *ngIf="editMode; then updateView else readView"></div>-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,20 @@ nb-card {
min-height: 367px;
max-height: 55vh;
}
.upload-button {
color: #3089fc;
background-color: transparent;
border: none;
font-weight: 600;
outline: none;
float: right;
border-radius: 15px;
padding: 6px 12px;
margin-right: 5px;
font-size: 0.875rem;
font-family: 'Montserrat';
transition: background-color 0.3s ease;
}
.upload-button:hover {
background-color: #171c30 !important;
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,16 @@ export class PolicyInterfaceComponent implements OnInit, AfterViewInit, OnChange
this.updateForm();
!!notify && this.editModeChange.emit(this.editMode);
}

onFileSelected(event: any) {
const file: File = event.target.files[0];
const reader: FileReader = new FileReader();

reader.onload = (e: any) => {
const fileContent = e.target.result;
this.code = fileContent;
};

reader.readAsText(file);
}
}