diff --git a/frontend/src/metabase-types/api/collection.ts b/frontend/src/metabase-types/api/collection.ts index 02df191385ab4c06aee34d1c0694c3e0f69f6dd1..9b4f745bee0bb7440c0a41c335e5d745bc43b47f 100644 --- a/frontend/src/metabase-types/api/collection.ts +++ b/frontend/src/metabase-types/api/collection.ts @@ -49,8 +49,10 @@ type CollectionItemModel = | "pulse" | "collection"; +export type CollectionItemId = number; + export interface CollectionItem<T = CollectionItemModel> { - id: number; + id: CollectionItemId; model: T; name: string; description: string | null; diff --git a/frontend/src/metabase-types/api/index.ts b/frontend/src/metabase-types/api/index.ts index ad1a2c22dd5747184a44b7707227a2e1db228b5d..5cba3cd9d21d23e1471e70d9641bd852b3133bc0 100644 --- a/frontend/src/metabase-types/api/index.ts +++ b/frontend/src/metabase-types/api/index.ts @@ -19,6 +19,7 @@ export * from "./notifications"; export * from "./permissions"; export * from "./query"; export * from "./revision"; +export * from "./schema"; export * from "./segment"; export * from "./settings"; export * from "./setup"; diff --git a/frontend/src/metabase-types/api/schema.ts b/frontend/src/metabase-types/api/schema.ts new file mode 100644 index 0000000000000000000000000000000000000000..407e616b13fb643eed8ed2b34adc65e82579f278 --- /dev/null +++ b/frontend/src/metabase-types/api/schema.ts @@ -0,0 +1,71 @@ +import { WritebackAction } from "./actions"; +import { Alert } from "./alert"; +import { Database, DatabaseId } from "./database"; +import { Card } from "./card"; +import { Collection, CollectionId, CollectionItemId } from "./collection"; +import { Dashboard } from "./dashboard"; +import { Field, FieldDimension, FieldId } from "./field"; +import { Metric, MetricId } from "./metric"; +import { Segment, SegmentId } from "./segment"; +import { NativeQuerySnippet } from "./snippets"; +import { Schema, SchemaId, Table, TableId } from "./table"; +import { Timeline, TimelineEventId } from "./timeline"; +import { User } from "./user"; + +export type NormalizedWritebackAction = WritebackAction; +export type NormalizedAlert = Alert; +export type NormalizedDashboard = Dashboard; +export type NormalizedUser = User; +export type NormalizedCard = Card; +export type NormalizedNativeQuerySnippet = NativeQuerySnippet; + +export interface NormalizedDatabase + extends Omit<Database, "tables" | "schemas"> { + tables?: TableId[]; + schemas?: SchemaId[]; +} + +export interface NormalizedSchema extends Omit<Schema, "database" | "tables"> { + database?: DatabaseId; + tables?: TableId[]; +} + +export interface NormalizedTable + extends Omit<Table, "db" | "fields" | "segments" | "metrics" | "schema"> { + db?: DatabaseId; + fields?: FieldId[]; + segments?: SegmentId[]; + metrics?: MetricId[]; + schema?: SchemaId; +} + +export interface NormalizedFieldDimension + extends Omit<FieldDimension, "human_readable_field"> { + human_readable_field?: FieldId; +} + +export interface NormalizedField + extends Omit<Field, "target" | "table" | "name_field" | "dimensions"> { + target?: FieldId; + table?: TableId; + name_field?: FieldId; + dimensions?: NormalizedFieldDimension; +} + +export interface NormalizedSegment extends Omit<Segment, "table"> { + table?: TableId; +} + +export interface NormalizedMetric extends Omit<Metric, "table"> { + table?: TableId; +} + +export interface NormalizedTimeline + extends Omit<Timeline, "collection" | "events"> { + collection?: CollectionId; + events?: TimelineEventId[]; +} + +export interface NormalizedCollection extends Omit<Collection, "items"> { + items?: CollectionItemId[]; +} diff --git a/frontend/src/metabase-types/store/entities.ts b/frontend/src/metabase-types/store/entities.ts index e2b0bf357e4693fd941bcbf956bad99509121b37..a83fff933f21f8ae4e06be8425226c3d7fa7f31c 100644 --- a/frontend/src/metabase-types/store/entities.ts +++ b/frontend/src/metabase-types/store/entities.ts @@ -1,31 +1,31 @@ import { - Alert, - Card, - Collection, - Dashboard, - Database, - Field, - Metric, - NativeQuerySnippet, - Schema, - Segment, - Table, - User, - WritebackAction, + NormalizedAlert, + NormalizedCard, + NormalizedCollection, + NormalizedDashboard, + NormalizedDatabase, + NormalizedField, + NormalizedMetric, + NormalizedNativeQuerySnippet, + NormalizedSchema, + NormalizedSegment, + NormalizedTable, + NormalizedUser, + NormalizedWritebackAction, } from "metabase-types/api"; export interface EntitiesState { - actions: Record<string, WritebackAction>; - alerts: Record<string, Alert>; - collections: Record<string, Collection>; - dashboards: Record<string, Dashboard>; - databases: Record<string, Database>; - schemas: Record<string, Schema>; - tables: Record<string, Table>; - fields: Record<string, Field>; - segments: Record<string, Segment>; - metrics: Record<string, Metric>; - snippets: Record<string, NativeQuerySnippet>; - users: Record<string, User>; - questions: Record<string, Card>; + actions: Record<string, NormalizedWritebackAction>; + alerts: Record<string, NormalizedAlert>; + collections: Record<string, NormalizedCollection>; + dashboards: Record<string, NormalizedDashboard>; + databases: Record<string, NormalizedDatabase>; + schemas: Record<string, NormalizedSchema>; + tables: Record<string, NormalizedTable>; + fields: Record<string, NormalizedField>; + segments: Record<string, NormalizedSegment>; + metrics: Record<string, NormalizedMetric>; + snippets: Record<string, NormalizedNativeQuerySnippet>; + users: Record<string, NormalizedUser>; + questions: Record<string, NormalizedCard>; } diff --git a/frontend/src/metabase/dashboard/containers/CreateDashboardModal.unit.spec.tsx b/frontend/src/metabase/dashboard/containers/CreateDashboardModal.unit.spec.tsx index 6f78bffd6d94003de81b7664eacd524c57ccec57..8d67de41e73a74674045f93d12527628b1e109a9 100644 --- a/frontend/src/metabase/dashboard/containers/CreateDashboardModal.unit.spec.tsx +++ b/frontend/src/metabase/dashboard/containers/CreateDashboardModal.unit.spec.tsx @@ -4,11 +4,11 @@ import userEvent from "@testing-library/user-event"; import { renderWithProviders, screen, waitFor } from "__support__/ui"; import { setupEnterpriseTest } from "__support__/enterprise"; +import { createEntitiesState } from "__support__/store"; + import { mockSettings } from "__support__/settings"; import type { Collection } from "metabase-types/api"; -import { createMockEntitiesState } from "metabase-types/store/mocks"; - import CreateDashboardModal from "./CreateDashboardModal"; const ROOT_COLLECTION = { @@ -31,10 +31,8 @@ function setup({ renderWithProviders(<CreateDashboardModal onClose={onClose} />, { storeInitialState: { - entities: createMockEntitiesState({ - collections: { - root: ROOT_COLLECTION, - }, + entities: createEntitiesState({ + collections: [ROOT_COLLECTION], }), settings, }, diff --git a/frontend/src/metabase/entities/containers/EntityName.unit.spec.tsx b/frontend/src/metabase/entities/containers/EntityName.unit.spec.tsx index 36a4ca1ec0d9408f21343c52840ab567ade108dd..7249670442a379e27128feca196322df127d8087 100644 --- a/frontend/src/metabase/entities/containers/EntityName.unit.spec.tsx +++ b/frontend/src/metabase/entities/containers/EntityName.unit.spec.tsx @@ -2,8 +2,8 @@ import React from "react"; import { screen } from "@testing-library/react"; import { renderWithProviders } from "__support__/ui"; +import { createEntitiesState } from "__support__/store"; import { createMockUser } from "metabase-types/api/mocks"; -import { createMockEntitiesState } from "metabase-types/store/mocks"; import EntityName from "./EntityName"; describe("EntityName", () => { @@ -16,10 +16,8 @@ describe("EntityName", () => { <EntityName entityType="users" entityId={mockUser.id} />, { storeInitialState: { - entities: createMockEntitiesState({ - users: { - [mockUser.id]: mockUser, - }, + entities: createEntitiesState({ + users: [mockUser], }), }, }, diff --git a/frontend/src/metabase/nav/containers/MainNavbar/MainNavbar.unit.spec.tsx b/frontend/src/metabase/nav/containers/MainNavbar/MainNavbar.unit.spec.tsx index f68adc1dd288e0611177898ea46b1ca9c3360f82..5515138a66297ed3a16820237980a62f2fda47de 100644 --- a/frontend/src/metabase/nav/containers/MainNavbar/MainNavbar.unit.spec.tsx +++ b/frontend/src/metabase/nav/containers/MainNavbar/MainNavbar.unit.spec.tsx @@ -12,10 +12,11 @@ import { setupCollectionsEndpoints, setupDatabasesEndpoints, } from "__support__/server-mocks"; +import { createEntitiesState } from "__support__/store"; import * as Urls from "metabase/lib/urls"; -import { ROOT_COLLECTION } from "metabase/entities/collections"; +import { ROOT_COLLECTION } from "metabase/entities/collections"; import type { Card, Dashboard, User } from "metabase-types/api"; import { createMockCard, @@ -24,13 +25,12 @@ import { createMockDashboard, createMockUser, } from "metabase-types/api/mocks"; + import { createMockState, createMockDashboardState, - createMockEntitiesState, createMockQueryBuilderState, } from "metabase-types/store/mocks"; - import MainNavbar from "./MainNavbar"; type SetupOpts = { @@ -112,7 +112,7 @@ async function setup({ currentUser: user, dashboard: createMockDashboardState({ dashboardId, dashboards }), qb: createMockQueryBuilderState({ card: openQuestionCard }), - entities: createMockEntitiesState({ dashboards }), + entities: createEntitiesState({ dashboards: Object.values(dashboards) }), }); renderWithProviders( diff --git a/frontend/test/__support__/sample_database_fixture.ts b/frontend/test/__support__/sample_database_fixture.ts index 10df7712d7aeb171e66e6b9be20f0dec77197eb2..8dfcf707497ea6132816b80b05760a319b3f9ab5 100644 --- a/frontend/test/__support__/sample_database_fixture.ts +++ b/frontend/test/__support__/sample_database_fixture.ts @@ -64,7 +64,7 @@ export function createMetadata(updateState = (state: EnhancedState) => state) { const stateModified = updateState(chain(state)).thaw().value(); stateModified.entities.fields = normalizeFields( - stateModified.entities.fields || {}, + (stateModified.entities.fields as any) || {}, ); const metadata = getMetadata(stateModified);