Skip to content

Commit e3d6460

Browse files
dkmytanateweller
andcommitted
ThreatsDataViews: Improve responsiveness (#40670)
* Init project branch * Init project branch * Improve component responsiveness * Init project branch * Fix merge conflict * Simplify, and only default to list view in mobile * Fix spacing * Minor adjustments to initialization of defaultLayouts, remove memo * Remove style overrides on core component * Reapply min-width for ScanToggleGroupControl --------- Co-authored-by: Nate Weller <[email protected]>
1 parent 0aa68f7 commit e3d6460

File tree

3 files changed

+28
-12
lines changed

3 files changed

+28
-12
lines changed

projects/js-packages/components/components/threats-data-views/index.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { __ } from '@wordpress/i18n';
1616
import { Icon } from '@wordpress/icons';
1717
import { useCallback, useMemo, useState } from 'react';
1818
import Badge from '../badge/index.js';
19+
import useBreakpointMatch from '../layout/use-breakpoint-match/index.js';
1920
import ThreatFixerButton from '../threat-fixer-button/index.js';
2021
import ThreatSeverityBadge from '../threat-severity-badge/index.js';
2122
import {
@@ -91,6 +92,8 @@ export default function ThreatsDataViews( {
9192
onUnignoreThreats?: ActionButton< Threat >[ 'callback' ];
9293
header?: JSX.Element;
9394
} ): JSX.Element {
95+
const [ isSm ] = useBreakpointMatch( [ 'sm', 'lg' ], [ null, '<' ] );
96+
9497
const baseView = {
9598
sort: {
9699
field: 'severity',
@@ -126,14 +129,21 @@ export default function ThreatsDataViews( {
126129
},
127130
};
128131

132+
/**
133+
* Default View Type.
134+
*
135+
* Set the default view type (list or table) based on the initial screen size.
136+
*/
137+
const defaultViewType: 'list' | 'table' = isSm ? 'list' : 'table';
138+
129139
/**
130140
* DataView view object - configures how the dataset is visible to the user.
131141
*
132142
* @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-dataviews/#view-object
133143
*/
134144
const [ view, setView ] = useState< View >( {
135-
type: 'table',
136-
...defaultLayouts.table,
145+
type: defaultViewType,
146+
...defaultLayouts[ defaultViewType ],
137147
} );
138148

139149
/**

projects/plugins/protect/src/js/routes/home/styles.module.scss

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@
22
padding-left: 0;
33
padding-right: 0;
44
overflow: hidden;
5-
6-
> * {
7-
margin-left: calc( var( --spacing-base ) * -3 ); // -24px
8-
margin-right: calc( var( --spacing-base ) * -3 ); // -24px
9-
}
105
}
116

127
.view-scan-report {

projects/plugins/protect/src/js/routes/scan/styles.module.scss

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
.scan-results-container {
2+
:global {
3+
@media ( max-width: 599px ) {
4+
div.dataviews-wrapper .dataviews__view-actions {
5+
flex-wrap: wrap;
6+
justify-content: center;
7+
gap: calc( var( --spacing-base ) * 1.5 ); // 12px;
8+
}
9+
}
10+
}
11+
}
12+
113
.hero-main {
214
max-width: 550px;
315
}
@@ -17,11 +29,6 @@
1729
padding-left: 0;
1830
padding-right: 0;
1931
overflow: hidden;
20-
21-
> * {
22-
margin-left: calc( var( --spacing-base ) * -3 ); // -24px
23-
margin-right: calc( var( --spacing-base ) * -3 ); // -24px
24-
}
2532
}
2633

2734
.progress-animation {
@@ -33,3 +40,7 @@
3340
.last-checked {
3441
width: fit-content;
3542
}
43+
44+
.toggle-group-control {
45+
min-width: 300px;
46+
}

0 commit comments

Comments
 (0)