Skip to content

Commit

Permalink
Dataviews: Ensure items and fields are using a unique id
Browse files Browse the repository at this point in the history
  • Loading branch information
ntsekouras committed Nov 21, 2023
1 parent fe958de commit 7dda6db
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/edit-site/src/components/dataviews/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ This file documents the DataViews UI component, which provides an API to render
```js
<DataViews
data={ pages }
getItemId={ ( item ) => item.id }
isLoading={ isLoadingPages }
view={ view }
onChangeView={ onChangeView }
Expand Down
2 changes: 2 additions & 0 deletions packages/edit-site/src/components/dataviews/dataviews.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export default function DataViews( {
searchLabel = undefined,
actions,
data,
getItemId,
isLoading = false,
paginationInfo,
supportedLayouts,
Expand Down Expand Up @@ -86,6 +87,7 @@ export default function DataViews( {
paginationInfo={ paginationInfo }
actions={ actions }
data={ data }
getItemId={ getItemId }
isLoading={ isLoading }
/>
<Pagination
Expand Down
4 changes: 2 additions & 2 deletions packages/edit-site/src/components/dataviews/view-grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
*/
import ItemActions from './item-actions';

export function ViewGrid( { data, fields, view, actions } ) {
export function ViewGrid( { data, fields, view, actions, getItemId } ) {
const mediaField = fields.find(
( field ) => field.id === view.layout.mediaField
);
Expand All @@ -27,7 +27,7 @@ export function ViewGrid( { data, fields, view, actions } ) {
<Grid gap={ 8 } columns={ 2 } alignment="top">
{ data.map( ( item, index ) => {
return (
<VStack key={ index }>
<VStack key={ getItemId?.( item ) || index }>
<div className="dataviews-view-grid__media">
{ mediaField?.render( { item, view } ) || (
<Placeholder
Expand Down
4 changes: 3 additions & 1 deletion packages/edit-site/src/components/dataviews/view-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ function ViewList( {
fields,
actions,
data,
getItemId,
isLoading = false,
paginationInfo,
} ) {
Expand Down Expand Up @@ -370,6 +371,7 @@ function ViewList( {
},
columnVisibility: columnVisibility ?? EMPTY_OBJECT,
},
getRowId: getItemId,
onSortingChange: ( sortingUpdater ) => {
onChangeView( ( currentView ) => {
const sort =
Expand Down Expand Up @@ -488,7 +490,7 @@ function ViewList( {
<tr key={ row.id }>
{ row.getVisibleCells().map( ( cell ) => (
<td
key={ cell.id }
key={ cell.column.id }
style={ {
width:
cell.column.columnDef.width ||
Expand Down
1 change: 1 addition & 0 deletions packages/edit-site/src/components/page-pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ export default function PagePages() {
fields={ fields }
actions={ actions }
data={ pages || EMPTY_ARRAY }
getItemId={ ( item ) => item.id }
isLoading={ isLoadingPages || isLoadingAuthors }
view={ view }
onChangeView={ onChangeView }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ export default function DataviewsTemplates() {
fields={ fields }
actions={ actions }
data={ shownTemplates }
getItemId={ ( item ) => item.id }
isLoading={ isLoadingData }
view={ view }
onChangeView={ onChangeView }
Expand Down

0 comments on commit 7dda6db

Please sign in to comment.