Skip to content

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

Fix ChartTypeDropdown overflowing (#68455)

Sébastien862dc50c644f
diff --git a/.loki/reference/chrome_laptop_EmbeddingSDK_SdkQuestion_ChartTypeDropdownInner_Question_Chart_Type_Selector_List.png b/.loki/reference/chrome_laptop_EmbeddingSDK_SdkQuestion_ChartTypeDropdownInner_Question_Chart_Type_Selector_List.png
new file mode 100644
index 00000000000..04c2f97045c
Binary files /dev/null and b/.loki/reference/chrome_laptop_EmbeddingSDK_SdkQuestion_ChartTypeDropdownInner_Question_Chart_Type_Selector_List.png differ
diff --git a/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/ChartTypeSelectorList/ChartTypeDropdown.stories.tsx b/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/ChartTypeDropdown/ChartTypeDropdown.stories.tsx
similarity index 93%
rename from frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/ChartTypeSelectorList/ChartTypeDropdown.stories.tsx
rename to frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/ChartTypeDropdown/ChartTypeDropdown.stories.tsx
index 4fe6e8d1961..1dca0aeceda 100644
--- a/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/ChartTypeSelectorList/ChartTypeDropdown.stories.tsx
+++ b/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/ChartTypeDropdown/ChartTypeDropdown.stories.tsx
@@ -7,7 +7,7 @@ import { ChartTypeDropdown } from "./ChartTypeDropdown";
const QUESTION_ID = (window as any).QUESTION_ID || 12;
export default {
- title: "EmbeddingSDK/SdkQuestion/ChartTypeSelectorsList",
+ title: "EmbeddingSDK/SdkQuestion/ChartTypeDropdown",
component: ChartTypeDropdown,
parameters: {
layout: "fullscreen",
diff --git a/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/ChartTypeSelectorList/ChartTypeDropdown.tsx b/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/ChartTypeDropdown/ChartTypeDropdown.tsx
similarity index 72%
rename from frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/ChartTypeSelectorList/ChartTypeDropdown.tsx
rename to frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/ChartTypeDropdown/ChartTypeDropdown.tsx
index fa4db4afbc5..1626a4d4c49 100644
--- a/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/ChartTypeSelectorList/ChartTypeDropdown.tsx
+++ b/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/ChartTypeDropdown/ChartTypeDropdown.tsx
@@ -34,6 +34,40 @@ export const ChartTypeDropdown = ({ ...menuProps }: ChartTypeDropdownProps) => {
const { sensibleVisualizations, nonSensibleVisualizations } =
useSensibleVisualizations();
+ return (
+ <ChartTypeDropdownInner
+ selectedVisualization={selectedVisualization}
+ updateQuestionVisualization={updateQuestionVisualization}
+ sensibleVisualizations={sensibleVisualizations}
+ nonSensibleVisualizations={nonSensibleVisualizations}
+ {...menuProps}
+ />
+ );
+};
+
+interface ChartTypeDropdownInnerProps extends ChartTypeDropdownProps {
+ selectedVisualization: CardDisplayType;
+ updateQuestionVisualization: (display: CardDisplayType) => void;
+ sensibleVisualizations: CardDisplayType[];
+ nonSensibleVisualizations: CardDisplayType[];
+}
+
+/**
+ * Exported for testing purposes
+ * Renders a menu with a list of visualizations to choose from
+ *
+ * @internal
+ * @param props ChartTypeDropdownInnerProps
+ */
+export const ChartTypeDropdownInner = (props: ChartTypeDropdownInnerProps) => {
+ const {
+ selectedVisualization,
+ updateQuestionVisualization,
+ sensibleVisualizations,
+ nonSensibleVisualizations,
+ ...menuProps
+ } = props;
+
const getVisualizationItems = (
visualizationType: CardDisplayType,
): {
@@ -63,7 +97,7 @@ export const ChartTypeDropdown = ({ ...menuProps }: ChartTypeDropdownProps) => {
[nonSensibleVisualizations],
);
- const selectedElem = useMemo(
+ const selectedElement = useMemo(
() =>
getVisualizationItems(selectedVisualization) ??
sensibleItems[0] ??
@@ -76,9 +110,9 @@ export const ChartTypeDropdown = ({ ...menuProps }: ChartTypeDropdownProps) => {
<Menu.Target>
<ToolbarButton
data-testid="chart-type-selector-button"
- disabled={!selectedElem}
- label={selectedElem?.label}
- icon={selectedElem?.iconName}
+ disabled={!selectedElement}
+ label={selectedElement?.label}
+ icon={selectedElement?.iconName}
isHighlighted={false}
variant="default"
px={undefined}
@@ -87,7 +121,8 @@ export const ChartTypeDropdown = ({ ...menuProps }: ChartTypeDropdownProps) => {
className={ToolbarButtonS.PrimaryToolbarButton}
/>
</Menu.Target>
- <Menu.Dropdown h="30rem">
+ {/* Using overflow: "auto" because Menus have a default overflow: "visible" */}
+ <Menu.Dropdown h="30rem" style={{ overflow: "auto" }}>
{sensibleItems.map(({ iconName, label, value }, index) => (
<Menu.Item
key={`${value}/${index}`}
diff --git a/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/ChartTypeDropdown/ChartTypeDropdownInner.stories.tsx b/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/ChartTypeDropdown/ChartTypeDropdownInner.stories.tsx
new file mode 100644
index 00000000000..4477ff16ceb
--- /dev/null
+++ b/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/ChartTypeDropdown/ChartTypeDropdownInner.stories.tsx
@@ -0,0 +1,54 @@
+import { Box } from "metabase/ui";
+import registerVisualizations from "metabase/visualizations/register";
+
+import { ChartTypeDropdownInner } from "./ChartTypeDropdown";
+
+registerVisualizations();
+
+export default {
+ title: "EmbeddingSDK/SdkQuestion/ChartTypeDropdownInner",
+ component: ChartTypeDropdownInner,
+ parameters: {
+ layout: "fullscreen",
+ },
+};
+
+export const QuestionChartTypeSelectorList = {
+ render() {
+ return (
+ <>
+ <ChartTypeDropdownInner
+ defaultOpened
+ selectedVisualization="table"
+ updateQuestionVisualization={() => {}}
+ sensibleVisualizations={["table", "object"]}
+ nonSensibleVisualizations={[
+ "bar",
+ "line",
+ "pie",
+ "scalar",
+ "row",
+ "area",
+ "combo",
+ "pivot",
+ "smartscalar",
+ "gauge",
+ "progress",
+ "funnel",
+ "map",
+ "scatter",
+ "waterfall",
+ "sankey",
+ ]}
+ />
+ <Box
+ pos="absolute"
+ // the space between the popover and the target element
+ mt="8px"
+ w={300}
+ h={600}
+ />
+ </>
+ );
+ },
+};
diff --git a/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/ChartTypeSelectorList/index.ts b/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/ChartTypeDropdown/index.ts
similarity index 100%
rename from frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/ChartTypeSelectorList/index.ts
rename to frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/ChartTypeDropdown/index.ts
diff --git a/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/index.ts b/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/index.ts
index 7b7796a5a5c..2a73b5fc2b4 100644
--- a/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/index.ts
+++ b/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/index.ts
@@ -1,7 +1,7 @@
export * from "./BackButton";
export * from "./Breakout";
export * from "./ChartTypeSelector";
-export * from "./ChartTypeSelectorList";
+export * from "./ChartTypeDropdown";
export * from "./DownloadWidget";
export * from "./Filter";
export * from "./Editor";
diff --git a/frontend/src/embedding-sdk-bundle/components/private/SdkQuestionDefaultView/SdkQuestionDefaultView.tsx b/frontend/src/embedding-sdk-bundle/components/private/SdkQuestionDefaultView/SdkQuestionDefaultView.tsx
index d5be8f8dabe..9dc2018985f 100644
--- a/frontend/src/embedding-sdk-bundle/components/private/SdkQuestionDefaultView/SdkQuestionDefaultView.tsx
+++ b/frontend/src/embedding-sdk-bundle/components/private/SdkQuestionDefaultView/SdkQuestionDefaultView.tsx
@@ -36,7 +36,7 @@ import {
} from "../FlexibleSizeComponent";
import { BackButton } from "../SdkQuestion/components/BackButton/BackButton";
import { BreakoutDropdown } from "../SdkQuestion/components/Breakout/BreakoutDropdown";
-import { ChartTypeDropdown } from "../SdkQuestion/components/ChartTypeSelectorList";
+import { ChartTypeDropdown } from "../SdkQuestion/components/ChartTypeDropdown";
import { DownloadWidgetDropdown } from "../SdkQuestion/components/DownloadWidget";
import { Editor } from "../SdkQuestion/components/Editor";
import { EditorButton } from "../SdkQuestion/components/EditorButton/EditorButton";
diff --git a/loki.config.js b/loki.config.js
index ee2d9c1ed6d..3e7123716b9 100644
--- a/loki.config.js
+++ b/loki.config.js
@@ -17,6 +17,7 @@ module.exports = {
"^Components/Feedback/Alert",
"^Components/Table",
"^App/Palette",
+ "^EmbeddingSDK/SdkQuestion/ChartTypeDropdownInner",
].join("|"),
configurations: {
"chrome.laptop": {