Skip to content

Commit

Permalink
remove duplicate code
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgefilipecosta committed Jan 31, 2024
1 parent c543418 commit ffc183e
Showing 1 changed file with 2 additions and 55 deletions.
57 changes: 2 additions & 55 deletions packages/dataviews/src/view-table.js
Expand Up @@ -6,7 +6,7 @@ import classnames from 'classnames';
/**
* WordPress dependencies
*/
import { __, sprintf } from '@wordpress/i18n';
import { __ } from '@wordpress/i18n';
import { useAsyncList } from '@wordpress/compose';
import { unseen, funnel } from '@wordpress/icons';
import {
Expand All @@ -32,6 +32,7 @@ import { unlock } from './lock-unlock';
import ItemActions from './item-actions';
import { ENUMERATION_TYPE, OPERATORS, SORTING_DIRECTIONS } from './constants';
import { DropdownMenuRadioItemCustom } from './dropdown-menu-helper';
import SingleSelectionCheckbox from './single-selection-checkbox';

const {
DropdownMenuV2: DropdownMenu,
Expand Down Expand Up @@ -327,60 +328,6 @@ function BulkSelectionCheckbox( { selection, onSelectionChange, data } ) {
);
}

function SingleSelectionCheckbox( {
selection,
onSelectionChange,
item,
data,
getItemId,
primaryField,
} ) {
const id = getItemId( item );
const isSelected = selection.includes( id );
let selectionLabel;
if ( primaryField?.getValue && item ) {
// eslint-disable-next-line @wordpress/valid-sprintf
selectionLabel = sprintf(
/* translators: %s: item title. */
isSelected ? __( 'Deselect item: %s' ) : __( 'Select item: %s' ),
primaryField.getValue( { item } )
);
} else {
selectionLabel = isSelected
? __( 'Select a new item' )
: __( 'Deselect item' );
}
return (
<CheckboxControl
className="dataviews-view-table-selection-checkbox"
__nextHasNoMarginBottom
checked={ isSelected }
label={ selectionLabel }
onChange={ () => {
if ( ! isSelected ) {
onSelectionChange(
data.filter( ( _item ) => {
const itemId = getItemId?.( _item );
return (
itemId === id || selection.includes( itemId )
);
} )
);
} else {
onSelectionChange(
data.filter( ( _item ) => {
const itemId = getItemId?.( _item );
return (
itemId !== id && selection.includes( itemId )
);
} )
);
}
} }
/>
);
}

function ViewTable( {
view,
onChangeView,
Expand Down

0 comments on commit ffc183e

Please sign in to comment.