Skip to content

Commit

Permalink
Update TS definition for Filters plugin and Core methods (#10494)
Browse files Browse the repository at this point in the history
  • Loading branch information
budnix committed Sep 4, 2023
1 parent f29c16e commit c97ac1a
Show file tree
Hide file tree
Showing 11 changed files with 123 additions and 72 deletions.
8 changes: 8 additions & 0 deletions .changelogs/10494.json
@@ -0,0 +1,8 @@
{
"issuesOrigin": "private",
"title": "Updated TS definition for Filters plugin and Core methods",
"type": "changed",
"issueOrPR": 10494,
"breaking": false,
"framework": "none"
}
@@ -1,32 +1,55 @@
import Handsontable from 'handsontable';

const hot = new Handsontable(document.createElement('div'), {});
const columnSorting = hot.getPlugin('columnSorting');

columnSorting.clearSort();

columnSorting.getSortConfig();
columnSorting.getSortConfig(0);

const sortConfig0 = columnSorting.getSortConfig(0);
const hot = new Handsontable(document.createElement('div'), {
columnSorting: true,
});
new Handsontable(document.createElement('div'), {
columnSorting: {
sortEmptyCells: true,
indicator: true,
headerAction: true,
compareFunctionFactory(sortOrder, columnMeta) {
return (a: any, b: any) => columnMeta.type === 'text' && sortOrder === 'asc' ? -1 : 1;
},
initialConfig: {
column: 1,
sortOrder: 'asc'
}
}
});
new Handsontable(document.createElement('div'), {
columnSorting: {
initialConfig: {
column: 1,
sortOrder: 'desc'
}
}
});
const plugin = hot.getPlugin('columnSorting');

plugin.clearSort();
plugin.getSortConfig();
plugin.getSortConfig(0);

const sortConfig0 = plugin.getSortConfig(0);

if (typeof sortConfig0 !== 'undefined' && !Array.isArray(sortConfig0)) {
sortConfig0.column;
sortConfig0.sortOrder;
}

const sortConfigs = columnSorting.getSortConfig();
const sortConfigs = plugin.getSortConfig();

if (Array.isArray(sortConfigs)) {
sortConfigs[0].column;
sortConfigs[0].sortOrder;
}

columnSorting.setSortConfig({ column: 0, sortOrder: 'asc' });
columnSorting.setSortConfig([{ column: 0, sortOrder: 'asc' }]);
columnSorting.setSortConfig([]);
plugin.setSortConfig({ column: 0, sortOrder: 'asc' });
plugin.setSortConfig([{ column: 0, sortOrder: 'asc' }]);
plugin.setSortConfig([]);

columnSorting.isSorted();
const isSorted: boolean = plugin.isSorted();

columnSorting.sort({ column: 0, sortOrder: 'asc' });
columnSorting.sort([{ column: 0, sortOrder: 'asc' }]);
plugin.sort({ column: 0, sortOrder: 'asc' });
plugin.sort([{ column: 0, sortOrder: 'asc' }]);
@@ -1,4 +1,6 @@
import Handsontable from 'handsontable';
import Handsontable from 'handsontable/base';
import { ColumnConditions, OperationType } from 'handsontable/plugins/filters';
import { Condition } from 'handsontable/plugins/filters/conditionCollection';

const hot = new Handsontable(document.createElement('div'), {
filters: true,
Expand Down Expand Up @@ -36,14 +38,22 @@ if (conditionCollection) {
conditionCollection.addCondition(2, condition);
conditionCollection.addCondition(2, condition, 'conjunction');
conditionCollection.addCondition(2, condition, 'conjunction', 3);
conditionCollection.getConditions(3);
conditionCollection.getFilteredColumns();
conditionCollection.getColumnStackPosition(3);
conditionCollection.getOperation(3);
conditionCollection.exportAllConditions();
conditionCollection.importAllConditions([condition]);
conditionCollection.importAllConditions([{
column: 1,
conditions: [{
name: 'gt',
args: [],
}],
operation: 'conjunction',
}]);
conditionCollection.removeConditions(3);
conditionCollection.hasConditions(3, 'eq');
conditionCollection.clean();
conditionCollection.destroy();

const conditions: Condition[] = conditionCollection.getConditions(3);
const filteredColumns = conditionCollection.getFilteredColumns();
const columnStackPosition: Maybe<number> = conditionCollection.getColumnStackPosition(3);
const operation: Maybe<OperationType> = conditionCollection.getOperation(3);
const exportAllConditions: ColumnConditions[] = conditionCollection.exportAllConditions();
}
@@ -1,32 +1,62 @@
import Handsontable from 'handsontable';

const hot = new Handsontable(document.createElement('div'), {});
const columnSorting = hot.getPlugin('multiColumnSorting');

columnSorting.clearSort();

columnSorting.getSortConfig();
columnSorting.getSortConfig(0);

const sortConfig0 = columnSorting.getSortConfig(0);
const hot = new Handsontable(document.createElement('div'), {
multiColumnSorting: true,
});
new Handsontable(document.createElement('div'), {
multiColumnSorting: {
sortEmptyCells: true,
indicator: true,
headerAction: true,
compareFunctionFactory(sortOrder, columnMeta) {
return (a: any, b: any) => columnMeta.type === 'text' && sortOrder === 'asc' ? -1 : 1;
},
initialConfig: {
column: 1,
sortOrder: 'asc'
}
}
});
new Handsontable(document.createElement('div'), {
multiColumnSorting: {
initialConfig: [
{
column: 1,
sortOrder: 'desc'
},
{
column: 3,
sortOrder: 'asc'
}
]
}
});

const plugin = hot.getPlugin('multiColumnSorting');

plugin.clearSort();
plugin.getSortConfig();
plugin.getSortConfig(0);

const sortConfig0 = plugin.getSortConfig(0);

if (typeof sortConfig0 !== 'undefined' && !Array.isArray(sortConfig0)) {
sortConfig0.column;
sortConfig0.sortOrder;
}

const sortConfigs = columnSorting.getSortConfig();
const sortConfigs = plugin.getSortConfig();

if (Array.isArray(sortConfigs)) {
sortConfigs[0].column;
sortConfigs[0].sortOrder;
}

columnSorting.setSortConfig({ column: 0, sortOrder: 'asc' });
columnSorting.setSortConfig([{ column: 0, sortOrder: 'asc' }]);
columnSorting.setSortConfig([]);
plugin.setSortConfig({ column: 0, sortOrder: 'asc' });
plugin.setSortConfig([{ column: 0, sortOrder: 'asc' }]);
plugin.setSortConfig([]);

columnSorting.isSorted();
const isSorted: boolean = plugin.isSorted();

columnSorting.sort({ column: 0, sortOrder: 'asc' });
columnSorting.sort([{ column: 1, sortOrder: 'desc' }, { column: 2, sortOrder: 'asc' }]);
plugin.sort({ column: 0, sortOrder: 'asc' });
plugin.sort([{ column: 1, sortOrder: 'desc' }, { column: 2, sortOrder: 'asc' }]);
1 change: 1 addition & 0 deletions handsontable/test/types/common.d.ts
@@ -0,0 +1 @@
type Maybe<T> = NonNullable<T> | void;
3 changes: 2 additions & 1 deletion handsontable/test/types/methods.types.ts
Expand Up @@ -112,7 +112,8 @@ hot.listen();
hot.loadData([[1, 2, 3], [1, 2, 3]]);
hot.loadData([{ a: 'a', b: 2, c: '' }, { a: 'a', b: 2, c: '' }]);
hot.populateFromArray(123, 123, [], 123, 123, 'foo', 'shift_down');
hot.propToCol('foo') === 123;
hot.propToCol('know_prop') === 123;
hot.propToCol('not_known_prop') === 'not_known_prop';
hot.propToCol(123) === 123;
hot.redo();
hot.refreshDimensions();
Expand Down
26 changes: 2 additions & 24 deletions handsontable/test/types/settings.types.ts
Expand Up @@ -116,18 +116,7 @@ const allSettings: Required<Handsontable.GridSettings> = {
{ type: 'numeric', numericFormat: { pattern: '0,0.00 $' } },
{ type: 'text', readOnly: true }
],
columnSorting: true_or_false || {
initialConfig: {
column: 1,
sortOrder: 'asc'
},
sortEmptyCells: true,
indicator: true,
headerAction: false,
compareFunctionFactory(sortOrder, columnMeta) {
return (a: any, b: any) => columnMeta.type === 'text' && sortOrder === 'asc' ? -1 : 1;
}
},
columnSorting: true_or_false,
columnSummary: [
{
destinationRow: 4,
Expand Down Expand Up @@ -294,18 +283,7 @@ const allSettings: Required<Handsontable.GridSettings> = {
minRows: 123,
minSpareCols: 123,
minSpareRows: 123,
multiColumnSorting: true_or_false || {
initialConfig: oneOf(
{ column: 1, sortOrder: SortDirection.desc },
[{ column: 1, sortOrder: SortDirection.asc }, { column: 0, sortOrder: SortDirection.desc }]
),
sortEmptyCells: true,
indicator: true,
headerAction: false,
compareFunctionFactory(sortOrder, columnMeta) {
return (a: any, b: any) => columnMeta.type === 'text' && sortOrder === 'asc' ? -1 : 1;
}
},
multiColumnSorting: true_or_false,
nestedHeaders: [
['A', {label: 'B', colspan: 8}, 'C'],
['D', {label: 'E', colspan: 4}, {label: 'F', colspan: 4}, 'G'],
Expand Down
1 change: 1 addition & 0 deletions handsontable/test/types/tsconfig.json
Expand Up @@ -17,6 +17,7 @@
}
},
"include": [
"./common.d.ts",
"**/*.types.ts",
"../../src/**/__tests__/*.types.ts"
]
Expand Down
2 changes: 1 addition & 1 deletion handsontable/types/core.d.ts
Expand Up @@ -114,7 +114,7 @@ export default class Core {
loadData(data: CellValue[][] | RowObject[], source?: string): void;
populateFromArray(row: number, col: number, input: CellValue[][], endRow?: number,
endCol?: number, source?: string, method?: 'shift_down' | 'shift_right' | 'overwrite'): void;
propToCol(prop: string | number): number;
propToCol(prop: string | number): string | number;
redo(): void;
refreshDimensions(): void;
removeCellMeta(row: number, col: number, key: (keyof CellMeta) | string): void;
Expand Down
5 changes: 3 additions & 2 deletions handsontable/types/plugins/filters/conditionCollection.d.ts
Expand Up @@ -2,6 +2,7 @@ import {
ConditionId,
OperationType,
CellLikeData,
ColumnConditions,
} from './filters';

export type ConditionName = 'begins_with' | 'between' | 'by_value' | 'contains' | 'empty' | 'ends_with' |
Expand All @@ -18,7 +19,7 @@ export default class ConditionCollection {
addCondition(column: number, conditionDefinition: ConditionId, operation?: OperationType, position?: number): void;
clean(): void;
destroy(): void;
exportAllConditions(): ConditionId[];
exportAllConditions(): ColumnConditions[];
getConditions(column: number): Condition[];
getFilteredColumns(): number[];
getColumnStackPosition(column: number): number | void;
Expand All @@ -27,6 +28,6 @@ export default class ConditionCollection {
isEmpty(): boolean;
isMatch(value: CellLikeData, column: number): boolean;
isMatchInConditions(conditions: Condition[], value: CellLikeData, operationType?: OperationType): boolean;
importAllConditions(conditions: ConditionId[]): void;
importAllConditions(conditions: ColumnConditions[]): void;
removeConditions(column: number): void;
}
8 changes: 3 additions & 5 deletions handsontable/types/plugins/filters/filters.d.ts
@@ -1,14 +1,12 @@
import Core from '../../core';
import { BasePlugin } from '../base';
import ConditionCollection from './conditionCollection';
import ConditionCollection, {
ConditionName as _ConditionName,
} from './conditionCollection';
import ConditionUpdateObserver from './conditionUpdateObserver';

type _OperationType = 'conjunction' | 'disjunction';
export type OperationType = _OperationType;

type _ConditionName = 'begins_with' | 'between' | 'by_value' | 'contains' | 'empty' |
'ends_with' | 'eq' | 'gt' | 'gte' | 'lt' | 'lte' | 'not_between' | 'not_contains' |
'not_empty' | 'neq';
export type ConditionName = _ConditionName;

export interface ColumnConditions {
Expand Down

0 comments on commit c97ac1a

Please sign in to comment.