@automattic/jetpack-scan 0.5.9 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/build/components/index.d.ts +4 -0
- package/build/components/index.js +4 -0
- package/build/components/threat-fixer-button/index.d.ts +16 -0
- package/build/components/threat-fixer-button/index.js +56 -0
- package/build/components/threat-modal/fixer-state-notice.d.ts +19 -0
- package/build/components/threat-modal/fixer-state-notice.js +44 -0
- package/build/components/threat-modal/index.d.ts +51 -0
- package/build/components/threat-modal/index.js +45 -0
- package/build/components/threat-modal/threat-actions.d.ts +7 -0
- package/build/components/threat-modal/threat-actions.js +40 -0
- package/build/components/threat-modal/threat-fix-confirmation.d.ts +7 -0
- package/build/components/threat-modal/threat-fix-confirmation.js +19 -0
- package/build/components/threat-modal/threat-fix-details.d.ts +7 -0
- package/build/components/threat-modal/threat-fix-details.js +40 -0
- package/build/components/threat-modal/threat-notice.d.ts +16 -0
- package/build/components/threat-modal/threat-notice.js +23 -0
- package/build/components/threat-modal/threat-summary.d.ts +7 -0
- package/build/components/threat-modal/threat-summary.js +16 -0
- package/build/components/threat-modal/threat-technical-details.d.ts +7 -0
- package/build/components/threat-modal/threat-technical-details.js +26 -0
- package/build/components/threat-severity-badge/index.d.ts +4 -0
- package/build/components/threat-severity-badge/index.js +13 -0
- package/build/components/threat-severity-badge/test/index.test.d.ts +1 -0
- package/build/components/threat-severity-badge/test/index.test.js +9 -0
- package/build/components/threats-data-views/constants.d.ts +33 -0
- package/build/components/threats-data-views/constants.js +37 -0
- package/build/components/threats-data-views/index.d.ts +29 -0
- package/build/components/threats-data-views/index.js +412 -0
- package/build/components/threats-data-views/test/index.test.d.ts +1 -0
- package/build/components/threats-data-views/test/index.test.js +51 -0
- package/build/components/threats-data-views/threats-status-toggle-group-control.d.ts +15 -0
- package/build/components/threats-data-views/threats-status-toggle-group-control.js +95 -0
- package/build/index.d.ts +4 -3
- package/build/index.js +4 -3
- package/build/types/index.d.ts +3 -3
- package/build/types/index.js +3 -3
- package/build/types/status.d.ts +1 -1
- package/build/types/threats.d.ts +1 -1
- package/build/utils/index.d.ts +2 -2
- package/build/utils/index.js +7 -9
- package/package.json +19 -14
- package/src/components/index.js +4 -0
- package/src/components/threat-fixer-button/index.tsx +101 -0
- package/src/components/threat-fixer-button/styles.module.scss +16 -0
- package/src/components/threat-modal/fixer-state-notice.tsx +63 -0
- package/src/components/threat-modal/index.tsx +109 -0
- package/src/components/threat-modal/styles.module.scss +82 -0
- package/src/components/threat-modal/threat-actions.tsx +93 -0
- package/src/components/threat-modal/threat-fix-confirmation.tsx +54 -0
- package/src/components/threat-modal/threat-fix-details.tsx +64 -0
- package/src/components/threat-modal/threat-notice.tsx +84 -0
- package/src/components/threat-modal/threat-summary.tsx +29 -0
- package/src/components/threat-modal/threat-technical-details.tsx +65 -0
- package/src/components/threat-severity-badge/index.tsx +24 -0
- package/src/components/threat-severity-badge/styles.module.scss +27 -0
- package/src/components/threat-severity-badge/test/index.test.jsx +9 -0
- package/src/components/threats-data-views/constants.ts +49 -0
- package/src/components/threats-data-views/index.tsx +533 -0
- package/src/components/threats-data-views/styles.module.scss +40 -0
- package/src/components/threats-data-views/test/index.test.jsx +56 -0
- package/src/components/threats-data-views/threats-status-toggle-group-control.tsx +158 -0
- package/src/index.ts +4 -3
- package/src/types/index.ts +3 -3
- package/src/types/status.ts +1 -1
- package/src/types/threats.ts +1 -1
- package/src/utils/index.ts +3 -3
- /package/src/{index.test.ts → index.test.js} +0 -0
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__experimentalToggleGroupControl as ToggleGroupControl, // eslint-disable-line @wordpress/no-unsafe-wp-apis
|
|
3
|
+
__experimentalToggleGroupControlOption as ToggleGroupControlOption, // eslint-disable-line @wordpress/no-unsafe-wp-apis
|
|
4
|
+
} from '@wordpress/components';
|
|
5
|
+
import { type View } from '@wordpress/dataviews';
|
|
6
|
+
import { useMemo, useCallback } from '@wordpress/element';
|
|
7
|
+
import { __, sprintf } from '@wordpress/i18n';
|
|
8
|
+
import { type Threat, type ThreatStatus } from '@automattic/jetpack-scan';
|
|
9
|
+
import styles from './styles.module.scss';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* ToggleGroupControl component for filtering threats by status.
|
|
13
|
+
* @param {object} props - Component props.
|
|
14
|
+
* @param { Threat[]} props.data - Threats data.
|
|
15
|
+
* @param { View } props.view - The current view.
|
|
16
|
+
* @param { Function } props.onChangeView - Callback function to handle view changes.
|
|
17
|
+
* @return {JSX.Element|null} The component or null.
|
|
18
|
+
*/
|
|
19
|
+
export default function ThreatsStatusToggleGroupControl( {
|
|
20
|
+
data,
|
|
21
|
+
view,
|
|
22
|
+
onChangeView,
|
|
23
|
+
}: {
|
|
24
|
+
data: Threat[];
|
|
25
|
+
view: View;
|
|
26
|
+
onChangeView: ( newView: View ) => void;
|
|
27
|
+
} ): JSX.Element {
|
|
28
|
+
/**
|
|
29
|
+
* Compute values from the provided threats data.
|
|
30
|
+
*
|
|
31
|
+
* @member {number} activeThreatsCount - Count of active threats.
|
|
32
|
+
* @member {number} historicThreatsCount - Count of historic threats.
|
|
33
|
+
*/
|
|
34
|
+
const {
|
|
35
|
+
activeThreatsCount,
|
|
36
|
+
historicThreatsCount,
|
|
37
|
+
}: {
|
|
38
|
+
activeThreatsCount: number;
|
|
39
|
+
historicThreatsCount: number;
|
|
40
|
+
} = useMemo( () => {
|
|
41
|
+
return data.reduce(
|
|
42
|
+
( acc, threat ) => {
|
|
43
|
+
if ( threat.status ) {
|
|
44
|
+
if ( threat.status === 'current' ) {
|
|
45
|
+
acc.activeThreatsCount++;
|
|
46
|
+
} else {
|
|
47
|
+
acc.historicThreatsCount++;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return acc;
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
activeThreatsCount: 0,
|
|
54
|
+
historicThreatsCount: 0,
|
|
55
|
+
}
|
|
56
|
+
);
|
|
57
|
+
}, [ data ] );
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Callback function to handle the status change filter.
|
|
61
|
+
*
|
|
62
|
+
* @param {string} newStatus - The new status filter value.
|
|
63
|
+
*/
|
|
64
|
+
const onStatusFilterChange = useCallback(
|
|
65
|
+
( newStatus: string ) => {
|
|
66
|
+
const updatedFilters = view.filters.filter( filter => filter.field !== 'status' );
|
|
67
|
+
|
|
68
|
+
if ( newStatus === 'active' ) {
|
|
69
|
+
updatedFilters.push( {
|
|
70
|
+
field: 'status',
|
|
71
|
+
operator: 'isAny',
|
|
72
|
+
value: [ 'current' ],
|
|
73
|
+
} );
|
|
74
|
+
} else if ( newStatus === 'historic' ) {
|
|
75
|
+
updatedFilters.push( {
|
|
76
|
+
field: 'status',
|
|
77
|
+
operator: 'isAny',
|
|
78
|
+
value: [ 'fixed', 'ignored' ],
|
|
79
|
+
} );
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
onChangeView( {
|
|
83
|
+
...view,
|
|
84
|
+
filters: updatedFilters,
|
|
85
|
+
} );
|
|
86
|
+
},
|
|
87
|
+
[ view, onChangeView ]
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Memoized function to determine if a status filter is selected.
|
|
92
|
+
*
|
|
93
|
+
* @param {Array} threatStatuses - List of threat statuses.
|
|
94
|
+
*/
|
|
95
|
+
const isStatusFilterSelected = useMemo(
|
|
96
|
+
() => ( threatStatuses: ThreatStatus[] ) =>
|
|
97
|
+
view.filters.some(
|
|
98
|
+
filter =>
|
|
99
|
+
filter.field === 'status' &&
|
|
100
|
+
Array.isArray( filter.value ) &&
|
|
101
|
+
filter.value.length === threatStatuses.length &&
|
|
102
|
+
threatStatuses.every( threatStatus => filter.value.includes( threatStatus ) )
|
|
103
|
+
),
|
|
104
|
+
[ view.filters ]
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
const selectedValue = useMemo( () => {
|
|
108
|
+
if ( isStatusFilterSelected( [ 'current' ] ) ) {
|
|
109
|
+
return 'active' as const;
|
|
110
|
+
}
|
|
111
|
+
if ( isStatusFilterSelected( [ 'fixed', 'ignored' ] ) ) {
|
|
112
|
+
return 'historic' as const;
|
|
113
|
+
}
|
|
114
|
+
return '' as const;
|
|
115
|
+
}, [ isStatusFilterSelected ] );
|
|
116
|
+
|
|
117
|
+
if ( ! ( activeThreatsCount + historicThreatsCount ) ) {
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
try {
|
|
122
|
+
return (
|
|
123
|
+
<div>
|
|
124
|
+
<div className={ styles[ 'toggle-group-control' ] }>
|
|
125
|
+
<ToggleGroupControl
|
|
126
|
+
value={ selectedValue }
|
|
127
|
+
onChange={ onStatusFilterChange }
|
|
128
|
+
isBlock
|
|
129
|
+
hideLabelFromVision
|
|
130
|
+
__nextHasNoMarginBottom
|
|
131
|
+
__next40pxDefaultSize
|
|
132
|
+
>
|
|
133
|
+
<ToggleGroupControlOption
|
|
134
|
+
value="active"
|
|
135
|
+
label={ sprintf(
|
|
136
|
+
/* translators: %d: number of active threats */ __(
|
|
137
|
+
'Active threats (%d)',
|
|
138
|
+
'jetpack-scan'
|
|
139
|
+
),
|
|
140
|
+
activeThreatsCount
|
|
141
|
+
) }
|
|
142
|
+
/>
|
|
143
|
+
<ToggleGroupControlOption
|
|
144
|
+
value="historic"
|
|
145
|
+
label={ sprintf(
|
|
146
|
+
/* translators: %d: number of historic threats */
|
|
147
|
+
__( 'History (%d)', 'jetpack-scan' ),
|
|
148
|
+
historicThreatsCount
|
|
149
|
+
) }
|
|
150
|
+
/>
|
|
151
|
+
</ToggleGroupControl>
|
|
152
|
+
</div>
|
|
153
|
+
</div>
|
|
154
|
+
);
|
|
155
|
+
} catch {
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export * from './types/index.
|
|
2
|
-
export * from './constants/index.
|
|
3
|
-
export * from './utils/index.
|
|
1
|
+
export * from './types/index.ts';
|
|
2
|
+
export * from './constants/index.ts';
|
|
3
|
+
export * from './utils/index.ts';
|
|
4
|
+
export * from './components/index.js';
|
package/src/types/index.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './fixers.
|
|
2
|
-
export * from './status.
|
|
3
|
-
export * from './threats.
|
|
1
|
+
export * from './fixers.ts';
|
|
2
|
+
export * from './status.ts';
|
|
3
|
+
export * from './threats.ts';
|
package/src/types/status.ts
CHANGED
package/src/types/threats.ts
CHANGED
package/src/utils/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { __, sprintf } from '@wordpress/i18n';
|
|
2
|
-
import { FIXER_IS_STALE_THRESHOLD } from '../constants/index.
|
|
3
|
-
import { type ThreatFixStatus } from '../types/fixers.
|
|
4
|
-
import { type Threat } from '../types/threats.
|
|
2
|
+
import { FIXER_IS_STALE_THRESHOLD } from '../constants/index.ts';
|
|
3
|
+
import { type ThreatFixStatus } from '../types/fixers.ts';
|
|
4
|
+
import { type Threat } from '../types/threats.ts';
|
|
5
5
|
|
|
6
6
|
export const getThreatType = ( threat: Threat ) => {
|
|
7
7
|
if ( threat.signature === 'Vulnerable.WP.Core' ) {
|
|
File without changes
|