Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"fallow": "fallow",
"fallow:dead-code": "fallow dead-code --production",
"fallow:dupes": "fallow dupes",
"fallow:health": "fallow health",
"fallow:health": "fallow health --coverage test/vitest-coverage",
"fallow:fix:preview": "fallow fix --dry-run --production",
"fallow:fix": "fallow fix --production",
"lint": "oxlint .",
Expand Down
7 changes: 5 additions & 2 deletions packages/common/src/extensions/slickCellExcelCopyManager.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { BindingEventService } from '@slickgrid-universal/binding';
import { isPrimitiveOrHTML, stripTags } from '@slickgrid-universal/utils';
import { SlickEventHandler, SlickGlobalEditorLock, type SlickDataView, type SlickGrid } from '../core/index.js';
import { SlickEventHandler, SlickGlobalEditorLock } from '../core/slickCore.js';
import type { SlickDataView } from '../core/slickDataview.js';
import type { SlickGrid } from '../core/slickGrid.js';
import type {
Column,
EditCommand,
Expand All @@ -10,7 +12,8 @@ import type {
FormatterResultWithText,
GridOption,
} from '../interfaces/index.js';
import { SlickCellExternalCopyManager, SlickHybridSelectionModel } from './index.js';
import { SlickCellExternalCopyManager } from './slickCellExternalCopyManager.js';
import { SlickHybridSelectionModel } from './slickHybridSelectionModel.js';

/*
This manager enables users to copy/paste data from/to an external Spreadsheet application
Expand Down
12 changes: 4 additions & 8 deletions packages/common/src/extensions/slickGroupItemMetadataProvider.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import { createDomElement, extend, isHtml } from '@slickgrid-universal/utils';
import {
applyHtmlToElement,
SlickEventHandler,
SlickGroup,
type SlickDataView,
type SlickEventData,
type SlickGrid,
} from '../core/index.js';
import { SlickEventHandler, SlickGroup, type SlickEventData } from '../core/slickCore.js';
import type { SlickDataView } from '../core/slickDataview.js';
import type { SlickGrid } from '../core/slickGrid.js';
import { applyHtmlToElement } from '../core/utils.js';
import type {
Column,
GridOption,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { dayStart } from '@formkit/tempo';
import { type FieldType, type SearchTerm } from '../enums/index.js';
import type { FilterConditionOption } from '../interfaces/index.js';
import { mapTempoDateFormatWithFieldType, tryParseDate } from '../services/index.js';
import { mapTempoDateFormatWithFieldType, tryParseDate } from '../services/dateUtils.js';
import { testFilterCondition } from './filterUtilities.js';

/**
Expand Down
31 changes: 17 additions & 14 deletions packages/common/src/sortComparers/__tests__/sortUtilities.spec.ts
Original file line number Diff line number Diff line change
@@ -1,55 +1,58 @@
import { describe, expect, it, vi } from 'vitest';
import { SortDirectionNumber } from '../../enums/index.js';
import type { Column } from '../../interfaces/index.js';
import { SortComparers } from '../sortComparers.index.js';
import * as booleanModule from '../booleanSortComparer.js';
import * as numericModule from '../numericSortComparer.js';
import * as objectStringModule from '../objectStringSortComparer.js';
import { sortByFieldType } from '../sortUtilities.js';
import * as stringModule from '../stringSortComparer.js';

describe('sortUtilities', () => {
it('should call the SortComparers.boolean when FieldType is boolean', () => {
const spy = vi.spyOn(SortComparers, 'boolean');
it('should call the booleanSortComparer when FieldType is boolean', () => {
const spy = vi.spyOn(booleanModule, 'booleanSortComparer');
sortByFieldType('boolean', 0, 4, SortDirectionNumber.asc, { id: 'field1', field: 'field1' });
expect(spy).toHaveBeenCalledWith(0, 4, SortDirectionNumber.asc, { id: 'field1', field: 'field1' }, undefined);
});

it('should call the SortComparers.numeric when FieldType is number', () => {
const spy = vi.spyOn(SortComparers, 'numeric');
it('should call the numericSortComparer when FieldType is number', () => {
const spy = vi.spyOn(numericModule, 'numericSortComparer');
sortByFieldType('number', 0, 4, SortDirectionNumber.asc, { id: 'field1', field: 'field1' });
expect(spy).toHaveBeenCalledWith(0, 4, SortDirectionNumber.asc, { id: 'field1', field: 'field1' }, undefined);
});

it('should call the SortComparers.numeric when FieldType is integer', () => {
const spy = vi.spyOn(SortComparers, 'numeric');
it('should call the numericSortComparer when FieldType is integer', () => {
const spy = vi.spyOn(numericModule, 'numericSortComparer');
sortByFieldType('integer', 0, 4, SortDirectionNumber.asc, { id: 'field1', field: 'field1' });
expect(spy).toHaveBeenCalledWith(0, 4, SortDirectionNumber.asc, { id: 'field1', field: 'field1' }, undefined);
});

it('should call the SortComparers.numeric when FieldType is float', () => {
const spy = vi.spyOn(SortComparers, 'numeric');
it('should call the numericSortComparer when FieldType is float', () => {
const spy = vi.spyOn(numericModule, 'numericSortComparer');
sortByFieldType('float', 0, 4, SortDirectionNumber.asc, { id: 'field1', field: 'field1' });
expect(spy).toHaveBeenCalledWith(0, 4, SortDirectionNumber.asc, { id: 'field1', field: 'field1' }, undefined);
});

it('should call the SortComparers.string when FieldType is a string (which is also the default)', () => {
it('should call the stringSortComparer when FieldType is a string (which is also the default)', () => {
const string1 = 'John';
const string2 = 'Jane';
const spy = vi.spyOn(SortComparers, 'string');
const spy = vi.spyOn(stringModule, 'stringSortComparer');
sortByFieldType('string', string1, string2, SortDirectionNumber.asc, { id: 'field1', field: 'field1' });
expect(spy).toHaveBeenCalledWith(string1, string2, SortDirectionNumber.asc, { id: 'field1', field: 'field1' }, undefined);
});

it('should call the SortComparers.date when FieldType is any date types', () => {
it('should call the date comparer when FieldType is any date types', () => {
const result1 = sortByFieldType('dateIso', '2020-01-01', '2020-02-01', SortDirectionNumber.asc, { id: 'field1', field: 'field1' });
expect(result1).toBeLessThan(0);

const result2 = sortByFieldType('dateIso', '2020-02-01', '2020-01-01', SortDirectionNumber.asc, { id: 'field1', field: 'field1' });
expect(result2).toBeGreaterThan(0);
});

it('should call the SortComparers.objectString when FieldType is objectString', () => {
it('should call the objectStringSortComparer when FieldType is objectString', () => {
const object1 = { firstName: 'John', lastName: 'Z' };
const object2 = { firstName: 'Jane', lastName: 'Doe' };
const mockColumn = { id: 'field1', field: 'field1', dataKey: 'firstName' } as Column;
const spy = vi.spyOn(SortComparers, 'objectString');
const spy = vi.spyOn(objectStringModule, 'objectStringSortComparer');
sortByFieldType('object', object1, object2, SortDirectionNumber.asc, mockColumn);
expect(spy).toHaveBeenCalledWith(object1, object2, SortDirectionNumber.asc, mockColumn, undefined);
});
Expand Down
13 changes: 8 additions & 5 deletions packages/common/src/sortComparers/sortUtilities.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { type FieldType, type SortDirectionNumber } from '../enums/index.js';
import type { Column, GridOption } from '../interfaces/index.js';
import { isColumnDateType } from '../services/utilities.js';
import { booleanSortComparer } from './booleanSortComparer.js';
import { getAssociatedDateSortComparer } from './dateUtilities.js';
import { SortComparers } from './index.js';
import { numericSortComparer } from './numericSortComparer.js';
import { objectStringSortComparer } from './objectStringSortComparer.js';
import { stringSortComparer } from './stringSortComparer.js';

export function sortByFieldType(
fieldType: FieldType,
Expand All @@ -20,22 +23,22 @@ export function sortByFieldType(
} else {
switch (fieldType) {
case 'boolean':
sortResult = SortComparers.boolean(value1, value2, sortDirection, sortColumn, gridOptions);
sortResult = booleanSortComparer(value1, value2, sortDirection, sortColumn, gridOptions);
break;
case 'float':
case 'integer':
case 'number':
sortResult = SortComparers.numeric(value1, value2, sortDirection, sortColumn, gridOptions);
sortResult = numericSortComparer(value1, value2, sortDirection, sortColumn, gridOptions);
break;
case 'object':
sortResult = SortComparers.objectString(value1, value2, sortDirection, sortColumn, gridOptions);
sortResult = objectStringSortComparer(value1, value2, sortDirection, sortColumn, gridOptions);
break;
case 'string':
case 'text':
case 'password':
case 'readonly':
default:
sortResult = SortComparers.string(value1, value2, sortDirection, sortColumn, gridOptions);
sortResult = stringSortComparer(value1, value2, sortDirection, sortColumn, gridOptions);
break;
}
}
Expand Down
Loading