Skip to content

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

fix(sdk): Fix SDK TSC errors (#64328)

Mahatthana (Kelvin) Nomsawadi7fcd8b3ef7e5
diff --git a/enterprise/frontend/src/.eslintrc.js b/enterprise/frontend/src/.eslintrc.js
index 0e922bd1f58..897d575af1c 100644
--- a/enterprise/frontend/src/.eslintrc.js
+++ b/enterprise/frontend/src/.eslintrc.js
@@ -1,8 +1,10 @@
/* eslint-disable no-undef,import/no-commonjs */
const path = require("path");
-const baseRestrictredConfig = {
- patterns: ["cljs/metabase.lib*"],
+const TEST_FILES_NAME_PATTERN_ERROR_MESSAGE = `Please name your test setup and utils files with a ".spec.*" in the filename, or put them under "/tests", e.g. "setup.spec.ts", "MyComponent.setup.spec.ts", or "tests/setup.ts". This is to ensure they won't be imported in the SDK build.`;
+
+const baseRestrictedConfig = {
+ patterns: [{ group: ["cljs/metabase.lib*"] }],
paths: [
{
name: "@mantine/core",
@@ -45,7 +47,19 @@ module.exports = {
// Note: adding this rule to a eslint config file in a subfolder will remove
// *not* carry over the restricted imports from parent folders, you will
// need to copy them over
- "no-restricted-imports": ["error", baseRestrictredConfig],
+ "no-restricted-imports": [
+ "error",
+ {
+ ...baseRestrictedConfig,
+ patterns: [
+ ...baseRestrictedConfig.patterns,
+ {
+ group: ["__support__/**", "!__support__/metadata"],
+ message: TEST_FILES_NAME_PATTERN_ERROR_MESSAGE,
+ },
+ ],
+ },
+ ],
"ttag/no-module-declaration": 2,
},
overrides: [
@@ -55,9 +69,15 @@ module.exports = {
"no-restricted-imports": [
"error",
{
- ...baseRestrictredConfig,
+ patterns: [
+ ...baseRestrictedConfig.patterns,
+ {
+ group: ["__support__/**"],
+ message: TEST_FILES_NAME_PATTERN_ERROR_MESSAGE,
+ },
+ ],
paths: [
- ...baseRestrictredConfig.paths,
+ ...baseRestrictedConfig.paths,
{
name: "metabase/lib/redux",
importNames: ["useStore", "useDispatch"],
@@ -68,6 +88,17 @@ module.exports = {
],
},
},
+ {
+ files: [
+ "**/*.spec.*",
+ "**/test-utils.*",
+ "**/tests/**/*",
+ "**/test/**/*",
+ ],
+ rules: {
+ "no-restricted-imports": ["error", baseRestrictedConfig],
+ },
+ },
{
files: ["**/.storybook/*", "**/*.stories.tsx"],
rules: {
diff --git a/enterprise/frontend/src/embedding-sdk-bundle/components/private/SdkBreadcrumbs/SdkBreadcrumbs.unit.spec.tsx b/enterprise/frontend/src/embedding-sdk-bundle/components/private/SdkBreadcrumbs/SdkBreadcrumbs.unit.spec.tsx
index d14c631ef49..dc32265606c 100644
--- a/enterprise/frontend/src/embedding-sdk-bundle/components/private/SdkBreadcrumbs/SdkBreadcrumbs.unit.spec.tsx
+++ b/enterprise/frontend/src/embedding-sdk-bundle/components/private/SdkBreadcrumbs/SdkBreadcrumbs.unit.spec.tsx
@@ -1,6 +1,6 @@
import { act, screen, waitFor, within } from "__support__/ui";
-import { setup } from "./test-setup";
+import { setup } from "./setup.spec";
describe("SdkBreadcrumbs", () => {
it("shows the reported location from collection browser and dashboard", async () => {
diff --git a/enterprise/frontend/src/embedding-sdk-bundle/components/private/SdkBreadcrumbs/test-setup.tsx b/enterprise/frontend/src/embedding-sdk-bundle/components/private/SdkBreadcrumbs/setup.spec.tsx
similarity index 100%
rename from enterprise/frontend/src/embedding-sdk-bundle/components/private/SdkBreadcrumbs/test-setup.tsx
rename to enterprise/frontend/src/embedding-sdk-bundle/components/private/SdkBreadcrumbs/setup.spec.tsx
diff --git a/frontend/src/metabase/.eslintrc b/frontend/src/metabase/.eslintrc
deleted file mode 100644
index 4745a8b407e..00000000000
--- a/frontend/src/metabase/.eslintrc
+++ /dev/null
@@ -1,105 +0,0 @@
-{
- "rules": {
- // Note: adding this rule to a eslint config file in a subfolder will remove
- // *not* carry over the restricted imports from parent folders, you will
- // need to copy them over
- "no-restricted-imports": [
- "error",
- {
- "patterns": [
- "metabase-enterprise",
- "metabase-enterprise/*",
- "cljs/metabase.lib*",
- "/embedding-sdk",
- "/embedding-sdk-bundle",
- ],
- "paths": [
- {
- "name": "react-redux",
- "importNames": ["useSelector", "useDispatch", "connect"],
- "message": "Please import from `metabase/lib/redux` instead.",
- },
- {
- "name": "@mantine/core",
- "message": "Please import from `metabase/ui` instead.",
- },
- {
- "name": "moment",
- "message": "Moment is deprecated, please use dayjs",
- },
- {
- "name": "moment-timezone",
- "message": "Moment is deprecated, please use dayjs",
- },
- {
- "name": "@emotion/styled",
- "message": "Please style components using css modules.",
- },
- {
- "name": "@emotion/react",
- "message": "Please use components from `metabase/ui` instead and style them using css modules.",
- },
- {
- "name": "@storybook/test",
- "message": "Please use `testing-library/react` or `@testing-library/user-event`",
- },
- ],
- },
- ],
- "ttag/no-module-declaration": 2,
- },
- "overrides": [
- {
- "files": ["./app.js"],
- "rules": {
- "import/no-duplicates": 0,
- },
- },
- {
- "files": ["**/*.stories.tsx"],
- "rules": {
- "import/no-default-export": 0,
- "no-restricted-imports": 0,
- },
- },
- {
- "files": ["lib/redux/hooks.ts"],
- "rules": {
- "no-restricted-imports": 0,
- },
- },
- {
- "files": ["ui/**/*.{js,jsx,ts,tsx}"],
- "rules": {
- "no-restricted-imports": [
- "error",
- {
- "patterns": [
- "metabase-enterprise",
- "metabase-enterprise/*",
- "cljs/metabase.lib*",
- ],
- "paths": [
- {
- "name": "moment",
- "message": "Moment is deprecated, please use dayjs",
- },
- {
- "name": "moment-timezone",
- "message": "Moment is deprecated, please use dayjs",
- },
- {
- "name": "@emotion/styled",
- "message": "Please style components using css modules.",
- },
- {
- "name": "@emotion/react",
- "message": "Please use components from `metabase/ui` instead and style them using css modules.",
- },
- ],
- },
- ],
- },
- },
- ],
-}
diff --git a/frontend/src/metabase/.eslintrc.js b/frontend/src/metabase/.eslintrc.js
new file mode 100644
index 00000000000..d7a354a8c78
--- /dev/null
+++ b/frontend/src/metabase/.eslintrc.js
@@ -0,0 +1,144 @@
+/* eslint-disable import/no-commonjs */
+
+const TEST_FILES_NAME_PATTERN_ERROR_MESSAGE = `Please name your test setup and utils files with a ".spec.*" in the filename, or put them under "/tests", e.g. "setup.spec.ts", "MyComponent.setup.spec.ts", or "tests/setup.ts". This is to ensure they won't be imported in the SDK build.`;
+
+const baseRestrictedConfig = {
+ patterns: [
+ {
+ group: ["metabase-enterprise"],
+ },
+ {
+ group: ["metabase-enterprise/*"],
+ },
+ {
+ group: ["cljs/metabase.lib*"],
+ },
+ {
+ group: ["/embedding-sdk"],
+ },
+ {
+ group: ["/embedding-sdk-bundle"],
+ },
+ ],
+ paths: [
+ {
+ name: "react-redux",
+ importNames: ["useSelector", "useDispatch", "connect"],
+ message: "Please import from `metabase/lib/redux` instead.",
+ },
+ {
+ name: "@mantine/core",
+ message: "Please import from `metabase/ui` instead.",
+ },
+ {
+ name: "moment",
+ message: "Moment is deprecated, please use dayjs",
+ },
+ {
+ name: "moment-timezone",
+ message: "Moment is deprecated, please use dayjs",
+ },
+ {
+ name: "@emotion/styled",
+ message: "Please style components using css modules.",
+ },
+ {
+ name: "@emotion/react",
+ message:
+ "Please use components from `metabase/ui` instead and style them using css modules.",
+ },
+ {
+ name: "@storybook/test",
+ message:
+ "Please use `testing-library/react` or `@testing-library/user-event`",
+ },
+ ],
+};
+
+module.exports = {
+ rules: {
+ // Note: adding this rule to a eslint config file in a subfolder will remove
+ // *not* carry over the restricted imports from parent folders, you will
+ // need to copy them over
+ "no-restricted-imports": [
+ "error",
+ {
+ ...baseRestrictedConfig,
+ patterns: [
+ ...baseRestrictedConfig.patterns,
+ {
+ group: ["__support__/**", "!__support__/metadata"],
+ message: TEST_FILES_NAME_PATTERN_ERROR_MESSAGE,
+ },
+ ],
+ },
+ ],
+ "ttag/no-module-declaration": 2,
+ },
+ overrides: [
+ {
+ files: ["./app.js"],
+ rules: {
+ "import/no-duplicates": 0,
+ },
+ },
+ {
+ files: ["**/*.stories.tsx"],
+ rules: {
+ "import/no-default-export": 0,
+ "no-restricted-imports": 0,
+ },
+ },
+ {
+ files: ["lib/redux/hooks.ts"],
+ rules: {
+ "no-restricted-imports": 0,
+ },
+ },
+ {
+ files: [
+ "**/*.spec.*",
+ "**/test-utils.*",
+ "**/tests/**/*",
+ "**/test/**/*",
+ ],
+ rules: {
+ "no-restricted-imports": ["error", baseRestrictedConfig],
+ },
+ },
+ {
+ files: ["ui/**/*.{js,jsx,ts,tsx}"],
+ rules: {
+ "no-restricted-imports": [
+ "error",
+ {
+ patterns: [
+ "metabase-enterprise",
+ "metabase-enterprise/*",
+ "cljs/metabase.lib*",
+ ],
+ paths: [
+ {
+ name: "moment",
+ message: "Moment is deprecated, please use dayjs",
+ },
+ {
+ name: "moment-timezone",
+ message: "Moment is deprecated, please use dayjs",
+ },
+ {
+ name: "@emotion/styled",
+ message: "Please style components using css modules.",
+ },
+ {
+ name: "@emotion/react",
+ message:
+ "Please use components from `metabase/ui` instead and style them using css modules.",
+ },
+ ],
+ },
+ ],
+ },
+ },
+ ],
+};
diff --git a/frontend/src/metabase/common/components/TitleAndDescription/i18n-tests/common.unit.spec.tsx b/frontend/src/metabase/common/components/TitleAndDescription/i18n-tests/common.unit.spec.tsx
index cb260e0184c..a8f9b1b666d 100644
--- a/frontend/src/metabase/common/components/TitleAndDescription/i18n-tests/common.unit.spec.tsx
+++ b/frontend/src/metabase/common/components/TitleAndDescription/i18n-tests/common.unit.spec.tsx
@@ -3,7 +3,7 @@ import userEvent from "@testing-library/user-event";
import { setupTranslateContentStringSpy } from "__support__/content-translation";
import { screen } from "__support__/ui";
-import { setup } from "./utils";
+import { setup } from "./utils.spec";
describe("TitleAndDescription component (OSS)", () => {
const getContentTranslatorSpy = setupTranslateContentStringSpy();
diff --git a/frontend/src/metabase/common/components/TitleAndDescription/i18n-tests/premium.unit.spec.tsx b/frontend/src/metabase/common/components/TitleAndDescription/i18n-tests/premium.unit.spec.tsx
index 7ff520a6bfb..8602f138e2d 100644
--- a/frontend/src/metabase/common/components/TitleAndDescription/i18n-tests/premium.unit.spec.tsx
+++ b/frontend/src/metabase/common/components/TitleAndDescription/i18n-tests/premium.unit.spec.tsx
@@ -3,7 +3,7 @@ import userEvent from "@testing-library/user-event";
import { setupTranslateContentStringSpy } from "__support__/content-translation";
import { screen } from "__support__/ui";
-import { setup } from "./utils";
+import { setup } from "./utils.spec";
describe("TitleAndDescription component", () => {
describe("EE with content translation token and static embedding", () => {
diff --git a/frontend/src/metabase/common/components/TitleAndDescription/i18n-tests/utils.tsx b/frontend/src/metabase/common/components/TitleAndDescription/i18n-tests/utils.spec.tsx
similarity index 100%
rename from frontend/src/metabase/common/components/TitleAndDescription/i18n-tests/utils.tsx
rename to frontend/src/metabase/common/components/TitleAndDescription/i18n-tests/utils.spec.tsx
diff --git a/frontend/src/metabase/notifications/modals/CreateOrEditQuestionAlertModal/components/NotificationSchedule/NotificationSchedule.unit.spec.tsx b/frontend/src/metabase/notifications/modals/CreateOrEditQuestionAlertModal/components/NotificationSchedule/NotificationSchedule.unit.spec.tsx
index 2411d3c2c54..04ea5ebf359 100644
--- a/frontend/src/metabase/notifications/modals/CreateOrEditQuestionAlertModal/components/NotificationSchedule/NotificationSchedule.unit.spec.tsx
+++ b/frontend/src/metabase/notifications/modals/CreateOrEditQuestionAlertModal/components/NotificationSchedule/NotificationSchedule.unit.spec.tsx
@@ -1,7 +1,7 @@
import { screen } from "__support__/ui";
import type { ScheduleDisplayType } from "metabase-types/api";
-import { setup } from "./setup";
+import { setup } from "./setup.spec";
describe("NotificationSchedule", () => {
["builder", "raw"].forEach((uiDisplayType) => {
diff --git a/frontend/src/metabase/notifications/modals/CreateOrEditQuestionAlertModal/components/NotificationSchedule/setup.tsx b/frontend/src/metabase/notifications/modals/CreateOrEditQuestionAlertModal/components/NotificationSchedule/setup.spec.tsx
similarity index 100%
rename from frontend/src/metabase/notifications/modals/CreateOrEditQuestionAlertModal/components/NotificationSchedule/setup.tsx
rename to frontend/src/metabase/notifications/modals/CreateOrEditQuestionAlertModal/components/NotificationSchedule/setup.spec.tsx
diff --git a/frontend/src/metabase/parameters/components/ParameterWidget/i18n-tests/common.unit.spec.tsx b/frontend/src/metabase/parameters/components/ParameterWidget/i18n-tests/common.unit.spec.tsx
index e8cd92476db..851567a8e02 100644
--- a/frontend/src/metabase/parameters/components/ParameterWidget/i18n-tests/common.unit.spec.tsx
+++ b/frontend/src/metabase/parameters/components/ParameterWidget/i18n-tests/common.unit.spec.tsx
@@ -1,7 +1,7 @@
import { setupTranslateContentStringSpy } from "__support__/content-translation";
import { screen } from "__support__/ui";
-import { setup } from "./setup";
+import { setup } from "./setup.spec";
describe("ParameterWidget (OSS)", () => {
describe("content translation", () => {
diff --git a/frontend/src/metabase/parameters/components/ParameterWidget/i18n-tests/premium.unit.spec.tsx b/frontend/src/metabase/parameters/components/ParameterWidget/i18n-tests/premium.unit.spec.tsx
index 9f0e4ea52c1..321947ac90c 100644
--- a/frontend/src/metabase/parameters/components/ParameterWidget/i18n-tests/premium.unit.spec.tsx
+++ b/frontend/src/metabase/parameters/components/ParameterWidget/i18n-tests/premium.unit.spec.tsx
@@ -1,7 +1,7 @@
import { setupTranslateContentStringSpy } from "__support__/content-translation";
import { screen, waitFor } from "__support__/ui";
-import { setup } from "./setup";
+import { setup } from "./setup.spec";
describe("ParameterWidget (EE with token, in static embedding)", () => {
describe("content translation", () => {
diff --git a/frontend/src/metabase/parameters/components/ParameterWidget/i18n-tests/setup.tsx b/frontend/src/metabase/parameters/components/ParameterWidget/i18n-tests/setup.spec.tsx
similarity index 100%
rename from frontend/src/metabase/parameters/components/ParameterWidget/i18n-tests/setup.tsx
rename to frontend/src/metabase/parameters/components/ParameterWidget/i18n-tests/setup.spec.tsx
diff --git a/frontend/src/metabase/parameters/components/widgets/ParameterFieldWidget/FieldValuesWidget/testMocks.ts b/frontend/src/metabase/parameters/components/widgets/ParameterFieldWidget/FieldValuesWidget/testMocks.spec.ts
similarity index 100%
rename from frontend/src/metabase/parameters/components/widgets/ParameterFieldWidget/FieldValuesWidget/testMocks.ts
rename to frontend/src/metabase/parameters/components/widgets/ParameterFieldWidget/FieldValuesWidget/testMocks.spec.ts
diff --git a/frontend/src/metabase/parameters/components/widgets/ParameterFieldWidget/FieldValuesWidget/utils.unit.spec.js b/frontend/src/metabase/parameters/components/widgets/ParameterFieldWidget/FieldValuesWidget/utils.unit.spec.js
index b416ecbb52c..75c455f137a 100644
--- a/frontend/src/metabase/parameters/components/widgets/ParameterFieldWidget/FieldValuesWidget/utils.unit.spec.js
+++ b/frontend/src/metabase/parameters/components/widgets/ParameterFieldWidget/FieldValuesWidget/utils.unit.spec.js
@@ -4,7 +4,7 @@ import {
LISTABLE_FIELD_WITH_MANY_VALUES_ID,
STRING_PK_FIELD_ID,
metadata,
-} from "./testMocks";
+} from "./testMocks.spec";
import { getValuesMode, isSearchable, searchField } from "./utils";
describe("Components > FieldValuesWidget > utils", () => {
diff --git a/tsconfig.sdk.json b/tsconfig.sdk.json
index 5d020ed2a88..ed3e19b8e5a 100644
--- a/tsconfig.sdk.json
+++ b/tsconfig.sdk.json
@@ -11,12 +11,10 @@
"emitDeclarationOnly": true,
"outDir": "./resources/embedding-sdk/dist",
"paths": {
- "*": [
- "./frontend/src/*",
- "./enterprise/frontend/src/*"
- ],
+ "*": ["./frontend/src/*", "./enterprise/frontend/src/*"],
"build-configs/*": ["./frontend/build/*"],
- "cljs/*": ["./target/cljs_release/*"]
+ "cljs/*": ["./target/cljs_release/*"],
+ "__support__/*": ["./frontend/test/__support__/*"]
},
"stripInternal": true
},
@@ -28,15 +26,14 @@
],
"exclude": [
"node_modules",
- "**/*.unit.spec.*",
+ "**/*.spec.*",
"**/mocks/*",
"**/tests/*",
"**/test/*",
- "**/__support__/*",
- "**/test-utils.ts",
- "**/test-utils.tsx",
- "**/test-helpers.ts",
- "**/testMocks.ts",
- "**/*.stories.tsx"
+ "!frontend/test/__support__/metadata",
+ "**/test-utils.*",
+ "**/test-helpers.*",
+ "**/testMocks.*",
+ "**/*.stories.*"
]
}