Skip to content
Snippets Groups Projects
Unverified Commit 5929e664 authored by Jeff Bruemmer's avatar Jeff Bruemmer Committed by GitHub
Browse files

docs - sdk updates (#49173)

parent d616baf6
No related branches found
No related tags found
No related merge requests found
...@@ -32,7 +32,7 @@ if (auth.status === "success") { ...@@ -32,7 +32,7 @@ if (auth.status === "success") {
You can customize how the SDK fetches the refresh token by specifying the `fetchRefreshToken` function in the `config` prop: You can customize how the SDK fetches the refresh token by specifying the `fetchRefreshToken` function in the `config` prop:
```typescript jsx ```typescript
/** /**
* This is the default implementation used in the SDK. * This is the default implementation used in the SDK.
* You can customize this function to fit your needs, such as adding headers or excluding cookies. * You can customize this function to fit your needs, such as adding headers or excluding cookies.
...@@ -59,7 +59,7 @@ const config = { fetchRequestToken }; ...@@ -59,7 +59,7 @@ const config = { fetchRequestToken };
In case you need to reload a Metabase component, for example, your users modify your application data and that data is used to render a question in Metabase. If you embed this question and want to force Metabase to reload the question to show the latest data, you can do so by using the `key` prop to force a component to reload. In case you need to reload a Metabase component, for example, your users modify your application data and that data is used to render a question in Metabase. If you embed this question and want to force Metabase to reload the question to show the latest data, you can do so by using the `key` prop to force a component to reload.
```typescript jsx ```typescript
// Inside your application component // Inside your application component
const [data, setData] = useState({}); const [data, setData] = useState({});
// This is used to force reloading Metabase components // This is used to force reloading Metabase components
......
...@@ -12,17 +12,18 @@ You can embed Metabase's collection browser so that people can explore items in ...@@ -12,17 +12,18 @@ You can embed Metabase's collection browser so that people can explore items in
## `CollectionBrowser` props ## `CollectionBrowser` props
| Prop | Type | Description | | Prop | Type | Description |
| ------------------ | ---------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ------------------ | -------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| collectionId | `number` | The numerical ID of the collection. You can find this ID in the URL when accessing a collection in your Metabase instance. For example, the collection ID in `http://localhost:3000/collection/1-my-collection` would be `1`. If no ID is provided, the collection browser will start at the root `Our analytics` collection, which is ID = 0. | | collectionId | `number` | The numerical ID of the collection. You can find this ID in the URL when accessing a collection in your Metabase instance. For example, the collection ID in `http://localhost:3000/collection/1-my-collection` would be `1`. If no ID is provided, the collection browser will start at the root `Our analytics` collection, which is ID = 0. |
| onClick | `(item: CollectionItem) => void` | An optional click handler that emits the clicked entity. | | onClick | `(item: CollectionItem) => void` | An optional click handler that emits the clicked entity. |
| pageSize | `number` | The number of items to display per page. The default is 25. | | pageSize | `number` | The number of items to display per page. The default is 25. |
| visibleEntityTypes | `("question" \| "model" \| "dashboard" \| "collection")[]` | The types of entities that should be visible. If not provided, all entities will be shown. | | visibleEntityTypes | `["question", "model", "dashboard", "collection"]` | The types of entities that should be visible. If not provided, all entities will be shown. |
## Example embedding code with `CollectionBrowser` ## Example embedding code with `CollectionBrowser`
```tsx ```tsx
import React from "react"; import React from "react";
import { CollectionBrowser } from "@metabase/embedding-sdk-react" import { CollectionBrowser } from "@metabase/embedding-sdk-react";
export default function App() { export default function App() {
const collectionId = 123; // This is the collection ID you want to browse const collectionId = 123; // This is the collection ID you want to browse
......
...@@ -37,7 +37,7 @@ _\* Not available for `StaticDashboard`._ ...@@ -37,7 +37,7 @@ _\* Not available for `StaticDashboard`._
## Example embedded dashboard with `InteractiveDashboard` component ## Example embedded dashboard with `InteractiveDashboard` component
```typescript jsx ```typescript
import React from "react"; import React from "react";
import {MetabaseProvider, InteractiveDashboard} from "@metabase/embedding-sdk-react"; import {MetabaseProvider, InteractiveDashboard} from "@metabase/embedding-sdk-react";
...@@ -72,7 +72,7 @@ This plugin allows you to add, remove, and modify the custom actions on the over ...@@ -72,7 +72,7 @@ This plugin allows you to add, remove, and modify the custom actions on the over
The plugin's default configuration looks like this: The plugin's default configuration looks like this:
```typescript jsx ```typescript
const plugins = { const plugins = {
dashboard: { dashboard: {
dashcardMenu: { dashcardMenu: {
...@@ -86,7 +86,7 @@ const plugins = { ...@@ -86,7 +86,7 @@ const plugins = {
`dashcardMenu`: can be used in the InteractiveDashboard like this: `dashcardMenu`: can be used in the InteractiveDashboard like this:
```typescript jsx ```typescript
{% raw %} {% raw %}
<InteractiveDashboard <InteractiveDashboard
questionId={1} questionId={1}
...@@ -103,7 +103,7 @@ const plugins = { ...@@ -103,7 +103,7 @@ const plugins = {
To remove the download button from the dashcard menu, set `withDownloads` to `false`. To remove the edit link from the dashcard menu, set `withEditLink` to `false`. To remove the download button from the dashcard menu, set `withDownloads` to `false`. To remove the edit link from the dashcard menu, set `withEditLink` to `false`.
```typescript jsx ```typescript
const plugins = { const plugins = {
dashboard: { dashboard: {
dashcardMenu: { dashcardMenu: {
...@@ -119,7 +119,7 @@ const plugins = { ...@@ -119,7 +119,7 @@ const plugins = {
You can add custom actions to the dashcard menu by adding an object to the `customItems` array. Each element can either be an object or a function that takes in the dashcard's question, and outputs a list of custom items in the form of: You can add custom actions to the dashcard menu by adding an object to the `customItems` array. Each element can either be an object or a function that takes in the dashcard's question, and outputs a list of custom items in the form of:
```typescript jsx ```typescript
{ {
iconName: string; iconName: string;
label: string; label: string;
...@@ -130,7 +130,7 @@ You can add custom actions to the dashcard menu by adding an object to the `cust ...@@ -130,7 +130,7 @@ You can add custom actions to the dashcard menu by adding an object to the `cust
Here's an example: Here's an example:
```typescript jsx ```typescript
const plugins: SdkPluginsConfig = { const plugins: SdkPluginsConfig = {
dashboard: { dashboard: {
dashcardMenu: { dashcardMenu: {
...@@ -161,7 +161,7 @@ const plugins: SdkPluginsConfig = { ...@@ -161,7 +161,7 @@ const plugins: SdkPluginsConfig = {
If you want to replace the existing menu with your own component, you can do so by providing a function that returns a React component. This function also can receive the question as an argument. If you want to replace the existing menu with your own component, you can do so by providing a function that returns a React component. This function also can receive the question as an argument.
```typescript jsx ```typescript
const plugins: SdkPluginsConfig = { const plugins: SdkPluginsConfig = {
dashboard: { dashboard: {
dashcardMenu: ({ question }) => ( dashcardMenu: ({ question }) => (
...@@ -177,7 +177,7 @@ Creating a dashboard could be done with `useCreateDashboardApi` hook or `CreateD ...@@ -177,7 +177,7 @@ Creating a dashboard could be done with `useCreateDashboardApi` hook or `CreateD
### Hook ### Hook
```typescript jsx ```typescript
const { createDashboard } = useCreateDashboardApi(); const { createDashboard } = useCreateDashboardApi();
const handleDashboardCreate = async () => { const handleDashboardCreate = async () => {
...@@ -199,7 +199,7 @@ Props: ...@@ -199,7 +199,7 @@ Props:
### Component ### Component
```typescript jsx ```typescript
const [dashboard, setDashboard] = useState<Dashboard | null>(null); const [dashboard, setDashboard] = useState<Dashboard | null>(null);
if (dashboard) { if (dashboard) {
......
...@@ -18,16 +18,16 @@ To give you and idea of what's possible with the SDK, we've put together example ...@@ -18,16 +18,16 @@ To give you and idea of what's possible with the SDK, we've put together example
![Pug and play example app built with embedding SDK](../images/pug-and-play.png) ![Pug and play example app built with embedding SDK](../images/pug-and-play.png)
# Embedding SDK prerequisites # Embedded analytics SDK prerequisites
- React application. The SDK is tested to work with React 18 or higher, though it may work with earlier versions. - React application. The SDK is tested to work with React 18 or higher, though it may work with earlier versions.
- [Metabase Pro or Enterprise subscription or free trial](https://www.metabase.com/pricing/). - [Metabase Pro or Enterprise subscription or free trial](https://www.metabase.com/pricing/).
- Metabase version 1.50 or higher. - Metabase version 1.50 or higher.
- [Node.js 18.x LTS](https://nodejs.org/en) or higher. - [Node.js 18.x LTS](https://nodejs.org/en) or higher.
## Embedding SDK on NPM ## Embedded analytics SDK on NPM
Check out the [Metabase embedding SDK on NPM: [metaba.se/sdk](https://metaba.se/sdk). Check out the Metabase Embedded analytics SDK on NPM: [metaba.se/sdk](https://metaba.se/sdk).
## Installation ## Installation
......
...@@ -14,7 +14,7 @@ The Metabase Embedding SDK supports plugins to customize the behavior of compone ...@@ -14,7 +14,7 @@ The Metabase Embedding SDK supports plugins to customize the behavior of compone
To use a plugin globally, add the plugin to the `MetabaseProvider`'s `pluginsConfig` prop: To use a plugin globally, add the plugin to the `MetabaseProvider`'s `pluginsConfig` prop:
```typescript jsx ```typescript
{% raw %} {% raw %}
<MetabaseProvider <MetabaseProvider
config={config} config={config}
...@@ -32,7 +32,7 @@ To use a plugin globally, add the plugin to the `MetabaseProvider`'s `pluginsCon ...@@ -32,7 +32,7 @@ To use a plugin globally, add the plugin to the `MetabaseProvider`'s `pluginsCon
To use a plugin on a per-component basis, pass the plugin as a prop to the component: To use a plugin on a per-component basis, pass the plugin as a prop to the component:
```typescript jsx ```typescript
{% raw %} {% raw %}
<InteractiveQuestion <InteractiveQuestion
questionId={1} questionId={1}
......
...@@ -21,7 +21,7 @@ You can embed a static question using the `StaticQuestion` component. ...@@ -21,7 +21,7 @@ You can embed a static question using the `StaticQuestion` component.
The component has a default height, which can be customized by using the `height` prop. To inherit the height from the parent container, you can pass `100%` to the height prop. The component has a default height, which can be customized by using the `height` prop. To inherit the height from the parent container, you can pass `100%` to the height prop.
```typescript jsx ```typescript
import React from "react"; import React from "react";
import {MetabaseProvider, StaticQuestion} from "@metabase/embedding-sdk-react"; import {MetabaseProvider, StaticQuestion} from "@metabase/embedding-sdk-react";
...@@ -50,7 +50,7 @@ You can pass parameter values to questions defined with SQL via `parameterValues ...@@ -50,7 +50,7 @@ You can pass parameter values to questions defined with SQL via `parameterValues
You can embed an interactive question using the `InteractiveQuestion` component. You can embed an interactive question using the `InteractiveQuestion` component.
```typescript jsx ```typescript
import React from "react"; import React from "react";
import {MetabaseProvider, InteractiveQuestion} from "@metabase/embedding-sdk-react"; import {MetabaseProvider, InteractiveQuestion} from "@metabase/embedding-sdk-react";
...@@ -89,13 +89,13 @@ By default, the Embedded Analytics SDK provides a default layout for interactive ...@@ -89,13 +89,13 @@ By default, the Embedded Analytics SDK provides a default layout for interactive
Here's an example of using the `InteractiveQuestion` component with its default layout: Here's an example of using the `InteractiveQuestion` component with its default layout:
```typescript jsx ```typescript
<InteractiveQuestion questionId={95} /> <InteractiveQuestion questionId={95} />
``` ```
To customize the layout, use namespaced components within the `InteractiveQuestion` component. For example: To customize the layout, use namespaced components within the `InteractiveQuestion` component. For example:
```typescript jsx ```typescript
{% raw %} {% raw %}
<InteractiveQuestion questionId={95}> <InteractiveQuestion questionId={95}>
<div <div
...@@ -160,7 +160,7 @@ This plugin allows you to add custom actions to ...@@ -160,7 +160,7 @@ This plugin allows you to add custom actions to
the click-through menu of an interactive question. You can add and the click-through menu of an interactive question. You can add and
customize the appearance and behavior of the custom actions. customize the appearance and behavior of the custom actions.
```typescript jsx ```typescript
// You can provide a custom action with your own `onClick` logic. // You can provide a custom action with your own `onClick` logic.
const createCustomAction = clicked => ({ const createCustomAction = clicked => ({
buttonType: "horizontal", buttonType: "horizontal",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment