Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

1.3 KB
Raw Blame
import {
  defineMetabaseAuthConfig,
  InteractiveQuestion,
  MetabaseProvider,
} from "@metabase/embedding-sdk-react";

const authConfig = defineMetabaseAuthConfig({
  metabaseInstanceUrl: "http://localhost:3000",
});

const Example = () => {
  return (
    // [<snippet example>]
    <MetabaseProvider
      authConfig={authConfig}
      pluginsConfig={{
        mapQuestionClickActions: (clickActions, clicked) => {
          if (clicked?.column?.display_name === "Last Name") {
            // This adds a custom action to the menu
            return [
              ...clickActions,
              {
                buttonType: "horizontal",
                name: "custom",
                title: "This is the Last Name column",
                onClick: () => alert("You clicked the Last Name column!"),
              },
            ];
          }

          if (clicked?.column?.display_name === "Plan") {
            // This performs an immediate action instead of opening the menu
            return {
              onClick: () => alert("You clicked the Plan column!"),
            };
          }
          // default behavior (open Metabase's default click menu)
          return clickActions;
        },
      }}
    >
      <InteractiveQuestion questionId={1} />
    </MetabaseProvider>
  );
  // [<endsnippet example>]
};