The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
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.pngnew file mode 100644index 00000000000..04c2f97045cBinary files /dev/null and b/.loki/reference/chrome_laptop_EmbeddingSDK_SdkQuestion_ChartTypeDropdownInner_Question_Chart_Type_Selector_List.png differdiff --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.tsxsimilarity index 93%rename from frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/ChartTypeSelectorList/ChartTypeDropdown.stories.tsxrename to frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/ChartTypeDropdown/ChartTypeDropdown.stories.tsxindex 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.tsxsimilarity index 72%rename from frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/ChartTypeSelectorList/ChartTypeDropdown.tsxrename to frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/ChartTypeDropdown/ChartTypeDropdown.tsxindex 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><ToolbarButtondata-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.Itemkey={`${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.tsxnew file mode 100644index 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.tssimilarity index 100%rename from frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/ChartTypeSelectorList/index.tsrename to frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/ChartTypeDropdown/index.tsdiff --git a/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/index.ts b/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/index.tsindex 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.tsxindex 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.jsindex 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": {