diff --git a/packages/dataviews/src/style.scss b/packages/dataviews/src/style.scss
index 127a3182ba95b1..1f9b3850b702e2 100644
--- a/packages/dataviews/src/style.scss
+++ b/packages/dataviews/src/style.scss
@@ -328,8 +328,9 @@
line-height: 16px;
&:not(:empty) {
- padding: $grid-unit-15;
+ padding: $grid-unit-15 0;
padding-top: 0;
+ margin: 0 $grid-unit-15;
}
.dataviews-view-grid__field {
@@ -355,6 +356,24 @@
}
}
}
+
+ .dataviews-view-grid__badge-fields {
+ &:not(:empty) {
+ padding: $grid-unit-15;
+ padding-top: 0;
+ }
+
+ .dataviews-view-grid__field-value {
+ width: fit-content;
+ background: $gray-100;
+ padding: 0 $grid-unit-10;
+ min-height: $grid-unit-30;
+ border-radius: $radius-block-ui;
+ display: flex;
+ align-items: center;
+ font-size: 12px;
+ }
+ }
}
.dataviews-view-list {
diff --git a/packages/dataviews/src/view-grid.js b/packages/dataviews/src/view-grid.js
index 40b2b44c0cf9d7..97d8b7c342eb35 100644
--- a/packages/dataviews/src/view-grid.js
+++ b/packages/dataviews/src/view-grid.js
@@ -34,6 +34,7 @@ function GridItem( {
mediaField,
primaryField,
visibleFields,
+ badgeFields,
displayAsColumnFields,
} ) {
const hasBulkAction = useHasAPossibleBulkAction( actions, item );
@@ -99,46 +100,76 @@ function GridItem( {
-
- { visibleFields.map( ( field ) => {
- const renderedValue = field.render( {
- item,
- } );
- if ( ! renderedValue ) {
- return null;
- }
- return (
-
-
- { field.header }
-
+ { !! badgeFields?.length && (
+
+ { badgeFields.map( ( field ) => {
+ const renderedValue = field.render( {
+ item,
+ } );
+ if ( ! renderedValue ) {
+ return null;
+ }
+ return (
{ renderedValue }
-
- );
- } ) }
-
+ );
+ } ) }
+
+ ) }
+ { !! visibleFields?.length && (
+
+ { visibleFields.map( ( field ) => {
+ const renderedValue = field.render( {
+ item,
+ } );
+ if ( ! renderedValue ) {
+ return null;
+ }
+ return (
+
+ <>
+
+ { field.header }
+
+
+ { renderedValue }
+
+ >
+
+ );
+ } ) }
+
+ ) }
);
}
@@ -159,12 +190,25 @@ export default function ViewGrid( {
const primaryField = fields.find(
( field ) => field.id === view.layout.primaryField
);
- const visibleFields = fields.filter(
- ( field ) =>
- ! view.hiddenFields.includes( field.id ) &&
- ! [ view.layout.mediaField, view.layout.primaryField ].includes(
- field.id
- )
+ const { visibleFields, badgeFields } = fields.reduce(
+ ( accumulator, field ) => {
+ if (
+ view.hiddenFields.includes( field.id ) ||
+ [ view.layout.mediaField, view.layout.primaryField ].includes(
+ field.id
+ )
+ ) {
+ return accumulator;
+ }
+ // If the field is a badge field, add it to the badgeFields array
+ // otherwise add it to the rest visibleFields array.
+ const key = view.layout.badgeFields?.includes( field.id )
+ ? 'badgeFields'
+ : 'visibleFields';
+ accumulator[ key ].push( field );
+ return accumulator;
+ },
+ { visibleFields: [], badgeFields: [] }
);
const hasData = !! data?.length;
return (
@@ -190,6 +234,7 @@ export default function ViewGrid( {
mediaField={ mediaField }
primaryField={ primaryField }
visibleFields={ visibleFields }
+ badgeFields={ badgeFields }
displayAsColumnFields={
view.layout.displayAsColumnFields
}
diff --git a/packages/edit-site/src/components/page-patterns/index.js b/packages/edit-site/src/components/page-patterns/index.js
index f5a6d5f6bfc0ac..7f43bb1b4c3bb4 100644
--- a/packages/edit-site/src/components/page-patterns/index.js
+++ b/packages/edit-site/src/components/page-patterns/index.js
@@ -73,6 +73,7 @@ const defaultConfigPerViewType = {
[ LAYOUT_GRID ]: {
mediaField: 'preview',
primaryField: 'title',
+ badgeFields: [ 'sync-status' ],
},
};
const DEFAULT_VIEW = {
@@ -314,19 +315,23 @@ export default function DataviewsPatterns() {
];
if ( type === PATTERN_TYPES.theme ) {
_fields.push( {
- header: __( 'Sync Status' ),
+ header: __( 'Sync status' ),
id: 'sync-status',
render: ( { item } ) => {
// User patterns can have their sync statuses checked directly.
// Non-user patterns are all unsynced for the time being.
return (
- SYNC_FILTERS.find(
- ( { value } ) => value === item.syncStatus
- )?.label ||
- SYNC_FILTERS.find(
- ( { value } ) =>
- value === PATTERN_SYNC_TYPES.unsynced
- ).label
+
+ { SYNC_FILTERS.find(
+ ( { value } ) => value === item.syncStatus
+ )?.label ||
+ SYNC_FILTERS.find(
+ ( { value } ) =>
+ value === PATTERN_SYNC_TYPES.unsynced
+ ).label }
+
);
},
type: ENUMERATION_TYPE,
diff --git a/packages/edit-site/src/components/page-patterns/style.scss b/packages/edit-site/src/components/page-patterns/style.scss
index d4afcaea186476..74205b044b340b 100644
--- a/packages/edit-site/src/components/page-patterns/style.scss
+++ b/packages/edit-site/src/components/page-patterns/style.scss
@@ -111,6 +111,13 @@
.dataviews-pagination {
z-index: z-index(".edit-site-patterns__dataviews-list-pagination");
}
+
+ .dataviews-view-grid__badge-fields {
+ .dataviews-view-grid__field-value:has(.edit-site-patterns__field-sync-status-fully) {
+ background: rgba(var(--wp-block-synced-color--rgb), 0.04);
+ color: var(--wp-block-synced-color);
+ }
+ }
}
.dataviews-action-modal__duplicate-pattern {