-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathindex.ts
107 lines (84 loc) · 2.94 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import { action } from '@ember/object';
import { service } from '@ember/service';
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { task } from 'ember-concurrency';
import type IntlService from 'ember-intl/services/intl';
import type AnalysisModel from 'irene/models/analysis';
import type { Finding } from 'irene/models/analysis';
import {
isVulnerableApiFinding,
parseVulnerableApiFinding,
type VulnerableApiFinding,
} from 'irene/utils/parse-vulnerable-api-finding';
import styles from './index.scss';
export interface FileDetailsVulnerabilityAnalysisDetailsFindingsSignature {
Args: {
analysis: AnalysisModel;
};
}
export default class FileDetailsVulnerabilityAnalysisDetailsFindingsComponent extends Component<FileDetailsVulnerabilityAnalysisDetailsFindingsSignature> {
@tracked vulnerableApiFindings: VulnerableApiFinding[] = [];
@tracked customVulnerableFindings: Finding[] = [];
@tracked limit = 1;
@tracked offset = 0;
@service('notifications') declare notify: NotificationService;
@service declare intl: IntlService;
noop() {}
constructor(
owner: unknown,
args: FileDetailsVulnerabilityAnalysisDetailsFindingsSignature['Args']
) {
super(owner, args);
this.parseCustomAndApiVulnerableFindings.perform();
}
get classes() {
return {
selectClass: styles['ak-pagination-select'],
prevButtonIconClass: styles['ak-pagination-button-prev-icon'],
nextButtonIconClass: styles['ak-pagination-button-next-icon'],
};
}
get analysis() {
return this.args.analysis;
}
get hasVulnerableApiFinding() {
return this.vulnerableApiFindings.length !== 0;
}
get hasCustomVulnerableFinding() {
return this.customVulnerableFindings.length > 0;
}
get totalVulnerableApiFindings() {
return this.vulnerableApiFindings.length;
}
get currentVulnerableApiFindings() {
return this.vulnerableApiFindings.slice(
this.offset,
this.offset + this.limit
);
}
@action
handlePrevNextClick({ limit, offset }: { limit: number; offset: number }) {
this.limit = limit;
this.offset = offset;
}
parseCustomAndApiVulnerableFindings = task(async () => {
const vulnerableApiFindings: VulnerableApiFinding[] = [];
const customVulnerableFindings: Finding[] = [];
this.analysis.findings.forEach((finding) => {
const content = finding.description;
if (!isVulnerableApiFinding(content)) {
customVulnerableFindings.push(finding as Finding);
return;
}
vulnerableApiFindings.pushObjects(parseVulnerableApiFinding(content));
});
this.customVulnerableFindings = customVulnerableFindings;
this.vulnerableApiFindings = vulnerableApiFindings;
});
}
declare module '@glint/environment-ember-loose/registry' {
export default interface Registry {
'FileDetails::VulnerabilityAnalysisDetails::Findings': typeof FileDetailsVulnerabilityAnalysisDetailsFindingsComponent;
}
}