Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { __ } from '@wordpress/i18n';
import { Icon } from '@wordpress/icons';
import { useCallback, useMemo, useState } from 'react';
import Badge from '../badge';
import useBreakpointMatch from '../layout/use-breakpoint-match';
import ThreatFixerButton from '../threat-fixer-button';
import ThreatSeverityBadge from '../threat-severity-badge';
import {
Expand Down Expand Up @@ -79,6 +80,8 @@ export default function ThreatsDataViews( {
onIgnoreThreats?: ActionButton< Threat >[ 'callback' ];
onUnignoreThreats?: ActionButton< Threat >[ 'callback' ];
} ): JSX.Element {
const [ isSm ] = useBreakpointMatch( [ 'sm', 'lg' ], [ null, '<' ] );

const baseView = {
sort: {
field: 'severity',
Expand Down Expand Up @@ -119,14 +122,21 @@ export default function ThreatsDataViews( {
},
};

/**
* Default View Type.
*
* Set the default view type (list or table) based on the initial screen size.
*/
const defaultViewType: 'list' | 'table' = isSm ? 'list' : 'table';

/**
* DataView view object - configures how the dataset is visible to the user.
*
* @see https://developer.wordpress.org/block-editor/reference-guides/packages/packages-dataviews/#view-object
*/
const [ view, setView ] = useState< View >( {
type: 'table',
...defaultLayouts.table,
type: defaultViewType,
...defaultLayouts[ defaultViewType ],
} );

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export default function ThreatsStatusToggleGroupControl( {
*/
const isStatusFilterSelected = useMemo(
() => ( threatStatuses: ThreatStatus[] ) =>
Array.isArray( view.filters ) &&
view.filters.some(
filter =>
filter.field === 'status' &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@
padding-left: 0;
padding-right: 0;
overflow: hidden;

> * {
margin-left: calc( var( --spacing-base ) * -3 ); // -24px
margin-right: calc( var( --spacing-base ) * -3 ); // -24px
}
}

.view-scan-report {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@
padding-left: 0;
padding-right: 0;
overflow: hidden;

> * {
margin-left: calc( var( --spacing-base ) * -3 ); // -24px
margin-right: calc( var( --spacing-base ) * -3 ); // -24px
}
}

.progress-animation {
Expand Down
Loading