Skip to content

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

MBQL lib helpers for e2e tests (#68278)

Romeo Van Snick123f2dafd236
diff --git a/.github/workflows/e2e-stress-test-flake-fix.yml b/.github/workflows/e2e-stress-test-flake-fix.yml
index 520481802a6..271a9fb1de6 100644
--- a/.github/workflows/e2e-stress-test-flake-fix.yml
+++ b/.github/workflows/e2e-stress-test-flake-fix.yml
@@ -120,6 +120,10 @@ jobs:
- name: Prepare Cypress environment
id: cypress-prep
uses: ./.github/actions/prepare-cypress
+
+ - name: Compile CLJS
+ run: yarn build-pure:cljs
+
- name: Run Metabase
run: node e2e/runner/run_cypress_ci.js start
diff --git a/.github/workflows/e2e-test.yml b/.github/workflows/e2e-test.yml
index 677b46607ce..e0819d7d216 100644
--- a/.github/workflows/e2e-test.yml
+++ b/.github/workflows/e2e-test.yml
@@ -104,6 +104,9 @@ jobs:
if: github.run_attempt != '1'
run: echo "specs=$(cat failed-specs)" >> $GITHUB_ENV
+ - name: Compile CLJS
+ run: yarn build-pure:cljs
+
- name: Run Metabase
run: node e2e/runner/run_cypress_ci.js start
diff --git a/e2e/support/config.js b/e2e/support/config.js
index 8103f22b783..1b492f406a1 100644
--- a/e2e/support/config.js
+++ b/e2e/support/config.js
@@ -46,6 +46,67 @@ const assetsResolverPlugin = {
},
};
+// Plugin to allow loading the ClojureScript bundle only when it exists
+// on the filesystem. This is to avoid breaking the build when the bundle
+// is not present.
+//
+// If the bundle is not present, tests relying on it will fail, but the Cypress
+// process will be allowed to start.
+//
+// The error will look like this:
+//
+// Dynamic require of "cljs/metabase.types.core" is not supported
+//
+// This allows us to avoid building the ClojureScript bundle when we don't need to (like in certain CI tasks).
+const virtualClojureScriptPlugin = {
+ name: "virtualClojureScriptBundle",
+ setup(build) {
+ let cljsDir = null;
+
+ async function isDirectory(path) {
+ try {
+ const stat = await fs.promises.stat(path);
+ return stat.isDirectory();
+ } catch (e) {
+ return false;
+ }
+ }
+
+ build.onStart(async () => {
+ const baseDir = path.join(__dirname, "../../target");
+ const devDir = path.join(baseDir, "cljs_dev");
+ const prodDir = path.join(baseDir, "cljs_prod");
+
+ const [devDirExists, prodDirExists] = await Promise.all([
+ isDirectory(devDir),
+ isDirectory(prodDir),
+ ]);
+
+ if (prodDirExists) {
+ console.log("ClojureScript production bundle found");
+ cljsDir = prodDir;
+ } else if (devDirExists) {
+ console.log("ClojureScript development bundle found");
+ cljsDir = devDir;
+ } else {
+ console.log("No ClojureScript bundle found, not loading bundle");
+ cljsDir = null;
+ }
+ });
+
+ build.onResolve({ filter: /^cljs\// }, async (args) => {
+ if (cljsDir === null) {
+ return {
+ path: args.path,
+ external: true,
+ };
+ }
+ const unnested = args.path.split(path.sep).slice(1).join(path.sep);
+ return { path: path.join(cljsDir, unnested + ".js") };
+ });
+ },
+};
+
const defaultConfig = {
// This is the functionality of the old cypress-plugins.js file
setupNodeEvents(cypressOn, config) {
@@ -75,7 +136,11 @@ const defaultConfig = {
loader: {
".svg": "text",
},
- plugins: [NodeModulesPolyfillPlugin(), assetsResolverPlugin],
+ plugins: [
+ NodeModulesPolyfillPlugin(),
+ assetsResolverPlugin,
+ virtualClojureScriptPlugin,
+ ],
sourcemap: "inline",
}),
);
diff --git a/e2e/support/helpers/index.ts b/e2e/support/helpers/index.ts
index 61517cff7d6..233dd819446 100644
--- a/e2e/support/helpers/index.ts
+++ b/e2e/support/helpers/index.ts
@@ -1,4 +1,5 @@
export * from "./api";
+export * from "./mbql";
export * from "./e2e-action-helpers";
export * from "./e2e-ad-hoc-question-helpers";
export * from "./e2e-api-key-helpers";
diff --git a/e2e/support/helpers/mbql/index.ts b/e2e/support/helpers/mbql/index.ts
new file mode 100644
index 00000000000..5830aa52173
--- /dev/null
+++ b/e2e/support/helpers/mbql/index.ts
@@ -0,0 +1,6 @@
+export {
+ getMetadataProvider,
+ createQuery,
+ createNativeQuery,
+} from "./wrappers";
+export { createCardWithQuery, createCardWithNativeQuery } from "./question";
diff --git a/e2e/support/helpers/mbql/metadata-provider.ts b/e2e/support/helpers/mbql/metadata-provider.ts
new file mode 100644
index 00000000000..3b8953ae946
--- /dev/null
+++ b/e2e/support/helpers/mbql/metadata-provider.ts
@@ -0,0 +1,86 @@
+// WARNING:
+// This module should not be imported directly in cypress
+// harnesses, use an dynamic import instead.
+import { getMetadataWithoutSettings as getMetadataFromState } from "metabase/selectors/metadata";
+import * as Lib from "metabase-lib";
+import type {
+ Card,
+ CardId,
+ Database,
+ Table,
+ TableId,
+} from "metabase-types/api";
+
+import { createMockEntitiesState } from "../../../../frontend/test/__support__/store";
+import { SAMPLE_DB_ID, SAMPLE_DB_TABLES } from "../../cypress_data";
+
+import type { GetMetadataOpts } from "./types";
+
+const DEFAULT_TABLE_IDS: TableId[] = [
+ SAMPLE_DB_TABLES.STATIC_ORDERS_ID,
+ SAMPLE_DB_TABLES.STATIC_PEOPLE_ID,
+ SAMPLE_DB_TABLES.STATIC_PRODUCTS_ID,
+ SAMPLE_DB_TABLES.STATIC_REVIEWS_ID,
+];
+const DEFAULT_CARD_IDS: CardId[] = [];
+
+/**
+ * Returns a Lib.MetadataProvider instance containing metadata for the
+ * provided database, tables and cards.
+ *
+ * WARNING:
+ * DO NOT USE THIS DIRECTLY IN TESTS.
+ * Use the `getMetadataProvider` from ./wrappers" instead.
+ *
+ * NOTE:
+ * This function uses plain Promises and Promise.all to avoid type issues
+ * with Cypress. The result needs to wrapped in cy.wrap() to be correctly usable
+ * in Cypress tests.
+ */
+export async function getMetadataProvider({
+ databaseId = SAMPLE_DB_ID,
+ ...rest
+}: GetMetadataOpts = {}) {
+ const metadata = await getMetadata({ databaseId, ...rest });
+ return Lib.metadataProvider(databaseId, metadata);
+}
+
+async function getMetadata({
+ databaseId = SAMPLE_DB_ID,
+ tableIds = DEFAULT_TABLE_IDS,
+ cardIds = DEFAULT_CARD_IDS,
+}: GetMetadataOpts = {}) {
+ // Just one database for now, but wrapped to get the types to work
+ const databaseIds = [databaseId];
+
+ const [databases, tables, cards] = await Promise.all([
+ // databases
+ Promise.all(
+ databaseIds.map((databaseId) =>
+ GET<Database>(`/api/database/${databaseId}`),
+ ),
+ ),
+
+ // cards
+ Promise.all(
+ tableIds.map((tableId) =>
+ GET<Table>(`/api/table/${tableId}/query_metadata`),
+ ),
+ ),
+
+ // tables
+ Promise.all(cardIds.map((cardId) => GET<Card>(`/api/card/${cardId}`))),
+ ]);
+
+ const entities = createMockEntitiesState({
+ databases,
+ tables,
+ questions: cards,
+ });
+ return getMetadataFromState({ entities });
+}
+
+async function GET<T>(url: string): Promise<T> {
+ const response = await fetch(url);
+ return response.json();
+}
diff --git a/e2e/support/helpers/mbql/question.ts b/e2e/support/helpers/mbql/question.ts
new file mode 100644
index 00000000000..7ad9196f4f5
--- /dev/null
+++ b/e2e/support/helpers/mbql/question.ts
@@ -0,0 +1,104 @@
+import type * as Lib from "metabase-lib";
+import type { CreateTestQueryOpts } from "metabase-lib/test-helpers";
+import type { DatabaseId } from "metabase-types/api";
+
+import type { QuestionDetails } from "../api";
+import { type Options, question } from "../api/createQuestion";
+
+import type { GetMetadataOpts } from "./types";
+import { createNativeQuery, createQuery } from "./wrappers";
+
+/**
+ * Create a card using the provided details and a MBQL query.
+ *
+ * @param details.metadata -
+ * The metadata provider to use for the query,
+ * or options used to create one on the fly.
+ * If no metadata is provided, the query will be created with
+ * the default metadata provider.
+ *
+ * @example
+ * // If no metadata is provided, the card will be created with
+ * // the default metadata provider.
+ * H.createTestQuestion({
+ * name: "My question",
+ * query: {
+ * databaseId: SAMPLE_DATABASE_ID,
+ * stages: [
+ * ...
+ * ]
+ * }
+ * })
+ * })
+ *
+ * @example
+ * // Provide custom metadata entities relevant to your query.
+ * H.createTestQuestion({
+ * name: "My question",
+ * databaseId: SAMPLE_DATABASE_ID,
+ * query: "SELECT * FROM orders"
+ * })
+ * })
+ *
+ */
+
+type CardWithQueryDetails = Omit<QuestionDetails, "dataset_query"> & {
+ metadata?: GetMetadataOpts | Lib.MetadataProvider;
+ query: CreateTestQueryOpts;
+};
+
+export function createCardWithQuery(
+ { metadata = {}, query, ...details }: CardWithQueryDetails,
+ options: Options = {},
+) {
+ return createQuery(metadata, query).then((dataset_query) =>
+ question({ ...details, dataset_query }, options),
+ );
+}
+
+type CardWithNativeQueryDetails = Omit<QuestionDetails, "dataset_query"> & {
+ metadata?: GetMetadataOpts | Lib.MetadataProvider;
+ databaseId: DatabaseId;
+ query: string;
+};
+
+/**
+ * Create a card using the provided details and a native query.
+ *
+ * @param details.metadata -
+ * The metadata provider to use for the query,
+ * or options used to create one on the fly.
+ * If no metadata is provided, the query will be created with
+ * the default metadata provider.
+ *
+ * @example
+ * // If no metadata is provided, the card will be created with
+ * // the default metadata provider.
+ * H.createCardWithNativeQuery({
+ * name: "My question",
+ * databaseId: SAMPLE_DATABASE_ID,
+ * query: "SELECT * FROM orders"
+ * })
+ * })
+ *
+ * @example
+ * // Provide custom metadata entities relevant to your query.
+ * H.createCardWithNativeQuery({
+ * name: "My question",
+ * databaseId: SAMPLE_DATABASE_ID,
+ * metadata: {
+ * databaseId: SAMPLE_DATABASE_ID,
+ * cardIds: [SAMPLE_CARD_ID],
+ * },
+ * query: "SELECT * FROM orders"
+ * })
+ * })
+ */
+export function createCardWithNativeQuery(
+ { metadata = {}, databaseId, query, ...details }: CardWithNativeQueryDetails,
+ options: Options = {},
+) {
+ return createNativeQuery(metadata, databaseId, query).then((dataset_query) =>
+ question({ ...details, dataset_query }, options),
+ );
+}
diff --git a/e2e/support/helpers/mbql/types.ts b/e2e/support/helpers/mbql/types.ts
new file mode 100644
index 00000000000..adcc0c0b2f2
--- /dev/null
+++ b/e2e/support/helpers/mbql/types.ts
@@ -0,0 +1,7 @@
+import type { CardId, DatabaseId, TableId } from "metabase-types/api";
+
+export type GetMetadataOpts = {
+ databaseId?: DatabaseId;
+ tableIds?: TableId[];
+ cardIds?: CardId[];
+};
diff --git a/e2e/support/helpers/mbql/wrappers.ts b/e2e/support/helpers/mbql/wrappers.ts
new file mode 100644
index 00000000000..2c582938489
--- /dev/null
+++ b/e2e/support/helpers/mbql/wrappers.ts
@@ -0,0 +1,103 @@
+import type * as Lib from "metabase-lib";
+import type { CreateTestQueryOpts } from "metabase-lib/test-helpers";
+import type { DatabaseId, OpaqueDatasetQuery } from "metabase-types/api";
+
+import type { GetMetadataOpts } from "./types";
+
+/**
+ * Returns a Lib.MetadataProvider instance containing metadata for the
+ * entities defined in opts.
+ *
+ * @param opts.databaseId - The database to fetch metadata for
+ * @param opts.tableIds - The tables to fetch metadata for
+ * @param opts.cardIds - Cards to fetch metadata for
+ */
+export function getMetadataProvider(
+ opts?: GetMetadataOpts,
+): Cypress.Chainable<Lib.MetadataProvider> {
+ return (
+ cy
+ // we need to log in before we can get metadata
+ .getCookie("metabase.SESSION_ID")
+ .then(() => _getMetadataProvider({ ...opts }))
+ );
+}
+
+// Helper function which calls getMetadataProvider from ./metadata-provider
+// This module needs to imported lazily not to crash Cypress and to avoid importing
+// cljs in tests that don't need it.
+async function _getMetadataProvider(
+ opts?: GetMetadataOpts,
+): Promise<Lib.MetadataProvider> {
+ const { getMetadataProvider } = await import("./metadata-provider");
+ return getMetadataProvider(opts);
+}
+
+/**
+ * Build an MBQL query using a custom DSL that simplifies field selection and creation.
+ *
+ * @param metadataProvider - A Lib.MetadataProvider instance or a GetMetadataOpts object that will be user to instantiate a Lib.MetadataProvider
+ * @param opts - The details of the query to create
+ */
+export function createQuery(
+ metadataProvider: Lib.MetadataProvider | GetMetadataOpts,
+ opts: CreateTestQueryOpts,
+): Cypress.Chainable<OpaqueDatasetQuery> {
+ return ensureProvider(metadataProvider).then((provider) => {
+ return createTestJsQuery(provider, opts);
+ });
+}
+
+// Helper function which calls createTestJsQuery from metabase-lib/test-helpers.
+// This module needs to imported lazily not to crash Cypress and to avoid importing
+// cljs in tests that don't need it.
+async function createTestJsQuery(
+ metadataProvider: Lib.MetadataProvider,
+ opts: CreateTestQueryOpts,
+): Promise<OpaqueDatasetQuery> {
+ const { createTestJsQuery } = await import("metabase-lib/test-helpers");
+ return createTestJsQuery(metadataProvider, opts);
+}
+
+/**
+ * Build a native MBQL query using a custom DSL that simplifies field selection and creation.
+ *
+ * @param metadataProvider - A Lib.MetadataProvider instance or a GetMetadataOpts object that will be user to instantiate a Lib.MetadataProvider
+ * @param databaseId - The database the query is for
+ * @param query - The native query string
+ */
+export function createNativeQuery(
+ metadataProvider: Lib.MetadataProvider | GetMetadataOpts,
+ databaseId: DatabaseId,
+ query: string,
+): Cypress.Chainable<OpaqueDatasetQuery> {
+ return ensureProvider(metadataProvider).then((provider) =>
+ createTestNativeJsQuery(provider, databaseId, query),
+ );
+}
+
+// Helper function which calls createTestNativeJsQuery from metabase-lib/test-helpers.
+// This module needs to imported lazily not to crash Cypress and to avoid importing
+// cljs in tests that don't need it.
+async function createTestNativeJsQuery(
+ metadataProvider: Lib.MetadataProvider,
+ databaseId: DatabaseId,
+ query: string,
+) {
+ const { createTestNativeJsQuery } = await import("metabase-lib/test-helpers");
+ return createTestNativeJsQuery(metadataProvider, databaseId, query);
+}
+
+function ensureProvider(
+ providerOrOpts: GetMetadataOpts | Lib.MetadataProvider,
+): Cypress.Chainable<Lib.MetadataProvider> {
+ return isMetadataProvider(providerOrOpts)
+ ? cy.wrap(providerOrOpts)
+ : getMetadataProvider(providerOrOpts);
+}
+
+function isMetadataProvider(
+ opts: GetMetadataOpts | Lib.MetadataProvider,
+): opts is Lib.MetadataProvider {
+ return "cache" in opts;
+}
diff --git a/e2e/test/scenarios/question-reproductions/reproductions.cy.spec.ts b/e2e/test/scenarios/question-reproductions/reproductions.cy.spec.ts
index cb4d9958d0b..fd1a5e42340 100644
--- a/e2e/test/scenarios/question-reproductions/reproductions.cy.spec.ts
+++ b/e2e/test/scenarios/question-reproductions/reproductions.cy.spec.ts
@@ -1,6 +1,6 @@
const { H } = cy;
-import { WRITABLE_DB_ID } from "e2e/support/cypress_data";
+import { SAMPLE_DB_ID, WRITABLE_DB_ID } from "e2e/support/cypress_data";
import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";
import { ORDERS_QUESTION_ID } from "e2e/support/cypress_sample_instance_data";
import type {
@@ -1421,17 +1421,36 @@ describe("issue #47005", () => {
H.restore("postgres-12");
cy.signInAsNormalUser();
- H.createQuestion({
+ H.createCardWithQuery({
name: "Question A",
query: {
- "source-table": ORDERS_ID,
+ databaseId: SAMPLE_DB_ID,
+ stages: [
+ {
+ source: {
+ type: "table",
+ id: ORDERS_ID,
+ },
+ },
+ ],
},
}).then(({ body: question }) => {
- H.createQuestion(
+ H.createCardWithQuery(
{
name: "Question B",
+ metadata: {
+ cardIds: [question.id],
+ },
query: {
- "source-table": "card__" + question.id,
+ databaseId: SAMPLE_DB_ID,
+ stages: [
+ {
+ source: {
+ type: "card",
+ id: question.id,
+ },
+ },
+ ],
},
},
{ visitQuestion: true },
@@ -1454,13 +1473,30 @@ describe("issue 66210", () => {
H.restore();
cy.signInAsAdmin();
- H.createQuestion({
+ H.createCardWithQuery({
name: METRIC_NAME,
+ type: "metric",
query: {
- "source-table": ORDERS_ID,
- aggregation: [["count"]],
+ databaseId: SAMPLE_DB_ID,
+ stages: [
+ {
+ source: {
+ type: "table",
+ id: ORDERS_ID,
+ },
+ aggregations: [
+ {
+ name: "Count",
+ value: {
+ type: "operator",
+ operator: "count",
+ args: [],
+ },
+ },
+ ],
+ },
+ ],
},
- type: "metric",
});
cy.visit("/");
diff --git a/frontend/src/metabase-lib/test-helpers.ts b/frontend/src/metabase-lib/test-helpers.ts
index 6377892d1d2..beb39b73974 100644
--- a/frontend/src/metabase-lib/test-helpers.ts
+++ b/frontend/src/metabase-lib/test-helpers.ts
@@ -422,7 +422,7 @@ export function createLegendItemClickObject(
return { dimensions: [dimension] };
}
-type CreateTestQueryOpts = {
+export type CreateTestQueryOpts = {
databaseId: DatabaseId;
stages: [TestQueryStageWithSource, ...TestQueryStage[]];
};
@@ -647,10 +647,11 @@ function findSource(
provider: Lib.MetadataProvider,
source: TestQuerySource,
): Lib.TableMetadata | Lib.CardMetadata {
- const metadata = Lib.tableOrCardMetadata(provider, source.id);
+ const id = source.type === "card" ? `card__${source.id}` : source.id;
+ const metadata = Lib.tableOrCardMetadata(provider, id);
if (!metadata) {
- throw new Error(`Could not find source metadata for source: ${source.id}`);
+ throw new Error(`Could not find source metadata for source: ${id}`);
}
return metadata;
diff --git a/frontend/src/metabase/entities/containers/index.js b/frontend/src/metabase/entities/containers/index.jsx
similarity index 100%
rename from frontend/src/metabase/entities/containers/index.js
rename to frontend/src/metabase/entities/containers/index.jsx
diff --git a/frontend/src/metabase/schema.js b/frontend/src/metabase/schema.js
index 3ac6c38a99d..c5dc0db0824 100644
--- a/frontend/src/metabase/schema.js
+++ b/frontend/src/metabase/schema.js
@@ -159,3 +159,19 @@ export const QueryMetadataSchema = {
cards: [QuestionSchema],
dashboards: [DashboardSchema],
};
+
+export const EntitiesSchema = {
+ actions: [ActionSchema],
+ collections: [CollectionSchema],
+ dashboards: [DashboardSchema],
+ databases: [DatabaseSchema],
+ documents: [DocumentSchema],
+ schemas: [SchemaSchema],
+ tables: [TableSchema],
+ fields: [FieldSchema],
+ segments: [SegmentSchema],
+ measures: [MeasureSchema],
+ snippets: [SnippetSchema],
+ indexedEntities: [IndexedEntitySchema],
+ questions: [QuestionSchema],
+};
diff --git a/frontend/src/metabase/selectors/metadata.ts b/frontend/src/metabase/selectors/metadata.ts
index 3484aee93ad..cd08860f83b 100644
--- a/frontend/src/metabase/selectors/metadata.ts
+++ b/frontend/src/metabase/selectors/metadata.ts
@@ -28,6 +28,8 @@ import type {
} from "metabase-types/api";
import type { State } from "metabase-types/store";
+import type { EntitiesState } from "../../metabase-types/store/entities";
+
import { getSettings } from "./settings";
type TableSelectorOpts = {
@@ -40,13 +42,18 @@ type FieldSelectorOpts = {
export type MetadataSelectorOpts = TableSelectorOpts & FieldSelectorOpts;
-const getNormalizedDatabases = (state: State) => state.entities.databases;
-const getNormalizedSchemas = (state: State) => state.entities.schemas;
+const getNormalizedDatabases = (state: StateWithEntities) =>
+ state.entities.databases;
+const getNormalizedSchemas = (state: StateWithEntities) =>
+ state.entities.schemas;
-const getNormalizedTablesUnfiltered = (state: State) => state.entities.tables;
+const getNormalizedTablesUnfiltered = (state: StateWithEntities) =>
+ state.entities.tables;
-const getIncludeHiddenTables = (_state: State, props?: TableSelectorOpts) =>
- !!props?.includeHiddenTables;
+const getIncludeHiddenTables = (
+ _state: StateWithEntities,
+ props?: TableSelectorOpts,
+) => !!props?.includeHiddenTables;
const getNormalizedTables = createSelector(
[getNormalizedTablesUnfiltered, getIncludeHiddenTables],
@@ -60,9 +67,12 @@ const getNormalizedTables = createSelector(
),
);
-const getNormalizedFieldsUnfiltered = (state: State) => state.entities.fields;
-const getIncludeSensitiveFields = (_state: State, props?: FieldSelectorOpts) =>
- !!props?.includeSensitiveFields;
+const getNormalizedFieldsUnfiltered = (state: StateWithEntities) =>
+ state.entities.fields;
+const getIncludeSensitiveFields = (
+ _state: StateWithEntities,
+ props?: FieldSelectorOpts,
+) => !!props?.includeSensitiveFields;
const getNormalizedFields = createSelector(
[
@@ -87,10 +97,14 @@ const getNormalizedFields = createSelector(
),
);
-const getNormalizedSegments = (state: State) => state.entities.segments;
-const getNormalizedMeasures = (state: State) => state.entities.measures ?? {};
-const getNormalizedQuestions = (state: State) => state.entities.questions;
-const getNormalizedSnippets = (state: State) => state.entities.snippets;
+const getNormalizedSegments = (state: StateWithEntities) =>
+ state.entities.segments;
+const getNormalizedMeasures = (state: StateWithEntities) =>
+ state.entities.measures ?? {};
+const getNormalizedQuestions = (state: StateWithEntities) =>
+ state.entities.questions;
+const getNormalizedSnippets = (state: StateWithEntities) =>
+ state.entities.snippets;
export const getShallowDatabases = getNormalizedDatabases;
export const getShallowTables = getNormalizedTables;
@@ -98,8 +112,12 @@ export const getShallowFields = getNormalizedFields;
export const getShallowSegments = getNormalizedSegments;
export const getShallowMeasures = getNormalizedMeasures;
-export const getMetadata: (
- state: State,
+type StateWithEntities = {
+ entities: EntitiesState;
+};
+
+export const getMetadataWithoutSettings: (
+ state: StateWithEntities,
props?: MetadataSelectorOpts,
) => Metadata = createSelector(
[
@@ -111,7 +129,6 @@ export const getMetadata: (
getNormalizedMeasures,
getNormalizedQuestions,
getNormalizedSnippets,
- getSettings,
],
(
databases,
@@ -122,9 +139,8 @@ export const getMetadata: (
measures,
questions,
snippets,
- settings,
) => {
- const metadata = new Metadata({ settings });
+ const metadata = new Metadata({});
metadata.databases = Object.fromEntries(
Object.values(databases).map((d) => [d.id, createDatabase(d, metadata)]),
@@ -191,6 +207,17 @@ export const getMetadata: (
},
);
+export const getMetadata: (
+ state: State,
+ props?: MetadataSelectorOpts,
+) => Metadata = createSelector(
+ [getMetadataWithoutSettings, getSettings],
+ (metadata, settings) => {
+ metadata.settings = settings;
+ return metadata;
+ },
+);
+
export const getMetadataUnfiltered = (state: State) => {
return getMetadata(state, {
includeHiddenTables: true,
diff --git a/frontend/test/__support__/store.ts b/frontend/test/__support__/store.ts
index 849bce2f7e2..d3794829f0a 100644
--- a/frontend/test/__support__/store.ts
+++ b/frontend/test/__support__/store.ts
@@ -1,21 +1,6 @@
-import type { Schema as NormalizrSchema } from "normalizr";
import { normalize } from "normalizr";
-import {
- ActionSchema,
- CollectionSchema,
- DashboardSchema,
- DatabaseSchema,
- DocumentSchema,
- FieldSchema,
- IndexedEntitySchema,
- MeasureSchema,
- QuestionSchema,
- SchemaSchema,
- SegmentSchema,
- SnippetSchema,
- TableSchema,
-} from "metabase/schema";
+import { EntitiesSchema } from "metabase/schema";
import type {
Card,
Collection,
@@ -47,22 +32,6 @@ export interface EntitiesStateOpts {
questions?: Card[];
}
-const EntitiesSchema: Record<keyof EntitiesState, NormalizrSchema<any>> = {
- actions: [ActionSchema],
- collections: [CollectionSchema],
- dashboards: [DashboardSchema],
- databases: [DatabaseSchema],
- documents: [DocumentSchema],
- schemas: [SchemaSchema],
- tables: [TableSchema],
- fields: [FieldSchema],
- segments: [SegmentSchema],
- measures: [MeasureSchema],
- snippets: [SnippetSchema],
- indexedEntities: [IndexedEntitySchema],
- questions: [QuestionSchema],
-};
-
export const createMockEntitiesState = (
opts: EntitiesStateOpts,
): EntitiesState => {