diff --git a/frontend/src/metabase-types/types/Auto.js b/frontend/src/metabase-types/types/Auto.js deleted file mode 100644 index 7a1c78b16e1bde0318fea1235b08756b159a336a..0000000000000000000000000000000000000000 --- a/frontend/src/metabase-types/types/Auto.js +++ /dev/null @@ -1,21 +0,0 @@ -import type { TableId, SchemaName } from "metabase-types/types/Table"; - -export type DatabaseCandidates = SchemaCandidates[]; - -export type SchemaCandidates = { - schema: SchemaName, - score: number, - tables: Candidate[], -}; - -export type Candidate = { - title: string, - description: string, - score: number, - rule: string, - url: string, - table?: { - id: TableId, - schema: SchemaName, - }, -}; diff --git a/frontend/src/metabase-types/types/Auto.ts b/frontend/src/metabase-types/types/Auto.ts new file mode 100644 index 0000000000000000000000000000000000000000..22b769d7061de3b0e22b8fae4aa996ca2522f773 --- /dev/null +++ b/frontend/src/metabase-types/types/Auto.ts @@ -0,0 +1,21 @@ +import { TableId, SchemaName } from "metabase-types/types/Table"; + +export type DatabaseCandidates = SchemaCandidates[]; + +export type SchemaCandidates = { + schema: SchemaName; + score: number; + tables: Candidate[]; +}; + +export type Candidate = { + title: string; + description: string; + score: number; + rule: string; + url: string; + table?: { + id: TableId; + schema: SchemaName; + }; +}; diff --git a/frontend/src/metabase-types/types/Card.js b/frontend/src/metabase-types/types/Card.js deleted file mode 100644 index 63040064e8a6158993ab31d47d23c965d2a3756e..0000000000000000000000000000000000000000 --- a/frontend/src/metabase-types/types/Card.js +++ /dev/null @@ -1,54 +0,0 @@ -// TODO: Re-enable Flow after updating it, we maybe hit this with our dataset query types: -// https://github.com/facebook/flow/issues/1663 - -import type { DatabaseId } from "./Database"; -import type { StructuredQuery, NativeQuery } from "./Query"; -import type { Parameter, ParameterInstance } from "./Parameter"; - -export type CardId = number; - -export type VisualizationSettings = { - [key: string]: any, -}; - -export type UnsavedCard = { - dataset_query: DatasetQuery, - display: string, - visualization_settings: VisualizationSettings, - parameters?: Array<Parameter>, - original_card_id?: CardId, -}; - -export type Card = { - id: CardId, - name: ?string, - description: ?string, - dataset_query: DatasetQuery, - display: string, - visualization_settings: VisualizationSettings, - parameters?: Array<Parameter>, - can_write: boolean, - public_uuid: string, - - // Not part of the card API contract, a field used by query builder for showing lineage - original_card_id?: CardId, -}; - -export type StructuredDatasetQuery = { - type: "query", - database: ?DatabaseId, - query: StructuredQuery, - parameters?: Array<ParameterInstance>, -}; - -export type NativeDatasetQuery = { - type: "native", - database: ?DatabaseId, - native: NativeQuery, - parameters?: Array<ParameterInstance>, -}; - -/** - * All possible formats for `dataset_query` - */ -export type DatasetQuery = StructuredDatasetQuery | NativeDatasetQuery; diff --git a/frontend/src/metabase-types/types/Card.ts b/frontend/src/metabase-types/types/Card.ts new file mode 100644 index 0000000000000000000000000000000000000000..71826adfa7c34e176623c9dc1a9e017ddb8560ac --- /dev/null +++ b/frontend/src/metabase-types/types/Card.ts @@ -0,0 +1,51 @@ +import { DatabaseId } from "./Database"; +import { StructuredQuery, NativeQuery } from "./Query"; +import { Parameter, ParameterInstance } from "./Parameter"; + +export type CardId = number; + +export type VisualizationSettings = { + [key: string]: any; +}; + +export type UnsavedCard = { + dataset_query: DatasetQuery; + display: string; + visualization_settings: VisualizationSettings; + parameters?: Array<Parameter>; + original_card_id?: CardId; +}; + +export type Card = { + id: CardId; + name?: string; + description?: string; + dataset_query: DatasetQuery; + display: string; + visualization_settings: VisualizationSettings; + parameters?: Array<Parameter>; + can_write: boolean; + public_uuid: string; + + // Not part of the card API contract, a field used by query builder for showing lineage + original_card_id?: CardId; +}; + +export type StructuredDatasetQuery = { + type: "query"; + database?: DatabaseId; + query: StructuredQuery; + parameters?: Array<ParameterInstance>; +}; + +export type NativeDatasetQuery = { + type: "native"; + database?: DatabaseId; + native: NativeQuery; + parameters?: Array<ParameterInstance>; +}; + +/** + * All possible formats for `dataset_query` + */ +export type DatasetQuery = StructuredDatasetQuery | NativeDatasetQuery; diff --git a/frontend/src/metabase-types/types/Collection.js b/frontend/src/metabase-types/types/Collection.ts similarity index 55% rename from frontend/src/metabase-types/types/Collection.js rename to frontend/src/metabase-types/types/Collection.ts index 6e03f1a893ea6ee9b959c4a5c2fa3987ee452f00..210ee181db079798c0c4ff4a7679eeb80761b791 100644 --- a/frontend/src/metabase-types/types/Collection.js +++ b/frontend/src/metabase-types/types/Collection.ts @@ -1,7 +1,7 @@ export type CollectionId = number; export type Collection = { - id: CollectionId, - name: string, - color: string, + id: CollectionId; + name: string; + color: string; }; diff --git a/frontend/src/metabase-types/types/Dashboard.js b/frontend/src/metabase-types/types/Dashboard.js deleted file mode 100644 index 541b0f53018a0d45fe9a72dcc4b6f578c9040ad9..0000000000000000000000000000000000000000 --- a/frontend/src/metabase-types/types/Dashboard.js +++ /dev/null @@ -1,54 +0,0 @@ -import type { Card, CardId, VisualizationSettings } from "./Card"; -import type { Parameter, ParameterMapping } from "./Parameter"; -import type { EmbeddingParams } from "metabase/public/lib/types"; - -export type DashboardId = number; - -export type Dashboard = { - id: DashboardId, - name: string, - favorite: boolean, - archived: boolean, - created_at: ?string, - creator_id: number, - description: ?string, - caveats?: string, - points_of_interest?: string, - show_in_getting_started?: boolean, - // incomplete - parameters: Array<Parameter>, - collection_id: ?number, -}; - -// TODO Atte Keinänen 4/5/16: After upgrading Flow, use spread operator `...Dashboard` -export type DashboardWithCards = { - id: DashboardId, - name: string, - description: ?string, - ordered_cards: Array<DashCard>, - embedding_params: EmbeddingParams, - // incomplete - parameters: Array<Parameter>, - collection_id: ?number, -}; - -export type DashCardId = number; - -export type DashCard = { - id: DashCardId, - - card_id: CardId, - dashboard_id: DashboardId, - - card: Card, - series: Array<Card>, - - // incomplete - parameter_mappings: Array<ParameterMapping>, - visualization_settings: VisualizationSettings, - - col: number, - row: number, - sizeY: number, - sizeX: number, -}; diff --git a/frontend/src/metabase-types/types/Dashboard.ts b/frontend/src/metabase-types/types/Dashboard.ts new file mode 100644 index 0000000000000000000000000000000000000000..fa74da0497b036139249dd2ca15fc9220104c9c0 --- /dev/null +++ b/frontend/src/metabase-types/types/Dashboard.ts @@ -0,0 +1,53 @@ +import { Card, CardId, VisualizationSettings } from "./Card"; +import { Parameter, ParameterMapping } from "./Parameter"; + +export type DashboardId = number; + +export type Dashboard = { + id: DashboardId; + name: string; + favorite: boolean; + archived: boolean; + created_at?: string; + creator_id: number; + description?: string; + caveats?: string; + points_of_interest?: string; + show_in_getting_started?: boolean; + // incomplete + parameters: Array<Parameter>; + collection_id?: number; +}; + +// TODO Atte Keinänen 4/5/16: After upgrading Flow, use spread operator `...Dashboard` +export type DashboardWithCards = { + id: DashboardId; + name: string; + description?: string; + ordered_cards: Array<DashCard>; + embedding_params: Record<string, any>; + // incomplete + parameters: Array<Parameter>; + collection_id?: number; +}; + +export type DashCardId = number; + +export type DashCard = { + id: DashCardId; + + card_id: CardId; + dashboard_id: DashboardId; + + card: Card; + series: Array<Card>; + + // incomplete + parameter_mappings: Array<ParameterMapping>; + visualization_settings: VisualizationSettings; + + col: number; + row: number; + sizeY: number; + sizeX: number; +}; diff --git a/frontend/src/metabase-types/types/Database.js b/frontend/src/metabase-types/types/Database.ts similarity index 53% rename from frontend/src/metabase-types/types/Database.js rename to frontend/src/metabase-types/types/Database.ts index d382a1b0c559805a783da04c91d6740e37f7bd1c..60cda7f51b20955f683ab21ef3b7e6b6d04e447a 100644 --- a/frontend/src/metabase-types/types/Database.js +++ b/frontend/src/metabase-types/types/Database.ts @@ -1,5 +1,5 @@ -import type { ISO8601Time } from "."; -import type { Table } from "./Table"; +import { ISO8601Time } from "."; +import { Table } from "./Table"; export type DatabaseId = number; @@ -17,7 +17,7 @@ export type DatabaseFeature = | "binning"; export type DatabaseDetails = { - [key: string]: any, + [key: string]: any; }; export type DatabaseEngine = string; @@ -25,22 +25,22 @@ export type DatabaseEngine = string; export type DatabaseNativePermission = "write" | "read"; export type Database = { - id: DatabaseId, - name: string, - description: ?string, + id: DatabaseId; + name: string; + description?: string; - tables: Table[], + tables: Table[]; - details: DatabaseDetails, - engine: DatabaseType, - features: DatabaseFeature[], - is_full_sync: boolean, - is_sample: boolean, - native_permissions: DatabaseNativePermission, + details: DatabaseDetails; + engine: DatabaseType; + features: DatabaseFeature[]; + is_full_sync: boolean; + is_sample: boolean; + native_permissions: DatabaseNativePermission; - caveats: ?string, - points_of_interest: ?string, + caveats?: string; + points_of_interest?: string; - created_at: ISO8601Time, - updated_at: ISO8601Time, + created_at: ISO8601Time; + updated_at: ISO8601Time; }; diff --git a/frontend/src/metabase-types/types/Dataset.js b/frontend/src/metabase-types/types/Dataset.js deleted file mode 100644 index 441db33a32fa56fd7012373df5376bc8a8356672..0000000000000000000000000000000000000000 --- a/frontend/src/metabase-types/types/Dataset.js +++ /dev/null @@ -1,45 +0,0 @@ -import type { ISO8601Time } from "."; -import type { FieldId } from "./Field"; -import type { DatasetQuery } from "./Card"; -import type { DatetimeUnit, FieldLiteral, Field } from "./Query"; - -export type ColumnName = string; - -export type ColumnSettings = { [id: string]: any }; - -export type BinningInfo = { - bin_width: number, -}; - -// TODO: incomplete -export type Column = { - id: ?(FieldId | FieldLiteral), // NOTE: sometimes id is a field reference, e.x. nested queries? - name: ColumnName, - display_name: string, - base_type: string, - semantic_type: ?string, - source?: "fields" | "aggregation" | "breakout", - unit?: DatetimeUnit, - binning_info?: BinningInfo, - fk_field_id?: FieldId, - expression_name?: any, - settings?: ColumnSettings, - field_ref?: Field, -}; - -export type Value = string | number | ISO8601Time | boolean | null | {}; -export type Row = Value[]; - -export type DatasetData = { - cols: Column[], - rows: Row[], - rows_truncated?: number, - requested_timezone?: string, - results_timezone?: string, -}; - -export type Dataset = { - data: DatasetData, - json_query: DatasetQuery, - error?: string, -}; diff --git a/frontend/src/metabase-types/types/Dataset.ts b/frontend/src/metabase-types/types/Dataset.ts new file mode 100644 index 0000000000000000000000000000000000000000..ffe72e2745ef57baac531b42658aa0a18b90ea60 --- /dev/null +++ b/frontend/src/metabase-types/types/Dataset.ts @@ -0,0 +1,51 @@ +import { ISO8601Time } from "."; +import { FieldId } from "./Field"; +import { DatasetQuery } from "./Card"; +import { DatetimeUnit, FieldLiteral, Field } from "./Query"; + +export type ColumnName = string; + +export type ColumnSettings = { [id: string]: any }; + +export type BinningInfo = { + bin_width: number; +}; + +// TODO: incomplete +export type Column = { + id?: FieldId | FieldLiteral; // NOTE: sometimes id is a field reference, e.x. nested queries? + name: ColumnName; + display_name: string; + base_type: string; + semantic_type?: string; + source?: "fields" | "aggregation" | "breakout"; + unit?: DatetimeUnit; + binning_info?: BinningInfo; + fk_field_id?: FieldId; + expression_name?: any; + settings?: ColumnSettings; + field_ref?: Field; +}; + +export type Value = + | string + | number + | ISO8601Time + | boolean + | null + | Record<string, unknown>; +export type Row = Value[]; + +export type DatasetData = { + cols: Column[]; + rows: Row[]; + rows_truncated?: number; + requested_timezone?: string; + results_timezone?: string; +}; + +export type Dataset = { + data: DatasetData; + json_query: DatasetQuery; + error?: string; +}; diff --git a/frontend/src/metabase-types/types/Field.js b/frontend/src/metabase-types/types/Field.js deleted file mode 100644 index bc8c8fdeeb9a550df8861cee53fd95be1906e8fd..0000000000000000000000000000000000000000 --- a/frontend/src/metabase-types/types/Field.js +++ /dev/null @@ -1,59 +0,0 @@ -import type { ISO8601Time } from "."; -import type { TableId } from "./Table"; -import type { Value } from "./Dataset"; - -export type FieldId = number; - -export type BaseType = string; -export type SemanticType = string; - -export type FieldVisibilityType = - | "details-only" - | "hidden" - | "normal" - | "retired"; - -export type Field = { - id: FieldId, - - name: string, - display_name: string, - description: string, - base_type: BaseType, - effective_type?: BaseType, - semantic_type: SemanticType, - active: boolean, - visibility_type: FieldVisibilityType, - preview_display: boolean, - position: number, - parent_id: ?FieldId, - - table_id: TableId, - - fk_target_field_id: ?FieldId, - - max_value: ?number, - min_value: ?number, - - caveats: ?string, - points_of_interest: ?string, - - last_analyzed: ISO8601Time, - created_at: ISO8601Time, - updated_at: ISO8601Time, - - values?: FieldValues, - dimensions?: FieldDimension, -}; - -export type RawFieldValue = Value; -export type HumanReadableFieldValue = string; - -export type FieldValue = - | [RawFieldValue] - | [RawFieldValue, HumanReadableFieldValue]; -export type FieldValues = FieldValue[]; - -export type FieldDimension = { - name: string, -}; diff --git a/frontend/src/metabase-types/types/Field.ts b/frontend/src/metabase-types/types/Field.ts new file mode 100644 index 0000000000000000000000000000000000000000..9688cd0b065f8ad802a442743afc180805bdf792 --- /dev/null +++ b/frontend/src/metabase-types/types/Field.ts @@ -0,0 +1,59 @@ +import { ISO8601Time } from "."; +import { TableId } from "./Table"; +import { Value } from "./Dataset"; + +export type FieldId = number; + +export type BaseType = string; +export type SemanticType = string; + +export type FieldVisibilityType = + | "details-only" + | "hidden" + | "normal" + | "retired"; + +export type Field = { + id: FieldId; + + name: string; + display_name: string; + description: string; + base_type: BaseType; + effective_type?: BaseType; + semantic_type: SemanticType; + active: boolean; + visibility_type: FieldVisibilityType; + preview_display: boolean; + position: number; + parent_id?: FieldId; + + table_id: TableId; + + fk_target_field_id?: FieldId; + + max_value?: number; + min_value?: number; + + caveats?: string; + points_of_interest?: string; + + last_analyzed: ISO8601Time; + created_at: ISO8601Time; + updated_at: ISO8601Time; + + values?: FieldValues; + dimensions?: FieldDimension; +}; + +export type RawFieldValue = Value; +export type HumanReadableFieldValue = string; + +export type FieldValue = + | [RawFieldValue] + | [RawFieldValue, HumanReadableFieldValue]; +export type FieldValues = FieldValue[]; + +export type FieldDimension = { + name: string; +}; diff --git a/frontend/src/metabase-types/types/Label.js b/frontend/src/metabase-types/types/Label.js deleted file mode 100644 index f6f1b4090eda0b3faa9992958d81e6e16caed5ae..0000000000000000000000000000000000000000 --- a/frontend/src/metabase-types/types/Label.js +++ /dev/null @@ -1,8 +0,0 @@ -export type LabelId = number; - -export type Label = { - id: LabelId, - name: string, - slug: string, - icon: string, -}; diff --git a/frontend/src/metabase-types/types/Label.ts b/frontend/src/metabase-types/types/Label.ts new file mode 100644 index 0000000000000000000000000000000000000000..f145373881f372849358bed2e1073ecb55c7ef6e --- /dev/null +++ b/frontend/src/metabase-types/types/Label.ts @@ -0,0 +1,8 @@ +export type LabelId = number; + +export type Label = { + id: LabelId; + name: string; + slug: string; + icon: string; +}; diff --git a/frontend/src/metabase-types/types/Metadata.js b/frontend/src/metabase-types/types/Metadata.js deleted file mode 100644 index 8dc55518555438be4ed189b762ff7cd94138c8ac..0000000000000000000000000000000000000000 --- a/frontend/src/metabase-types/types/Metadata.js +++ /dev/null @@ -1,101 +0,0 @@ -// Legacy "tableMetadata" etc - -import type { Database, DatabaseId } from "metabase-types/types/Database"; -import type { Table, TableId } from "metabase-types/types/Table"; -import type { Field, FieldId } from "metabase-types/types/Field"; -import type { Segment, SegmentId } from "metabase-types/types/Segment"; -import type { Metric, MetricId } from "metabase-types/types/Metric"; - -export type Metadata = { - databases: { [id: DatabaseId]: DatabaseMetadata }, - tables: { [id: TableId]: TableMetadata }, - fields: { [id: FieldId]: FieldMetadata }, - metrics: { [id: MetricId]: MetricMetadata }, - segments: { [id: SegmentId]: SegmentMetadata }, -}; - -export type DatabaseMetadata = Database & { - tables: TableMetadata[], - tables_lookup: { [id: TableId]: TableMetadata }, -}; - -export type TableMetadata = Table & { - db: DatabaseMetadata, - - fields: FieldMetadata[], - fields_lookup: { [id: FieldId]: FieldMetadata }, - - segments: SegmentMetadata[], - metrics: MetricMetadata[], - - aggregation_operators: AggregationOperator[], -}; - -export type FieldMetadata = Field & { - table: TableMetadata, - target: FieldMetadata, - - filter_operators: FilterOperator[], - filter_operators_lookup: { [key: FilterOperatorName]: FilterOperator }, -}; - -export type SegmentMetadata = Segment & { - table: TableMetadata, -}; - -export type MetricMetadata = Metric & { - table: TableMetadata, -}; - -export type FieldValue = { - name: string, - key: string, -}; - -export type FilterOperatorName = string; - -export type FilterOperator = { - name: FilterOperatorName, - verboseName: string, - moreVerboseName: string, - fields: FilterOperatorField[], - multi: boolean, - placeholders?: string[], - validArgumentsFilters: ValidArgumentsFilter[], -}; - -export type FilterOperatorField = { - type: string, - values: FieldValue[], -}; - -export type ValidArgumentsFilter = (field: Field, table: Table) => boolean; - -type FieldsFilter = (fields: Field[]) => Field[]; - -export type AggregationOperator = { - name: string, - short: string, - fields: Field[], - validFieldsFilters: FieldsFilter[], -}; - -export type FieldOptions = { - count: number, - fields: Field[], - fks: { - field: Field, - fields: Field[], - }, -}; - -import Dimension from "metabase-lib/lib/Dimension"; - -export type DimensionOptions = { - count: number, - dimensions: Dimension[], - fks: Array<{ - field: FieldMetadata, - dimensions: Dimension[], - }>, -}; diff --git a/frontend/src/metabase-types/types/Metadata.ts b/frontend/src/metabase-types/types/Metadata.ts new file mode 100644 index 0000000000000000000000000000000000000000..864bf731793b2528fbea778c06dbbe718aee80e9 --- /dev/null +++ b/frontend/src/metabase-types/types/Metadata.ts @@ -0,0 +1,102 @@ +// Legacy "tableMetadata" etc + +import { Database, DatabaseId } from "metabase-types/types/Database"; +import { Table, TableId } from "metabase-types/types/Table"; +import { Field, FieldId } from "metabase-types/types/Field"; +import { Segment, SegmentId } from "metabase-types/types/Segment"; +import { Metric, MetricId } from "metabase-types/types/Metric"; + +export type Metadata = { + databases: { [id: DatabaseId]: DatabaseMetadata }; + tables: { [id: TableId]: TableMetadata }; + fields: { [id: FieldId]: FieldMetadata }; + metrics: { [id: MetricId]: MetricMetadata }; + segments: { [id: SegmentId]: SegmentMetadata }; +}; + +export type DatabaseMetadata = Database & { + tables: TableMetadata[]; + tables_lookup: { [id: TableId]: TableMetadata }; +}; + +export type TableMetadata = Table & { + db: DatabaseMetadata; + + fields: FieldMetadata[]; + fields_lookup: { [id: FieldId]: FieldMetadata }; + + segments: SegmentMetadata[]; + metrics: MetricMetadata[]; + + aggregation_operators: AggregationOperator[]; +}; + +export type FieldMetadata = Field & { + table: TableMetadata; + target: FieldMetadata; + + filter_operators: FilterOperator[]; + filter_operators_lookup: { [key: FilterOperatorName]: FilterOperator }; +}; + +export type SegmentMetadata = Segment & { + table: TableMetadata; +}; + +export type MetricMetadata = Metric & { + table: TableMetadata; +}; + +export type FieldValue = { + name: string; + key: string; +}; + +export type FilterOperatorName = string; + +export type FilterOperator = { + name: FilterOperatorName; + verboseName: string; + moreVerboseName: string; + fields: FilterOperatorField[]; + multi: boolean; + placeholders?: string[]; + validArgumentsFilters: ValidArgumentsFilter[]; +}; + +export type FilterOperatorField = { + type: string; + values: FieldValue[]; +}; + +export type ValidArgumentsFilter = (field: Field, table: Table) => boolean; + +type FieldsFilter = (fields: Field[]) => Field[]; + +export type AggregationOperator = { + name: string; + short: string; + fields: Field[]; + validFieldsFilters: FieldsFilter[]; +}; + +export type FieldOptions = { + count: number; + fields: Field[]; + fks: { + field: Field; + fields: Field[]; + }; +}; + +// import Dimension from "metabase-lib/lib/Dimension"; +type Dimension = any; + +export type DimensionOptions = { + count: number; + dimensions: Dimension[]; + fks: Array<{ + field: FieldMetadata; + dimensions: Dimension[]; + }>; +}; diff --git a/frontend/src/metabase-types/types/Metric.js b/frontend/src/metabase-types/types/Metric.js deleted file mode 100644 index bb1a7ed94c42b641df10f6848cc59d1cab20efe5..0000000000000000000000000000000000000000 --- a/frontend/src/metabase-types/types/Metric.js +++ /dev/null @@ -1,11 +0,0 @@ -import type { TableId } from "./Table"; - -export type MetricId = number; - -// TODO: incomplete -export type Metric = { - name: string, - id: MetricId, - table_id: TableId, - archived: boolean, -}; diff --git a/frontend/src/metabase-types/types/Metric.ts b/frontend/src/metabase-types/types/Metric.ts new file mode 100644 index 0000000000000000000000000000000000000000..e8a8eadd30c658e48785b0b3b6dbc6c7d438e537 --- /dev/null +++ b/frontend/src/metabase-types/types/Metric.ts @@ -0,0 +1,11 @@ +import { TableId } from "./Table"; + +export type MetricId = number; + +// TODO: incomplete +export type Metric = { + name: string; + id: MetricId; + table_id: TableId; + archived: boolean; +}; diff --git a/frontend/src/metabase-types/types/Parameter.js b/frontend/src/metabase-types/types/Parameter.ts similarity index 51% rename from frontend/src/metabase-types/types/Parameter.js rename to frontend/src/metabase-types/types/Parameter.ts index 3e672f02230282505edb9af30cc4db8cdddd3cae..9917aafa5ac967948b0d53425539d4b2afe2c4ac 100644 --- a/frontend/src/metabase-types/types/Parameter.js +++ b/frontend/src/metabase-types/types/Parameter.ts @@ -1,6 +1,6 @@ -import type { CardId } from "./Card"; -import type { FieldId } from "./Field"; -import type { LocalFieldReference, ForeignFieldReference } from "./Query"; +import { CardId } from "./Card"; +import { FieldId } from "./Field"; +import { LocalFieldReference, ForeignFieldReference } from "./Query"; export type ParameterId = string; @@ -12,15 +12,15 @@ export type ParameterValue = string; export type ParameterValueOrArray = string | Array<string>; export type Parameter = { - id: ParameterId, - name: string, - type: ParameterType, - slug: string, - default?: string, - field_ids?: FieldId[], - hasOnlyFieldTargets?: boolean, // true if the parameter is only connected to fields/dimensions rather than variables - target?: ParameterTarget, - filteringParameters?: ParameterId[], + id: ParameterId; + name: string; + type: ParameterType; + slug: string; + default?: string; + field_ids?: FieldId[]; + hasOnlyFieldTargets?: boolean; // true if the parameter is only connected to fields/dimensions rather than variables + target?: ParameterTarget; + filteringParameters?: ParameterId[]; }; export type VariableTarget = ["template-tag", string]; @@ -34,41 +34,41 @@ export type ParameterTarget = | ["dimension", DimensionTarget]; export type ParameterMappingOption = { - name: string, - target: ParameterTarget, + name: string; + target: ParameterTarget; }; export type ParameterMapping = { - card_id: CardId, - parameter_id: ParameterId, - target: ParameterTarget, + card_id: CardId; + parameter_id: ParameterId; + target: ParameterTarget; }; export type ParameterOption = { - name: string, - description?: string, - type: ParameterType, + name: string; + description?: string; + type: ParameterType; }; export type ParameterSection = { - id: string, - name: string, - description: string, - options: ParameterOption[], + id: string; + name: string; + description: string; + options: ParameterOption[]; }; export type ParameterInstance = { - type: ParameterType, - target: ParameterTarget, - value: ParameterValue, + type: ParameterType; + target: ParameterTarget; + value: ParameterValue; }; export type ParameterMappingUIOption = ParameterMappingOption & { - icon: ?string, - sectionName: string, - isForeign?: boolean, + icon?: string; + sectionName: string; + isForeign?: boolean; }; export type ParameterValues = { - [id: ParameterId]: ParameterValue, + [id: ParameterId]: ParameterValue; }; diff --git a/frontend/src/metabase-types/types/Permissions.js b/frontend/src/metabase-types/types/Permissions.ts similarity index 50% rename from frontend/src/metabase-types/types/Permissions.js rename to frontend/src/metabase-types/types/Permissions.ts index 2e498a4760ea5a5f8620b5d3d151099c45079cb2..d8ee5b8ac73db3698305ef5a1e43ef49618243f0 100644 --- a/frontend/src/metabase-types/types/Permissions.js +++ b/frontend/src/metabase-types/types/Permissions.ts @@ -1,29 +1,29 @@ -import type { DatabaseId } from "metabase-types/types/Database"; -import type { SchemaName, TableId } from "metabase-types/types/Table"; +import { DatabaseId } from "metabase-types/types/Database"; +import { SchemaName, TableId } from "metabase-types/types/Table"; export type GroupId = number; export type Group = { - id: GroupId, - name: string, + id: GroupId; + name: string; }; export type PermissionsGraph = { - groups: GroupsPermissions, - revision: number, + groups: GroupsPermissions; + revision: number; }; export type GroupsPermissions = { - [key: GroupId]: GroupPermissions, + [key: GroupId]: GroupPermissions; }; export type GroupPermissions = { - [key: DatabaseId]: DatabasePermissions, + [key: DatabaseId]: DatabasePermissions; }; export type DatabasePermissions = { - native: NativePermissions, - schemas: SchemasPermissions, + native: NativePermissions; + schemas: SchemasPermissions; }; export type NativePermissions = "read" | "write" | "none"; @@ -32,14 +32,14 @@ export type SchemasPermissions = | "all" | "none" | { - [key: SchemaName]: TablesPermissions, + [key: SchemaName]: TablesPermissions; }; export type TablesPermissions = | "all" | "none" | { - [key: TableId]: FieldsPermissions, + [key: TableId]: FieldsPermissions; }; export type FieldsPermissions = "all" | "none"; diff --git a/frontend/src/metabase-types/types/Query.js b/frontend/src/metabase-types/types/Query.ts similarity index 81% rename from frontend/src/metabase-types/types/Query.js rename to frontend/src/metabase-types/types/Query.ts index 87311923cbd39fec31497091baa3b7579f892b63..b01b94b3cfdfaddb19cb051ad0a2196173b89c9d 100644 --- a/frontend/src/metabase-types/types/Query.js +++ b/frontend/src/metabase-types/types/Query.ts @@ -1,8 +1,8 @@ -import type { TableId } from "./Table"; -import type { FieldId, BaseType } from "./Field"; -import type { SegmentId } from "./Segment"; -import type { MetricId } from "./Metric"; -import type { ParameterType } from "./Parameter"; +import { TableId } from "./Table"; +import { FieldId, BaseType } from "./Field"; +import { SegmentId } from "./Segment"; +import { MetricId } from "./Metric"; +import { ParameterType } from "./Parameter"; export type ExpressionName = string; @@ -50,34 +50,34 @@ export type TemplateTagName = string; export type TemplateTagType = "text" | "number" | "date" | "dimension"; export type TemplateTag = { - id: TemplateTagId, - name: TemplateTagName, - "display-name": string, - type: TemplateTagType, - dimension?: LocalFieldReference, - "widget-type"?: ParameterType, - required?: boolean, - default?: string, + id: TemplateTagId; + name: TemplateTagName; + "display-name": string; + type: TemplateTagType; + dimension?: LocalFieldReference; + "widget-type"?: ParameterType; + required?: boolean; + default?: string; }; export type TemplateTags = { [key: TemplateTagName]: TemplateTag }; export type NativeQuery = { - query: string, - "template-tags": TemplateTags, + query: string; + "template-tags": TemplateTags; }; export type StructuredQuery = { - "source-table"?: ?TableId, - "source-query"?: ?StructuredQuery, - aggregation?: AggregationClause, - breakout?: BreakoutClause, - filter?: FilterClause, - joins?: JoinClause, - "order-by"?: OrderByClause, - limit?: LimitClause, - expressions?: ExpressionClause, - fields?: FieldsClause, + "source-table"?: TableId; + "source-query"?: StructuredQuery; + aggregation?: AggregationClause; + breakout?: BreakoutClause; + filter?: FilterClause; + joins?: JoinClause; + "order-by"?: OrderByClause; + limit?: LimitClause; + expressions?: ExpressionClause; + fields?: FieldsClause; }; export type AggregationClause = @@ -106,7 +106,7 @@ export type AggregationWithOptions = [ ]; export type AggregationOptions = { - "display-name"?: string, + "display-name"?: string; }; type CountAgg = ["count"]; @@ -173,7 +173,7 @@ export type StringFilter = ]; export type StringFilterOptions = { - "case-sensitive"?: false, + "case-sensitive"?: false; }; export type NullFilter = ["is-null", ConcreteField]; @@ -205,7 +205,7 @@ export type TimeIntervalFilter = ]; export type TimeIntervalFilterOptions = { - "include-current"?: boolean, + "include-current"?: boolean; }; export type FilterOptions = StringFilterOptions | TimeIntervalFilterOptions; @@ -227,12 +227,12 @@ export type JoinFields = "all" | "none" | JoinedFieldReference[]; export type JoinClause = Array<Join>; export type Join = { - "source-table"?: TableId, - "source-query"?: StructuredQuery, - condition: JoinCondition, - alias?: JoinAlias, - strategy?: JoinStrategy, - fields?: JoinFields, + "source-table"?: TableId; + "source-query"?: StructuredQuery; + condition: JoinCondition; + alias?: JoinAlias; + strategy?: JoinStrategy; + fields?: JoinFields; }; export type LimitClause = number; @@ -247,7 +247,11 @@ export type ConcreteField = | DatetimeField | BinnedField; -export type LocalFieldReference = ["field", FieldId, {} | null]; +export type LocalFieldReference = [ + "field", + FieldId, + Record<string, unknown> | null, +]; export type ForeignFieldReference = [ "field", @@ -277,16 +281,16 @@ export type BinnedField = [ FieldId | string, { binning: - | { strategy: "num-bins", "num-bins": number } - | { strategy: "bin-width", "bin-width": number } - | { strategy: "default" }, + | { strategy: "num-bins"; "num-bins": number } + | { strategy: "bin-width"; "bin-width": number } + | { strategy: "default" }; }, ]; export type AggregateField = ["aggregation", number]; export type ExpressionClause = { - [key: ExpressionName]: Expression, + [key: ExpressionName]: Expression; }; export type Expression = [ diff --git a/frontend/src/metabase-types/types/Revision.js b/frontend/src/metabase-types/types/Revision.ts similarity index 82% rename from frontend/src/metabase-types/types/Revision.js rename to frontend/src/metabase-types/types/Revision.ts index ade633f5e95be53631ca68106ba80a634c7ba35b..df4ada2791c396445c484bafc87c38d29b3a5efd 100644 --- a/frontend/src/metabase-types/types/Revision.js +++ b/frontend/src/metabase-types/types/Revision.ts @@ -2,5 +2,5 @@ export type RevisionId = string; export type Revision = { // TODO: incomplete - id: RevisionId, + id: RevisionId; }; diff --git a/frontend/src/metabase-types/types/Segment.js b/frontend/src/metabase-types/types/Segment.js deleted file mode 100644 index 326d03948aeb0f111a1d5cbe7c6251eb10c77279..0000000000000000000000000000000000000000 --- a/frontend/src/metabase-types/types/Segment.js +++ /dev/null @@ -1,12 +0,0 @@ -import type { TableId } from "./Table"; - -export type SegmentId = number; - -// TODO: incomplete -export type Segment = { - name: string, - id: SegmentId, - table_id: TableId, - archived: boolean, - description: string, -}; diff --git a/frontend/src/metabase-types/types/Segment.ts b/frontend/src/metabase-types/types/Segment.ts new file mode 100644 index 0000000000000000000000000000000000000000..e3866c0db88b706c798d063bc69170d8534e6052 --- /dev/null +++ b/frontend/src/metabase-types/types/Segment.ts @@ -0,0 +1,12 @@ +import { TableId } from "./Table"; + +export type SegmentId = number; + +// TODO: incomplete +export type Segment = { + name: string; + id: SegmentId; + table_id: TableId; + archived: boolean; + description: string; +}; diff --git a/frontend/src/metabase-types/types/Snippet.js b/frontend/src/metabase-types/types/Snippet.js deleted file mode 100644 index 660d9c4f5fde41199a8564a027ac1bd37bd1fae5..0000000000000000000000000000000000000000 --- a/frontend/src/metabase-types/types/Snippet.js +++ /dev/null @@ -1,8 +0,0 @@ -export type Snippet = { - id?: number, - archived?: boolean, - name?: string, - description?: string, - content?: string, - database_id: ?number, -}; diff --git a/frontend/src/metabase-types/types/Snippet.ts b/frontend/src/metabase-types/types/Snippet.ts new file mode 100644 index 0000000000000000000000000000000000000000..beaac4b8cb11c6e8a58a8adc678af96ddb2f3de7 --- /dev/null +++ b/frontend/src/metabase-types/types/Snippet.ts @@ -0,0 +1,8 @@ +export type Snippet = { + id?: number; + archived?: boolean; + name?: string; + description?: string; + content?: string; + database_id?: number; +}; diff --git a/frontend/src/metabase-types/types/Table.js b/frontend/src/metabase-types/types/Table.js deleted file mode 100644 index c36775202e66f31ceb32c72649f9c4aef582244c..0000000000000000000000000000000000000000 --- a/frontend/src/metabase-types/types/Table.js +++ /dev/null @@ -1,40 +0,0 @@ -import type { ISO8601Time } from "."; - -import type { Field } from "./Field"; -import type { Segment } from "./Segment"; -import type { Metric } from "./Metric"; -import type { DatabaseId } from "./Database"; - -export type TableId = number; -export type SchemaName = string; - -type TableVisibilityType = string; // FIXME - -// TODO: incomplete -export type Table = { - id: TableId, - db_id: DatabaseId, - - schema: ?SchemaName, - name: string, - display_name: string, - - description: string, - active: boolean, - visibility_type: TableVisibilityType, - - // entity_type: null // unused? - - fields: Field[], - segments: Segment[], - metrics: Metric[], - - rows: number, - - caveats: ?string, - points_of_interest: ?string, - show_in_getting_started: boolean, - - updated_at: ISO8601Time, - created_at: ISO8601Time, -}; diff --git a/frontend/src/metabase-types/types/Table.ts b/frontend/src/metabase-types/types/Table.ts new file mode 100644 index 0000000000000000000000000000000000000000..c34a278c0a213b0021b39dbe21a3e86384f3e578 --- /dev/null +++ b/frontend/src/metabase-types/types/Table.ts @@ -0,0 +1,40 @@ +import { ISO8601Time } from "."; + +import { Field } from "./Field"; +import { Segment } from "./Segment"; +import { Metric } from "./Metric"; +import { DatabaseId } from "./Database"; + +export type TableId = number; +export type SchemaName = string; + +type TableVisibilityType = string; // FIXME + +// TODO: incomplete +export type Table = { + id: TableId; + db_id: DatabaseId; + + schema?: SchemaName; + name: string; + display_name: string; + + description: string; + active: boolean; + visibility_type: TableVisibilityType; + + // entity_type: null // unused? + + fields: Field[]; + segments: Segment[]; + metrics: Metric[]; + + rows: number; + + caveats?: string; + points_of_interest?: string; + show_in_getting_started: boolean; + + updated_at: ISO8601Time; + created_at: ISO8601Time; +}; diff --git a/frontend/src/metabase-types/types/User.js b/frontend/src/metabase-types/types/User.js deleted file mode 100644 index dd531c252cb64a667ac27102f72bcccd393067fc..0000000000000000000000000000000000000000 --- a/frontend/src/metabase-types/types/User.js +++ /dev/null @@ -1,13 +0,0 @@ -export type User = { - common_name: string, - date_joined: string, - email: string, - first_name: string, - google_auth: boolean, - id: number, - is_active: boolean, - is_qbnewb: false, - is_superuser: true, - last_login: string, - last_name: string, -}; diff --git a/frontend/src/metabase-types/types/User.ts b/frontend/src/metabase-types/types/User.ts new file mode 100644 index 0000000000000000000000000000000000000000..6ac48a7e95a8daf5dc86e6c1d592fe4a38c05fc3 --- /dev/null +++ b/frontend/src/metabase-types/types/User.ts @@ -0,0 +1,13 @@ +export type User = { + common_name: string; + date_joined: string; + email: string; + first_name: string; + google_auth: boolean; + id: number; + is_active: boolean; + is_qbnewb: false; + is_superuser: true; + last_login: string; + last_name: string; +}; diff --git a/frontend/src/metabase-types/types/Visualization.js b/frontend/src/metabase-types/types/Visualization.js deleted file mode 100644 index 12cd55ef929b418324fe059b9fa27e28b943eb30..0000000000000000000000000000000000000000 --- a/frontend/src/metabase-types/types/Visualization.js +++ /dev/null @@ -1,122 +0,0 @@ -import type { - DatasetData, - Column, - Row, - Value, -} from "metabase-types/types/Dataset"; -import type { Card, VisualizationSettings } from "metabase-types/types/Card"; -import type { ReduxAction } from "metabase-types/types/redux"; -import Question from "metabase-lib/lib/Question"; - -export type ActionCreator = (props: ClickActionProps) => ClickAction[]; - -export type QueryMode = { - name: string, - drills: () => ActionCreator[], -}; - -export type HoverData = Array<{ key: string, value: any, col?: Column }>; - -export type HoverObject = { - index?: number, - axisIndex?: number, - data?: HoverData, - element?: ?HTMLElement, - event?: MouseEvent, -}; - -export type DimensionValue = { - value: Value, - column: Column, -}; - -export type ClickObject = { - value?: Value, - column?: ?Column, - dimensions?: DimensionValue[], - event?: MouseEvent, - element?: HTMLElement, - seriesIndex?: number, - settings?: { [key: string]: any }, - origin?: { - row: Row, - cols: Column[], - }, - extraData?: { [key: string]: any }, -}; - -export type ClickAction = { - title?: any, // React Element - icon?: string, - popover?: (props: ClickActionPopoverProps) => any, // React Element - question?: () => ?Question, - url?: () => string, - action?: () => ?ReduxAction, - section?: string, - name?: string, - default?: boolean, - defaultAlways?: boolean, -}; - -export type ClickActionProps = { - question: Question, - clicked?: ClickObject, -}; - -export type OnChangeCardAndRun = ({ - nextCard: Card, - previousCard?: ?Card, -}) => void; - -export type ClickActionPopoverProps = { - onChangeCardAndRun: OnChangeCardAndRun, - onClose: () => void, -}; - -export type SingleSeries = { card: Card, data: DatasetData }; -export type RawSeries = SingleSeries[]; -export type TransformedSeries = RawSeries & { _raw: Series }; -export type Series = RawSeries | TransformedSeries; - -// These are the props provided to the visualization implementations BY the Visualization component -export type VisualizationProps = { - series: Series, - card: Card, - data: DatasetData, - settings: VisualizationSettings, - - className?: string, - gridSize: ?{ - width: number, - height: number, - }, - - width: number, - height: number, - - showTitle: boolean, - isDashboard: boolean, - isEditing: boolean, - isSettings: boolean, - actionButtons: Node, - - onRender: ({ - yAxisSplit?: number[][], - warnings?: string[], - }) => void, - onRenderError: (error: ?Error) => void, - - hovered: ?HoverObject, - onHoverChange: (?HoverObject) => void, - onVisualizationClick: (?ClickObject) => void, - visualizationIsClickable: (?ClickObject) => boolean, - onChangeCardAndRun: OnChangeCardAndRun, - - onUpdateVisualizationSettings: ({ [key: string]: any }) => void, - - onAddSeries?: Function, - onEditSeries?: Function, - onRemoveSeries?: Function, - - onUpdateWarnings?: Function, -}; diff --git a/frontend/src/metabase-types/types/Visualization.ts b/frontend/src/metabase-types/types/Visualization.ts new file mode 100644 index 0000000000000000000000000000000000000000..a0e9a33723a4b1cb2892c881c9d69e4c86442ac8 --- /dev/null +++ b/frontend/src/metabase-types/types/Visualization.ts @@ -0,0 +1,125 @@ +import { DatasetData, Column, Row, Value } from "metabase-types/types/Dataset"; +import { Card, VisualizationSettings } from "metabase-types/types/Card"; +import { ReduxAction } from "metabase-types/types/redux"; + +// import Question from "metabase-lib/lib/Question"; +type Question = any; + +export type ActionCreator = (props: ClickActionProps) => ClickAction[]; + +export type QueryMode = { + name: string; + drills: () => ActionCreator[]; +}; + +export type HoverData = Array<{ key: string; value: any; col?: Column }>; + +export type HoverObject = { + index?: number; + axisIndex?: number; + data?: HoverData; + element?: HTMLElement; + event?: MouseEvent; +}; + +export type DimensionValue = { + value: Value; + column: Column; +}; + +export type ClickObject = { + value?: Value; + column?: Column; + dimensions?: DimensionValue[]; + event?: MouseEvent; + element?: HTMLElement; + seriesIndex?: number; + settings?: { [key: string]: any }; + origin?: { + row: Row; + cols: Column[]; + }; + extraData?: { [key: string]: any }; +}; + +export type ClickAction = { + title?: any; // React Element + icon?: string; + popover?: (props: ClickActionPopoverProps) => any; // React Element + question?: () => Question | undefined; + url?: () => string; + action?: () => ReduxAction | undefined; + section?: string; + name?: string; + default?: boolean; + defaultAlways?: boolean; +}; + +export type ClickActionProps = { + question: Question; + clicked?: ClickObject; +}; + +export type OnChangeCardAndRun = ({ + nextCard, + previousCard, +}: { + nextCard: Card; + previousCard?: Card; +}) => void; + +export type ClickActionPopoverProps = { + onChangeCardAndRun: OnChangeCardAndRun; + onClose: () => void; +}; + +export type SingleSeries = { card: Card; data: DatasetData }; +export type RawSeries = SingleSeries[]; +export type TransformedSeries = RawSeries & { _raw: Series }; +export type Series = RawSeries | TransformedSeries; + +// These are the props provided to the visualization implementations BY the Visualization component +export type VisualizationProps = { + series: Series; + card: Card; + data: DatasetData; + settings: VisualizationSettings; + + className?: string; + gridSize?: { + width: number; + height: number; + }; + + width: number; + height: number; + + showTitle: boolean; + isDashboard: boolean; + isEditing: boolean; + isSettings: boolean; + actionButtons: Node; + + onRender: ({ + yAxisSplit, + warnings, + }: { + yAxisSplit?: number[][]; + warnings?: string[]; + }) => void; + onRenderError: (error?: Error) => void; + + hovered?: HoverObject; + onHoverChange: (hoverObject?: HoverObject) => void; + onVisualizationClick: (clickObject?: ClickObject) => void; + visualizationIsClickable: (clickObject?: ClickObject) => boolean; + onChangeCardAndRun: OnChangeCardAndRun; + + onUpdateVisualizationSettings: (settings: Record<string, any>) => void; + + onAddSeries?: any; + onEditSeries?: any; + onRemoveSeries?: any; + + onUpdateWarnings?: any; +}; diff --git a/frontend/src/metabase-types/types/index.js b/frontend/src/metabase-types/types/index.ts similarity index 74% rename from frontend/src/metabase-types/types/index.js rename to frontend/src/metabase-types/types/index.ts index 7961ccda47eba65d42438520b651339950f405b4..1c61c29f6f84595218bdb62977f19e023992655d 100644 --- a/frontend/src/metabase-types/types/index.js +++ b/frontend/src/metabase-types/types/index.ts @@ -12,25 +12,25 @@ export type IconName = string; /* Location descriptor used by react-router and history */ export type LocationDescriptor = { - hash: string, - pathname: string, - search?: string, - query?: { [key: string]: string }, + hash: string; + pathname: string; + search?: string; + query?: { [key: string]: string }; }; /* Map of query string names to string values */ export type QueryParams = { - [key: string]: string, + [key: string]: string; }; /* Metabase API error object returned by the backend */ export type ApiError = { - status: number, // HTTP status + status: number; // HTTP status // TODO: incomplete }; // FIXME: actual moment.js type export type Moment = { - locale: () => Moment, - format: (format: string) => string, + locale: () => Moment; + format: (format: string) => string; }; diff --git a/frontend/src/metabase-types/types/redux.js b/frontend/src/metabase-types/types/redux.ts similarity index 69% rename from frontend/src/metabase-types/types/redux.js rename to frontend/src/metabase-types/types/redux.ts index 29d4404fd89a97bb685afd0b4def0dae152e03d6..51114e055feca61513fa6c8ab58295393e9dc907 100644 --- a/frontend/src/metabase-types/types/redux.js +++ b/frontend/src/metabase-types/types/redux.ts @@ -1,9 +1,9 @@ // "Flux standard action" style redux action export type ReduxAction = - | { type: string, payload?: any, error?: boolean } + | { type: string; payload?: any; error?: boolean } | ReduxActionThunk; export type ReduxActionThunk = ( dispatch: (action: ReduxAction) => void, - getState: () => Object, + getState: () => any, ) => void;