diff --git a/packages/kbn-datemath/package.json b/packages/kbn-datemath/package.json index 5338b65d83f2dc..c469661070816f 100644 --- a/packages/kbn-datemath/package.json +++ b/packages/kbn-datemath/package.json @@ -5,8 +5,9 @@ "license": "Apache-2.0", "private": true, "main": "target/index.js", + "typings": "target/index.d.ts", "scripts": { - "build": "babel src --out-dir target", + "build": "babel src --out-dir target --copy-files", "kbn:bootstrap": "yarn build", "kbn:watch": "yarn build --watch" }, diff --git a/packages/kbn-datemath/src/index.d.ts b/packages/kbn-datemath/src/index.d.ts new file mode 100644 index 00000000000000..e3389fb255700f --- /dev/null +++ b/packages/kbn-datemath/src/index.d.ts @@ -0,0 +1,29 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +declare module '@kbn/datemath' { + const dateMath: { + parse: any; + unitsMap: any; + units: string[]; + unitsAsc: string[]; + unitsDesc: string[]; + }; + export default dateMath; +} diff --git a/packages/kbn-datemath/src/index.js b/packages/kbn-datemath/src/index.js index 17d91a530fdb38..6576a458fe77b6 100644 --- a/packages/kbn-datemath/src/index.js +++ b/packages/kbn-datemath/src/index.js @@ -19,9 +19,20 @@ import moment from 'moment'; -const units = ['y', 'M', 'w', 'd', 'h', 'm', 's', 'ms']; -const unitsDesc = units; -const unitsAsc = [...unitsDesc].reverse(); +const unitsMap = { + ms: { weight: 1, type: 'fixed', base: 1 }, + s: { weight: 2, type: 'fixed', base: 1000 }, + m: { weight: 3, type: 'mixed', base: 1000 * 60 }, + h: { weight: 4, type: 'mixed', base: 1000 * 60 * 60 }, + d: { weight: 5, type: 'mixed', base: 1000 * 60 * 60 * 24 }, + w: { weight: 6, type: 'calendar' }, + M: { weight: 7, type: 'calendar' }, + // q: { weight: 8, type: 'calendar' }, // TODO: moment duration does not support quarter + y: { weight: 9, type: 'calendar' }, +}; +const units = Object.keys(unitsMap).sort((a, b) => unitsMap[b].weight - unitsMap[a].weight); +const unitsDesc = [...units]; +const unitsAsc = [...units].reverse(); const isDate = d => Object.prototype.toString.call(d) === '[object Date]'; @@ -142,6 +153,7 @@ function parseDateMath(mathString, time, roundUp) { export default { parse: parse, + unitsMap: Object.freeze(unitsMap), units: Object.freeze(units), unitsAsc: Object.freeze(unitsAsc), unitsDesc: Object.freeze(unitsDesc), diff --git a/packages/kbn-datemath/tsconfig.json b/packages/kbn-datemath/tsconfig.json new file mode 100644 index 00000000000000..c23b6635a5c19e --- /dev/null +++ b/packages/kbn-datemath/tsconfig.json @@ -0,0 +1,10 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "declaration": true, + "outDir": "./target" + }, + "include": [ + "./src/**/*.ts" + ] +} diff --git a/src/ui/public/agg_types/controls/number_interval.html b/src/ui/public/agg_types/controls/number_interval.html index f0283d614cf163..a281875531d114 100644 --- a/src/ui/public/agg_types/controls/number_interval.html +++ b/src/ui/public/agg_types/controls/number_interval.html @@ -6,15 +6,6 @@ position="'right'" content="'Interval will be automatically scaled in the event that the provided value creates more buckets than specified by Advanced Setting\'s histogram:maxBars'" > - - +
+ {{editorConfig.interval.help}} +
diff --git a/src/ui/public/agg_types/controls/time_interval.html b/src/ui/public/agg_types/controls/time_interval.html index 1da3e3ddcd39be..4a980f39c727c5 100644 --- a/src/ui/public/agg_types/controls/time_interval.html +++ b/src/ui/public/agg_types/controls/time_interval.html @@ -9,6 +9,7 @@ >