嵌入式分析 SDK - 插件
嵌入式分析 SDK 仅在 Pro 和 Enterprise 计划(包括自托管和 Metabase Cloud)中可用。
Metabase 嵌入式分析 SDK 支持插件来定制组件的行为。这些插件可以全局使用,也可以按组件使用。
插件作用域
全局插件
要全局使用插件,请将插件添加到 MetabaseProvider 的 pluginsConfig prop 中
<MetabaseProvider
authConfig={authConfig}
theme={theme}
pluginsConfig={{
mapQuestionClickActions: () => [], // Add your custom actions here
}}
>
{children}
</MetabaseProvider>
组件插件
要按组件使用插件,请将插件作为 prop 传递给组件
<InteractiveQuestion
questionId={1}
plugins={{
mapQuestionClickActions: () => [],
}}
/>
请参阅特定组件的文档
全局插件
mapQuestionClickActions
插件 mapQuestionClickActions 允许您自定义用户点击仪表板或图表上的数据点时发生的操作。mapQuestionClickActions 可以全局使用,也可以在组件级别使用。
有关更多信息和示例,请参阅 mapQuestionClickActions 插件。
handleLink
要自定义用户点击嵌入式问题和仪表板中的链接时发生的操作,请使用全局插件 handleLink
const plugins = {
handleLink: (urlString: string) => {
const url = new URL(urlString, window.location.origin);
const isInternal = url.origin === window.location.origin;
if (isInternal) {
// Handle internal navigation (e.g., with your router)
console.log("Navigate to:", url.pathname + url.search + url.hash);
return { handled: true }; // prevent default navigation
}
return { handled: false }; // let the SDK do the default behavior
},
};
return (
<MetabaseProvider authConfig={authConfig} pluginsConfig={plugins}>
<InteractiveDashboard dashboardId={1} />
</MetabaseProvider>
);
插件 handleLink 只能在 全局 提供程序级别使用。
getNoDataIllustration 和 getNoObjectIllustration
默认情况下,当查询返回无结果时,Metabase 会显示一艘帆船的图片。要使用不同的图片,您可以使用 getNoDataIllustration 和 getNoObjectIllustration 插件,它们可以接受自定义的 base64 编码图片
const img_base64 = "..."; // base64-encoded image
const plugins = {
getNoDataIllustration: () => img_base64,
getNoObjectIllustration: () => img_base64,
};
return (
<MetabaseProvider authConfig={authConfig} pluginsConfig={plugins}>
<InteractiveDashboard dashboardId={1} />
</MetabaseProvider>
);
插件 getNoDataIllustration 和 getNoObjectIllustration 只能在 全局 提供程序级别使用。
延伸阅读
阅读其他版本的 Metabase 的文档。