Product Updates

DatoCMS changelog for new features and general improvements
Plugins
Plugin SDK exposes blocks usage information
September 15th, 2022

A small addition to our Plugin SDK: it is now possible to retrieve the number of blocks currently used inside a record via the ctx.blocksAnalysis property.

The information is exposed in every hook related to records editing, namely Field extensions, Sidebar panels, and Form outlets:

import React from 'react';
import ReactDOM from 'react-dom';
import { connect, RenderItemFormOutletCtx } from 'datocms-plugin-sdk';
connect({
itemFormOutlets(model, ctx) {
return [{ id: 'myOutlet' }];
},
renderItemFormOutlet(outletId, ctx) {
const {
blocksAnalysis: {
usage: {
/** Total number of blocks present in form state */
total,
/** Total number of blocks present in non-localized fields */
nonLocalized,
/** Total number of blocks present in localized fields, per locale */
perLocale,
},
/** Maximum number of blocks per item */
maximumPerItem,
},
} = ctx;
// render the outlet here
},
});