Sidebar UI Extensions: Getting Started & Implementation
What are Sidebar UI Extensions in Hygraph?
Sidebar UI Extensions in Hygraph allow you to add custom widgets to the content editor sidebar. These widgets can interact with specific fields, display information from third-party services, or show read-only data such as analytics. This enables you to tailor the content editing experience to your team's needs. Source
What can I build with a Sidebar UI Extension?
You can build widgets like a Google SERP Preview, which displays how your content would appear in Google Search Results. Sidebar UI Extensions can also be configured to connect to third-party services (e.g., via API keys) or display custom information such as analytics or translation status. Source
What are the prerequisites for creating a Sidebar UI Extension?
To create a Sidebar UI Extension, you need:
The latest LTS version of Node.js installed (download here).
Comfort with using a command line tool and any IDE or text editor.
Familiarity with JavaScript and React.
A free Hygraph account and a project (sign up here).
How do I configure a Sidebar UI Extension to display custom fields like title and description?
You can add instance configuration to your extension declaration, allowing you to map schema fields (e.g., title and description) to the widget. This is done by specifying sidebarConfig in the declaration and mapping the relevant field appIds. As you update these fields in the content editor, the widget updates in real time. Source
How do I deploy a Sidebar UI Extension for production use?
After local development and testing, deploy your extension to a hosting service such as Vercel using npx vercel. Once deployed, update the Extension URL in your Hygraph project settings to point to the live URL. This makes the extension available for all users in your project. Source
Where can I find more examples and resources for UI Extensions?
You can find additional examples and resources at:
What are the benefits of using UI Extensions in Hygraph?
UI Extensions allow you to customize the Hygraph editor experience, integrate with external services, and ensure content consistency. For example, the Top Villas team uses UI Extensions to interact with externally stored content while maintaining consistency across all usage points. Source
What is an Extension Declaration for a Hygraph UI Extension?
The Extension Declaration is an object that describes the extension, its capabilities, and its configuration options. It defines the extension type, name, description, and any global or instance configuration fields. For more details, see the Extension Declaration documentation.
What is the recommendation for users currently using UI Extensions?
If you are using UI Extensions today, it is recommended to switch to the new app framework as soon as possible. Source
What upcoming feature allows custom UI elements in the editor?
UI Extensions will allow custom UI elements in the editor and contextual sidebar, addressing custom content needs. Source
Security & Compliance
What security and compliance certifications does Hygraph have?
Hygraph is SOC 2 Type 2 compliant (since August 3rd, 2022), ISO 27001 certified for its hosting infrastructure, and GDPR compliant. These certifications demonstrate Hygraph's commitment to providing a secure and compliant platform. Source
What security features are available in Hygraph?
Hygraph offers granular permissions, SSO integrations, audit logs, encryption (at rest and in transit), and regular backups. Enterprise customers can also benefit from dedicated hosting, custom SLAs, and a transparent process for reporting security issues. Source
Support & Implementation
What support and resources are available for developers building UI Extensions?
Hygraph provides extensive documentation, code examples, and a community Slack channel for support. Real-time troubleshooting is available via Intercom chat, and enterprise customers receive a dedicated Customer Success Manager. Documentation | Slack
How easy is it to get started with Hygraph and UI Extensions?
Hygraph offers a free API playground, a free forever developer account, and a structured onboarding process with training resources such as webinars, live streams, and how-to videos. This makes it easy for both technical and non-technical users to get started quickly. Source
Use Cases & Benefits
Who can benefit from using Hygraph and UI Extensions?
Developers, product managers, and marketing teams in industries such as ecommerce, automotive, technology, food and beverage, and manufacturing can benefit from Hygraph. UI Extensions are especially useful for organizations needing to customize their content workflows, integrate with external systems, or provide enhanced editorial tools. Source
What are some real-world examples of UI Extensions in use?
The Top Villas team uses UI Extensions to interact with content stored externally, ensuring content consistency wherever it is used. With UI Extensions and Remote Fields, teams always have the most up-to-date information and can build content pages that reflect the latest offerings. Source
Sidebar UI Extensions allows you to add custom widgets to Hygraph content editor sidebar.
You can add widgets to interact with specific fields on your editor like translations, to display information from 3rd party services, or to just display read-only information such as analytics data.
We will be building Google SERP Preview Sidebar UI Extension. It will display a preview of how your content would appear on Google Search Results.
You will also learn how to add custom configurations, like an API Key to connect to a 3rd party service provider, or a configuration to the widget instance like Background Color.
In order to transform it into a UI Extension, you must install Hygraph React SDK as a dependency on your project. You can do it running the following command on your Terminal:
yarn add @graphcms/uix-react-sdk
2. Adding React SDK
Now, let's import some SDK components and hooks from Hygraph SDK.
Start with importing the Wrapper component and useFormSidebarExtension hook from the library inside your React application.
You should add the following code at the top of the GoogleSerpPreview.js file.
At this point, you should see the "SDK connection error, check logs" message in your browser. The reason is that it's expected to be running from Hygraph application. So, you should just ignore this message for now.
Now, let's install and test your new Sidebar UI Extension on localhost by following these steps:
Once site URL is the same for the whole website, we'll add it to the extension declaration as a global configuration.
On your code editor, add the following code to extension declaration:
// src/extensions/GoogleSerpPreview.js
const declaration ={
extensionType:'formSidebar',
name:'Google SERP Preview',
description:'Preview your content on Google',
config:{
SITE_URL:{
type:'string',
displayName:'Site URL',
required:true,
},
},
};
Then, change SerpPreview component like so:
constSerpPreview=()=>{
const{ extension }=useFormSidebarExtension();
const siteUrl = extension.config.SITE_URL;
return(
<div
style={{
padding:'10px',
backgroundColor:'#fff',
}}
>
<div
style={{
fontSize:'12px',
marginBottom:'5px',
}}
>
{siteUrl}
</div>
<div
style={{
fontSize:'16px',
fontWeight:'bold',
color:'blue',
marginBottom:'5px',
}}
>
Title here
</div>
<div>This is the description</div>
</div>
);
};
Go back to your browser and open your project dashboard
Go to Project Settings > UI Extension
On Google Serp Preview, click on the three dots and then click on Edit
Click Refresh next to the Edit button
Now, you should see the new Site URL field. Once it's a required one, enter any URL and hit the Update button.
Finally, go to any content and the URL should appear in the widget.
#Step 5.2: Displaying content title and description
Now, you should map the content fields that you want to display in the widget as Title and Description. Therefore, we'll add sidebar instance configuration, which you allow you to set these fields for each model.
Go back to GoogleSerpPreview.js in your code editor and do the following steps:
Import useState and useEffect hooks at the top of the file:
import{ useState, useEffect }from'react';
Then, change SerpPreview component like the following code:
constSerpPreview=()=>{
const{
extension,
form:{ subscribeToFieldState },
}=useFormSidebarExtension();
const[title, setTitle]=useState('This is the title');
const[description, setDescription]=useState('This is the description');
sidebarConfig is the object that stores sidebar configuration data. By declaring that, you should see two fields on sidebar widget dialog, where you will be able to enter the field names for title and description, respectively.
form.subscribeToFieldState is a method from the Hygraph SDK to interact with form fields in the content editor. In this case, we'll update Google Serp Preview widget while user update information in the fields that stores Title and Description. You'll see that happening in a moment.
Once we've updated extension declaration again, we need to refresh UI Extension installation.
On Hygraph app, go to Project Settings > UI Extension
On Google Serp Preview, click on the three dots and then click on Edit
Click Refresh next to the Edit button
Finally, click on Update
Now, let's map Schema fields to the sidebar widget:
Go to Schema
Click on the model you've added the widget
Click in the pencil icon to edit widget
You should see 2 new fields: Title and Description. You just need to enter the appId of the fields you want to display as Title and Description, respectively. Then, click Update.
Finally, go to Content and click on any existing content to edit it or click on Create Item.
As you type in the Title or Description fields, you should see it being updated in realtime on Google Serp Preview widget!
To use your UI Extension in a live website or application, you should host it somewhere on the internet. For the sake of this tutorial, we will deploy it on Vercel. But you can use any hosting service.
Do the following steps:
Open your Terminal
Navigate into your project root directory and run npx vercel
cd google-serp-preview-uix
npx vercel
Follow the step-by-step guide on your Terminal
Once it's deployed, the extension URL will be automatically copied to your clipboard
Open your project dashboard on your browser
Go to Project Settings > UI Extension
On Hello UIX World, click on the three dots, then click on Edit
Click on Edit button next to the Extension URL field