Dashboard Panels
Panels are customizable components within Insights dashboards.
Panels are the building blocks of analytics dashboards, enabling rapid, no-code creation of data visualizations with data from a Directus project. Panels can also contain interactive elements, making them suitable for building custom internal applications within dashboards.
This extension type is loaded into the Directus Data Studio. They are are built with Vue 3, and can use the provided composables exported by the @directus/extensions-sdk
package. Extensions can be written in JavaScript or TypeScript.
Panel Entrypoint
The index.js
or index.ts
file exports an object that is read by Directus. It contains properties that control how a panel is displayed within menus, it’s minimum width and height on the dashboard grid, what configurable options will be available to users, and the actual Vue component that will be loaded.
Entrypoint Example
import { defineInterface } from '@directus/extensions-sdk'
import PanelComponent from './panel.vue';
export default defineInterface({
id: 'custom',
name: 'Custom',
icon: 'box',
description: 'This is my custom panel!',
component: PanelComponent,
minWidth: 12,
minHeight: 8,
options: [
{
field: 'text',
name: 'Text',
type: 'string',
meta: {
interface: 'input',
width: 'full',
},
},
],
});
Properties
Property | Type | Description |
---|---|---|
id | string | A unique identifier for this extension. |
name | string | The displayed name for this panel in the Data Studio. |
icon | string | An icon name from the Google Material Icons set. Supports filled and outlined variants. |
description | string | A description of this panel shown in the Data Studio. Maximum 80 characters. |
component | component | A reference to the Vue component rendered in the dashboard. |
minWidth | number | Smallest number of grid units in the dashboard. |
minHeight | number | Smallest number of grid units in the dashboard. |
options | array | component | |
preview | string | Inline SVG to display in panel selection drawer. |
The extension id must not conflict with other extensions, so consider prefixing with author name.
In your SVG, use available theme CSS variables such as
--theme--primary
and --theme--primary-subdued
to match your panel preview with the project theme.Panel Component
The panel component is a Vue component that will be rendered in the Data Studio within a dashboard. Data from the entrypoint are passed in as props.
Component Example
This example assumes there is an item in the entrypoint’s options
array with a field
value of text
.
<template>
<div class="text" :class="{ 'has-header': showHeader }">
{{ text }}
</div>
</template>
<script setup>
defineProps(['showHeader', 'text']);
</script>
<style scoped>
.text {
padding: 12px;
}
.text.has-header {
padding: 0 12px;
}
</style>
Props
The panel component will be passed all user configuration options from the entrypoint file. It will also receive the following props:
Prop | Type | Description |
---|---|---|
id | uuid | The UUID for this panel. This is for a specific instance of the panel and will not be the defined id in the entrypoint file. |
dashboard | uuid | The UUID for the dashboard containing the panel. |
showHeader | boolean | Whether the panel header visibility is enabled in the options. |
width | number | The current number of grid units wide the panel is. |
height | number | The current number of grid units high the panel is. |
now | date | The date object at the time of loading the dashboard. |
Using Directus Internals
To access internal systems like the API or the stores in app extensions, you can use the useApi()
and useStores()
composables exported by the @directus/extensions-sdk
package.
Directus UI components are globally registered, making them accessible throughout your extension without the need to import them.
Using External APIs
To avoid Cross Site Request Forgery (CSRF), app extensions cannot make requests to external servers by default. A common approach to achieve this is to create a bundle containing an endpoint that makes the external request, and an app extension that uses the now-internal endpoint to retrieve data.