Skip to content

Commit 9f5a150

Browse files
committed
feat(rule-view): integrate Monaco Editor for YAML editing and enhance styling
Signed-off-by: Manuel Abascal <mjabascal10@gmail.com>
1 parent 2518995 commit 9f5a150

File tree

5 files changed

+105
-44
lines changed

5 files changed

+105
-44
lines changed

frontend/src/app/logstash/logstash-filters/logstash-filter-create/logstash-filter-create.component.scss

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,23 @@
7373
background-color: #f0f0f0 !important;
7474
}
7575

76-
// Syntax highlighting colors for YAML
77-
.mtk5 {
78-
color: #0277bd !important; // Keys - Blue
76+
.mtk7 {
77+
color: #2d7a1a !important;
78+
font-weight: 600 !important;
79+
}
80+
81+
.mtk22 {
82+
color: #0055cc !important;
7983
font-weight: 600 !important;
8084
}
8185

82-
.mtk1 {
83-
color: #ff6b6b !important; // Values - Red
86+
.mtk1,
87+
.mtk5 {
88+
color: #666666 !important;
89+
}
90+
91+
.mtk3 {
92+
color: #c26e00 !important;
8493
}
8594
}
8695
}

frontend/src/app/rule-management/app-rule/components/see-rule/rule-view.component.html

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@
1616
</div>
1717
</div>
1818

19-
<div class="d-flex h-100 m-h-0 overflow-auto p-2 rule-view-container">
20-
<pre class="yaml-preview w-100" [innerHTML]="yamlHighlighted"></pre>
19+
<div class="rule-view-container">
20+
<ngx-monaco-editor
21+
style="height: 650px"
22+
class="template-editor"
23+
name="logstashFilter"
24+
[options]="editorOptions"
25+
[ngModel]="yamlString">
26+
</ngx-monaco-editor>
2127
</div>
28+
29+
<!--<div class="d-flex h-100 m-h-0 overflow-auto p-2 rule-view-container">
30+
<pre class="yaml-preview w-100" [innerHTML]="yamlHighlighted"></pre>
31+
</div>-->

frontend/src/app/rule-management/app-rule/components/see-rule/rule-view.component.scss

Lines changed: 58 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -35,29 +35,6 @@ app-utm-modal-header {
3535
}
3636
}
3737

38-
.yaml-container {
39-
width: 100%;
40-
background: #ffffff;
41-
padding: 16px;
42-
border-radius: 6px;
43-
border: 1px solid #e5e7eb;
44-
}
45-
46-
.yaml-preview {
47-
white-space: pre-wrap;
48-
font-family: "Fira Code", monospace;
49-
font-size: 14px;
50-
}
51-
52-
::ng-deep .yaml-key {
53-
color: #0277bd;
54-
font-weight: 600;
55-
}
56-
57-
::ng-deep .yaml-value {
58-
color: #FF6B6B;
59-
}
60-
6138
.sub-header {
6239
background: transparent;
6340
border: none;
@@ -110,3 +87,61 @@ app-utm-modal-header {
11087
}
11188
}
11289

90+
.rule-view-container {
91+
border: 1px solid #d9d9d9;
92+
border-radius: 4px;
93+
overflow: hidden;
94+
height: 600px;
95+
width: 100%;
96+
flex: 1;
97+
98+
::ng-deep {
99+
.monaco-editor {
100+
width: 100% !important;
101+
height: 100% !important;
102+
}
103+
104+
.monaco-editor-background {
105+
background-color: #f5f5f5 !important;
106+
}
107+
108+
.overflow-guard {
109+
width: 100% !important;
110+
height: 100% !important;
111+
}
112+
113+
.monaco-scrollable-element {
114+
width: 100% !important;
115+
height: 100% !important;
116+
}
117+
118+
.monaco-editor.readonly {
119+
background-color: #f0f0f0 !important;
120+
opacity: 0.8 !important;
121+
}
122+
123+
.monaco-editor.readonly .monaco-editor-background {
124+
background-color: #f0f0f0 !important;
125+
}
126+
127+
.mtk7 {
128+
color: #2d7a1a !important;
129+
font-weight: 600 !important;
130+
}
131+
132+
.mtk22 {
133+
color: #0055cc !important;
134+
font-weight: 600 !important;
135+
}
136+
137+
.mtk1,
138+
.mtk5 {
139+
color: #666666 !important;
140+
}
141+
142+
.mtk3 {
143+
color: #c26e00 !important;
144+
}
145+
}
146+
}
147+

frontend/src/app/rule-management/app-rule/components/see-rule/rule-view.component.ts

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,27 @@ import {Rule} from '../../../models/rule.model';
88
templateUrl: './rule-view.component.html',
99
styleUrls: ['./rule-view.component.scss'],
1010
})
11-
export class RuleViewComponent implements OnInit {
11+
export class RuleViewComponent {
1212
@Input() rowDocument: Rule;
1313

1414
copied = false;
15-
16-
ngOnInit() {
17-
console.log('Rule received:', this.rowDocument);
18-
}
15+
editorOptions: any = {
16+
theme: 'vs-light',
17+
language: 'yaml',
18+
automaticLayout: true,
19+
fontSize: 13,
20+
lineHeight: 24,
21+
fontFamily: 'Courier New, Monaco, Menlo, monospace',
22+
lineNumbers: 'on',
23+
wordWrap: 'on',
24+
minimap: { enabled: false },
25+
scrollBeyondLastLine: false,
26+
formatOnPaste: true,
27+
formatOnType: true,
28+
tabSize: 2,
29+
insertSpaces: true,
30+
readOnly: true
31+
};
1932

2033
get yamlString(): string {
2134
try {
@@ -33,14 +46,6 @@ export class RuleViewComponent implements OnInit {
3346
}
3447
}
3548

36-
get yamlHighlighted(): string {
37-
return this.yamlString
38-
.replace(/^(\s*)([a-zA-Z0-9_]+):/gm, '$1<span class="yaml-key">$2</span>:')
39-
.replace(/: (.*)/g, ': <span class="yaml-value">$1</span>')
40-
.replace(/-\s+(.*)/g, '- <span class="yaml-value">$1</span>')
41-
.replace(/^\s{2,}(.+)/gm, ' <span class="yaml-value">$1</span>');
42-
}
43-
4449
exportYaml() {
4550
const yamlContent = this.yamlString;
4651

frontend/src/app/rule-management/rule-management.module.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import {RuleService} from './services/rule.service';
4646
import {RulesResolverService} from './services/rules.resolver.service';
4747
import {GenericFilterComponent} from './share/generic-filter/generic-filter.component';
4848
import {RuleDetailComponent} from "./app-rule/components/rule-list/components/rule-detail/rule-detail.component";
49+
import {MonacoEditorModule} from "ngx-monaco-editor";
4950

5051

5152
@NgModule({
@@ -87,7 +88,8 @@ import {RuleDetailComponent} from "./app-rule/components/rule-list/components/ru
8788
NgSelectModule,
8889
InfiniteScrollModule,
8990
FileBrowserModule,
90-
FormsModule
91+
FormsModule,
92+
MonacoEditorModule
9193
],
9294
providers: [
9395
RuleService,

0 commit comments

Comments
 (0)