rename groupby methods
This commit is contained in:
parent
69b8ae5687
commit
592eb5697d
9
lib/constants/sortTypes.d.ts
vendored
Normal file
9
lib/constants/sortTypes.d.ts
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
declare const sortDirections: {
|
||||
ASCENDING: string;
|
||||
DESCENDING: string;
|
||||
};
|
||||
declare const sortValueTypes: {
|
||||
NUMERIC: string;
|
||||
ALPHABETIC: string;
|
||||
};
|
||||
export { sortDirections, sortValueTypes };
|
13
lib/constants/sortTypes.js
Normal file
13
lib/constants/sortTypes.js
Normal file
@ -0,0 +1,13 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.sortValueTypes = exports.sortDirections = void 0;
|
||||
const sortDirections = {
|
||||
ASCENDING: 'ASCENDING',
|
||||
DESCENDING: 'DESCENDING'
|
||||
};
|
||||
exports.sortDirections = sortDirections;
|
||||
const sortValueTypes = {
|
||||
NUMERIC: 'NUMERIC',
|
||||
ALPHABETIC: 'ALPHABETIC'
|
||||
};
|
||||
exports.sortValueTypes = sortValueTypes;
|
2
lib/entities/nodules/FilterNodule.d.ts
vendored
2
lib/entities/nodules/FilterNodule.d.ts
vendored
@ -5,7 +5,7 @@ declare class FilterNodule extends Nodule {
|
||||
filterParams: filterParams;
|
||||
constructor(props: filterNoduleConstructionProps);
|
||||
addFilter: (params: filterParams) => void;
|
||||
setFilterType: (filterType: filterType) => void;
|
||||
setFilterType: (filterType: string) => void;
|
||||
export: () => import("../../types/tableTypes").tableRow[];
|
||||
private createFilterMethods;
|
||||
private validateFilters;
|
||||
|
2
lib/entities/nodules/GroupByNodule.d.ts
vendored
2
lib/entities/nodules/GroupByNodule.d.ts
vendored
@ -7,7 +7,7 @@ declare class GroupByNodule extends Nodule {
|
||||
asTables: () => Table[];
|
||||
asTable: () => never;
|
||||
export: () => never;
|
||||
exportTables: () => groupedByRows;
|
||||
exportRowGroups: () => groupedByRows;
|
||||
setGroupByValue: (value: string) => void;
|
||||
private validateGroupByValue;
|
||||
}
|
||||
|
11
lib/entities/nodules/SortNodule.d.ts
vendored
Normal file
11
lib/entities/nodules/SortNodule.d.ts
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
import { sortDirection, sortKey, sortNoduleConstructorProps, sortValueType } from '../../types/noduleTypes';
|
||||
import { tableRow } from '../../types/tableTypes';
|
||||
import Nodule from '../Nodule';
|
||||
declare class SortNodule extends Nodule {
|
||||
sortValueType: sortValueType;
|
||||
sortDirection: sortDirection;
|
||||
sortKey: sortKey;
|
||||
constructor(props: sortNoduleConstructorProps);
|
||||
export: () => tableRow[];
|
||||
}
|
||||
export default SortNodule;
|
42
lib/entities/nodules/SortNodule.js
Normal file
42
lib/entities/nodules/SortNodule.js
Normal file
@ -0,0 +1,42 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const sortTypes_1 = require("../../constants/sortTypes");
|
||||
const Nodule_1 = require("../Nodule");
|
||||
class SortNodule extends Nodule_1.default {
|
||||
sortValueType = sortTypes_1.sortValueTypes.ALPHABETIC;
|
||||
sortDirection = sortTypes_1.sortDirections.ASCENDING;
|
||||
sortKey = '';
|
||||
constructor(props) {
|
||||
super(props);
|
||||
const { sortValueType, sortDirection, sortKey } = props;
|
||||
if (sortValueType)
|
||||
this.sortValueType = sortValueType;
|
||||
if (sortDirection)
|
||||
this.sortDirection = sortDirection;
|
||||
if (sortKey)
|
||||
this.sortKey = sortKey;
|
||||
}
|
||||
export = () => {
|
||||
const { sortValueType, sortDirection, sortKey } = this;
|
||||
const { NUMERIC } = sortTypes_1.sortValueTypes;
|
||||
const { DESCENDING } = sortTypes_1.sortDirections;
|
||||
let sortMethod;
|
||||
if (sortValueType === NUMERIC)
|
||||
sortMethod = (a, b) => {
|
||||
const aValue = a[sortKey];
|
||||
const bValue = b[sortKey];
|
||||
return aValue - bValue;
|
||||
};
|
||||
else
|
||||
sortMethod = (a, b) => {
|
||||
const aValue = a[sortKey];
|
||||
const bValue = b[sortKey];
|
||||
return aValue.toLowerCase().localeCompare(bValue.toLowerCase());
|
||||
};
|
||||
let rows = this.tables.map(t => t.export()).flat().sort(sortMethod);
|
||||
if (sortDirection === DESCENDING)
|
||||
rows = rows.reverse();
|
||||
return rows;
|
||||
};
|
||||
}
|
||||
exports.default = SortNodule;
|
@ -30,7 +30,7 @@ class TransformNodule extends Nodule_1.default {
|
||||
const err = {
|
||||
status: 'ERR',
|
||||
error: {
|
||||
label: 'Ptructure Parameters are not valid',
|
||||
label: 'Structure Parameters are not valid',
|
||||
messages: []
|
||||
}
|
||||
};
|
||||
|
20
lib/types/noduleTypes.d.ts
vendored
20
lib/types/noduleTypes.d.ts
vendored
@ -1,3 +1,5 @@
|
||||
import filterTypes from "../constants/filterTypes";
|
||||
import { sortValueTypes, sortDirections } from "../constants/sortTypes";
|
||||
import Table from "../entities/Table";
|
||||
import { tableRow } from "./tableTypes";
|
||||
declare type noduleConstructorProps = {
|
||||
@ -6,7 +8,9 @@ declare type noduleConstructorProps = {
|
||||
type?: 'Nodule';
|
||||
tables?: Table[];
|
||||
};
|
||||
declare type filterType = 'EQUAL' | 'GREATER' | 'GREATEREQUAL' | 'LESSER' | 'LESSEREQUAL';
|
||||
declare type filterKeys = keyof typeof filterTypes;
|
||||
declare type filterValues = typeof filterTypes[filterKeys];
|
||||
declare type filterType = filterValues;
|
||||
declare type filterParams = Record<string, string | number>;
|
||||
declare type filterNoduleConstructionProps = noduleConstructorProps & {
|
||||
filterType: filterType;
|
||||
@ -33,4 +37,16 @@ declare type groupByNoduleConstructorProps = noduleConstructorProps & {
|
||||
groupByValue: string;
|
||||
};
|
||||
declare type groupedByRows = Record<string, tableRow[]>;
|
||||
export { noduleConstructorProps, filterNoduleConstructionProps, filterType, filterParams, joinParam, joinBy, joinNoduleConstructionProps, transformStruct, transformNoduleConstructionProps, groupByNoduleConstructorProps, groupedByRows };
|
||||
declare type sortDirectionKeys = keyof typeof sortDirections;
|
||||
declare type sortDirectionValues = typeof sortDirections[sortDirectionKeys];
|
||||
declare type sortDirection = sortDirectionValues;
|
||||
declare type sortValueTypeKeys = keyof typeof sortValueTypes;
|
||||
declare type sortValueTypeValues = typeof sortValueTypes[sortValueTypeKeys];
|
||||
declare type sortValueType = sortValueTypeValues;
|
||||
declare type sortKey = string;
|
||||
declare type sortNoduleConstructorProps = noduleConstructorProps & {
|
||||
sortDirection: sortDirection;
|
||||
sortValueType: sortValueType;
|
||||
sortKey: sortKey;
|
||||
};
|
||||
export { noduleConstructorProps, filterNoduleConstructionProps, filterType, filterParams, joinParam, joinBy, joinNoduleConstructionProps, transformStruct, transformNoduleConstructionProps, groupByNoduleConstructorProps, groupedByRows, sortDirection, sortValueType, sortKey, sortNoduleConstructorProps, };
|
||||
|
@ -13,7 +13,7 @@ class GroupByNodule extends Nodule {
|
||||
}
|
||||
|
||||
asTables = (): Table[] => {
|
||||
const exports = this.exportTables()
|
||||
const exports = this.exportRowGroups()
|
||||
const tables = []
|
||||
for (let key in exports) {
|
||||
const newTableProps: tableConstructorProps = {
|
||||
@ -35,7 +35,7 @@ class GroupByNodule extends Nodule {
|
||||
throw new Error('"export()" can not be called by GroupByNodule. Call "exportTables()"')
|
||||
}
|
||||
|
||||
exportTables = (): groupedByRows => {
|
||||
exportRowGroups = (): groupedByRows => {
|
||||
const { groupByValue } = this
|
||||
const rows = this.tables.map(t => t.export() ).flat()
|
||||
const groupedByRows = rows.reduce((groups: groupedByRows, r) => {
|
||||
|
@ -42,7 +42,7 @@ const groupByTest = () => {
|
||||
return false
|
||||
}
|
||||
|
||||
const groupedRows = groupByNodule.exportTables()
|
||||
const groupedRows = groupByNodule.exportRowGroups()
|
||||
if (JSON.stringify(groupedRows) === JSON.stringify(expectedOutput)) {
|
||||
return true
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user