Skip to content

Commit

Permalink
feat(aggregators): add better TS typing for all Aggregators
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiscoding committed Sep 9, 2021
1 parent f4d3843 commit 1518d6a
Show file tree
Hide file tree
Showing 14 changed files with 93 additions and 92 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Column, GroupTotalsFormatter } from './../interfaces/index';
import { Column, GroupTotalsFormatter, SlickGrid } from './../interfaces/index';
import { formatNumber } from './../services/utilities';
import { getValueFromParamsOrFormatterOptions } from '../formatters/formatterUtilities';

export const avgTotalsDollarFormatter: GroupTotalsFormatter = (totals: any, columnDef: Column, grid?: any) => {
const field = columnDef.field || '';
const val = totals.avg && totals.avg[field];
const params = columnDef && columnDef.params;
const prefix = params && params.groupFormatterPrefix || '';
const suffix = params && params.groupFormatterSuffix || '';
export const avgTotalsDollarFormatter: GroupTotalsFormatter = (totals: any, columnDef: Column, grid: SlickGrid) => {
const field = columnDef.field ?? '';
const val = totals.avg?.[field];
const params = columnDef?.params;
const prefix = params?.groupFormatterPrefix || '';
const suffix = params?.groupFormatterSuffix || '';
const minDecimal = getValueFromParamsOrFormatterOptions('minDecimal', columnDef, grid, 2);
const maxDecimal = getValueFromParamsOrFormatterOptions('maxDecimal', columnDef, grid, 4);
const decimalSeparator = getValueFromParamsOrFormatterOptions('decimalSeparator', columnDef, grid, '.');
Expand Down
14 changes: 7 additions & 7 deletions packages/common/src/grouping-formatters/avgTotalsFormatter.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Column, GroupTotalsFormatter } from './../interfaces/index';
import { Column, GroupTotalsFormatter, SlickGrid } from './../interfaces/index';
import { decimalFormatted, thousandSeparatorFormatted } from '../services/utilities';
import { getValueFromParamsOrFormatterOptions } from '../formatters/formatterUtilities';

export const avgTotalsFormatter: GroupTotalsFormatter = (totals: any, columnDef: Column, grid?: any) => {
const field = columnDef.field || '';
let val = totals.avg && totals.avg[field];
const params = columnDef && columnDef.params;
let prefix = params && params.groupFormatterPrefix || '';
const suffix = params && params.groupFormatterSuffix || '';
export const avgTotalsFormatter: GroupTotalsFormatter = (totals: any, columnDef: Column, grid: SlickGrid) => {
const field = columnDef.field ?? '';
let val = totals.avg?.[field];
const params = columnDef?.params;
let prefix = params?.groupFormatterPrefix || '';
const suffix = params?.groupFormatterSuffix || '';
const minDecimal = getValueFromParamsOrFormatterOptions('minDecimal', columnDef, grid);
const maxDecimal = getValueFromParamsOrFormatterOptions('maxDecimal', columnDef, grid);
const decimalSeparator = getValueFromParamsOrFormatterOptions('decimalSeparator', columnDef, grid, '.');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Column, GroupTotalsFormatter } from './../interfaces/index';
import { Column, GroupTotalsFormatter, SlickGrid } from './../interfaces/index';
import { decimalFormatted, thousandSeparatorFormatted } from '../services/utilities';
import { getValueFromParamsOrFormatterOptions } from '../formatters/formatterUtilities';

export const avgTotalsPercentageFormatter: GroupTotalsFormatter = (totals: any, columnDef: Column, grid?: any) => {
const field = columnDef.field || '';
let val = totals.avg && totals.avg[field];
const params = columnDef && columnDef.params;
let prefix = params && params.groupFormatterPrefix || '';
const suffix = params && params.groupFormatterSuffix || '';
export const avgTotalsPercentageFormatter: GroupTotalsFormatter = (totals: any, columnDef: Column, grid: SlickGrid) => {
const field = columnDef.field ?? '';
let val = totals.avg?.[field];
const params = columnDef?.params;
let prefix = params?.groupFormatterPrefix || '';
const suffix = params?.groupFormatterSuffix || '';
const minDecimal = getValueFromParamsOrFormatterOptions('minDecimal', columnDef, grid);
const maxDecimal = getValueFromParamsOrFormatterOptions('maxDecimal', columnDef, grid);
const decimalSeparator = getValueFromParamsOrFormatterOptions('decimalSeparator', columnDef, grid, '.');
Expand Down
14 changes: 7 additions & 7 deletions packages/common/src/grouping-formatters/maxTotalsFormatter.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Column, GroupTotalsFormatter } from './../interfaces/index';
import { Column, GroupTotalsFormatter, SlickGrid } from './../interfaces/index';
import { formatNumber } from '../services/utilities';
import { getValueFromParamsOrFormatterOptions } from '../formatters/formatterUtilities';

export const maxTotalsFormatter: GroupTotalsFormatter = (totals: any, columnDef: Column, grid?: any) => {
const field = columnDef.field || '';
const val = totals.max && totals.max[field];
const params = columnDef && columnDef.params;
const prefix = params && params.groupFormatterPrefix || '';
const suffix = params && params.groupFormatterSuffix || '';
export const maxTotalsFormatter: GroupTotalsFormatter = (totals: any, columnDef: Column, grid: SlickGrid) => {
const field = columnDef.field ?? '';
const val = totals.max?.[field];
const params = columnDef?.params;
const prefix = params?.groupFormatterPrefix || '';
const suffix = params?.groupFormatterSuffix || '';
const minDecimal = getValueFromParamsOrFormatterOptions('minDecimal', columnDef, grid);
const maxDecimal = getValueFromParamsOrFormatterOptions('maxDecimal', columnDef, grid);
const decimalSeparator = getValueFromParamsOrFormatterOptions('decimalSeparator', columnDef, grid, '.');
Expand Down
14 changes: 7 additions & 7 deletions packages/common/src/grouping-formatters/minTotalsFormatter.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Column, GroupTotalsFormatter } from './../interfaces/index';
import { Column, GroupTotalsFormatter, SlickGrid } from './../interfaces/index';
import { formatNumber } from '../services/utilities';
import { getValueFromParamsOrFormatterOptions } from '../formatters/formatterUtilities';

export const minTotalsFormatter: GroupTotalsFormatter = (totals: any, columnDef: Column, grid?: any) => {
const field = columnDef.field || '';
const val = totals.min && totals.min[field];
const params = columnDef && columnDef.params;
const prefix = params && params.groupFormatterPrefix || '';
const suffix = params && params.groupFormatterSuffix || '';
export const minTotalsFormatter: GroupTotalsFormatter = (totals: any, columnDef: Column, grid: SlickGrid) => {
const field = columnDef.field ?? '';
const val = totals.min?.[field];
const params = columnDef?.params;
const prefix = params?.groupFormatterPrefix || '';
const suffix = params?.groupFormatterSuffix || '';
const minDecimal = getValueFromParamsOrFormatterOptions('minDecimal', columnDef, grid);
const maxDecimal = getValueFromParamsOrFormatterOptions('maxDecimal', columnDef, grid);
const decimalSeparator = getValueFromParamsOrFormatterOptions('decimalSeparator', columnDef, grid, '.');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Column, GroupTotalsFormatter } from './../interfaces/index';
import { Column, GroupTotalsFormatter, SlickGrid } from './../interfaces/index';
import { formatNumber } from '../services/utilities';
import { getValueFromParamsOrFormatterOptions } from '../formatters/formatterUtilities';

export const sumTotalsBoldFormatter: GroupTotalsFormatter = (totals: any, columnDef: Column, grid?: any) => {
const field = columnDef.field || '';
const val = totals.sum && totals.sum[field];
const params = columnDef && columnDef.params;
const prefix = params && params.groupFormatterPrefix || '';
const suffix = params && params.groupFormatterSuffix || '';
export const sumTotalsBoldFormatter: GroupTotalsFormatter = (totals: any, columnDef: Column, grid: SlickGrid) => {
const field = columnDef.field ?? '';
const val = totals.sum?.[field];
const params = columnDef?.params;
const prefix = params?.groupFormatterPrefix || '';
const suffix = params?.groupFormatterSuffix || '';
const minDecimal = getValueFromParamsOrFormatterOptions('minDecimal', columnDef, grid);
const maxDecimal = getValueFromParamsOrFormatterOptions('maxDecimal', columnDef, grid);
const decimalSeparator = getValueFromParamsOrFormatterOptions('decimalSeparator', columnDef, grid, '.');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Column, GroupTotalsFormatter } from './../interfaces/index';
import { Column, GroupTotalsFormatter, SlickGrid } from './../interfaces/index';
import { formatNumber } from '../services/utilities';
import { getValueFromParamsOrFormatterOptions } from '../formatters/formatterUtilities';

export const sumTotalsColoredFormatter: GroupTotalsFormatter = (totals: any, columnDef: Column, grid?: any) => {
const field = columnDef.field || '';
const val = totals.sum && totals.sum[field];
const params = columnDef && columnDef.params;
const prefix = params && params.groupFormatterPrefix || '';
const suffix = params && params.groupFormatterSuffix || '';
export const sumTotalsColoredFormatter: GroupTotalsFormatter = (totals: any, columnDef: Column, grid: SlickGrid) => {
const field = columnDef.field ?? '';
const val = totals.sum?.[field];
const params = columnDef?.params;
const prefix = params?.groupFormatterPrefix || '';
const suffix = params?.groupFormatterSuffix || '';
const minDecimal = getValueFromParamsOrFormatterOptions('minDecimal', columnDef, grid);
const maxDecimal = getValueFromParamsOrFormatterOptions('maxDecimal', columnDef, grid);
const decimalSeparator = getValueFromParamsOrFormatterOptions('decimalSeparator', columnDef, grid, '.');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Column, GroupTotalsFormatter } from './../interfaces/index';
import { Column, GroupTotalsFormatter, SlickGrid } from './../interfaces/index';
import { formatNumber } from './../services/utilities';
import { getValueFromParamsOrFormatterOptions } from '../formatters/formatterUtilities';

export const sumTotalsDollarBoldFormatter: GroupTotalsFormatter = (totals: any, columnDef: Column, grid?: any) => {
const field = columnDef.field || '';
const val = totals.sum && totals.sum[field];
const params = columnDef && columnDef.params;
const prefix = params && params.groupFormatterPrefix || '';
const suffix = params && params.groupFormatterSuffix || '';
export const sumTotalsDollarBoldFormatter: GroupTotalsFormatter = (totals: any, columnDef: Column, grid: SlickGrid) => {
const field = columnDef.field ?? '';
const val = totals.sum?.[field];
const params = columnDef?.params;
const prefix = params?.groupFormatterPrefix || '';
const suffix = params?.groupFormatterSuffix || '';
const minDecimal = getValueFromParamsOrFormatterOptions('minDecimal', columnDef, grid, 2);
const maxDecimal = getValueFromParamsOrFormatterOptions('maxDecimal', columnDef, grid, 4);
const decimalSeparator = getValueFromParamsOrFormatterOptions('decimalSeparator', columnDef, grid, '.');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Column, GroupTotalsFormatter } from './../interfaces/index';
import { Column, GroupTotalsFormatter, SlickGrid } from './../interfaces/index';
import { formatNumber } from './../services/utilities';
import { getValueFromParamsOrFormatterOptions } from '../formatters/formatterUtilities';

export const sumTotalsDollarColoredBoldFormatter: GroupTotalsFormatter = (totals: any, columnDef: Column, grid?: any) => {
const field = columnDef.field || '';
const val = totals.sum && totals.sum[field];
const params = columnDef && columnDef.params;
const prefix = params && params.groupFormatterPrefix || '';
const suffix = params && params.groupFormatterSuffix || '';
export const sumTotalsDollarColoredBoldFormatter: GroupTotalsFormatter = (totals: any, columnDef: Column, grid: SlickGrid) => {
const field = columnDef.field ?? '';
const val = totals.sum?.[field];
const params = columnDef?.params;
const prefix = params?.groupFormatterPrefix || '';
const suffix = params?.groupFormatterSuffix || '';
const minDecimal = getValueFromParamsOrFormatterOptions('minDecimal', columnDef, grid, 2);
const maxDecimal = getValueFromParamsOrFormatterOptions('maxDecimal', columnDef, grid, 4);
const decimalSeparator = getValueFromParamsOrFormatterOptions('decimalSeparator', columnDef, grid, '.');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Column, GroupTotalsFormatter } from './../interfaces/index';
import { Column, GroupTotalsFormatter, SlickGrid } from './../interfaces/index';
import { formatNumber } from './../services/utilities';
import { getValueFromParamsOrFormatterOptions } from '../formatters/formatterUtilities';

export const sumTotalsDollarColoredFormatter: GroupTotalsFormatter = (totals: any, columnDef: Column, grid?: any) => {
const field = columnDef.field || '';
const val = totals.sum && totals.sum[field];
const params = columnDef && columnDef.params;
const prefix = params && params.groupFormatterPrefix || '';
const suffix = params && params.groupFormatterSuffix || '';
export const sumTotalsDollarColoredFormatter: GroupTotalsFormatter = (totals: any, columnDef: Column, grid: SlickGrid) => {
const field = columnDef.field ?? '';
const val = totals.sum?.[field];
const params = columnDef?.params;
const prefix = params?.groupFormatterPrefix || '';
const suffix = params?.groupFormatterSuffix || '';
const minDecimal = getValueFromParamsOrFormatterOptions('minDecimal', columnDef, grid, 2);
const maxDecimal = getValueFromParamsOrFormatterOptions('maxDecimal', columnDef, grid, 4);
const decimalSeparator = getValueFromParamsOrFormatterOptions('decimalSeparator', columnDef, grid, '.');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Column, GroupTotalsFormatter } from './../interfaces/index';
import { Column, GroupTotalsFormatter, SlickGrid } from './../interfaces/index';
import { formatNumber } from './../services/utilities';
import { getValueFromParamsOrFormatterOptions } from '../formatters/formatterUtilities';

export const sumTotalsDollarFormatter: GroupTotalsFormatter = (totals: any, columnDef: Column, grid?: any) => {
const field = columnDef.field || '';
const val = totals.sum && totals.sum[field];
const params = columnDef && columnDef.params;
const prefix = params && params.groupFormatterPrefix || '';
const suffix = params && params.groupFormatterSuffix || '';
export const sumTotalsDollarFormatter: GroupTotalsFormatter = (totals: any, columnDef: Column, grid: SlickGrid) => {
const field = columnDef.field ?? '';
const val = totals.sum?.[field];
const params = columnDef?.params;
const prefix = params?.groupFormatterPrefix || '';
const suffix = params?.groupFormatterSuffix || '';
const minDecimal = getValueFromParamsOrFormatterOptions('minDecimal', columnDef, grid, 2);
const maxDecimal = getValueFromParamsOrFormatterOptions('maxDecimal', columnDef, grid, 4);
const decimalSeparator = getValueFromParamsOrFormatterOptions('decimalSeparator', columnDef, grid, '.');
Expand Down
14 changes: 7 additions & 7 deletions packages/common/src/grouping-formatters/sumTotalsFormatter.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Column, GroupTotalsFormatter } from './../interfaces/index';
import { Column, GroupTotalsFormatter, SlickGrid } from './../interfaces/index';
import { formatNumber } from '../services/utilities';
import { getValueFromParamsOrFormatterOptions } from '../formatters/formatterUtilities';

export const sumTotalsFormatter: GroupTotalsFormatter = (totals: any, columnDef: Column, grid?: any) => {
const field = columnDef.field || '';
const val = totals.sum && totals.sum[field];
const params = columnDef && columnDef.params;
const prefix = params && params.groupFormatterPrefix || '';
const suffix = params && params.groupFormatterSuffix || '';
export const sumTotalsFormatter: GroupTotalsFormatter = (totals: any, columnDef: Column, grid: SlickGrid) => {
const field = columnDef.field ?? '';
const val = totals.sum?.[field];
const params = columnDef?.params;
const prefix = params?.groupFormatterPrefix || '';
const suffix = params?.groupFormatterSuffix || '';
const minDecimal = getValueFromParamsOrFormatterOptions('minDecimal', columnDef, grid);
const maxDecimal = getValueFromParamsOrFormatterOptions('maxDecimal', columnDef, grid);
const decimalSeparator = getValueFromParamsOrFormatterOptions('decimalSeparator', columnDef, grid, '.');
Expand Down
14 changes: 7 additions & 7 deletions packages/common/src/interfaces/aggregator.interface.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
export interface Aggregator {
/** Aggregator associated Field Id */
field?: number | string;
/** Column definition field Id of the associated Aggregator */
field: number | string;

/** Aggregator associated type */
type?: string;
/** Type of Aggregator (sum, avg, ...) */
type: string;

/** Aggregator initialize method */
init: () => void;

/** Mathod to accumulate the result with different logic depending on each aggregator type */
/** Method to accumulate the result which will be different for each Aggregator type */
accumulate?: (item: any) => void;

/** Method to store the result into the given group total argument provided */
storeResult?: (groupTotals: any | undefined) => void;
/** Method to store the result into the given group total object provided as argument */
storeResult: (groupTotals: any | undefined) => void;
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Column } from './column.interface';
import { SlickGrid } from './slickGrid.interface';

export type GroupTotalsFormatter = (totals: any, columnDef: Column, grid?: any) => string;
export type GroupTotalsFormatter = (totals: any, columnDef: Column, grid: SlickGrid) => string;

0 comments on commit 1518d6a

Please sign in to comment.