Skip to content

Commit eb5ff78

Browse files
feat(rule_list): added rule visualizer
1 parent 4b023ef commit eb5ff78

10 files changed

Lines changed: 95 additions & 6 deletions

File tree

frontend/src/app/rule-management/app-rule/components/add-rule/add-rule.component.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ export class AddRuleComponent implements OnInit, OnDestroy {
101101
if (controlName !== 'afterEvents') {
102102
const control = this.ruleForm.get(controlName);
103103
if (control && !control.valid) {
104-
console.log(control,'is invalid')
105104
isValid = false;
106105
}
107106
}

frontend/src/app/rule-management/app-rule/components/import-rules/import-rule.service.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ export class ImportRuleService {
1313
}
1414
}
1515

16-
private minWordsCheck(value: string, min: number, max: number): boolean {
16+
private minWordsCheck(value: string, min: number, minLengthPerWord: number): boolean {
1717
if (!value) return false;
18-
const words = value.trim().split(/\s+/);
19-
return words.length >= min && words.length <= max;
18+
const words = value.trim().split(/\s+/).filter(word => word.length >= minLengthPerWord);
19+
return words.length >= min;
20+
2021
}
2122

2223
isValidRule(obj: Rule): { isValid: boolean; errors: Record<string, string[]> } {

frontend/src/app/rule-management/app-rule/components/rule-list/rule-list.component.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@
4141
<td class="td-action">
4242
<div class="d-flex justify-content-end align-items-center medium-icon">
4343

44+
<i (click)="visualizeRule(rule)"
45+
class="icon-eye cursor-pointer ml-2"
46+
ngbTooltip="View Rule"
47+
container="body"
48+
placement="left"></i>
49+
4450
<i (click)="activeRule(rule)"
4551
class="cursor-pointer ml-2"
4652
[ngClass]="{'icon-blocked': rule.ruleActive, 'icon-check2': !rule.ruleActive}"

frontend/src/app/rule-management/app-rule/components/rule-list/rule-list.component.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {FilterService} from '../../../services/filter.service';
1919
import {RuleService} from '../../../services/rule.service';
2020
import {AddRuleComponent} from '../add-rule/add-rule.component';
2121
import {ImportRuleComponent} from '../import-rules/import-rule.component';
22+
import {SeeRuleComponent} from '../see-rule/see-rule.component'
2223

2324

2425
@Component({
@@ -203,6 +204,12 @@ export class RuleListComponent implements OnInit, OnDestroy {
203204
this.handleResponse(modal);
204205
}
205206

207+
208+
visualizeRule(rule:Rule){
209+
const modal = this.modalService.open(SeeRuleComponent, {size: 'lg', centered: true});
210+
modal.componentInstance.rowDocument = rule;
211+
}
212+
206213
handleResponse(modal: NgbModalRef) {
207214
modal.result.then((result: boolean) => {
208215
if (result) {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
<app-utm-modal-header [name]="'Rule Details'"></app-utm-modal-header>
3+
4+
5+
<!-- utm-json-detail-view.component.html -->
6+
<div class="json-detail-container p-4">
7+
<div class="header d-flex flex-row w-100 align-items-center justify-content-end">
8+
<button class="btn utm-button utm-button-primary" (click)="copyToClipboard()" title="Copy YAML">
9+
<i class="icon-clipboard"></i>Copy
10+
</button>
11+
<small *ngIf="copied" class="copied-msg">✅ Copied!</small>
12+
13+
</div>
14+
<app-utm-json-detail-view [rowDocument]="rowDocument"></app-utm-json-detail-view>
15+
</div>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
/* utm-json-detail-view.component.scss */
3+
.json-detail-container {
4+
display: flex;
5+
flex-direction: column;
6+
gap: 8px;
7+
}
8+
9+
10+
.copy-btn {
11+
border: none;
12+
background: transparent;
13+
cursor: pointer;
14+
font-size: 18px;
15+
}
16+
17+
.copied-msg {
18+
color: green;
19+
font-size: 12px;
20+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
import { Component, Input } from '@angular/core';
3+
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
4+
import { Rule } from '../../../models/rule.model';
5+
import * as yaml from 'js-yaml';
6+
7+
@Component({
8+
selector: 'app-see-rule',
9+
templateUrl: './see-rule.component.html',
10+
styleUrls: ['./see-rule.component.scss'],
11+
})
12+
export class SeeRuleComponent {
13+
@Input() rowDocument: Rule;
14+
15+
copied = false;
16+
17+
get yamlString(): string {
18+
try {
19+
return yaml.dump(this.rowDocument, { indent: 2 });
20+
} catch (e) {
21+
console.log(e)
22+
return 'Error parsing YAML';
23+
}
24+
}
25+
26+
copyToClipboard() {
27+
navigator.clipboard.writeText(this.yamlString).then(() => {
28+
this.copied = true;
29+
setTimeout(() => (this.copied = false), 1500);
30+
});
31+
}}
32+
33+
34+

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,13 @@ import {RuleResolverService} from './services/rule.resolver.service';
4545
import {RuleService} from './services/rule.service';
4646
import {RulesResolverService} from './services/rules.resolver.service';
4747
import {GenericFilterComponent} from './share/generic-filter/generic-filter.component';
48+
import {SeeRuleComponent} from './app-rule/components/see-rule/see-rule.component'
4849

4950

5051
@NgModule({
5152
declarations: [
5253
AppRuleComponent,
54+
SeeRuleComponent,
5355
RuleListComponent,
5456
RuleFieldComponent,
5557
RuleDetailComponent,
@@ -104,7 +106,8 @@ import {GenericFilterComponent} from './share/generic-filter/generic-filter.comp
104106
AddTypeComponent,
105107
AddPatternComponent,
106108
AddAssetComponent,
107-
ImportRuleComponent
109+
ImportRuleComponent,
110+
SeeRuleComponent,
108111
]
109112
})
110113
export class RuleManagementModule { }

frontend/src/app/shared/components/utm/table/utm-table/utm-table-detail/utm-json-detail-view/utm-json-detail-view.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<div *ngFor="let key of keys; let i = index"
33
[ngClass]="{'error-highlight': hasError(key)}">
44
<ngx-json-viewer [expanded]="false" [json]="separatedObject[i]"></ngx-json-viewer>
5-
<small *ngIf="hasError(key)" class="error-message">
5+
<small *ngIf="hasError(key)" class="error-message text-xs">
66
{{ getErrors(key).join(', ') }}
77
</small>
88
</div>

frontend/src/app/shared/components/utm/table/utm-table/utm-table-detail/utm-json-detail-view/utm-json-detail-view.component.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,7 @@
4949
font-size: 0.75rem;
5050
margin-left: 8px;
5151
}
52+
53+
.text-xs{
54+
font-size:9px;
55+
}

0 commit comments

Comments
 (0)