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
Push shared files down from feature modules (#71137)
Fraserb8c90cdfbe75
diff --git a/enterprise/frontend/src/metabase-enterprise/caching/constants.ts b/enterprise/frontend/src/metabase-enterprise/caching/constants.tsindex a6627ad68ce..210f4a1045b 100644--- a/enterprise/frontend/src/metabase-enterprise/caching/constants.ts+++ b/enterprise/frontend/src/metabase-enterprise/caching/constants.ts@@ -9,7 +9,7 @@ import {PerformanceTabId,type StrategyData,} from "metabase/admin/performance/types";-import { defaultCron } from "metabase/admin/performance/utils";+import { defaultCron } from "metabase/common/components/Schedule/cron";import { CacheDurationUnit } from "metabase-types/api";import type { AdminPath } from "metabase-types/store";diff --git a/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/DownloadWidget/DownloadWidget.tsx b/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/DownloadWidget/DownloadWidget.tsxindex 3574a71bd17..f4625cc79e2 100644--- a/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/DownloadWidget/DownloadWidget.tsx+++ b/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/components/DownloadWidget/DownloadWidget.tsx@@ -1,11 +1,11 @@import { useMemo } from "react";-import { useEmbeddingEntityContext } from "metabase/embedding/context";-import { QuestionDownloadWidget } from "metabase/query_builder/components/QuestionDownloadWidget";import {+ QuestionDownloadWidget,type UseDownloadDataParams,useDownloadData,-} from "metabase/query_builder/components/QuestionDownloadWidget/use-download-data";+} from "metabase/common/components/QuestionDownloadWidget";+import { useEmbeddingEntityContext } from "metabase/embedding/context";import type { StackProps } from "metabase/ui";import { getComputedSettingsForSeries } from "metabase/visualizations/lib/settings/visualization";diff --git a/frontend/src/embedding-sdk-bundle/components/public/dashboard/InteractiveDashboard/InteractiveDashboard.tsx b/frontend/src/embedding-sdk-bundle/components/public/dashboard/InteractiveDashboard/InteractiveDashboard.tsxindex 4d5f8e48a42..92405d0bd64 100644--- a/frontend/src/embedding-sdk-bundle/components/public/dashboard/InteractiveDashboard/InteractiveDashboard.tsx+++ b/frontend/src/embedding-sdk-bundle/components/public/dashboard/InteractiveDashboard/InteractiveDashboard.tsx@@ -8,8 +8,8 @@ import { getPlugins } from "embedding-sdk-bundle/store/selectors";import type { MetabasePluginsConfig } from "embedding-sdk-bundle/types/plugins";import { PublicOrEmbeddedDashCardMenu } from "metabase/dashboard/components/DashCard/PublicOrEmbeddedDashCardMenu";import { DASHBOARD_ACTION } from "metabase/dashboard/components/DashboardHeader/DashboardHeaderButtonRow/dashboard-action-keys";-import { isQuestionCard } from "metabase/dashboard/utils";import type { MetabasePluginsConfig as InternalMetabasePluginsConfig } from "metabase/embedding-sdk/types/plugins";+import { isQuestionCard } from "metabase/lib/dashboard";import { getEmbeddingMode } from "metabase/visualizations/click-actions/lib/modes";import { createEmbeddingSdkMode } from "metabase/visualizations/click-actions/modes/EmbeddingSdkMode";import type { ClickActionModeGetter } from "metabase/visualizations/types";diff --git a/frontend/src/embedding-sdk-bundle/components/public/dashboard/StaticDashboard/StaticDashboard.tsx b/frontend/src/embedding-sdk-bundle/components/public/dashboard/StaticDashboard/StaticDashboard.tsxindex aa6f10bf141..46c70da0eba 100644--- a/frontend/src/embedding-sdk-bundle/components/public/dashboard/StaticDashboard/StaticDashboard.tsx+++ b/frontend/src/embedding-sdk-bundle/components/public/dashboard/StaticDashboard/StaticDashboard.tsx@@ -3,7 +3,7 @@ import { useNormalizeGuestEmbedQuestionOrDashboardComponentProps } from "embeddiimport type { SdkDashboardEntityPublicProps } from "embedding-sdk-bundle/types/dashboard";import { PublicOrEmbeddedDashCardMenu } from "metabase/dashboard/components/DashCard/PublicOrEmbeddedDashCardMenu";import { DASHBOARD_ACTION } from "metabase/dashboard/components/DashboardHeader/DashboardHeaderButtonRow/dashboard-action-keys";-import { isQuestionCard } from "metabase/dashboard/utils";+import { isQuestionCard } from "metabase/lib/dashboard";import { getEmbeddingMode } from "metabase/visualizations/click-actions/lib/modes";import { EmbeddingSdkStaticMode } from "metabase/visualizations/click-actions/modes/EmbeddingSdkStaticMode";import type { ClickActionModeGetter } from "metabase/visualizations/types";diff --git a/frontend/src/metabase/actions/components/ActionViz/ActionVizForm.tsx b/frontend/src/metabase/actions/components/ActionViz/ActionVizForm.tsxindex d1b021d67da..89b347439f3 100644--- a/frontend/src/metabase/actions/components/ActionViz/ActionVizForm.tsx+++ b/frontend/src/metabase/actions/components/ActionViz/ActionVizForm.tsx@@ -8,7 +8,7 @@ import ActionParametersInputForm, {import { useActionInitialValues } from "metabase/actions/hooks/use-action-initial-values";import { getFormTitle, isImplicitUpdateAction } from "metabase/actions/utils";import { Modal } from "metabase/common/components/Modal";-import { getDashboardType } from "metabase/dashboard/utils";+import { getDashboardType } from "metabase/lib/dashboard";import { ActionsApi, PublicApi } from "metabase/services";import type {ActionDashboardCard,diff --git a/frontend/src/metabase/admin/performance/components/StrategyForm.tsx b/frontend/src/metabase/admin/performance/components/StrategyForm.tsxindex 71835161e4e..e7ca42d8460 100644--- a/frontend/src/metabase/admin/performance/components/StrategyForm.tsx+++ b/frontend/src/metabase/admin/performance/components/StrategyForm.tsx@@ -7,6 +7,7 @@ import _ from "underscore";import { LoadingAndErrorWrapper } from "metabase/common/components/LoadingAndErrorWrapper";import { Schedule } from "metabase/common/components/Schedule/Schedule";+import { cronToScheduleSettings } from "metabase/common/components/Schedule/cron";import type { FormTextInputProps } from "metabase/forms";import {Form,@@ -44,11 +45,7 @@ import { strategyValidationSchema } from "../constants/complex";import { defaultCronSchedule, rootId } from "../constants/simple";import { useIsFormPending } from "../hooks/useIsFormPending";import { isModelWithClearableCache } from "../types";-import {- cronToScheduleSettings,- getDefaultValueForField,- getLabelString,-} from "../utils";+import { getDefaultValueForField, getLabelString } from "../utils";import Styles from "./PerformanceApp.module.css";import {diff --git a/frontend/src/metabase/admin/performance/utils.tsx b/frontend/src/metabase/admin/performance/utils.tsxindex b0a43ed0a8c..60f56d4f7bf 100644--- a/frontend/src/metabase/admin/performance/utils.tsx+++ b/frontend/src/metabase/admin/performance/utils.tsx@@ -1,12 +1,9 @@import { match } from "ts-pattern";-import { c, t } from "ttag";-import { memoize } from "underscore";+import { c } from "ttag";import type { SchemaObjectDescription } from "yup/lib/schema";-import {- Cron,- getScheduleStrings,-} from "metabase/common/components/Schedule/strings";+import { cronToScheduleSettings } from "metabase/common/components/Schedule/cron";+import { getScheduleStrings } from "metabase/common/components/Schedule/strings";import { isNullOrUndefined } from "metabase/lib/types";import { PLUGIN_CACHING } from "metabase/plugins";import type {@@ -15,199 +12,11 @@ import type {CacheStrategy,CacheStrategyType,CacheableModel,- ScheduleDayType,- ScheduleFrameType,- ScheduleSettings,- ScheduleType,} from "metabase-types/api";import { defaultMinDurationMs, rootId } from "./constants/simple";import type { PerformanceTabId, StrategyData, StrategyLabel } from "./types";-const AM = 0;-const PM = 1;--const everyToCronSyntax = (every: number | string) =>- `${Cron.EveryPrefix}${every}`;-export const isRepeatingEvery = (every: string) =>- every.startsWith(Cron.EveryPrefix);-export const cronUnitToNumber = (unit: string) =>- parseInt(unit.replace(Cron.EveryPrefix, ""));--const dayToCron = (day: ScheduleSettings["schedule_day"]) => {- const { weekdays } = getScheduleStrings();- const index = weekdays.findIndex((o) => o.value === day);- if (index === -1) {- throw new Error(`Invalid day: ${day}`);- }- return index + 1;-};--const frameToCronMap = { first: "1", last: "L", mid: "15" };-const frameToCron = (frame: ScheduleFrameType) => frameToCronMap[frame];--const frameFromCronMap: Record<string, ScheduleFrameType> = {- "15": "mid",- "1": "first",- L: "last",-};-const frameFromCron = (frameInCronFormat: string) =>- frameFromCronMap[frameInCronFormat];--export const scheduleSettingsToCron = (settings: ScheduleSettings): string => {- const second = "0";- const year = "*";- let minute = settings.schedule_minute?.toString() ?? Cron.AllValues;- const hour = settings.schedule_hour?.toString() ?? Cron.AllValues;- let weekday = settings.schedule_day- ? dayToCron(settings.schedule_day).toString()- : Cron.NoSpecificValue;- const month = Cron.AllValues;- let dayOfMonth: string = settings.schedule_day- ? Cron.NoSpecificValue- : Cron.AllValues;- if (settings.schedule_type === "every_n_minutes") {- minute = everyToCronSyntax(minute);- } else if (settings.schedule_type === "monthly" && settings.schedule_frame) {- // There are two kinds of monthly schedule:- // - weekday-based (e.g. "on the first Monday of the month")- // - date-based (e.g. "on the 15th of the month")- if (settings.schedule_day) {- // Handle weekday-based monthly schedule- const frameInCronFormat = frameToCron(settings.schedule_frame).replace(- /^1$/,- "#1",- );- const dayInCronFormat = dayToCron(settings.schedule_day);- weekday = `${dayInCronFormat}${frameInCronFormat}`;- } else {- // Handle date-based monthly schedule- dayOfMonth = frameToCron(settings.schedule_frame);- }- }- const cronExpression = [- second,- minute,- hour,- dayOfMonth,- month,- weekday,- year,- ].join(" ");- return cronExpression;-};--/** Returns null if we can't convert the cron expression to a ScheduleSettings object */-export const cronToScheduleSettings_unmemoized = (- cron: string | null | undefined,- isCustomSchedule: boolean = false,-): ScheduleSettings | null => {- if (!cron) {- return defaultSchedule;- }-- const { weekdays } = getScheduleStrings();-- // The Quartz cron library used in the backend distinguishes between 'no specific value' and 'all values',- // but for simplicity we can treat them as the same here- cron = cron.replace(- new RegExp(Cron.NoSpecificValue_Escaped, "g"),- Cron.AllValues,- );-- const [_second, minute, hour, dayOfMonth, month, weekday] = cron.split(" ");-- if (month !== Cron.AllValues && !isCustomSchedule) {- return null;- }- let schedule_type: ScheduleType | undefined;- if (isCustomSchedule) {- schedule_type = "cron";- } else if (dayOfMonth === Cron.AllValues) {- if (weekday === Cron.AllValues) {- if (hour === Cron.AllValues) {- schedule_type = isRepeatingEvery(minute) ? "every_n_minutes" : "hourly";- } else {- schedule_type = "daily";- }- } else {- // If the weekday part of the cron expression is something like '1#1' (first Monday),- // or '2L' (last Tuesday), then the frequency is monthly- const oneWeekPerMonth = weekday.match(/[#L]/);- schedule_type = oneWeekPerMonth ? "monthly" : "weekly";- }- } else {- schedule_type = "monthly";- }- let schedule_frame: ScheduleFrameType | undefined;- let schedule_day: ScheduleDayType | undefined;- if (schedule_type === "monthly") {- if (weekday === Cron.AllValues) {- schedule_frame = frameFromCron(dayOfMonth);- } else {- const dayStr = weekday.match(/^\d+/)?.[0];- if (!dayStr) {- throw new Error(- t`The cron expression contains an invalid weekday: ${weekday}`,- );- }- const day = parseInt(dayStr);- schedule_day = weekdays[day - 1]?.value as ScheduleDayType;- if (dayOfMonth === Cron.AllValues) {- // Match the part after the '#' in a string like '6#1' or the letter in '6L'- const frameInCronFormat = weekday- .match(/^\d+(\D.*)$/)?.[1]- .replace(/^#/, "");- if (!frameInCronFormat) {- throw new Error(- t`The cron expression contains an invalid weekday: ${weekday}`,- );- }- schedule_frame = frameFromCron(frameInCronFormat);- } else {- schedule_frame = frameFromCron(dayOfMonth);- }- }- } else {- if (weekday !== Cron.AllValues) {- schedule_day = weekdays[parseInt(weekday) - 1]?.value as ScheduleDayType;- }- }-- const scheduleMinute =- minute === Cron.AllValues ? null : cronUnitToNumber(minute);- const scheduleHour = hour === Cron.AllValues ? null : cronUnitToNumber(hour);- return {- schedule_type,- schedule_minute: scheduleMinute,- schedule_hour: scheduleHour,- schedule_day,- schedule_frame,- };-};-export const cronToScheduleSettings = memoize(- cronToScheduleSettings_unmemoized,- (cron, isCustomSchedule) => `${cron}_${isCustomSchedule}`,-);--const defaultSchedule: ScheduleSettings = {- schedule_type: "hourly",- schedule_minute: 0,-};-export const defaultCron = scheduleSettingsToCron(defaultSchedule);--const isValidAmPm = (amPm: number) => amPm === AM || amPm === PM;--export const hourToTwelveHourFormat = (hour: number) => hour % 12 || 12;--export const hourTo24HourFormat = (hour: number, amPm: number): number => {- if (!isValidAmPm(amPm)) {- amPm = AM;- }- const hour24 = amPm === PM ? (hour % 12) + 12 : hour % 12;- return hour24 === 24 ? 0 : hour24;-};-type ErrorWithMessage = { data: { message: string } };export const isErrorWithMessage = (error: unknown): error is ErrorWithMessage =>typeof error === "object" &&diff --git a/frontend/src/metabase/admin/performance/utils.unit.spec.ts b/frontend/src/metabase/admin/performance/utils.unit.spec.tsindex 3696aedae84..11e8a2e3355 100644--- a/frontend/src/metabase/admin/performance/utils.unit.spec.ts+++ b/frontend/src/metabase/admin/performance/utils.unit.spec.ts@@ -1,324 +1,6 @@-import type {- AdaptiveStrategy,- InheritStrategy,- ScheduleSettings,-} from "metabase-types/api";+import type { AdaptiveStrategy, InheritStrategy } from "metabase-types/api";-import {- cronToScheduleSettings,- getShortStrategyLabel,- hourTo24HourFormat,- hourToTwelveHourFormat,- scheduleSettingsToCron,-} from "./utils";--describe("scheduleSettingsToCron", () => {- it("converts every_n_minutes schedule to cron", () => {- const settings: ScheduleSettings = {- schedule_type: "every_n_minutes",- schedule_minute: 10,- schedule_hour: null,- };- const cron = scheduleSettingsToCron(settings);- expect(cron).toEqual("0 0/10 * * * ? *");- });-- it("converts hourly schedule to cron", () => {- const settings: ScheduleSettings = {- schedule_type: "hourly",- schedule_minute: 1,- schedule_hour: 1,- };- const cron = scheduleSettingsToCron(settings);- expect(cron).toEqual("0 1 1 * * ? *");- });-- it("converts daily schedule to cron", () => {- const settings: ScheduleSettings = {- schedule_type: "daily",- schedule_minute: 30,- schedule_hour: 14,- };- const cron = scheduleSettingsToCron(settings);- expect(cron).toEqual("0 30 14 * * ? *");- });-- it("converts weekly schedule to cron", () => {- const settings: ScheduleSettings = {- schedule_type: "weekly",- schedule_day: "mon",- schedule_minute: 0,- schedule_hour: 12,- };- const cron = scheduleSettingsToCron(settings);- expect(cron).toEqual("0 0 12 ? * 2 *");- });-- it("converts 'first Wednesday of the month at 9:15am' to cron", () => {- const settings: ScheduleSettings = {- schedule_type: "monthly",- schedule_day: "wed",- schedule_frame: "first",- schedule_minute: 15,- schedule_hour: 9,- };- const cron = scheduleSettingsToCron(settings);- expect(cron).toEqual("0 15 9 ? * 4#1 *");- });-- it("converts 'last calendar day of the month' to cron", () => {- const settings: ScheduleSettings = {- schedule_type: "monthly",- schedule_frame: "last",- schedule_minute: 45,- schedule_hour: 16,- };- const cron = scheduleSettingsToCron(settings);- expect(cron).toEqual("0 45 16 L * ? *");- });-- it("converts 'monthly on the 15th' to cron", () => {- const settings: ScheduleSettings = {- schedule_type: "monthly",- schedule_frame: "mid",- schedule_minute: 5,- schedule_hour: 23,- };- const cron = scheduleSettingsToCron(settings);- expect(cron).toEqual("0 5 23 15 * ? *");- });-- it("missing minute and hour should default to wildcard", () => {- const settings: ScheduleSettings = {- schedule_type: "daily",- };- const cron = scheduleSettingsToCron(settings);- expect(cron).toEqual("0 * * * * ? *");- });-});--describe("cronToScheduleSettings", () => {- it("returns default schedule when input is null or undefined", () => {- const defaultSchedule = {- schedule_type: "hourly",- schedule_minute: 0,- };- expect(cronToScheduleSettings(null)).toEqual(defaultSchedule);- expect(cronToScheduleSettings(undefined)).toEqual(defaultSchedule);- });-- it("returns null when month is specified in cron", () => {- const cron = "0 15 10 15 1 ?";- expect(cronToScheduleSettings(cron)).toBeNull();- });-- describe("schedule type determination", () => {- it('sets schedule type to "every_n_minutes" when minute is "0/15"', () => {- const cron = `0 0/15 * * * ?`;- expect(cronToScheduleSettings(cron)?.schedule_type).toBe(- "every_n_minutes",- );- });-- it('sets schedule type to "hourly" when hour is "*" and both dayOfMonth and dayOfWeek are "*"', () => {- const cron = "0 30 * * * *";- expect(cronToScheduleSettings(cron)?.schedule_type).toBe("hourly");- });-- it('sets schedule type to "daily" when dayOfMonth and dayOfWeek are "*", and hour is specified', () => {- const cron = "0 30 8 * * *";- expect(cronToScheduleSettings(cron)?.schedule_type).toBe("daily");- });-- it('sets schedule type to "weekly" when dayOfWeek is specified', () => {- const cron = "0 30 8 ? * 1";- expect(cronToScheduleSettings(cron)?.schedule_type).toBe("weekly");- });-- it('sets schedule type to "monthly" when dayOfMonth is specific', () => {- const cron = "0 30 8 15 * ?";- expect(cronToScheduleSettings(cron)?.schedule_type).toBe("monthly");- });-- it('sets schedule type to "cron" when isCustomSchedule is true', () => {- const cron = "0 30 8 15 * ?";- expect(cronToScheduleSettings(cron, true)?.schedule_type).toBe("cron");- });- });-- describe("monthly schedule determination", () => {- it('sets schedule frame to "mid" when dayOfMonth is "15"', () => {- const cron = "0 30 8 15 * ?";- expect(cronToScheduleSettings(cron)?.schedule_frame).toBe("mid");- });-- it('sets schedule frame to "first" when dayOfMonth is "1"', () => {- const cron = "0 30 8 1 * ?";- expect(cronToScheduleSettings(cron)?.schedule_frame).toBe("first");- });-- it('sets schedule frame to "last" when dayOfMonth is "L"', () => {- const cron = "0 30 8 L * ?";- expect(cronToScheduleSettings(cron)?.schedule_frame).toBe("last");- });- });-- describe("weekly schedule determination", () => {- it('sets schedule_day to "sun" when dayOfWeek is 1', () => {- const cron = "0 30 8 ? * 1";- expect(cronToScheduleSettings(cron)?.schedule_day).toBe("sun");- });-- it('sets schedule_day to "mon" when dayOfWeek is 2', () => {- const cron = "0 30 8 ? * 2";- expect(cronToScheduleSettings(cron)?.schedule_day).toBe("mon");- });-- it('sets schedule_day to "tue" when dayOfWeek is 3', () => {- const cron = "0 30 8 ? * 3";- expect(cronToScheduleSettings(cron)?.schedule_day).toBe("tue");- });-- it('sets schedule_day to "wed" when dayOfWeek is 4', () => {- const cron = "0 30 8 ? * 4";- expect(cronToScheduleSettings(cron)?.schedule_day).toBe("wed");- });-- it('sets schedule_day to "thu" when dayOfWeek is 5', () => {- const cron = "0 30 8 ? * 5";- expect(cronToScheduleSettings(cron)?.schedule_day).toBe("thu");- });-- it('sets schedule_day to "fri" when dayOfWeek is 6', () => {- const cron = "0 30 8 ? * 6";- expect(cronToScheduleSettings(cron)?.schedule_day).toBe("fri");- });-- it('sets schedule_day to "sat" when dayOfWeek is 7', () => {- const cron = "0 30 8 ? * 7";- expect(cronToScheduleSettings(cron)?.schedule_day).toBe("sat");- });-- it('sets schedule_day to undefined if dayOfWeek is "?"', () => {- const cron = "0 30 8 ? * ?";- expect(cronToScheduleSettings(cron)?.schedule_day).toBeUndefined();- });- });-- describe("hours and minutes extraction", () => {- it("correctly extracts the hour and minute from the cron", () => {- const cron = "0 20 3 * * *";- const result = cronToScheduleSettings(cron);- expect(result).toEqual(- expect.objectContaining({- schedule_minute: 20,- schedule_hour: 3,- }),- );- });- });-- describe("every n minutes schedule determination", () => {- it('sets schedule type to "every_n_minutes" when minute is "0/15"', () => {- const cron = `0 0/15 * * * ?`;- expect(cronToScheduleSettings(cron)).toEqual(- expect.objectContaining({- schedule_type: "every_n_minutes",- schedule_minute: 15,- schedule_hour: null,- }),- );- });- });-- describe("specific cron strings", () => {- it("converts 0 0 22 ? * 2L correctly", () => {- const cron = "0 0 22 ? * 2L";- expect(cronToScheduleSettings(cron)).toEqual({- schedule_type: "monthly",- schedule_minute: 0,- schedule_hour: 22,- schedule_day: "mon",- schedule_frame: "last",- });- });-- it("converts 0 0 6 ? * 6#1 correctly", () => {- const cron = "0 0 6 ? * 6#1";- expect(cronToScheduleSettings(cron)).toEqual({- schedule_type: "monthly",- schedule_minute: 0,- schedule_hour: 6,- schedule_day: "fri",- schedule_frame: "first",- });- });- });-});--describe("hourToTwelveHourFormat", () => {- it("converts 24-hour format to 12-hour format correctly", () => {- expect(hourToTwelveHourFormat(0)).toBe(12);- expect(hourToTwelveHourFormat(13)).toBe(1);- expect(hourToTwelveHourFormat(23)).toBe(11);- expect(hourToTwelveHourFormat(12)).toBe(12);- });-- it("does not change hours that are already in 12-hour format", () => {- expect(hourToTwelveHourFormat(11)).toBe(11);- expect(hourToTwelveHourFormat(10)).toBe(10);- expect(hourToTwelveHourFormat(1)).toBe(1);- });-});--describe("hourTo24HourFormat", () => {- // Test AM cases- it("converts 12 AM to 0", () => {- expect(hourTo24HourFormat(12, 0)).toBe(0);- });-- it("converts 1 AM to 1", () => {- expect(hourTo24HourFormat(1, 0)).toBe(1);- });-- it("converts 11 AM to 11", () => {- expect(hourTo24HourFormat(11, 0)).toBe(11);- });-- // Test PM cases- it("converts 12 PM to 12", () => {- expect(hourTo24HourFormat(12, 1)).toBe(12);- });-- it("converts 1 PM to 13", () => {- expect(hourTo24HourFormat(1, 1)).toBe(13);- });-- it("converts 11 PM to 23", () => {- expect(hourTo24HourFormat(11, 1)).toBe(23);- });-- // Edge cases- it("converts 0 AM to 0", () => {- expect(hourTo24HourFormat(0, 0)).toBe(0);- });-- it("converts 0 PM to 12", () => {- expect(hourTo24HourFormat(0, 1)).toBe(12);- });-- it("converts NaN PM to NaN", () => {- expect(hourTo24HourFormat(NaN, 1)).toBeNaN();- });-- it("converts 11 NaN to 11 (that is, fall back to AM if the AM/PM is NaN)", () => {- expect(hourTo24HourFormat(11, NaN)).toBe(11);- });-- it("converts NaN NaN to NaN", () => {- expect(hourTo24HourFormat(NaN, NaN)).toBeNaN();- });-});+import { getShortStrategyLabel } from "./utils";describe("getShortStrategyLabel", () => {it("should return null if no strategy is provided", () => {diff --git a/frontend/src/metabase/api/tags/utils.ts b/frontend/src/metabase/api/tags/utils.tsindex 7db5c53a2d0..4a0b2bab9af 100644--- a/frontend/src/metabase/api/tags/utils.ts+++ b/frontend/src/metabase/api/tags/utils.ts@@ -1,6 +1,6 @@import type { TagDescription } from "@reduxjs/toolkit/query";-import { isVirtualDashCard } from "metabase/dashboard/utils";+import { isVirtualDashCard } from "metabase/lib/dashboard";import type {Alert,ApiKey,diff --git a/frontend/src/metabase/query_builder/components/QuestionDownloadWidget/QuestionDownloadWidget.tsx b/frontend/src/metabase/common/components/QuestionDownloadWidget/QuestionDownloadWidget.tsxsimilarity index 98%rename from frontend/src/metabase/query_builder/components/QuestionDownloadWidget/QuestionDownloadWidget.tsxrename to frontend/src/metabase/common/components/QuestionDownloadWidget/QuestionDownloadWidget.tsxindex 1204638272a..573d0acdbd3 100644--- a/frontend/src/metabase/query_builder/components/QuestionDownloadWidget/QuestionDownloadWidget.tsx+++ b/frontend/src/metabase/common/components/QuestionDownloadWidget/QuestionDownloadWidget.tsx@@ -27,7 +27,10 @@ import { canSavePng } from "metabase/visualizations";import type Question from "metabase-lib/v1/Question";import type { Dataset } from "metabase-types/api";-import type { FormatPreference } from "../QuestionDownloadPopover/QuestionDownloadPopover";+export type FormatPreference = {+ last_download_format: ExportFormat;+ last_table_download_format: TableExportFormat;+};type QuestionDownloadWidgetProps = {question: Question;diff --git a/frontend/src/metabase/common/components/QuestionDownloadWidget/index.ts b/frontend/src/metabase/common/components/QuestionDownloadWidget/index.tsnew file mode 100644index 00000000000..44739091c5c--- /dev/null+++ b/frontend/src/metabase/common/components/QuestionDownloadWidget/index.ts@@ -0,0 +1,4 @@+export { QuestionDownloadWidget } from "./QuestionDownloadWidget";+export type { FormatPreference } from "./QuestionDownloadWidget";+export { useDownloadData } from "./use-download-data";+export type { UseDownloadDataParams } from "./use-download-data";diff --git a/frontend/src/metabase/query_builder/components/QuestionDownloadWidget/use-download-data.ts b/frontend/src/metabase/common/components/QuestionDownloadWidget/use-download-data.tssimilarity index 100%rename from frontend/src/metabase/query_builder/components/QuestionDownloadWidget/use-download-data.tsrename to frontend/src/metabase/common/components/QuestionDownloadWidget/use-download-data.tsdiff --git a/frontend/src/metabase/common/components/Schedule/Schedule.tsx b/frontend/src/metabase/common/components/Schedule/Schedule.tsxindex 39395318d52..dad4c1027d3 100644--- a/frontend/src/metabase/common/components/Schedule/Schedule.tsx+++ b/frontend/src/metabase/common/components/Schedule/Schedule.tsx@@ -4,10 +4,6 @@ import { match } from "ts-pattern";import { c, msgid, ngettext } from "ttag";import _ from "underscore";-import {- cronToScheduleSettings,- scheduleSettingsToCron,-} from "metabase/admin/performance/utils";import { CronExpressionInput } from "metabase/common/components/CronExpressioInput";import { formatCronExpressionForUI } from "metabase/lib/cron";import { removeNullAndUndefinedValues } from "metabase/lib/types";@@ -27,6 +23,7 @@ import {SelectWeekday,SelectWeekdayOfMonth,} from "./components";+import { cronToScheduleSettings, scheduleSettingsToCron } from "./cron";import { byTheMinuteIntervals } from "./strings";import type { UpdateSchedule } from "./types";import { getScheduleDefaults } from "./utils";diff --git a/frontend/src/metabase/common/components/Schedule/components.tsx b/frontend/src/metabase/common/components/Schedule/components.tsxindex 95ec8f02bc9..a56c848f64e 100644--- a/frontend/src/metabase/common/components/Schedule/components.tsx+++ b/frontend/src/metabase/common/components/Schedule/components.tsx@@ -1,10 +1,6 @@import { useMemo } from "react";import { t } from "ttag";-import {- hourTo24HourFormat,- hourToTwelveHourFormat,-} from "metabase/admin/performance/utils";import { capitalize } from "metabase/lib/formatting/strings";import { useSelector } from "metabase/lib/redux";import { has24HourModeSetting } from "metabase/lib/time-dayjs";@@ -19,6 +15,7 @@ import type {import { AutoWidthSelect } from "./AutoWidthSelect";import { defaultHour } from "./constants";+import { hourTo24HourFormat, hourToTwelveHourFormat } from "./cron";import {type Weekday,getHours,diff --git a/frontend/src/metabase/common/components/Schedule/cron.ts b/frontend/src/metabase/common/components/Schedule/cron.tsnew file mode 100644index 00000000000..1a3b5696413--- /dev/null+++ b/frontend/src/metabase/common/components/Schedule/cron.ts@@ -0,0 +1,194 @@+import { memoize } from "underscore";++import type {+ ScheduleDayType,+ ScheduleFrameType,+ ScheduleSettings,+ ScheduleType,+} from "metabase-types/api";++import { Cron, getScheduleStrings } from "./strings";++const AM = 0;+const PM = 1;++const everyToCronSyntax = (every: number | string) =>+ `${Cron.EveryPrefix}${every}`;+export const isRepeatingEvery = (every: string) =>+ every.startsWith(Cron.EveryPrefix);+export const cronUnitToNumber = (unit: string) =>+ parseInt(unit.replace(Cron.EveryPrefix, ""));++const dayToCron = (day: ScheduleSettings["schedule_day"]) => {+ const { weekdays } = getScheduleStrings();+ const index = weekdays.findIndex((o) => o.value === day);+ if (index === -1) {+ throw new Error(`Invalid day: ${day}`);+ }+ return index + 1;+};++const frameToCronMap = { first: "1", last: "L", mid: "15" };+const frameToCron = (frame: ScheduleFrameType) => frameToCronMap[frame];++const frameFromCronMap: Record<string, ScheduleFrameType> = {+ "15": "mid",+ "1": "first",+ L: "last",+};+const frameFromCron = (frameInCronFormat: string) =>+ frameFromCronMap[frameInCronFormat];++export const scheduleSettingsToCron = (settings: ScheduleSettings): string => {+ const second = "0";+ const year = "*";+ let minute = settings.schedule_minute?.toString() ?? Cron.AllValues;+ const hour = settings.schedule_hour?.toString() ?? Cron.AllValues;+ let weekday = settings.schedule_day+ ? dayToCron(settings.schedule_day).toString()+ : Cron.NoSpecificValue;+ const month = Cron.AllValues;+ let dayOfMonth: string = settings.schedule_day+ ? Cron.NoSpecificValue+ : Cron.AllValues;+ if (settings.schedule_type === "every_n_minutes") {+ minute = everyToCronSyntax(minute);+ } else if (settings.schedule_type === "monthly" && settings.schedule_frame) {+ // There are two kinds of monthly schedule:+ // - weekday-based (e.g. "on the first Monday of the month")+ // - date-based (e.g. "on the 15th of the month")+ if (settings.schedule_day) {+ // Handle weekday-based monthly schedule+ const frameInCronFormat = frameToCron(settings.schedule_frame).replace(+ /^1$/,+ "#1",+ );+ const dayInCronFormat = dayToCron(settings.schedule_day);+ weekday = `${dayInCronFormat}${frameInCronFormat}`;+ } else {+ // Handle date-based monthly schedule+ dayOfMonth = frameToCron(settings.schedule_frame);+ }+ }+ const cronExpression = [+ second,+ minute,+ hour,+ dayOfMonth,+ month,+ weekday,+ year,+ ].join(" ");+ return cronExpression;+};++const defaultSchedule: ScheduleSettings = {+ schedule_type: "hourly",+ schedule_minute: 0,+};+export const defaultCron = scheduleSettingsToCron(defaultSchedule);++/** Returns null if we can't convert the cron expression to a ScheduleSettings object */+export const cronToScheduleSettings_unmemoized = (+ cron: string | null | undefined,+ isCustomSchedule: boolean = false,+): ScheduleSettings | null => {+ if (!cron) {+ return defaultSchedule;+ }++ const { weekdays } = getScheduleStrings();++ // The Quartz cron library used in the backend distinguishes between 'no specific value' and 'all values',+ // but for simplicity we can treat them as the same here+ cron = cron.replace(+ new RegExp(Cron.NoSpecificValue_Escaped, "g"),+ Cron.AllValues,+ );++ const [_second, minute, hour, dayOfMonth, month, weekday] = cron.split(" ");++ if (month !== Cron.AllValues && !isCustomSchedule) {+ return null;+ }+ let schedule_type: ScheduleType | undefined;+ if (isCustomSchedule) {+ schedule_type = "cron";+ } else if (dayOfMonth === Cron.AllValues) {+ if (weekday === Cron.AllValues) {+ if (hour === Cron.AllValues) {+ schedule_type = isRepeatingEvery(minute) ? "every_n_minutes" : "hourly";+ } else {+ schedule_type = "daily";+ }+ } else {+ // If the weekday part of the cron expression is something like '1#1' (first Monday),+ // or '2L' (last Tuesday), then the frequency is monthly+ const oneWeekPerMonth = weekday.match(/[#L]/);+ schedule_type = oneWeekPerMonth ? "monthly" : "weekly";+ }+ } else {+ schedule_type = "monthly";+ }+ let schedule_frame: ScheduleFrameType | undefined;+ let schedule_day: ScheduleDayType | undefined;+ if (schedule_type === "monthly") {+ if (weekday === Cron.AllValues) {+ schedule_frame = frameFromCron(dayOfMonth);+ } else {+ const dayStr = weekday.match(/^\d+/)?.[0];+ if (!dayStr) {+ throw new Error(+ `The cron expression contains an invalid weekday: ${weekday}`,+ );+ }+ const day = parseInt(dayStr);+ schedule_day = weekdays[day - 1]?.value as ScheduleDayType;+ if (dayOfMonth === Cron.AllValues) {+ // Match the part after the '#' in a string like '6#1' or the letter in '6L'+ const frameInCronFormat = weekday+ .match(/^\d+(\D.*)$/)?.[1]+ .replace(/^#/, "");+ if (!frameInCronFormat) {+ throw new Error(+ `The cron expression contains an invalid weekday: ${weekday}`,+ );+ }+ schedule_frame = frameFromCron(frameInCronFormat);+ } else {+ schedule_frame = frameFromCron(dayOfMonth);+ }+ }+ } else {+ if (weekday !== Cron.AllValues) {+ schedule_day = weekdays[parseInt(weekday) - 1]?.value as ScheduleDayType;+ }+ }++ const scheduleMinute =+ minute === Cron.AllValues ? null : cronUnitToNumber(minute);+ const scheduleHour = hour === Cron.AllValues ? null : cronUnitToNumber(hour);+ return {+ schedule_type,+ schedule_minute: scheduleMinute,+ schedule_hour: scheduleHour,+ schedule_day,+ schedule_frame,+ };+};+export const cronToScheduleSettings = memoize(+ cronToScheduleSettings_unmemoized,+ (cron, isCustomSchedule) => `${cron}_${isCustomSchedule}`,+);++const isValidAmPm = (amPm: number) => amPm === AM || amPm === PM;++export const hourToTwelveHourFormat = (hour: number) => hour % 12 || 12;++export const hourTo24HourFormat = (hour: number, amPm: number): number => {+ if (!isValidAmPm(amPm)) {+ amPm = AM;+ }+ const hour24 = amPm === PM ? (hour % 12) + 12 : hour % 12;+ return hour24 === 24 ? 0 : hour24;+};diff --git a/frontend/src/metabase/common/components/Schedule/cron.unit.spec.ts b/frontend/src/metabase/common/components/Schedule/cron.unit.spec.tsnew file mode 100644index 00000000000..3f75ad9a3ed--- /dev/null+++ b/frontend/src/metabase/common/components/Schedule/cron.unit.spec.ts@@ -0,0 +1,316 @@+import type { ScheduleSettings } from "metabase-types/api";++import {+ cronToScheduleSettings,+ hourTo24HourFormat,+ hourToTwelveHourFormat,+ scheduleSettingsToCron,+} from "./cron";++describe("scheduleSettingsToCron", () => {+ it("converts every_n_minutes schedule to cron", () => {+ const settings: ScheduleSettings = {+ schedule_type: "every_n_minutes",+ schedule_minute: 10,+ schedule_hour: null,+ };+ const cron = scheduleSettingsToCron(settings);+ expect(cron).toEqual("0 0/10 * * * ? *");+ });++ it("converts hourly schedule to cron", () => {+ const settings: ScheduleSettings = {+ schedule_type: "hourly",+ schedule_minute: 1,+ schedule_hour: 1,+ };+ const cron = scheduleSettingsToCron(settings);+ expect(cron).toEqual("0 1 1 * * ? *");+ });++ it("converts daily schedule to cron", () => {+ const settings: ScheduleSettings = {+ schedule_type: "daily",+ schedule_minute: 30,+ schedule_hour: 14,+ };+ const cron = scheduleSettingsToCron(settings);+ expect(cron).toEqual("0 30 14 * * ? *");+ });++ it("converts weekly schedule to cron", () => {+ const settings: ScheduleSettings = {+ schedule_type: "weekly",+ schedule_day: "mon",+ schedule_minute: 0,+ schedule_hour: 12,+ };+ const cron = scheduleSettingsToCron(settings);+ expect(cron).toEqual("0 0 12 ? * 2 *");+ });++ it("converts 'first Wednesday of the month at 9:15am' to cron", () => {+ const settings: ScheduleSettings = {+ schedule_type: "monthly",+ schedule_day: "wed",+ schedule_frame: "first",+ schedule_minute: 15,+ schedule_hour: 9,+ };+ const cron = scheduleSettingsToCron(settings);+ expect(cron).toEqual("0 15 9 ? * 4#1 *");+ });++ it("converts 'last calendar day of the month' to cron", () => {+ const settings: ScheduleSettings = {+ schedule_type: "monthly",+ schedule_frame: "last",+ schedule_minute: 45,+ schedule_hour: 16,+ };+ const cron = scheduleSettingsToCron(settings);+ expect(cron).toEqual("0 45 16 L * ? *");+ });++ it("converts 'monthly on the 15th' to cron", () => {+ const settings: ScheduleSettings = {+ schedule_type: "monthly",+ schedule_frame: "mid",+ schedule_minute: 5,+ schedule_hour: 23,+ };+ const cron = scheduleSettingsToCron(settings);+ expect(cron).toEqual("0 5 23 15 * ? *");+ });++ it("missing minute and hour should default to wildcard", () => {+ const settings: ScheduleSettings = {+ schedule_type: "daily",+ };+ const cron = scheduleSettingsToCron(settings);+ expect(cron).toEqual("0 * * * * ? *");+ });+});++describe("cronToScheduleSettings", () => {+ it("returns default schedule when input is null or undefined", () => {+ const defaultSchedule = {+ schedule_type: "hourly",+ schedule_minute: 0,+ };+ expect(cronToScheduleSettings(null)).toEqual(defaultSchedule);+ expect(cronToScheduleSettings(undefined)).toEqual(defaultSchedule);+ });++ it("returns null when month is specified in cron", () => {+ const cron = "0 15 10 15 1 ?";+ expect(cronToScheduleSettings(cron)).toBeNull();+ });++ describe("schedule type determination", () => {+ it('sets schedule type to "every_n_minutes" when minute is "0/15"', () => {+ const cron = `0 0/15 * * * ?`;+ expect(cronToScheduleSettings(cron)?.schedule_type).toBe(+ "every_n_minutes",+ );+ });++ it('sets schedule type to "hourly" when hour is "*" and both dayOfMonth and dayOfWeek are "*"', () => {+ const cron = "0 30 * * * *";+ expect(cronToScheduleSettings(cron)?.schedule_type).toBe("hourly");+ });++ it('sets schedule type to "daily" when dayOfMonth and dayOfWeek are "*", and hour is specified', () => {+ const cron = "0 30 8 * * *";+ expect(cronToScheduleSettings(cron)?.schedule_type).toBe("daily");+ });++ it('sets schedule type to "weekly" when dayOfWeek is specified', () => {+ const cron = "0 30 8 ? * 1";+ expect(cronToScheduleSettings(cron)?.schedule_type).toBe("weekly");+ });++ it('sets schedule type to "monthly" when dayOfMonth is specific', () => {+ const cron = "0 30 8 15 * ?";+ expect(cronToScheduleSettings(cron)?.schedule_type).toBe("monthly");+ });++ it('sets schedule type to "cron" when isCustomSchedule is true', () => {+ const cron = "0 30 8 15 * ?";+ expect(cronToScheduleSettings(cron, true)?.schedule_type).toBe("cron");+ });+ });++ describe("monthly schedule determination", () => {+ it('sets schedule frame to "mid" when dayOfMonth is "15"', () => {+ const cron = "0 30 8 15 * ?";+ expect(cronToScheduleSettings(cron)?.schedule_frame).toBe("mid");+ });++ it('sets schedule frame to "first" when dayOfMonth is "1"', () => {+ const cron = "0 30 8 1 * ?";+ expect(cronToScheduleSettings(cron)?.schedule_frame).toBe("first");+ });++ it('sets schedule frame to "last" when dayOfMonth is "L"', () => {+ const cron = "0 30 8 L * ?";+ expect(cronToScheduleSettings(cron)?.schedule_frame).toBe("last");+ });+ });++ describe("weekly schedule determination", () => {+ it('sets schedule_day to "sun" when dayOfWeek is 1', () => {+ const cron = "0 30 8 ? * 1";+ expect(cronToScheduleSettings(cron)?.schedule_day).toBe("sun");+ });++ it('sets schedule_day to "mon" when dayOfWeek is 2', () => {+ const cron = "0 30 8 ? * 2";+ expect(cronToScheduleSettings(cron)?.schedule_day).toBe("mon");+ });++ it('sets schedule_day to "tue" when dayOfWeek is 3', () => {+ const cron = "0 30 8 ? * 3";+ expect(cronToScheduleSettings(cron)?.schedule_day).toBe("tue");+ });++ it('sets schedule_day to "wed" when dayOfWeek is 4', () => {+ const cron = "0 30 8 ? * 4";+ expect(cronToScheduleSettings(cron)?.schedule_day).toBe("wed");+ });++ it('sets schedule_day to "thu" when dayOfWeek is 5', () => {+ const cron = "0 30 8 ? * 5";+ expect(cronToScheduleSettings(cron)?.schedule_day).toBe("thu");+ });++ it('sets schedule_day to "fri" when dayOfWeek is 6', () => {+ const cron = "0 30 8 ? * 6";+ expect(cronToScheduleSettings(cron)?.schedule_day).toBe("fri");+ });++ it('sets schedule_day to "sat" when dayOfWeek is 7', () => {+ const cron = "0 30 8 ? * 7";+ expect(cronToScheduleSettings(cron)?.schedule_day).toBe("sat");+ });++ it('sets schedule_day to undefined if dayOfWeek is "?"', () => {+ const cron = "0 30 8 ? * ?";+ expect(cronToScheduleSettings(cron)?.schedule_day).toBeUndefined();+ });+ });++ describe("hours and minutes extraction", () => {+ it("correctly extracts the hour and minute from the cron", () => {+ const cron = "0 20 3 * * *";+ const result = cronToScheduleSettings(cron);+ expect(result).toEqual(+ expect.objectContaining({+ schedule_minute: 20,+ schedule_hour: 3,+ }),+ );+ });+ });++ describe("every n minutes schedule determination", () => {+ it('sets schedule type to "every_n_minutes" when minute is "0/15"', () => {+ const cron = `0 0/15 * * * ?`;+ expect(cronToScheduleSettings(cron)).toEqual(+ expect.objectContaining({+ schedule_type: "every_n_minutes",+ schedule_minute: 15,+ schedule_hour: null,+ }),+ );+ });+ });++ describe("specific cron strings", () => {+ it("converts 0 0 22 ? * 2L correctly", () => {+ const cron = "0 0 22 ? * 2L";+ expect(cronToScheduleSettings(cron)).toEqual({+ schedule_type: "monthly",+ schedule_minute: 0,+ schedule_hour: 22,+ schedule_day: "mon",+ schedule_frame: "last",+ });+ });++ it("converts 0 0 6 ? * 6#1 correctly", () => {+ const cron = "0 0 6 ? * 6#1";+ expect(cronToScheduleSettings(cron)).toEqual({+ schedule_type: "monthly",+ schedule_minute: 0,+ schedule_hour: 6,+ schedule_day: "fri",+ schedule_frame: "first",+ });+ });+ });+});++describe("hourToTwelveHourFormat", () => {+ it("converts 24-hour format to 12-hour format correctly", () => {+ expect(hourToTwelveHourFormat(0)).toBe(12);+ expect(hourToTwelveHourFormat(13)).toBe(1);+ expect(hourToTwelveHourFormat(23)).toBe(11);+ expect(hourToTwelveHourFormat(12)).toBe(12);+ });++ it("does not change hours that are already in 12-hour format", () => {+ expect(hourToTwelveHourFormat(11)).toBe(11);+ expect(hourToTwelveHourFormat(10)).toBe(10);+ expect(hourToTwelveHourFormat(1)).toBe(1);+ });+});++describe("hourTo24HourFormat", () => {+ // Test AM cases+ it("converts 12 AM to 0", () => {+ expect(hourTo24HourFormat(12, 0)).toBe(0);+ });++ it("converts 1 AM to 1", () => {+ expect(hourTo24HourFormat(1, 0)).toBe(1);+ });++ it("converts 11 AM to 11", () => {+ expect(hourTo24HourFormat(11, 0)).toBe(11);+ });++ // Test PM cases+ it("converts 12 PM to 12", () => {+ expect(hourTo24HourFormat(12, 1)).toBe(12);+ });++ it("converts 1 PM to 13", () => {+ expect(hourTo24HourFormat(1, 1)).toBe(13);+ });++ it("converts 11 PM to 23", () => {+ expect(hourTo24HourFormat(11, 1)).toBe(23);+ });++ // Edge cases+ it("converts 0 AM to 0", () => {+ expect(hourTo24HourFormat(0, 0)).toBe(0);+ });++ it("converts 0 PM to 12", () => {+ expect(hourTo24HourFormat(0, 1)).toBe(12);+ });++ it("converts NaN PM to NaN", () => {+ expect(hourTo24HourFormat(NaN, 1)).toBeNaN();+ });++ it("converts 11 NaN to 11 (that is, fall back to AM if the AM/PM is NaN)", () => {+ expect(hourTo24HourFormat(11, NaN)).toBe(11);+ });++ it("converts NaN NaN to NaN", () => {+ expect(hourTo24HourFormat(NaN, NaN)).toBeNaN();+ });+});diff --git a/frontend/src/metabase/dashboard/components/Sidebar.module.css b/frontend/src/metabase/common/components/Sidebar/Sidebar.module.csssimilarity index 100%rename from frontend/src/metabase/dashboard/components/Sidebar.module.cssrename to frontend/src/metabase/common/components/Sidebar/Sidebar.module.cssdiff --git a/frontend/src/metabase/dashboard/components/Sidebar.tsx b/frontend/src/metabase/common/components/Sidebar/Sidebar.tsxsimilarity index 100%rename from frontend/src/metabase/dashboard/components/Sidebar.tsxrename to frontend/src/metabase/common/components/Sidebar/Sidebar.tsxdiff --git a/frontend/src/metabase/common/components/Sidebar/index.ts b/frontend/src/metabase/common/components/Sidebar/index.tsnew file mode 100644index 00000000000..7f0af9cdb41--- /dev/null+++ b/frontend/src/metabase/common/components/Sidebar/index.ts@@ -0,0 +1 @@+export { Sidebar, SIDEBAR_WIDTH } from "./Sidebar";diff --git a/frontend/src/metabase/querying/components/QueryVisualization/Warnings.tsx b/frontend/src/metabase/common/components/Warnings.tsxsimilarity index 100%rename from frontend/src/metabase/querying/components/QueryVisualization/Warnings.tsxrename to frontend/src/metabase/common/components/Warnings.tsxdiff --git a/frontend/src/metabase/dashboard/actions/actions.ts b/frontend/src/metabase/dashboard/actions/actions.tsindex 050318ff288..50ad93fb348 100644--- a/frontend/src/metabase/dashboard/actions/actions.ts+++ b/frontend/src/metabase/dashboard/actions/actions.ts@@ -3,6 +3,7 @@ import {getActionExecutionMessage,} from "metabase/actions/utils";import { SIDEBAR_NAME } from "metabase/dashboard/constants";+import { getDashboardType } from "metabase/lib/dashboard";import { addUndo } from "metabase/redux/undo";import { ActionsApi, PublicApi } from "metabase/services";import type {@@ -14,8 +15,6 @@ import type {} from "metabase-types/api";import type { Dispatch } from "metabase-types/store";-import { getDashboardType } from "../utils";-import { setDashCardAttributes } from "./core";import { closeSidebar, setSidebar } from "./ui";diff --git a/frontend/src/metabase/dashboard/actions/auto-wire-parameters/actions.ts b/frontend/src/metabase/dashboard/actions/auto-wire-parameters/actions.tsindex e56280e424b..59b219f7964 100644--- a/frontend/src/metabase/dashboard/actions/auto-wire-parameters/actions.ts+++ b/frontend/src/metabase/dashboard/actions/auto-wire-parameters/actions.ts@@ -19,10 +19,8 @@ import {getSelectedTabId,getTabs,} from "metabase/dashboard/selectors";-import {- findDashCardForInlineParameter,- isQuestionDashCard,-} from "metabase/dashboard/utils";+import { findDashCardForInlineParameter } from "metabase/dashboard/utils";+import { isQuestionDashCard } from "metabase/lib/dashboard";import {getMappingOptionByTarget,getParameterMappingOptions,diff --git a/frontend/src/metabase/dashboard/actions/auto-wire-parameters/utils.ts b/frontend/src/metabase/dashboard/actions/auto-wire-parameters/utils.tsindex dc1006588d6..e23e4b4f4f4 100644--- a/frontend/src/metabase/dashboard/actions/auto-wire-parameters/utils.ts+++ b/frontend/src/metabase/dashboard/actions/auto-wire-parameters/utils.ts@@ -2,11 +2,8 @@ import _ from "underscore";import { isActionDashCard } from "metabase/actions/utils";import { getExistingDashCards } from "metabase/dashboard/actions/utils";-import {- findDashCardForInlineParameter,- isQuestionDashCard,- isVirtualDashCard,-} from "metabase/dashboard/utils";+import { findDashCardForInlineParameter } from "metabase/dashboard/utils";+import { isQuestionDashCard, isVirtualDashCard } from "metabase/lib/dashboard";import {type ParameterMappingOption,getMappingOptionByTarget,diff --git a/frontend/src/metabase/dashboard/actions/cards-typed.ts b/frontend/src/metabase/dashboard/actions/cards-typed.tsindex 679caab9c15..caad26ae1c2 100644--- a/frontend/src/metabase/dashboard/actions/cards-typed.ts+++ b/frontend/src/metabase/dashboard/actions/cards-typed.ts@@ -3,6 +3,7 @@ import { t } from "ttag";import _ from "underscore";import { Questions } from "metabase/entities/questions";+import { isQuestionDashCard, isVirtualDashCard } from "metabase/lib/dashboard";import {DEFAULT_CARD_SIZE,GRID_WIDTH,@@ -51,8 +52,6 @@ import {createVirtualCard,generateTemporaryDashcardId,hasInlineParameters,- isQuestionDashCard,- isVirtualDashCard,} from "../utils";import { showAutoWireToastNewCard } from "./auto-wire-parameters/actions";diff --git a/frontend/src/metabase/dashboard/actions/data-fetching.ts b/frontend/src/metabase/dashboard/actions/data-fetching.tsindex 6afe1e058f0..80852134f56 100644--- a/frontend/src/metabase/dashboard/actions/data-fetching.ts+++ b/frontend/src/metabase/dashboard/actions/data-fetching.ts@@ -21,10 +21,12 @@ import {fetchDataOrError,getAllDashboardCards,getCurrentTabDashboardCards,+} from "metabase/dashboard/utils";+import {getDashboardType,isQuestionDashCard,isVirtualDashCard,-} from "metabase/dashboard/utils";+} from "metabase/lib/dashboard";import { entityCompatibleQuery } from "metabase/lib/entities";import type { Deferred } from "metabase/lib/promise";import { defer } from "metabase/lib/promise";diff --git a/frontend/src/metabase/dashboard/actions/data-fetching.unit.spec.ts b/frontend/src/metabase/dashboard/actions/data-fetching.unit.spec.tsindex 85edcf68dca..5ebd291d4b4 100644--- a/frontend/src/metabase/dashboard/actions/data-fetching.unit.spec.ts+++ b/frontend/src/metabase/dashboard/actions/data-fetching.unit.spec.ts@@ -8,6 +8,7 @@ import {} from "__support__/server-mocks";import { createMockEntitiesState } from "__support__/store";import { Api } from "metabase/api";+import { isQuestionDashCard } from "metabase/lib/dashboard";import type { Dashboard } from "metabase-types/api";import {createMockCard,@@ -24,7 +25,6 @@ import {} from "metabase-types/store/mocks";import { dashboardReducers } from "../reducers";-import { isQuestionDashCard } from "../utils";import {fetchCardDataAction,diff --git a/frontend/src/metabase/dashboard/actions/navigation.ts b/frontend/src/metabase/dashboard/actions/navigation.tsindex 3a4893ee1bc..2cc17ca7ebe 100644--- a/frontend/src/metabase/dashboard/actions/navigation.ts+++ b/frontend/src/metabase/dashboard/actions/navigation.ts@@ -1,3 +1,4 @@+import { isQuestionDashCard } from "metabase/lib/dashboard";import { createThunkAction } from "metabase/lib/redux";import * as Urls from "metabase/lib/urls";import { openUrl } from "metabase/redux/app";@@ -7,8 +8,6 @@ import type Question from "metabase-lib/v1/Question";import type { Card, DashboardCard, VirtualCard } from "metabase-types/api";import type { Dispatch, GetState } from "metabase-types/store";-import { isQuestionDashCard } from "../utils";-import { getNewCardUrl } from "./getNewCardUrl";export const EDIT_QUESTION = "metabase/dashboard/EDIT_QUESTION";diff --git a/frontend/src/metabase/dashboard/actions/parameters.tsx b/frontend/src/metabase/dashboard/actions/parameters.tsxindex 9e73658b28f..d8b2aaae349 100644--- a/frontend/src/metabase/dashboard/actions/parameters.tsx+++ b/frontend/src/metabase/dashboard/actions/parameters.tsx@@ -13,6 +13,7 @@ import {import { getParameterMappings } from "metabase/dashboard/actions/auto-wire-parameters/utils";import { updateDashboard } from "metabase/dashboard/actions/save";import { SIDEBAR_NAME } from "metabase/dashboard/constants";+import { isQuestionDashCard } from "metabase/lib/dashboard";import { createAction, createThunkAction } from "metabase/lib/redux";import {type NewParameterOpts,@@ -78,7 +79,6 @@ import {findDashCardForInlineParameter,hasInlineParameters,isDashcardInlineParameter,- isQuestionDashCard,setDashboardHeaderParameterIndex,supportsInlineParameters,} from "../utils";diff --git a/frontend/src/metabase/dashboard/actions/tabs.ts b/frontend/src/metabase/dashboard/actions/tabs.tsindex 4746159e339..d389d109b37 100644--- a/frontend/src/metabase/dashboard/actions/tabs.ts+++ b/frontend/src/metabase/dashboard/actions/tabs.ts@@ -8,6 +8,7 @@ import {INITIALIZE,} from "metabase/dashboard/actions/core";import { Dashboards } from "metabase/entities/dashboards";+import { isVirtualDashCard } from "metabase/lib/dashboard";import { getPositionForNewDashCard } from "metabase/lib/dashboard_grid";import { checkNotNull } from "metabase/lib/types";import { addUndo } from "metabase/redux/undo";@@ -32,7 +33,6 @@ import { getDashCardById } from "../selectors";import {calculateDashCardRowAfterUndo,generateTemporaryDashcardId,- isVirtualDashCard,} from "../utils";import { getDashCardMoveToTabUndoMessage, getExistingDashCards } from "./utils";diff --git a/frontend/src/metabase/dashboard/actions/utils.ts b/frontend/src/metabase/dashboard/actions/utils.tsindex d088082e681..d4b51cf5767 100644--- a/frontend/src/metabase/dashboard/actions/utils.ts+++ b/frontend/src/metabase/dashboard/actions/utils.ts@@ -1,6 +1,7 @@import { t } from "ttag";import _ from "underscore";+import { isActionDashCard } from "metabase/lib/dashboard";import { getIframeDomainName } from "metabase/visualizations/visualizations/IFrameViz/utils";import type {DashCardId,@@ -12,7 +13,7 @@ import type {import type { StoreDashboard, StoreDashcard } from "metabase-types/store";import { trackIFrameDashcardsSaved } from "../analytics";-import { isActionDashCard, isIFrameDashCard } from "../utils";+import { isIFrameDashCard } from "../utils";export function getExistingDashCards(dashboards: Record<DashboardId, StoreDashboard>,diff --git a/frontend/src/metabase/dashboard/components/ActionSidebar/ActionSidebar.tsx b/frontend/src/metabase/dashboard/components/ActionSidebar/ActionSidebar.tsxindex 1247dd21501..a74c6e148ff 100644--- a/frontend/src/metabase/dashboard/components/ActionSidebar/ActionSidebar.tsx+++ b/frontend/src/metabase/dashboard/components/ActionSidebar/ActionSidebar.tsx@@ -7,8 +7,8 @@ import { ConnectedActionDashcardSettings } from "metabase/actions/components/Actimport { isActionDashCard } from "metabase/actions/utils";import { Ellipsified } from "metabase/common/components/Ellipsified";import { FormField } from "metabase/common/components/FormField/FormField";+import { Sidebar } from "metabase/common/components/Sidebar";import CS from "metabase/css/core/index.css";-import { Sidebar } from "metabase/dashboard/components/Sidebar";import { useDashboardContext } from "metabase/dashboard/context";import { Form, FormProvider, FormSelect, FormTextInput } from "metabase/forms";import { Box, Button, Divider, Flex, Modal, Stack, Title } from "metabase/ui";diff --git a/frontend/src/metabase/dashboard/components/AddCardSidebar/AddCardSidebar.tsx b/frontend/src/metabase/dashboard/components/AddCardSidebar/AddCardSidebar.tsxindex 9a117b38006..1ca3629a4eb 100644--- a/frontend/src/metabase/dashboard/components/AddCardSidebar/AddCardSidebar.tsx+++ b/frontend/src/metabase/dashboard/components/AddCardSidebar/AddCardSidebar.tsx@@ -1,6 +1,6 @@import { useCallback } from "react";-import { Sidebar } from "metabase/dashboard/components/Sidebar";+import { Sidebar } from "metabase/common/components/Sidebar";import { useDashboardContext } from "metabase/dashboard/context";import type { CardId } from "metabase-types/api";diff --git a/frontend/src/metabase/dashboard/components/ClickBehaviorSidebar/ClickBehaviorSidebar.tsx b/frontend/src/metabase/dashboard/components/ClickBehaviorSidebar/ClickBehaviorSidebar.tsxindex 18046113c45..61bf9f1412f 100644--- a/frontend/src/metabase/dashboard/components/ClickBehaviorSidebar/ClickBehaviorSidebar.tsx+++ b/frontend/src/metabase/dashboard/components/ClickBehaviorSidebar/ClickBehaviorSidebar.tsx@@ -2,8 +2,8 @@ import { getIn } from "icepick";import { useCallback, useEffect, useMemo, useState } from "react";import { useMount, usePrevious } from "react-use";+import { Sidebar } from "metabase/common/components/Sidebar";import { useDashboardQuery } from "metabase/common/hooks";-import { Sidebar } from "metabase/dashboard/components/Sidebar";import {type DashboardContextReturned,useDashboardContext,diff --git a/frontend/src/metabase/dashboard/components/ClickMappings/hooks.ts b/frontend/src/metabase/dashboard/components/ClickMappings/hooks.tsindex b6d1a08c66d..4e47fa46462 100644--- a/frontend/src/metabase/dashboard/components/ClickMappings/hooks.ts+++ b/frontend/src/metabase/dashboard/components/ClickMappings/hooks.ts@@ -1,7 +1,7 @@import { useEffect, useMemo, useState } from "react";import { getDashcardData, getParameters } from "metabase/dashboard/selectors";-import { isQuestionDashCard } from "metabase/dashboard/utils";+import { isQuestionDashCard } from "metabase/lib/dashboard";import { useDispatch, useSelector } from "metabase/lib/redux";import MetabaseSettings from "metabase/lib/settings";import { loadMetadataForCard } from "metabase/questions/actions";diff --git a/frontend/src/metabase/dashboard/components/DashCard/DashCard.tsx b/frontend/src/metabase/dashboard/components/DashCard/DashCard.tsxindex 919157c9e95..83e25d51ca4 100644--- a/frontend/src/metabase/dashboard/components/DashCard/DashCard.tsx+++ b/frontend/src/metabase/dashboard/components/DashCard/DashCard.tsx@@ -14,10 +14,9 @@ import { getDashcardData, getDashcardHref } from "metabase/dashboard/selectors";import {getDashcardResultsError,isDashcardLoading,- isQuestionCard,- isQuestionDashCard,} from "metabase/dashboard/utils";import { isEmbeddingSdk } from "metabase/embedding-sdk/config";+import { isQuestionCard, isQuestionDashCard } from "metabase/lib/dashboard";import { useDispatch, useSelector, useStore } from "metabase/lib/redux";import type { NewParameterOpts } from "metabase/parameters/utils/dashboards";import { PLUGIN_COLLECTIONS } from "metabase/plugins";diff --git a/frontend/src/metabase/dashboard/components/DashCard/DashCardActionsPanel/DashCardActionsPanel.tsx b/frontend/src/metabase/dashboard/components/DashCard/DashCardActionsPanel/DashCardActionsPanel.tsxindex bc71737f062..49c9a19c5b8 100644--- a/frontend/src/metabase/dashboard/components/DashCard/DashCardActionsPanel/DashCardActionsPanel.tsx+++ b/frontend/src/metabase/dashboard/components/DashCard/DashCardActionsPanel/DashCardActionsPanel.tsx@@ -8,11 +8,10 @@ import { AddFilterParameterMenu } from "metabase/dashboard/components/AddFilterPimport {isHeadingDashCard,isLinkDashCard,- isQuestionDashCard,- isVirtualDashCard,supportsInlineParameters,} from "metabase/dashboard/utils";import { trackSimpleEvent } from "metabase/lib/analytics";+import { isQuestionDashCard, isVirtualDashCard } from "metabase/lib/dashboard";import type { NewParameterOpts } from "metabase/parameters/utils/dashboards";import { Box, Icon } from "metabase/ui";import { getVisualizationRaw } from "metabase/visualizations";diff --git a/frontend/src/metabase/dashboard/components/DashCard/DashCardMenu/DashCardMenu.tsx b/frontend/src/metabase/dashboard/components/DashCard/DashCardMenu/DashCardMenu.tsxindex c0c421d08f8..8acab312b1d 100644--- a/frontend/src/metabase/dashboard/components/DashCard/DashCardMenu/DashCardMenu.tsx+++ b/frontend/src/metabase/dashboard/components/DashCard/DashCardMenu/DashCardMenu.tsx@@ -3,20 +3,18 @@ import cx from "classnames";import { useMemo, useState } from "react";import { t } from "ttag";-import {- canDownloadResults,- canEditQuestion,-} from "metabase/dashboard/components/DashCard/DashCardMenu/utils";+import { QuestionDownloadWidget } from "metabase/common/components/QuestionDownloadWidget";+import { useDownloadData } from "metabase/common/components/QuestionDownloadWidget/use-download-data";+import { canEditQuestion } from "metabase/dashboard/components/DashCard/DashCardMenu/utils";import {type DashboardContextReturned,useDashboardContext,} from "metabase/dashboard/context";import { getParameterValuesBySlugMap } from "metabase/dashboard/selectors";import { transformSdkQuestion } from "metabase/embedding-sdk/lib/transform-question";+import { canDownloadResults } from "metabase/lib/downloads";import { useStore } from "metabase/lib/redux";import { checkNotNull } from "metabase/lib/types";-import { QuestionDownloadWidget } from "metabase/query_builder/components/QuestionDownloadWidget";-import { useDownloadData } from "metabase/query_builder/components/QuestionDownloadWidget/use-download-data";import { ActionIcon, Icon, Menu, type MenuProps } from "metabase/ui";import { SAVING_DOM_IMAGE_HIDDEN_CLASS } from "metabase/visualizations/lib/save-chart-image";import type Question from "metabase-lib/v1/Question";diff --git a/frontend/src/metabase/dashboard/components/DashCard/DashCardMenu/DashCardMenuItems.tsx b/frontend/src/metabase/dashboard/components/DashCard/DashCardMenu/DashCardMenuItems.tsxindex f872284069a..1774a901e5c 100644--- a/frontend/src/metabase/dashboard/components/DashCard/DashCardMenu/DashCardMenuItems.tsx+++ b/frontend/src/metabase/dashboard/components/DashCard/DashCardMenu/DashCardMenuItems.tsx@@ -7,6 +7,7 @@ import { SIDEBAR_NAME } from "metabase/dashboard/constants";import { useDashboardContext } from "metabase/dashboard/context";import { transformSdkQuestion } from "metabase/embedding-sdk/lib/transform-question";import type { DashboardCardCustomMenuItem } from "metabase/embedding-sdk/types/plugins";+import { canDownloadResults } from "metabase/lib/downloads";import { useDispatch } from "metabase/lib/redux";import { useMetabotEnabledEmbeddingAware } from "metabase/metabot/hooks";import { canAnalyzeQuestion } from "metabase/metabot/utils/chart-analysis";@@ -15,7 +16,7 @@ import type Question from "metabase-lib/v1/Question";import type { DashCardId, Dataset } from "metabase-types/api";import type { DashCardMenuItem } from "./dashcard-menu";-import { canDownloadResults, canEditQuestion } from "./utils";+import { canEditQuestion } from "./utils";type DashCardMenuItemsProps = {question: Question;diff --git a/frontend/src/metabase/dashboard/components/DashCard/DashCardMenu/utils.ts b/frontend/src/metabase/dashboard/components/DashCard/DashCardMenu/utils.tsindex d2f086b2ade..bf2047b675e 100644--- a/frontend/src/metabase/dashboard/components/DashCard/DashCardMenu/utils.ts+++ b/frontend/src/metabase/dashboard/components/DashCard/DashCardMenu/utils.ts@@ -1,7 +1,5 @@-import { PLUGIN_FEATURE_LEVEL_PERMISSIONS } from "metabase/plugins";import * as Lib from "metabase-lib";import type Question from "metabase-lib/v1/Question";-import type { Dataset } from "metabase-types/api";export const canEditQuestion = (question: Question) => {// question.query() is an expensive call, short circuit when possible@@ -12,11 +10,3 @@ export const canEditQuestion = (question: Question) => {const { isEditable } = Lib.queryDisplayInfo(question.query());return isEditable;};--export const canDownloadResults = (result?: Dataset) => {- return (- !!result?.data &&- !result.error &&- PLUGIN_FEATURE_LEVEL_PERMISSIONS.canDownloadResults(result)- );-};diff --git a/frontend/src/metabase/dashboard/components/DashCard/DashCardParameterMapper/DashCardCardParameterMapper.tsx b/frontend/src/metabase/dashboard/components/DashCard/DashCardParameterMapper/DashCardCardParameterMapper.tsxindex 0dc67f78486..0ecc711b858 100644--- a/frontend/src/metabase/dashboard/components/DashCard/DashCardParameterMapper/DashCardCardParameterMapper.tsx+++ b/frontend/src/metabase/dashboard/components/DashCard/DashCardParameterMapper/DashCardCardParameterMapper.tsx@@ -8,7 +8,8 @@ import {getParameterTarget,getQuestionByCard,} from "metabase/dashboard/selectors";-import { isNativeDashCard, isQuestionDashCard } from "metabase/dashboard/utils";+import { isNativeDashCard } from "metabase/dashboard/utils";+import { isQuestionDashCard } from "metabase/lib/dashboard";import { connect } from "metabase/lib/redux";import {type ParameterMappingOption,diff --git a/frontend/src/metabase/dashboard/components/DashCard/DashCardParameterMapper/DashCardCardParameterMapperContent.tsx b/frontend/src/metabase/dashboard/components/DashCard/DashCardParameterMapper/DashCardCardParameterMapperContent.tsxindex acc349a47a9..b0e93eb19b4 100644--- a/frontend/src/metabase/dashboard/components/DashCard/DashCardParameterMapper/DashCardCardParameterMapperContent.tsx+++ b/frontend/src/metabase/dashboard/components/DashCard/DashCardParameterMapper/DashCardCardParameterMapperContent.tsx@@ -8,10 +8,9 @@ import CS from "metabase/css/core/index.css";import { setParameterMapping } from "metabase/dashboard/actions/parameters";import {getVirtualCardType,- isQuestionDashCard,- isVirtualDashCard,showVirtualDashCardInfoText,} from "metabase/dashboard/utils";+import { isQuestionDashCard, isVirtualDashCard } from "metabase/lib/dashboard";import { useDispatch } from "metabase/lib/redux";import type { ParameterMappingOption } from "metabase/parameters/utils/mapping-options";import {diff --git a/frontend/src/metabase/dashboard/components/DashCard/DashCardParameterMapper/DashCardParameterMapper.tsx b/frontend/src/metabase/dashboard/components/DashCard/DashCardParameterMapper/DashCardParameterMapper.tsxindex 7da38d575ac..1ab9a241b1c 100644--- a/frontend/src/metabase/dashboard/components/DashCard/DashCardParameterMapper/DashCardParameterMapper.tsx+++ b/frontend/src/metabase/dashboard/components/DashCard/DashCardParameterMapper/DashCardParameterMapper.tsx@@ -2,7 +2,7 @@ import cx from "classnames";import { t } from "ttag";import CS from "metabase/css/core/index.css";-import { isQuestionDashCard } from "metabase/dashboard/utils";+import { isQuestionDashCard } from "metabase/lib/dashboard";import { Flex } from "metabase/ui";import { color } from "metabase/ui/utils/colors";import type { DashboardCard } from "metabase-types/api";diff --git a/frontend/src/metabase/dashboard/components/DashCard/DashCardVisualization.tsx b/frontend/src/metabase/dashboard/components/DashCard/DashCardVisualization.tsxindex 04012470c86..03d6a3c1b88 100644--- a/frontend/src/metabase/dashboard/components/DashCard/DashCardVisualization.tsx+++ b/frontend/src/metabase/dashboard/components/DashCard/DashCardVisualization.tsx@@ -13,11 +13,9 @@ import {getDashCardInlineValuePopulatedParameters,getDashcardData,} from "metabase/dashboard/selectors";-import {- getVirtualCardType,- isVirtualDashCard,-} from "metabase/dashboard/utils";+import { getVirtualCardType } from "metabase/dashboard/utils";import { EmbeddingEntityContextProvider } from "metabase/embedding/context";+import { isVirtualDashCard } from "metabase/lib/dashboard";import { duration } from "metabase/lib/formatting";import { measureTextWidth } from "metabase/lib/measure-text";import { useSelector } from "metabase/lib/redux";diff --git a/frontend/src/metabase/dashboard/components/DashCard/PublicOrEmbeddedDashCardMenu.tsx b/frontend/src/metabase/dashboard/components/DashCard/PublicOrEmbeddedDashCardMenu.tsxindex ad9b1210087..34cefdd70e3 100644--- a/frontend/src/metabase/dashboard/components/DashCard/PublicOrEmbeddedDashCardMenu.tsx+++ b/frontend/src/metabase/dashboard/components/DashCard/PublicOrEmbeddedDashCardMenu.tsx@@ -3,12 +3,12 @@ import cx from "classnames";import { useMemo, useState } from "react";import { t } from "ttag";+import { QuestionDownloadWidget } from "metabase/common/components/QuestionDownloadWidget";+import { useDownloadData } from "metabase/common/components/QuestionDownloadWidget/use-download-data";import { useDashboardContext } from "metabase/dashboard/context";import { getParameterValuesBySlugMap } from "metabase/dashboard/selectors";import { useSelector, useStore } from "metabase/lib/redux";import { checkNotNull } from "metabase/lib/types";-import { QuestionDownloadWidget } from "metabase/query_builder/components/QuestionDownloadWidget";-import { useDownloadData } from "metabase/query_builder/components/QuestionDownloadWidget/use-download-data";import { getMetadata } from "metabase/selectors/metadata";import { ActionIcon, Icon, Menu } from "metabase/ui";import { SAVING_DOM_IMAGE_HIDDEN_CLASS } from "metabase/visualizations/lib/save-chart-image";diff --git a/frontend/src/metabase/dashboard/components/DashboardGrid.tsx b/frontend/src/metabase/dashboard/components/DashboardGrid.tsxindex 5e9d8c0e503..49951d1f82c 100644--- a/frontend/src/metabase/dashboard/components/DashboardGrid.tsx+++ b/frontend/src/metabase/dashboard/components/DashboardGrid.tsx@@ -17,10 +17,8 @@ import {} from "metabase/common/components/Pickers/QuestionPicker";import { ContentViewportContext } from "metabase/common/context/ContentViewportContext";import DashboardS from "metabase/css/dashboard.module.css";-import {- getVisibleCardIds,- isQuestionDashCard,-} from "metabase/dashboard/utils";+import { getVisibleCardIds } from "metabase/dashboard/utils";+import { isQuestionDashCard } from "metabase/lib/dashboard";import {GRID_ASPECT_RATIO,GRID_BREAKPOINTS,diff --git a/frontend/src/metabase/dashboard/components/DashboardHeader/DashboardHeaderView.tsx b/frontend/src/metabase/dashboard/components/DashboardHeader/DashboardHeaderView.tsxindex 3c1d05410a6..ddabb1f7e42 100644--- a/frontend/src/metabase/dashboard/components/DashboardHeader/DashboardHeaderView.tsx+++ b/frontend/src/metabase/dashboard/components/DashboardHeader/DashboardHeaderView.tsx@@ -5,6 +5,7 @@ import { useCallback, useEffect, useMemo, useRef, useState } from "react";import { isInstanceAnalyticsCollection } from "metabase/collections/utils";import { EditBar } from "metabase/common/components/EditBar";import { LastEditInfoLabel } from "metabase/common/components/LastEditInfoLabel";+import { SIDEBAR_WIDTH } from "metabase/common/components/Sidebar";import CS from "metabase/css/core/index.css";import {applyDraftParameterValues,@@ -31,7 +32,6 @@ import type { Collection, Dashboard as IDashboard } from "metabase-types/api";import { Dashboard } from "../Dashboard";import { FixedWidthContainer } from "../Dashboard/DashboardComponents";-import { SIDEBAR_WIDTH } from "../Sidebar";import S from "./DashboardHeaderView.module.css";diff --git a/frontend/src/metabase/dashboard/components/DashboardTabs/DashboardTabs.tsx b/frontend/src/metabase/dashboard/components/DashboardTabs/DashboardTabs.tsxindex c9ad1bd37fe..88738302294 100644--- a/frontend/src/metabase/dashboard/components/DashboardTabs/DashboardTabs.tsx+++ b/frontend/src/metabase/dashboard/components/DashboardTabs/DashboardTabs.tsx@@ -10,7 +10,7 @@ import { TabRow } from "metabase/common/components/TabRow";import { useConfirmation } from "metabase/common/hooks/use-confirmation";import CS from "metabase/css/core/index.css";import { useDashboardContext } from "metabase/dashboard/context";-import { isVirtualDashCard } from "metabase/dashboard/utils";+import { isVirtualDashCard } from "metabase/lib/dashboard";import { useRegisterShortcut } from "metabase/palette/hooks/useRegisterShortcut";import { Flex, List } from "metabase/ui";import type { SelectedTabId } from "metabase-types/store";diff --git a/frontend/src/metabase/dashboard/containers/CopyDashboardForm.tsx b/frontend/src/metabase/dashboard/containers/CopyDashboardForm.tsxindex e0c764fa513..7cce6a5b7f6 100644--- a/frontend/src/metabase/dashboard/containers/CopyDashboardForm.tsx+++ b/frontend/src/metabase/dashboard/containers/CopyDashboardForm.tsx@@ -19,6 +19,7 @@ import {FormTextInput,FormTextarea,} from "metabase/forms";+import { isVirtualDashCard } from "metabase/lib/dashboard";import * as Errors from "metabase/lib/errors";import { Group, Icon, Tooltip } from "metabase/ui";import type { CollectionId, Dashboard, DashboardId } from "metabase-types/api";@@ -27,7 +28,6 @@ import {DASHBOARD_DESCRIPTION_MAX_LENGTH,DASHBOARD_NAME_MAX_LENGTH,} from "../constants";-import { isVirtualDashCard } from "../utils";const DASHBOARD_SCHEMA = Yup.object({name: Yup.string()diff --git a/frontend/src/metabase/dashboard/selectors.ts b/frontend/src/metabase/dashboard/selectors.tsindex 55bb63c34d6..0e244791c58 100644--- a/frontend/src/metabase/dashboard/selectors.ts+++ b/frontend/src/metabase/dashboard/selectors.ts@@ -8,6 +8,7 @@ import {SIDEBAR_NAME,} from "metabase/dashboard/constants";import { isEmbeddingSdk } from "metabase/embedding-sdk/config";+import { isQuestionCard, isQuestionDashCard } from "metabase/lib/dashboard";import { isNotNull } from "metabase/lib/types";import * as Urls from "metabase/lib/urls";import {@@ -56,8 +57,6 @@ import {hasDatabaseActionsEnabled,hasInlineParameters,isDashcardInlineParameter,- isQuestionCard,- isQuestionDashCard,} from "./utils";type SidebarState = State["dashboard"]["sidebar"];diff --git a/frontend/src/metabase/dashboard/utils.ts b/frontend/src/metabase/dashboard/utils.tsindex fb0e26c6d96..f17e297e378 100644--- a/frontend/src/metabase/dashboard/utils.ts+++ b/frontend/src/metabase/dashboard/utils.ts@@ -1,11 +1,10 @@import type { Location } from "history";import _ from "underscore";+import { isQuestionDashCard, isVirtualDashCard } from "metabase/lib/dashboard";import { SERVER_ERROR_TYPES } from "metabase/lib/errors";import { isStaticEmbeddingEntityLoadingError } from "metabase/lib/errors/is-static-embedding-entity-loading-error";import type { StaticEmbeddingEntityError } from "metabase/lib/errors/types";-import { isJWT } from "metabase/lib/utils";-import { isUuid } from "metabase/lib/uuid";import {getGenericErrorMessage,getPermissionErrorMessage,@@ -87,36 +86,6 @@ export function expandInlineCard(card?: Card | VirtualCard) {};}-export function isQuestionCard(card: Card | VirtualCard) {- // Some old virtual cards have dataset_query equal to {} so we need to check for null and empty object- return (- card.dataset_query != null && Object.keys(card.dataset_query).length > 0- );-}--export function isQuestionDashCard(- dashcard: BaseDashboardCard,-): dashcard is QuestionDashboardCard {- return (- "card_id" in dashcard &&- "card" in dashcard &&- !isVirtualDashCard(dashcard) &&- !isActionDashCard(dashcard)- );-}--export function isActionDashCard(- dashcard: BaseDashboardCard,-): dashcard is ActionDashboardCard {- return "action" in dashcard;-}--export function isVirtualDashCard(- dashcard: Pick<BaseDashboardCard, "visualization_settings">,-): dashcard is VirtualDashboardCard {- return _.isObject(dashcard?.visualization_settings?.virtual_card);-}-export function getVirtualCardType(dashcard: BaseDashboardCard) {return dashcard?.visualization_settings?.virtual_card?.display;}@@ -243,25 +212,6 @@ export function hasDatabaseActionsEnabled(database: Database) {return database.settings?.["database-enable-actions"] ?? false;}-export function isTransientId(id: unknown) {- return typeof id === "string" && /\/auto\/dashboard/.test(id);-}--export function getDashboardType(id: unknown) {- if (id == null || typeof id === "object") {- // HACK: support inline dashboards- return "inline";- } else if (isUuid(id)) {- return "public";- } else if (isJWT(id)) {- return "embed";- } else if (isTransientId(id)) {- return "transient";- } else {- return "normal";- }-}-export async function fetchDataOrError<T>(dataPromise: Promise<T>) {try {return await dataPromise;diff --git a/frontend/src/metabase/lib/dashboard.ts b/frontend/src/metabase/lib/dashboard.tsnew file mode 100644index 00000000000..51a69b82c56--- /dev/null+++ b/frontend/src/metabase/lib/dashboard.ts@@ -0,0 +1,61 @@+import _ from "underscore";++import { isJWT } from "metabase/lib/utils";+import { isUuid } from "metabase/lib/uuid";+import type {+ ActionDashboardCard,+ BaseDashboardCard,+ Card,+ QuestionDashboardCard,+ VirtualCard,+ VirtualDashboardCard,+} from "metabase-types/api";++export function isQuestionCard(card: Card | VirtualCard) {+ // Some old virtual cards have dataset_query equal to {} so we need to check for null and empty object+ return (+ card.dataset_query != null && Object.keys(card.dataset_query).length > 0+ );+}++export function isActionDashCard(+ dashcard: BaseDashboardCard,+): dashcard is ActionDashboardCard {+ return "action" in dashcard;+}++export function isVirtualDashCard(+ dashcard: Pick<BaseDashboardCard, "visualization_settings">,+): dashcard is VirtualDashboardCard {+ return _.isObject(dashcard?.visualization_settings?.virtual_card);+}++export function isQuestionDashCard(+ dashcard: BaseDashboardCard,+): dashcard is QuestionDashboardCard {+ return (+ "card_id" in dashcard &&+ "card" in dashcard &&+ !isVirtualDashCard(dashcard) &&+ !isActionDashCard(dashcard)+ );+}++export function isTransientId(id: unknown) {+ return typeof id === "string" && /\/auto\/dashboard/.test(id);+}++export function getDashboardType(id: unknown) {+ if (id == null || typeof id === "object") {+ // HACK: support inline dashboards+ return "inline";+ } else if (isUuid(id)) {+ return "public";+ } else if (isJWT(id)) {+ return "embed";+ } else if (isTransientId(id)) {+ return "transient";+ } else {+ return "normal";+ }+}diff --git a/frontend/src/metabase/lib/downloads.ts b/frontend/src/metabase/lib/downloads.tsnew file mode 100644index 00000000000..2d2ca8467ea--- /dev/null+++ b/frontend/src/metabase/lib/downloads.ts@@ -0,0 +1,10 @@+import { PLUGIN_FEATURE_LEVEL_PERMISSIONS } from "metabase/plugins";+import type { Dataset } from "metabase-types/api";++export const canDownloadResults = (result?: Dataset) => {+ return (+ !!result?.data &&+ !result.error &&+ PLUGIN_FEATURE_LEVEL_PERMISSIONS.canDownloadResults(result)+ );+};diff --git a/frontend/src/metabase/lib/notifications.ts b/frontend/src/metabase/lib/notifications.tsindex f6c6f6e705d..49d4797eb0b 100644--- a/frontend/src/metabase/lib/notifications.ts+++ b/frontend/src/metabase/lib/notifications.ts@@ -2,7 +2,7 @@ import { c, msgid, ngettext, t } from "ttag";import _ from "underscore";import type { NotificationListItem } from "metabase/account/notifications/types";-import { cronToScheduleSettings } from "metabase/admin/performance/utils";+import { cronToScheduleSettings } from "metabase/common/components/Schedule/cron";import { getEmailDomain, isEmail } from "metabase/lib/email";import { formatDateTimeWithUnit } from "metabase/lib/formatting/date";import { formatTimeWithUnit } from "metabase/lib/formatting/time";diff --git a/frontend/src/metabase/metabot/components/AIDashboardAnalysisSidebar/AIDashboardAnalysisSidebar.tsx b/frontend/src/metabase/metabot/components/AIDashboardAnalysisSidebar/AIDashboardAnalysisSidebar.tsxindex 142ab3ab081..4726f4ae3e3 100644--- a/frontend/src/metabase/metabot/components/AIDashboardAnalysisSidebar/AIDashboardAnalysisSidebar.tsx+++ b/frontend/src/metabase/metabot/components/AIDashboardAnalysisSidebar/AIDashboardAnalysisSidebar.tsx@@ -1,6 +1,6 @@import { t } from "ttag";-import { Sidebar } from "metabase/dashboard/components/Sidebar";+import { Sidebar } from "metabase/common/components/Sidebar";import { useDashboardContext } from "metabase/dashboard/context";import { getIsDashCardsLoadingComplete } from "metabase/dashboard/selectors";import { useSelector } from "metabase/lib/redux";diff --git a/frontend/src/metabase/notifications/AddEditSidebar/AddEditEmailSidebar.tsx b/frontend/src/metabase/notifications/AddEditSidebar/AddEditEmailSidebar.tsxindex d18120e702a..b99065e0633 100644--- a/frontend/src/metabase/notifications/AddEditSidebar/AddEditEmailSidebar.tsx+++ b/frontend/src/metabase/notifications/AddEditSidebar/AddEditEmailSidebar.tsx@@ -9,9 +9,9 @@ import {SchedulePicker,} from "metabase/common/components/SchedulePicker";import { SendTestPulse } from "metabase/common/components/SendTestPulse";+import { Sidebar } from "metabase/common/components/Sidebar";import { Toggle } from "metabase/common/components/Toggle";import CS from "metabase/css/core/index.css";-import { Sidebar } from "metabase/dashboard/components/Sidebar";import { isEmbeddingSdk } from "metabase/embedding-sdk/config";import { dashboardPulseIsValid } from "metabase/lib/pulse";import { useSelector } from "metabase/lib/redux";diff --git a/frontend/src/metabase/notifications/AddEditSidebar/AddEditSlackSidebar.tsx b/frontend/src/metabase/notifications/AddEditSidebar/AddEditSlackSidebar.tsxindex f523fc209f9..ea389d939ac 100644--- a/frontend/src/metabase/notifications/AddEditSidebar/AddEditSlackSidebar.tsx+++ b/frontend/src/metabase/notifications/AddEditSidebar/AddEditSlackSidebar.tsx@@ -7,9 +7,9 @@ import {SchedulePicker,} from "metabase/common/components/SchedulePicker";import { SendTestPulse } from "metabase/common/components/SendTestPulse";+import { Sidebar } from "metabase/common/components/Sidebar";import { Toggle } from "metabase/common/components/Toggle";import CS from "metabase/css/core/index.css";-import { Sidebar } from "metabase/dashboard/components/Sidebar";import { dashboardPulseIsValid } from "metabase/lib/pulse";import { SlackChannelField } from "metabase/notifications/channels/SlackChannelField";import { PLUGIN_DASHBOARD_SUBSCRIPTION_PARAMETERS_SECTION_OVERRIDE } from "metabase/plugins";diff --git a/frontend/src/metabase/notifications/DashboardSubscriptionsSidebar/DashboardSubscriptionsSidebar.tsx b/frontend/src/metabase/notifications/DashboardSubscriptionsSidebar/DashboardSubscriptionsSidebar.tsxindex 2d4f46e7384..0fe63dc2792 100644--- a/frontend/src/metabase/notifications/DashboardSubscriptionsSidebar/DashboardSubscriptionsSidebar.tsx+++ b/frontend/src/metabase/notifications/DashboardSubscriptionsSidebar/DashboardSubscriptionsSidebar.tsx@@ -3,7 +3,7 @@ import _ from "underscore";import { LoadingAndErrorWrapper } from "metabase/common/components/LoadingAndErrorWrapper";import type { ScheduleChangeProp } from "metabase/common/components/SchedulePicker";-import { Sidebar } from "metabase/dashboard/components/Sidebar";+import { Sidebar } from "metabase/common/components/Sidebar";import { useDashboardContext } from "metabase/dashboard/context";import { isEmbeddingSdk } from "metabase/embedding-sdk/config";import { Pulses } from "metabase/entities/pulses";diff --git a/frontend/src/metabase/notifications/NewPulseSidebar.tsx b/frontend/src/metabase/notifications/NewPulseSidebar.tsxindex ad298873cca..8785608174f 100644--- a/frontend/src/metabase/notifications/NewPulseSidebar.tsx+++ b/frontend/src/metabase/notifications/NewPulseSidebar.tsx@@ -1,7 +1,7 @@import { t } from "ttag";import { Link } from "metabase/common/components/Link";-import { Sidebar } from "metabase/dashboard/components/Sidebar";+import { Sidebar } from "metabase/common/components/Sidebar";import { useSelector } from "metabase/lib/redux";import { ChannelCard } from "metabase/notifications/pulse/components/ChannelCard";import { getApplicationName } from "metabase/selectors/whitelabel";diff --git a/frontend/src/metabase/notifications/PulsesListSidebar.tsx b/frontend/src/metabase/notifications/PulsesListSidebar.tsxindex 23b7886e2c0..a8b3d9dfead 100644--- a/frontend/src/metabase/notifications/PulsesListSidebar.tsx+++ b/frontend/src/metabase/notifications/PulsesListSidebar.tsx@@ -2,10 +2,10 @@ import cx from "classnames";import { msgid, ngettext, t } from "ttag";import _ from "underscore";+import { Sidebar } from "metabase/common/components/Sidebar";import { Label } from "metabase/common/components/type/Label";import { Subhead } from "metabase/common/components/type/Subhead";import CS from "metabase/css/core/index.css";-import { Sidebar } from "metabase/dashboard/components/Sidebar";import { getParameters } from "metabase/dashboard/selectors";import {conjunct,diff --git a/frontend/src/metabase/notifications/modals/CreateOrEditQuestionAlertModal/components/NotificationSchedule/NotificationSchedule.tsx b/frontend/src/metabase/notifications/modals/CreateOrEditQuestionAlertModal/components/NotificationSchedule/NotificationSchedule.tsxindex d2c4599ee12..8f4db63e522 100644--- a/frontend/src/metabase/notifications/modals/CreateOrEditQuestionAlertModal/components/NotificationSchedule/NotificationSchedule.tsx+++ b/frontend/src/metabase/notifications/modals/CreateOrEditQuestionAlertModal/components/NotificationSchedule/NotificationSchedule.tsx@@ -1,12 +1,12 @@import { type HTMLAttributes, useCallback, useMemo } from "react";import { c, t } from "ttag";+import { Schedule } from "metabase/common/components/Schedule/Schedule";import {cronToScheduleSettings,cronUnitToNumber,isRepeatingEvery,-} from "metabase/admin/performance/utils";-import { Schedule } from "metabase/common/components/Schedule/Schedule";+} from "metabase/common/components/Schedule/cron";import { getScheduleExplanation } from "metabase/lib/cron";import { formatNotificationScheduleDescription } from "metabase/lib/notifications";import { useSelector } from "metabase/lib/redux";diff --git a/frontend/src/metabase/parameters/components/ParameterSettings/MoveParameterMenu/MoveParameterMenu.tsx b/frontend/src/metabase/parameters/components/ParameterSettings/MoveParameterMenu/MoveParameterMenu.tsxindex 0b5836b453f..03dca069708 100644--- a/frontend/src/metabase/parameters/components/ParameterSettings/MoveParameterMenu/MoveParameterMenu.tsx+++ b/frontend/src/metabase/parameters/components/ParameterSettings/MoveParameterMenu/MoveParameterMenu.tsx@@ -9,8 +9,8 @@ import { getCurrentDashcards, getTabs } from "metabase/dashboard/selectors";import {findDashCardForInlineParameter,isHeadingDashCard,- isQuestionDashCard,} from "metabase/dashboard/utils";+import { isQuestionDashCard } from "metabase/lib/dashboard";import { useDispatch, useSelector } from "metabase/lib/redux";import { Flex, Group, Icon, type IconName, Select, Text } from "metabase/ui";import visualizations from "metabase/visualizations";diff --git a/frontend/src/metabase/parameters/components/ParameterSettings/ParameterSettings.tsx b/frontend/src/metabase/parameters/components/ParameterSettings/ParameterSettings.tsxindex 3e7fa9e322b..9d6a0e11f72 100644--- a/frontend/src/metabase/parameters/components/ParameterSettings/ParameterSettings.tsx+++ b/frontend/src/metabase/parameters/components/ParameterSettings/ParameterSettings.tsx@@ -8,7 +8,7 @@ import {import { t } from "ttag";import { resetParameterMapping } from "metabase/dashboard/actions";-import { isQuestionDashCard } from "metabase/dashboard/utils";+import { isQuestionDashCard } from "metabase/lib/dashboard";import { useDispatch } from "metabase/lib/redux";import {getDashboardParameterSections,diff --git a/frontend/src/metabase/parameters/components/ParameterSidebar/ParameterSidebar.tsx b/frontend/src/metabase/parameters/components/ParameterSidebar/ParameterSidebar.tsxindex 9eb87157245..017c9262464 100644--- a/frontend/src/metabase/parameters/components/ParameterSidebar/ParameterSidebar.tsx+++ b/frontend/src/metabase/parameters/components/ParameterSidebar/ParameterSidebar.tsx@@ -2,7 +2,7 @@ import { useCallback, useEffect, useMemo, useState } from "react";import { usePrevious } from "react-use";import { t } from "ttag";-import { Sidebar } from "metabase/dashboard/components/Sidebar";+import { Sidebar } from "metabase/common/components/Sidebar";import { useDashboardContext } from "metabase/dashboard/context";import {getEditingParameterInlineDashcard,diff --git a/frontend/src/metabase/parameters/components/widgets/ParameterFieldWidget/FieldValuesWidget/utils.ts b/frontend/src/metabase/parameters/components/widgets/ParameterFieldWidget/FieldValuesWidget/utils.tsindex 5f3201ab332..8baf9a9e243 100644--- a/frontend/src/metabase/parameters/components/widgets/ParameterFieldWidget/FieldValuesWidget/utils.ts+++ b/frontend/src/metabase/parameters/components/widgets/ParameterFieldWidget/FieldValuesWidget/utils.ts@@ -1,7 +1,7 @@import { t } from "ttag";import _ from "underscore";-import { isTransientId } from "metabase/dashboard/utils";+import { isTransientId } from "metabase/lib/dashboard";import { stripId } from "metabase/lib/formatting";import type { ComboboxItem } from "metabase/ui";import type Field from "metabase-lib/v1/metadata/Field";diff --git a/frontend/src/metabase/parameters/utils/dashboards.ts b/frontend/src/metabase/parameters/utils/dashboards.tsindex c3932388276..5a18f335c52 100644--- a/frontend/src/metabase/parameters/utils/dashboards.ts+++ b/frontend/src/metabase/parameters/utils/dashboards.ts@@ -1,7 +1,7 @@import _ from "underscore";import { tag_names } from "cljs/metabase.parameters.shared";-import { isQuestionCard, isQuestionDashCard } from "metabase/dashboard/utils";+import { isQuestionCard, isQuestionDashCard } from "metabase/lib/dashboard";import { slugify } from "metabase/lib/formatting";import { isNotNull } from "metabase/lib/types";import { generateParameterId } from "metabase/parameters/utils/parameter-id";diff --git a/frontend/src/metabase/parameters/utils/mapping-options.ts b/frontend/src/metabase/parameters/utils/mapping-options.tsindex a17046a68ca..bd980606c35 100644--- a/frontend/src/metabase/parameters/utils/mapping-options.ts+++ b/frontend/src/metabase/parameters/utils/mapping-options.ts@@ -7,7 +7,7 @@ import {isActionDashCard,isQuestionDashCard,isVirtualDashCard,-} from "metabase/dashboard/utils";+} from "metabase/lib/dashboard";import { getGroupName } from "metabase/querying/filters/utils/groups";import { getAllowedIframeAttributes } from "metabase/visualizations/visualizations/IFrameViz/utils";import * as Lib from "metabase-lib";diff --git a/frontend/src/metabase/public/components/EmbedFrame/EmbedFrame.tsx b/frontend/src/metabase/public/components/EmbedFrame/EmbedFrame.tsxindex 2faf669ee34..569a4a849a2 100644--- a/frontend/src/metabase/public/components/EmbedFrame/EmbedFrame.tsx+++ b/frontend/src/metabase/public/components/EmbedFrame/EmbedFrame.tsx@@ -14,9 +14,9 @@ import {DASHBOARD_PDF_EXPORT_ROOT_ID,} from "metabase/dashboard/constants";import { useIsParameterPanelSticky } from "metabase/dashboard/hooks/use-is-parameter-panel-sticky";-import { getDashboardType } from "metabase/dashboard/utils";import { EmbeddingFooter } from "metabase/embedding/components/EmbeddingFooter/EmbeddingFooter";import { isEmbeddingSdk } from "metabase/embedding-sdk/config";+import { getDashboardType } from "metabase/lib/dashboard";import { initializeIframeResizer, isSmallScreen } from "metabase/lib/dom";import { useSelector } from "metabase/lib/redux";import { FilterApplyToast } from "metabase/parameters/components/FilterApplyToast";diff --git a/frontend/src/metabase/public/containers/PublicOrEmbeddedDashboard/PublicOrEmbeddedDashboard.tsx b/frontend/src/metabase/public/containers/PublicOrEmbeddedDashboard/PublicOrEmbeddedDashboard.tsxindex 2edc1381b95..c48f0f08b0a 100644--- a/frontend/src/metabase/public/containers/PublicOrEmbeddedDashboard/PublicOrEmbeddedDashboard.tsx+++ b/frontend/src/metabase/public/containers/PublicOrEmbeddedDashboard/PublicOrEmbeddedDashboard.tsx@@ -5,7 +5,7 @@ import {type DashboardContextProps,DashboardContextProvider,} from "metabase/dashboard/context";-import { isActionDashCard, isQuestionCard } from "metabase/dashboard/utils";+import { isActionDashCard, isQuestionCard } from "metabase/lib/dashboard";import type { EmbeddingAdditionalHashOptions } from "metabase/public/lib/types";import { PublicOrEmbeddedDashboardView } from "./PublicOrEmbeddedDashboardView";diff --git a/frontend/src/metabase/public/containers/PublicOrEmbeddedDashboard/PublicOrEmbeddedDashboardPage/PublicOrEmbeddedDashboardPage.tsx b/frontend/src/metabase/public/containers/PublicOrEmbeddedDashboard/PublicOrEmbeddedDashboardPage/PublicOrEmbeddedDashboardPage.tsxindex 45576cfa7fb..d682f59f039 100644--- a/frontend/src/metabase/public/containers/PublicOrEmbeddedDashboard/PublicOrEmbeddedDashboardPage/PublicOrEmbeddedDashboardPage.tsx+++ b/frontend/src/metabase/public/containers/PublicOrEmbeddedDashboard/PublicOrEmbeddedDashboardPage/PublicOrEmbeddedDashboardPage.tsx@@ -5,8 +5,8 @@ import { DASHBOARD_DISPLAY_ACTIONS } from "metabase/dashboard/components/Dashboaimport { useDashboardLocationSync } from "metabase/dashboard/containers/DashboardApp/use-dashboard-location-sync";import { DashboardContextProvider } from "metabase/dashboard/context";import { useDashboardUrlQuery } from "metabase/dashboard/hooks/use-dashboard-url-query";-import { isActionDashCard, isQuestionCard } from "metabase/dashboard/utils";import { EmbeddingEntityContextProvider } from "metabase/embedding/context";+import { isActionDashCard, isQuestionCard } from "metabase/lib/dashboard";import { useDispatch, useSelector } from "metabase/lib/redux";import { LocaleProvider } from "metabase/public/LocaleProvider";import { useEmbedFrameOptions, useSetEmbedFont } from "metabase/public/hooks";diff --git a/frontend/src/metabase/query_builder/components/QuestionDownloadPopover/QuestionDownloadPopover.tsx b/frontend/src/metabase/query_builder/components/QuestionDownloadPopover/QuestionDownloadPopover.tsxindex f4d2b0d18a1..08b092b145e 100644--- a/frontend/src/metabase/query_builder/components/QuestionDownloadPopover/QuestionDownloadPopover.tsx+++ b/frontend/src/metabase/query_builder/components/QuestionDownloadPopover/QuestionDownloadPopover.tsx@@ -2,10 +2,12 @@ import cx from "classnames";import { useState } from "react";import { t } from "ttag";-import type {- ExportFormat,- TableExportFormat,-} from "metabase/common/types/export";+import {+ type FormatPreference,+ QuestionDownloadWidget,+ type UseDownloadDataParams,+ useDownloadData,+} from "metabase/common/components/QuestionDownloadWidget";import { useEmbeddingEntityContext } from "metabase/embedding/context";import { PLUGIN_FEATURE_LEVEL_PERMISSIONS } from "metabase/plugins";import {@@ -18,14 +20,10 @@ import {} from "metabase/ui";import type { Dataset } from "metabase-types/api";-import { QuestionDownloadWidget } from "../QuestionDownloadWidget";-import {- type UseDownloadDataParams,- useDownloadData,-} from "../QuestionDownloadWidget/use-download-data";-import S from "./QuestionDownloadPopover.module.css";+export type { FormatPreference };+export type QuestionDownloadPopoverProps = {className?: string;floating?: boolean;@@ -33,11 +31,6 @@ export type QuestionDownloadPopoverProps = {Pick<ActionIconProps, "variant"> &Partial<Omit<UseDownloadDataParams, "question" | "result">>;-export type FormatPreference = {- last_download_format: ExportFormat;- last_table_download_format: TableExportFormat;-};-export type BaseQuestionDownloadPopoverProps = QuestionDownloadPopoverProps & {formatPreference?: FormatPreference;};diff --git a/frontend/src/metabase/query_builder/components/QuestionDownloadWidget/QuestionDownloadWidget.unit.spec.tsx b/frontend/src/metabase/query_builder/components/QuestionDownloadWidget/QuestionDownloadWidget.unit.spec.tsxindex a2e6d6fbbd5..1cd9f437dd4 100644--- a/frontend/src/metabase/query_builder/components/QuestionDownloadWidget/QuestionDownloadWidget.unit.spec.tsx+++ b/frontend/src/metabase/query_builder/components/QuestionDownloadWidget/QuestionDownloadWidget.unit.spec.tsx@@ -7,6 +7,7 @@ import {import { mockSettings } from "__support__/settings";import { createMockEntitiesState } from "__support__/store";import { act, renderWithProviders, screen } from "__support__/ui";+import { QuestionDownloadWidget } from "metabase/common/components/QuestionDownloadWidget";import { checkNotNull } from "metabase/lib/types";import { getMetadata } from "metabase/selectors/metadata";import registerVisualizations from "metabase/visualizations/register";@@ -19,8 +20,6 @@ import {import { ORDERS_ID, SAMPLE_DB_ID } from "metabase-types/api/mocks/presets";import { createMockState } from "metabase-types/store/mocks";-import { QuestionDownloadWidget } from "./QuestionDownloadWidget";-registerVisualizations();const TEST_CARD = createMockCard({diff --git a/frontend/src/metabase/query_builder/components/QuestionDownloadWidget/index.ts b/frontend/src/metabase/query_builder/components/QuestionDownloadWidget/index.tsdeleted file mode 100644index d714a5ac7bc..00000000000--- a/frontend/src/metabase/query_builder/components/QuestionDownloadWidget/index.ts+++ /dev/null@@ -1 +0,0 @@-export { QuestionDownloadWidget } from "./QuestionDownloadWidget";diff --git a/frontend/src/metabase/query_builder/components/Warnings.unit.spec.js b/frontend/src/metabase/query_builder/components/Warnings.unit.spec.jsindex 4bc5ef44f2f..2c048bc57d4 100644--- a/frontend/src/metabase/query_builder/components/Warnings.unit.spec.js+++ b/frontend/src/metabase/query_builder/components/Warnings.unit.spec.js@@ -1,7 +1,7 @@import userEvent from "@testing-library/user-event";import { render, screen } from "__support__/ui";-import { Warnings } from "metabase/querying/components/QueryVisualization/Warnings";+import { Warnings } from "metabase/common/components/Warnings";describe("Warnings", () => {it("should render a warning icon", () => {diff --git a/frontend/src/metabase/querying/components/QueryVisualization/QueryVisualization.jsx b/frontend/src/metabase/querying/components/QueryVisualization/QueryVisualization.jsxindex b9f297e7498..afdb8565e35 100644--- a/frontend/src/metabase/querying/components/QueryVisualization/QueryVisualization.jsx+++ b/frontend/src/metabase/querying/components/QueryVisualization/QueryVisualization.jsx@@ -6,6 +6,7 @@ import { c, t } from "ttag";import EmptyCodeResult from "assets/img/empty-states/code.svg";import { LoadingSpinner } from "metabase/common/components/LoadingSpinner";+import { Warnings } from "metabase/common/components/Warnings";import CS from "metabase/css/core/index.css";import QueryBuilderS from "metabase/css/query_builder.module.css";import { isMac } from "metabase/lib/browser";@@ -19,7 +20,6 @@ import { HARD_ROW_LIMIT } from "metabase-lib/v1/queries/utils";import { RunButtonWithTooltip } from "./RunButtonWithTooltip";import { VisualizationError } from "./VisualizationError";import { VisualizationResult } from "./VisualizationResult";-import { Warnings } from "./Warnings";const SLOW_MESSAGE_TIMEOUT = 4000;diff --git a/frontend/src/metabase/rich_text_editing/tiptap/extensions/CardEmbed/CardEmbedMenuDropdown.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/CardEmbed/CardEmbedMenuDropdown.tsxindex adac6f24bb8..a103ce416a8 100644--- a/frontend/src/metabase/rich_text_editing/tiptap/extensions/CardEmbed/CardEmbedMenuDropdown.tsx+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/CardEmbed/CardEmbedMenuDropdown.tsx@@ -1,9 +1,9 @@import { t } from "ttag";import { ForwardRefLink } from "metabase/common/components/Link";-import { canDownloadResults } from "metabase/dashboard/components/DashCard/DashCardMenu/utils";+import { QuestionDownloadWidget } from "metabase/common/components/QuestionDownloadWidget";import { isWithinIframe } from "metabase/lib/dom";-import { QuestionDownloadWidget } from "metabase/query_builder/components/QuestionDownloadWidget";+import { canDownloadResults } from "metabase/lib/downloads";import { Icon, Menu } from "metabase/ui";import type Question from "metabase-lib/v1/Question";import type { Dataset } from "metabase-types/api";diff --git a/frontend/src/metabase/rich_text_editing/tiptap/extensions/CardEmbed/CardEmbedNode.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/CardEmbed/CardEmbedNode.tsxindex 97a844b87ac..54cf3fa6877 100644--- a/frontend/src/metabase/rich_text_editing/tiptap/extensions/CardEmbed/CardEmbedNode.tsx+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/CardEmbed/CardEmbedNode.tsx@@ -17,6 +17,7 @@ import { Ellipsified } from "metabase/common/components/Ellipsified";import { ExplicitSizeRefreshModeContext } from "metabase/common/components/ExplicitSize/ExplicitSize";import { QuestionPickerModal } from "metabase/common/components/Pickers";import type { QuestionPickerValueItem } from "metabase/common/components/Pickers/QuestionPicker/types";+import { useDownloadData } from "metabase/common/components/QuestionDownloadWidget/use-download-data";import { navigateToCardFromDocument } from "metabase/documents/actions";import {trackDocumentAddSupportingText,@@ -39,7 +40,6 @@ import {import { useDispatch, useSelector } from "metabase/lib/redux";import { usePublicDocumentContext } from "metabase/public/contexts/PublicDocumentContext";import { usePublicDocumentCardData } from "metabase/public/hooks/use-public-document-card-data";-import { useDownloadData } from "metabase/query_builder/components/QuestionDownloadWidget/use-download-data";import { DropZone } from "metabase/rich_text_editing/tiptap/extensions/shared/dnd/DropZone";import { getMetadata } from "metabase/selectors/metadata";import { Box, Flex, Icon, Loader, Menu, Text, TextInput } from "metabase/ui";diff --git a/frontend/src/metabase/rich_text_editing/tiptap/extensions/CardEmbed/PublicDocumentCardMenu.tsx b/frontend/src/metabase/rich_text_editing/tiptap/extensions/CardEmbed/PublicDocumentCardMenu.tsxindex 1f052b7386d..4a1a1cf8202 100644--- a/frontend/src/metabase/rich_text_editing/tiptap/extensions/CardEmbed/PublicDocumentCardMenu.tsx+++ b/frontend/src/metabase/rich_text_editing/tiptap/extensions/CardEmbed/PublicDocumentCardMenu.tsx@@ -3,11 +3,11 @@ import cx from "classnames";import { useMemo, useState } from "react";import { t } from "ttag";+import { QuestionDownloadWidget } from "metabase/common/components/QuestionDownloadWidget";+import { useDownloadData } from "metabase/common/components/QuestionDownloadWidget/use-download-data";import { useSelector } from "metabase/lib/redux";import { checkNotNull } from "metabase/lib/types";import { usePublicDocumentContext } from "metabase/public/contexts/PublicDocumentContext";-import { QuestionDownloadWidget } from "metabase/query_builder/components/QuestionDownloadWidget";-import { useDownloadData } from "metabase/query_builder/components/QuestionDownloadWidget/use-download-data";import { getMetadata } from "metabase/selectors/metadata";import { ActionIcon, Icon, Menu } from "metabase/ui";import { SAVING_DOM_IMAGE_HIDDEN_CLASS } from "metabase/visualizations/lib/save-chart-image";diff --git a/frontend/src/metabase/visualizations/components/ChartSettings/ChartSettingsVisualization/ChartSettingsVisualization.styled.tsx b/frontend/src/metabase/visualizations/components/ChartSettings/ChartSettingsVisualization/ChartSettingsVisualization.styled.tsxindex df4d79cf8c5..b3548642b60 100644--- a/frontend/src/metabase/visualizations/components/ChartSettings/ChartSettingsVisualization/ChartSettingsVisualization.styled.tsx+++ b/frontend/src/metabase/visualizations/components/ChartSettings/ChartSettingsVisualization/ChartSettingsVisualization.styled.tsx@@ -1,7 +1,7 @@// eslint-disable-next-line no-restricted-importsimport styled from "@emotion/styled";-import { Warnings } from "metabase/querying/components/QueryVisualization/Warnings";+import { Warnings } from "metabase/common/components/Warnings";import { color } from "metabase/ui/colors";export const SectionWarnings = styled(Warnings)`diff --git a/frontend/src/metabase/visualizations/components/Visualization/Watermark/Watermark.tsx b/frontend/src/metabase/visualizations/components/Visualization/Watermark/Watermark.tsxindex 80246088cdf..ac0178b4af7 100644--- a/frontend/src/metabase/visualizations/components/Visualization/Watermark/Watermark.tsx+++ b/frontend/src/metabase/visualizations/components/Visualization/Watermark/Watermark.tsx@@ -1,4 +1,4 @@-import { isVirtualDashCard } from "metabase/dashboard/utils";+import { isVirtualDashCard } from "metabase/lib/dashboard";import type { BaseDashboardCard, Card } from "metabase-types/api";import S from "./Watermark.module.css";diff --git a/frontend/src/metabase/visualizations/lib/settings/visualization.ts b/frontend/src/metabase/visualizations/lib/settings/visualization.tsindex 00cfd89b0a6..b453472c123 100644--- a/frontend/src/metabase/visualizations/lib/settings/visualization.ts+++ b/frontend/src/metabase/visualizations/lib/settings/visualization.ts@@ -1,7 +1,7 @@import { assocIn } from "icepick";import { t } from "ttag";-import { isVirtualDashCard } from "metabase/dashboard/utils";+import { isVirtualDashCard } from "metabase/lib/dashboard";import { getVisualizationRaw } from "metabase/visualizations";import { trackCardSetToHideWhenNoResults } from "metabase/visualizations/lib/settings/analytics";import type {