Skip to content

Commit

Permalink
Utils for selecting values and formatting them based on defined Split
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianmroz-allegro committed Feb 22, 2022
1 parent 092753f commit 1d85d37
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/common/models/split/split.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
* limitations under the License.
*/

import { Duration } from "chronoshift";
import { Duration, Timezone } from "chronoshift";
import { Record } from "immutable";
import { Expression, NumberBucketExpression, TimeBucketExpression } from "plywood";
import { Datum, Expression, NumberBucketExpression, PlywoodValue, TimeBucketExpression } from "plywood";
import { formatValue } from "../../utils/formatter/formatter";
import { isTruthy } from "../../utils/general/general";
import nullableEquals from "../../utils/immutable-utils/nullable-equals";
import { Dimension, DimensionKind } from "../dimension/dimension";
Expand Down Expand Up @@ -112,6 +113,14 @@ export class Split extends Record<SplitValue>(defaultSplit) {
return (dimension ? dimension.title : "?") + this.getBucketTitle();
}

public selectValue<T extends PlywoodValue>(datum: Datum): T {
return datum[this.toKey()] as T;
}

public formatValue(datum: Datum, timezone: Timezone): string {
return formatValue(datum[this.toKey()], timezone);
}

public getBucketTitle(): string {
const { bucket } = this;
if (!isTruthy(bucket)) {
Expand Down

0 comments on commit 1d85d37

Please sign in to comment.