Skip to content
Snippets Groups Projects
Commit a041e4c7 authored by Tom Robinson's avatar Tom Robinson
Browse files

Fix flow

parent 164e68f0
Branches
Tags
No related merge requests found
......@@ -54,6 +54,11 @@ import colors from "metabase/lib/colors";
import { getGlobalSettingsForColumn } from "metabase/visualizations/lib/settings/column";
import { isCurrency } from "metabase/lib/schema_metadata";
import type { ColumnSettings as ColumnSettingsType } from "metabase/meta/types/Dataset";
import type { DatabaseId } from "metabase/meta/types/Database";
import type { TableId } from "metabase/meta/types/Table";
import type { FieldId } from "metabase/meta/types/Field";
const mapStateToProps = (state, props) => {
return {
databaseId: parseInt(props.params.databaseId),
......@@ -86,9 +91,9 @@ export default class FieldApp extends React.Component {
saveStatus: null;
props: {
databaseId: number,
tableId: number,
fieldId: number,
databaseId: DatabaseId,
tableId: TableId,
fieldId: FieldId,
metadata: Metadata,
idfields: Object[],
......@@ -97,11 +102,18 @@ export default class FieldApp extends React.Component {
fetchFieldValues: number => Promise<void>,
updateField: any => Promise<void>,
updateFieldValues: any => Promise<void>,
updateFieldDimension: any => Promise<void>,
deleteFieldDimension: any => Promise<void>,
fetchDatabaseIdfields: number => Promise<void>,
updateFieldDimension: (FieldId, any) => Promise<void>,
deleteFieldDimension: FieldId => Promise<void>,
fetchDatabaseIdfields: DatabaseId => Promise<void>,
rescanFieldValues: FieldId => Promise<void>,
discardFieldValues: FieldId => Promise<void>,
location: any,
params: any,
};
// $FlowFixMe
async componentWillMount() {
const {
databaseId,
......@@ -131,11 +143,11 @@ export default class FieldApp extends React.Component {
await fetchDatabaseIdfields(databaseId);
}
linkWithSaveStatus = saveMethod => {
linkWithSaveStatus = (saveMethod: Function) => {
const self = this;
return async (...params) => {
return async (...args: any[]) => {
self.saveStatus && self.saveStatus.setSaving();
await saveMethod(...params);
await saveMethod(...args);
self.saveStatus && self.saveStatus.setSaved();
};
};
......@@ -166,7 +178,8 @@ export default class FieldApp extends React.Component {
this.props.deleteFieldDimension,
);
onUpdateFieldSettings = settings => {
// $FlowFixMe
onUpdateFieldSettings = (settings: ColumnSettingsType): void => {
return this.onUpdateFieldProperties({ settings });
};
......@@ -377,7 +390,13 @@ const FieldSettingsPane = ({ field, onUpdateFieldSettings }) => (
// TODO: Should this invoke goBack() instead?
// not sure if it's possible to do that neatly with Link component
export const BackButton = ({ databaseId, tableId }) => (
export const BackButton = ({
databaseId,
tableId,
}: {
databaseId: DatabaseId,
tableId: TableId,
}) => (
<Link
to={`/admin/datamodel/database/${databaseId}/table/${tableId}`}
className="circle text-white p2 flex align-center justify-center inline"
......@@ -388,10 +407,10 @@ export const BackButton = ({ databaseId, tableId }) => (
);
export class FieldHeader extends React.Component {
onNameChange = e => {
onNameChange = (e: { target: HTMLInputElement }) => {
this.updateNameDebounced(e.target.value);
};
onDescriptionChange = e => {
onDescriptionChange = (e: { target: HTMLInputElement }) => {
this.updateDescriptionDebounced(e.target.value);
};
......
......@@ -45,10 +45,10 @@ import type {
} from "metabase/lib/formatting/date";
// a one or two character string specifying the decimal and grouping separator characters
type NumberSeparators = ".," | ", " | ",." | ".";
export type NumberSeparators = ".," | ", " | ",." | ".";
// single character string specifying date separators
type DateSeparator = "/" | "-" | ".";
export type DateSeparator = "/" | "-" | ".";
export type FormattingOptions = {
// GENERIC
......@@ -455,8 +455,8 @@ export function formatDateTimeWithUnit(
let timeFormat = options.time_format;
if (!dateFormat) {
// $FlowFixMe: date_style default set above
dateFormat = getDateFormatFromStyle(
// $FlowFixMe: date_style default set above
options["date_style"],
unit,
options["date_separator"],
......
/* @flow */
import type { DateSeparator } from "metabase/lib/formatting";
import type { DatetimeUnit } from "metabase/meta/types/Query";
export type DateStyle =
......@@ -84,17 +86,9 @@ export function getDateFormatFromStyle(
return replaceSeparators(style);
}
const UNITS_WITH_HOUR: DatetimeUnit[] = [
"default",
"millisecond",
"second",
"minute",
"hour",
];
const UNITS_WITH_HOUR: DatetimeUnit[] = ["default", "minute", "hour"];
const UNITS_WITH_DAY: DatetimeUnit[] = [
"default",
"millisecond",
"second",
"minute",
"hour",
"day",
......
......@@ -7,6 +7,8 @@ import type { DatetimeUnit, FieldLiteral } from "./Query";
export type ColumnName = string;
export type ColumnSettings = { [id: string]: any };
export type BinningInfo = {
bin_width: number,
};
......@@ -23,6 +25,7 @@ export type Column = {
binning_info?: BinningInfo,
fk_field_id?: FieldId,
"expression-name"?: any,
settings?: ColumnSettings,
};
export type Value = string | number | ISO8601Time | boolean | null | {};
......
......@@ -46,6 +46,7 @@ const ColumnSettings = ({
column = { ...column, unit: "millisecond" };
}
// $FlowFixMe
const settingsDefs = getSettingDefintionsForColumn(series, column);
const computedSettings = getComputedSettings(
......@@ -86,7 +87,7 @@ const ColumnSettings = ({
))
) : (
<EmptyState
title={t`No formatting settings`}
message={t`No formatting settings`}
illustrationElement={<img src="../app/assets/img/no_results.svg" />}
/>
)}
......
......@@ -45,6 +45,7 @@ export type SettingDef = {
widget?: string | React$Component<any, any, any>,
writeDependencies?: SettingId[],
readDependencies?: SettingId[],
noReset?: boolean,
};
export type WidgetDef = {
......@@ -54,6 +55,7 @@ export type WidgetDef = {
hidden: boolean,
disabled: boolean,
props: { [key: string]: any },
noReset?: boolean,
// $FlowFixMe
widget?: React$Component<any, any, any>,
onChange: (value: any) => void,
......
......@@ -72,13 +72,14 @@ export function columnSettings({
import MetabaseSettings from "metabase/lib/settings";
import { isa } from "metabase/lib/types";
export function getGlobalSettingsForColumn(column) {
export function getGlobalSettingsForColumn(column: Column) {
let settings = {};
const customFormatting = MetabaseSettings.get("custom-formatting");
// NOTE: the order of these doesn't matter as long as there's no overlap between settings
for (const [type, globalSettings] of Object.entries(customFormatting || {})) {
if (isa(column.special_type, type)) {
// $FlowFixMe
Object.assign(settings, globalSettings);
}
}
......@@ -86,11 +87,11 @@ export function getGlobalSettingsForColumn(column) {
return settings;
}
function getLocalSettingsForColumn(column) {
function getLocalSettingsForColumn(column: Column): Settings {
return column.settings || {};
}
function getInhertiedSettingsForColumn(column) {
function getInhertiedSettingsForColumn(column: Column): Settings {
return {
...getGlobalSettingsForColumn(column),
...getLocalSettingsForColumn(column),
......@@ -102,7 +103,7 @@ const EXAMPLE_DATE = moment("2018-01-07 17:24");
function getDateStyleOptionsForUnit(
unit: ?DatetimeUnit,
abbreviate?: boolean = false,
separator?: string = null,
separator?: string,
) {
const options = [
dateStyleOption("MMMM D, YYYY", unit, null, abbreviate, separator),
......@@ -147,7 +148,7 @@ function dateStyleOption(
unit: ?DatetimeUnit,
description?: ?string,
abbreviate?: boolean = false,
separator?: string = null,
separator?: string,
) {
let format = getDateFormatFromStyle(style, unit, separator);
if (abbreviate) {
......@@ -280,10 +281,10 @@ export const NUMBER_COLUMN_SETTINGS = {
{ name: "Currency", value: "currency" },
],
},
getDefault: (column, settings) =>
getDefault: (column: Column, settings: ColumnSettings) =>
isCurrency(column) && settings["currency"] ? "currency" : "decimal",
// hide this for currency
getHidden: (column, settings) =>
getHidden: (column: Column, settings: ColumnSettings) =>
isCurrency(column) && settings["number_style"] === "currency",
},
currency: {
......@@ -291,10 +292,13 @@ export const NUMBER_COLUMN_SETTINGS = {
widget: "select",
props: {
// FIXME: rest of these options
options: Object.values(currency).map(currency => ({
name: currency.name,
value: currency.code,
})),
options: Object.values(currency).map(
// $FlowFixMe
(currency: { name: string, code: string }) => ({
name: currency.name,
value: currency.code,
}),
),
searchProp: "name",
searchCaseSensitive: false,
},
......@@ -331,7 +335,11 @@ export const NUMBER_COLUMN_SETTINGS = {
],
},
default: true,
getHidden: (column: Column, settings: ColumnSettings, { series }) =>
getHidden: (
column: Column,
settings: ColumnSettings,
{ series }: { series: Series },
) =>
settings["number_style"] !== "currency" ||
series[0].card.display !== "table",
readDependencies: ["number_style"],
......@@ -399,7 +407,7 @@ export const NUMBER_COLUMN_SETTINGS = {
],
},
_column_title_full: {
getValue: (column, settings) => {
getValue: (column: Column, settings: ColumnSettings) => {
let columnTitle = settings["column_title"];
const headerUnit = settings["_header_unit"];
if (headerUnit) {
......
......@@ -46,7 +46,7 @@ function getSettingDefintionsForSeries(series: ?Series): SettingDefs {
}
export function getStoredSettingsForSeries(series: ?Series): Settings {
return series[0].card.visualization_settings || {};
return (series && series[0] && series[0].card.visualization_settings) || {};
}
export function getComputedSettingsForSeries(series: ?Series): Settings {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment