Skip to content

Commit

Permalink
in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgefilipecosta committed Mar 12, 2024
1 parent ddffca9 commit c85a8b8
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 40 deletions.
2 changes: 2 additions & 0 deletions packages/dataviews/src/bulk-actions-popover.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export default function BulkActionsPopover( {
actions = EMPTY_ARRAY,
setSelection,
getItemId,
anchor,
} ) {
const selectedItems = useMemo( () => {
return data.filter( ( item ) =>
Expand Down Expand Up @@ -70,6 +71,7 @@ export default function BulkActionsPopover( {
<Popover
placement="bottom-middle"
className="dataviews-bulk-actions-popover"
anchor={ anchor }
>
<Toolbar label="Bulk actions">
<div className="dataviews-bulk-actions-toolbar-wrapper">
Expand Down
32 changes: 18 additions & 14 deletions packages/dataviews/src/dataviews.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export default function DataViews( {
} ) {
const [ selection, setSelection ] = useState( [] );
const [ openedFilter, setOpenedFilter ] = useState( null );
const [ viewComponentAnchor, setViewComponentAnchor ] = useState();

useEffect( () => {
if (
Expand Down Expand Up @@ -133,6 +134,7 @@ export default function DataViews( {
/>
</HStack>
<ViewComponent
ref={ setViewComponentAnchor }
fields={ _fields }
view={ view }
onChangeView={ onChangeView }
Expand All @@ -146,20 +148,22 @@ export default function DataViews( {
deferredRendering={ deferredRendering }
setOpenedFilter={ setOpenedFilter }
/>
<div>
<Pagination
view={ view }
onChangeView={ onChangeView }
paginationInfo={ paginationInfo }
/>
<BulkActionsPopover
data={ data }
actions={ actions }
selection={ selection }
setSelection={ setSelection }
getItemId={ getItemId }
/>
</div>
<Pagination
view={ view }
onChangeView={ onChangeView }
paginationInfo={ paginationInfo }
/>
{ [ LAYOUT_TABLE, LAYOUT_GRID ].includes( view.type ) &&
hasPossibleBulkAction && (
<BulkActionsPopover
anchor={ viewComponentAnchor }
data={ data }
actions={ actions }
selection={ selection }
setSelection={ setSelection }
getItemId={ getItemId }
/>
) }
</div>
);
}
28 changes: 16 additions & 12 deletions packages/dataviews/src/view-grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
} from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { useAsyncList } from '@wordpress/compose';
import { forwardRef } from '@wordpress/element';

/**
* Internal dependencies
Expand Down Expand Up @@ -125,17 +126,18 @@ function GridItem( {
);
}

export default function ViewGrid( {
data,
fields,
view,
actions,
isLoading,
getItemId,
deferredRendering,
selection,
onSelectionChange,
} ) {
const ViewGrid = forwardRef( ( props, ref ) => {
const {
data,
fields,
view,
actions,
isLoading,
getItemId,
deferredRendering,
selection,
onSelectionChange,
} = props;
const mediaField = fields.find(
( field ) => field.id === view.layout.mediaField
);
Expand All @@ -161,6 +163,7 @@ export default function ViewGrid( {
alignment="top"
className="dataviews-view-grid"
aria-busy={ isLoading }
ref={ ref }
>
{ usedData.map( ( item ) => {
return (
Expand Down Expand Up @@ -192,4 +195,5 @@ export default function ViewGrid( {
) }
</>
);
}
} );
export default ViewGrid;
30 changes: 16 additions & 14 deletions packages/dataviews/src/view-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,19 +331,20 @@ function TableRow( {
);
}

function ViewTable( {
view,
onChangeView,
fields,
actions,
data,
getItemId,
isLoading = false,
deferredRendering,
selection,
onSelectionChange,
setOpenedFilter,
} ) {
const ViewTable = forwardRef( ( pros, ref ) => {
const {
view,
onChangeView,
fields,
actions,
data,
getItemId,
isLoading = false,
deferredRendering,
selection,
onSelectionChange,
setOpenedFilter,
} = pros;
const headerMenuRefs = useRef( new Map() );
const headerMenuToFocusRef = useRef();
const [ nextHeaderMenuToFocus, setNextHeaderMenuToFocus ] = useState();
Expand Down Expand Up @@ -393,6 +394,7 @@ function ViewTable( {
className="dataviews-view-table"
aria-busy={ isLoading }
aria-describedby={ tableNoticeId }
ref={ ref }
>
<thead>
<tr className="dataviews-view-table__row">
Expand Down Expand Up @@ -502,6 +504,6 @@ function ViewTable( {
</div>
</>
);
}
} );

export default ViewTable;

0 comments on commit c85a8b8

Please sign in to comment.