rename groupby methods

This commit is contained in:
joshuashoemaker 2022-06-26 01:09:35 -05:00
parent 69b8ae5687
commit 592eb5697d
10 changed files with 99 additions and 8 deletions

9
lib/constants/sortTypes.d.ts vendored Normal file
View File

@ -0,0 +1,9 @@
declare const sortDirections: {
ASCENDING: string;
DESCENDING: string;
};
declare const sortValueTypes: {
NUMERIC: string;
ALPHABETIC: string;
};
export { sortDirections, sortValueTypes };

View 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;

View File

@ -5,7 +5,7 @@ declare class FilterNodule extends Nodule {
filterParams: filterParams; filterParams: filterParams;
constructor(props: filterNoduleConstructionProps); constructor(props: filterNoduleConstructionProps);
addFilter: (params: filterParams) => void; addFilter: (params: filterParams) => void;
setFilterType: (filterType: filterType) => void; setFilterType: (filterType: string) => void;
export: () => import("../../types/tableTypes").tableRow[]; export: () => import("../../types/tableTypes").tableRow[];
private createFilterMethods; private createFilterMethods;
private validateFilters; private validateFilters;

View File

@ -7,7 +7,7 @@ declare class GroupByNodule extends Nodule {
asTables: () => Table[]; asTables: () => Table[];
asTable: () => never; asTable: () => never;
export: () => never; export: () => never;
exportTables: () => groupedByRows; exportRowGroups: () => groupedByRows;
setGroupByValue: (value: string) => void; setGroupByValue: (value: string) => void;
private validateGroupByValue; private validateGroupByValue;
} }

11
lib/entities/nodules/SortNodule.d.ts vendored Normal file
View 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;

View 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;

View File

@ -30,7 +30,7 @@ class TransformNodule extends Nodule_1.default {
const err = { const err = {
status: 'ERR', status: 'ERR',
error: { error: {
label: 'Ptructure Parameters are not valid', label: 'Structure Parameters are not valid',
messages: [] messages: []
} }
}; };

View File

@ -1,3 +1,5 @@
import filterTypes from "../constants/filterTypes";
import { sortValueTypes, sortDirections } from "../constants/sortTypes";
import Table from "../entities/Table"; import Table from "../entities/Table";
import { tableRow } from "./tableTypes"; import { tableRow } from "./tableTypes";
declare type noduleConstructorProps = { declare type noduleConstructorProps = {
@ -6,7 +8,9 @@ declare type noduleConstructorProps = {
type?: 'Nodule'; type?: 'Nodule';
tables?: Table[]; 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 filterParams = Record<string, string | number>;
declare type filterNoduleConstructionProps = noduleConstructorProps & { declare type filterNoduleConstructionProps = noduleConstructorProps & {
filterType: filterType; filterType: filterType;
@ -33,4 +37,16 @@ declare type groupByNoduleConstructorProps = noduleConstructorProps & {
groupByValue: string; groupByValue: string;
}; };
declare type groupedByRows = Record<string, tableRow[]>; 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, };

View File

@ -13,7 +13,7 @@ class GroupByNodule extends Nodule {
} }
asTables = (): Table[] => { asTables = (): Table[] => {
const exports = this.exportTables() const exports = this.exportRowGroups()
const tables = [] const tables = []
for (let key in exports) { for (let key in exports) {
const newTableProps: tableConstructorProps = { const newTableProps: tableConstructorProps = {
@ -35,7 +35,7 @@ class GroupByNodule extends Nodule {
throw new Error('"export()" can not be called by GroupByNodule. Call "exportTables()"') throw new Error('"export()" can not be called by GroupByNodule. Call "exportTables()"')
} }
exportTables = (): groupedByRows => { exportRowGroups = (): groupedByRows => {
const { groupByValue } = this const { groupByValue } = this
const rows = this.tables.map(t => t.export() ).flat() const rows = this.tables.map(t => t.export() ).flat()
const groupedByRows = rows.reduce((groups: groupedByRows, r) => { const groupedByRows = rows.reduce((groups: groupedByRows, r) => {

View File

@ -42,7 +42,7 @@ const groupByTest = () => {
return false return false
} }
const groupedRows = groupByNodule.exportTables() const groupedRows = groupByNodule.exportRowGroups()
if (JSON.stringify(groupedRows) === JSON.stringify(expectedOutput)) { if (JSON.stringify(groupedRows) === JSON.stringify(expectedOutput)) {
return true return true
} else { } else {