Skip to content

Commit

Permalink
minimal filter refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
m2a2x committed Aug 23, 2024
1 parent e1a82d3 commit 69ed58a
Show file tree
Hide file tree
Showing 11 changed files with 386 additions and 194 deletions.
2 changes: 1 addition & 1 deletion docs
Submodule docs updated 207 files
10 changes: 2 additions & 8 deletions src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,28 @@ import { HTMLStencilElement, JSXBase } from "@stencil/core/internal";
import { AfterEditEvent, AllDimensionType, ApplyFocusEvent, BeforeCellRenderEvent, BeforeEdit, BeforeRangeSaveDataDetails, BeforeRowRenderEvent, BeforeSaveDataDetails, Cell, ChangedRange, ColumnDataSchemaModel, ColumnGrouping, ColumnProp, ColumnRegular, ColumnType, DataFormat, DataType, DimensionCols, DimensionRows, DimensionSettingsState, DimensionType, DimensionTypeCol, DragStartEvent, EditCell, EditorCtr, Editors, ElementScroll, FocusAfterRenderEvent, FocusRenderEvent, FocusTemplateFunc, InitialHeaderClick, MultiDimensionType, Nullable, PluginBaseComponent, PositionItem, RangeArea, RangeClipboardCopyEventProps, RangeClipboardPasteEvent, RowDefinition, RowHeaders, SaveDataDetails, SelectionStoreState, TempRange, Theme, ViewportData, ViewPortResizeEvent, ViewPortScrollEvent, ViewportState, ViewSettingSizeProp } from "./types/index";
import { GridPlugin } from "./plugins/base.plugin";
import { AutoSizeColumnConfig } from "./plugins/column.auto-size.plugin";
import { ColumnFilterConfig, FilterCaptions, FilterCollection } from "./plugins/filter/filter.plugin";
import { ColumnFilterConfig, FilterCaptions, FilterCollection, LogicFunction, MultiFilterItem, ShowData } from "./plugins/filter/filter.types";
import { GroupingOptions } from "./plugins/groupingRow/grouping.row.types";
import { VNode } from "@stencil/core";
import { FocusedData } from "./components/revoGrid/viewport.service";
import { ColumnCollection } from "./utils/column.utils";
import { DataInput } from "./plugins/export/types";
import { Observable } from "./utils/store.utils";
import { DSourceState, Groups } from "./store/index";
import { MultiFilterItem, ShowData } from "./plugins/filter/filter.panel";
import { LogicFunction } from "./plugins/filter/filter.types";
import { ResizeProps } from "./components/header/resizable.directive";
import { Cell as Cell1, ColumnRegular as ColumnRegular1, DataType as DataType1, DimensionCols as DimensionCols1, DimensionRows as DimensionRows1, DimensionSettingsState as DimensionSettingsState1, Observable as Observable1, SelectionStoreState as SelectionStoreState1 } from "./components";
import { EventData } from "./components/overlay/selection.utils";
export { AfterEditEvent, AllDimensionType, ApplyFocusEvent, BeforeCellRenderEvent, BeforeEdit, BeforeRangeSaveDataDetails, BeforeRowRenderEvent, BeforeSaveDataDetails, Cell, ChangedRange, ColumnDataSchemaModel, ColumnGrouping, ColumnProp, ColumnRegular, ColumnType, DataFormat, DataType, DimensionCols, DimensionRows, DimensionSettingsState, DimensionType, DimensionTypeCol, DragStartEvent, EditCell, EditorCtr, Editors, ElementScroll, FocusAfterRenderEvent, FocusRenderEvent, FocusTemplateFunc, InitialHeaderClick, MultiDimensionType, Nullable, PluginBaseComponent, PositionItem, RangeArea, RangeClipboardCopyEventProps, RangeClipboardPasteEvent, RowDefinition, RowHeaders, SaveDataDetails, SelectionStoreState, TempRange, Theme, ViewportData, ViewPortResizeEvent, ViewPortScrollEvent, ViewportState, ViewSettingSizeProp } from "./types/index";
export { GridPlugin } from "./plugins/base.plugin";
export { AutoSizeColumnConfig } from "./plugins/column.auto-size.plugin";
export { ColumnFilterConfig, FilterCaptions, FilterCollection } from "./plugins/filter/filter.plugin";
export { ColumnFilterConfig, FilterCaptions, FilterCollection, LogicFunction, MultiFilterItem, ShowData } from "./plugins/filter/filter.types";
export { GroupingOptions } from "./plugins/groupingRow/grouping.row.types";
export { VNode } from "@stencil/core";
export { FocusedData } from "./components/revoGrid/viewport.service";
export { ColumnCollection } from "./utils/column.utils";
export { DataInput } from "./plugins/export/types";
export { Observable } from "./utils/store.utils";
export { DSourceState, Groups } from "./store/index";
export { MultiFilterItem, ShowData } from "./plugins/filter/filter.panel";
export { LogicFunction } from "./plugins/filter/filter.types";
export { ResizeProps } from "./components/header/resizable.directive";
export { Cell as Cell1, ColumnRegular as ColumnRegular1, DataType as DataType1, DimensionCols as DimensionCols1, DimensionRows as DimensionRows1, DimensionSettingsState as DimensionSettingsState1, Observable as Observable1, SelectionStoreState as SelectionStoreState1 } from "./components";
export { EventData } from "./components/overlay/selection.utils";
Expand Down Expand Up @@ -404,7 +400,6 @@ export namespace Components {
"filterEntities": Record<string, LogicFunction>;
"filterItems": MultiFilterItem;
"filterNames": Record<string, string>;
"filterTypes": Record<string, string[]>;
"getChanges": () => Promise<ShowData | undefined>;
"show": (newEntity?: ShowData) => Promise<void>;
}
Expand Down Expand Up @@ -1712,7 +1707,6 @@ declare namespace LocalJSX {
"filterEntities"?: Record<string, LogicFunction>;
"filterItems"?: MultiFilterItem;
"filterNames"?: Record<string, string>;
"filterTypes"?: Record<string, string[]>;
"onFilterChange"?: (event: RevogrFilterPanelCustomEvent<MultiFilterItem>) => void;
}
/**
Expand Down
5 changes: 3 additions & 2 deletions src/components/data/cell-renderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import {
} from '@type';

import {
getCellData,
DRAGGABLE_CLASS,
DRAG_ICON_CLASS,
} from '../../utils/consts';
} from '../../utils';

import { getCellData, isRowDragService } from './column.service';
import { isRowDragService } from './column.service';

interface RenderProps {
model: ColumnDataSchemaModel;
Expand Down
14 changes: 3 additions & 11 deletions src/components/data/column.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DSourceState, getSourceItem, getVisibleSourceItem } from '@store';
import { CELL_CLASS, DISABLED_CLASS } from '../../utils/consts';
import { getCellData, Observable, CELL_CLASS, DISABLED_CLASS } from '../../utils';
import { getRange } from '@store';

import { isGroupingColumn } from '../../plugins/groupingRow/grouping.service';
Expand All @@ -23,7 +23,6 @@ import {
EditorCtr,
Editors,
} from '@type';
import { Observable } from '../../utils/store.utils';

export type ColumnStores = {
[T in DimensionCols]: Observable<DSourceState<ColumnRegular, DimensionCols>>;
Expand Down Expand Up @@ -108,10 +107,10 @@ export default class ColumnService {
colIndex: number,
val?: string,
): BeforeSaveDataDetails {
const data = this.rowDataModel(rowIndex, colIndex);
if (typeof val === 'undefined') {
val = this.getCellData(rowIndex, colIndex);
val = getCellData(data.model[data.prop as number]);
}
const data = this.rowDataModel(rowIndex, colIndex);
return {
prop: data.prop,
rowIndex,
Expand Down Expand Up @@ -386,13 +385,6 @@ export default class ColumnService {
}
}

export function getCellData(val?: any) {
if (typeof val === 'undefined' || val === null) {
return '';
}
return val;
}

/**
* Checks if the given rowDrag is a service for dragging rows.
*/
Expand Down
3 changes: 1 addition & 2 deletions src/components/revoGrid/revo-grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ import AutoSize, {

import {
FilterPlugin,
ColumnFilterConfig,
FilterCollection,
} from '../../plugins/filter/filter.plugin';
import SortingPlugin from '../../plugins/sorting/sorting.plugin';
import ExportFilePlugin from '../../plugins/export/export.plugin';
Expand All @@ -81,6 +79,7 @@ import type { Observable } from '../../utils/store.utils';
import type { GridPlugin } from '../../plugins/base.plugin';
import { ColumnCollection, getColumnByProp, getColumns } from '../../utils/column.utils';
import { WCAGPlugin } from '../../plugins/wcag';
import { ColumnFilterConfig, FilterCollection } from '../../plugins/filter/filter.types';


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,8 @@ import beginsWith from './conditions/string/beginswith';
import contains, { notContains } from './conditions/string/contains';
import { LogicFunction } from './filter.types';

export const filterNames = {
none: 'None',
empty: 'Not set',
notEmpty: 'Set',

eq: 'Equal',
notEq: 'Not equal',
begins: 'Begins with',
contains: 'Contains',
notContains: 'Does not contain',

eqN: '=',
neqN: '!=',
gt: '>',
gte: '>=',
lt: '<',
lte: '<=',
};

export type FilterType = keyof typeof filterNames;

export const filterEntities: Record<FilterType, LogicFunction> = {
export const filterCoreFunctionsIndexedByType: Record<FilterType, LogicFunction> = {
none: () => true,
empty: notSet,
notEmpty: set,
Expand All @@ -51,3 +31,24 @@ export const filterTypes: Record<string, FilterType[]> = {
string: ['notEmpty', 'empty', 'eq', 'notEq', 'begins', 'contains', 'notContains'],
number: ['notEmpty', 'empty', 'eqN', 'neqN', 'gt', 'gte', 'lt', 'lte'],
};

export const filterNames = {
none: 'None',
empty: 'Not set',
notEmpty: 'Set',

eq: 'Equal',
notEq: 'Not equal',
begins: 'Begins with',
contains: 'Contains',
notContains: 'Does not contain',

eqN: '=',
neqN: '!=',
gt: '>',
gte: '>=',
lt: '<',
lte: '<=',
};

export type FilterType = keyof typeof filterNames;
Loading

0 comments on commit 69ed58a

Please sign in to comment.