Skip to content

Commit

Permalink
Merge pull request #523 from revolist/522-refactor-column-grouping-pl…
Browse files Browse the repository at this point in the history
…ugin-and-column-provider

#522 - refactored column provider
  • Loading branch information
revolist authored Aug 15, 2024
2 parents cdaea96 + a9f07cc commit 684eab3
Show file tree
Hide file tree
Showing 13 changed files with 277 additions and 243 deletions.
12 changes: 6 additions & 6 deletions src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { ColumnFilterConfig, FilterCaptions, FilterCollection } from "./plugins/
import { GroupingOptions } from "./plugins/groupingRow/grouping.row.types";
import { VNode } from "@stencil/core";
import { FocusedData } from "./components/revoGrid/viewport.service";
import { ColumnCollection } from "./services/column.data.provider";
import { ColumnCollection } from "./utils/column.utils";
import { DataInput } from "./plugins/export/types";
import { Observable } from "./utils/store.utils";
import { DSourceState, Groups } from "./store/index";
Expand All @@ -28,7 +28,7 @@ export { ColumnFilterConfig, FilterCaptions, FilterCollection } from "./plugins/
export { GroupingOptions } from "./plugins/groupingRow/grouping.row.types";
export { VNode } from "@stencil/core";
export { FocusedData } from "./components/revoGrid/viewport.service";
export { ColumnCollection } from "./services/column.data.provider";
export { ColumnCollection } from "./utils/column.utils";
export { DataInput } from "./plugins/export/types";
export { Observable } from "./utils/store.utils";
export { DSourceState, Groups } from "./store/index";
Expand Down Expand Up @@ -1059,8 +1059,8 @@ declare global {
"rangeeditapply": BeforeRangeSaveDataDetails;
"clipboardrangecopy": RangeClipboardCopyEventProps;
"clipboardrangepaste": RangeClipboardPasteEvent;
"beforekeydown": KeyboardEvent & EventData;
"beforekeyup": KeyboardEvent & EventData;
"beforekeydown": { original: KeyboardEvent } & EventData;
"beforekeyup": { original: KeyboardEvent } & EventData;
"beforecellsave": any;
}
/**
Expand Down Expand Up @@ -1953,11 +1953,11 @@ declare namespace LocalJSX {
/**
* Before key up event proxy, used to prevent key up trigger. If you have some custom behaviour event, use this event to check if it wasn't processed by internal logic. Call preventDefault().
*/
"onBeforekeydown"?: (event: RevogrOverlaySelectionCustomEvent<KeyboardEvent & EventData>) => void;
"onBeforekeydown"?: (event: RevogrOverlaySelectionCustomEvent<{ original: KeyboardEvent } & EventData>) => void;
/**
* Before key down event proxy, used to prevent key down trigger. If you have some custom behaviour event, use this event to check if it wasn't processed by internal logic. Call preventDefault().
*/
"onBeforekeyup"?: (event: RevogrOverlaySelectionCustomEvent<KeyboardEvent & EventData>) => void;
"onBeforekeyup"?: (event: RevogrOverlaySelectionCustomEvent<{ original: KeyboardEvent } & EventData>) => void;
/**
* Fired when change of viewport happens. Usually when we switch between pinned regions.
*/
Expand Down
4 changes: 2 additions & 2 deletions src/components/clipboard/revogr-clipboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class Clipboard {
* @property {string[][]} data - data to paste
* @property {boolean} defaultPrevented - if true, paste will be canceled
*/
@Event({ eventName: 'pasteregion', bubbles: false })
@Event({ eventName: 'pasteregion' })
pasteRegion: EventEmitter<string[][]>;

/**
Expand Down Expand Up @@ -90,7 +90,7 @@ export class Clipboard {
* Copy 2. Fired when region copied
* defaultPrevented - if true, copy will be canceled
*/
@Event({ eventName: 'copyregion', bubbles: false })
@Event({ eventName: 'copyregion' })
copyRegion: EventEmitter<DataTransfer>;

@Listen('paste', { target: 'document' }) onPaste(e: ClipboardEvent) {
Expand Down
9 changes: 4 additions & 5 deletions src/components/revoGrid/revo-grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ import {
Host,
} from '@stencil/core';

import ColumnDataProvider, {
ColumnCollection,
} from '../../services/column.data.provider';
import ColumnDataProvider from '../../services/column.data.provider';
import { DataProvider } from '../../services/data.provider';
import { DSourceState, getVisibleSourceItem } from '@store';
import DimensionProvider from '../../services/dimension.provider';
Expand Down Expand Up @@ -79,6 +77,7 @@ import {
} from '@type';
import type { Observable } from '../../utils/store.utils';
import type { GridPlugin } from '../../plugins/base.plugin';
import { ColumnCollection, getColumnByProp, getColumns } from '../../utils/column.utils';


/**
Expand Down Expand Up @@ -653,7 +652,7 @@ export class RevoGridComponent {
prop: ColumnProp,
rowSource: DimensionRows = 'rgRow',
) {
const rgCol = ColumnDataProvider.getColumnByProp(this.columns, prop);
const rgCol = getColumnByProp(this.columns, prop);
if (!rgCol) {
return;
}
Expand Down Expand Up @@ -973,7 +972,7 @@ export class RevoGridComponent {
this.columnChanged(this.columns);
}
@Watch('columns') columnChanged(newVal: (ColumnGrouping | ColumnRegular)[] = []) {
const columnGather = ColumnDataProvider.getColumns(
const columnGather = getColumns(
newVal,
0,
this.columnTypes,
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export * from './plugins/base.plugin';
export * from './plugins/dispatcher';
export * from './components';
export * from './utils/store.utils';
export * from './utils/column.utils';
export { h } from '@stencil/core';
10 changes: 3 additions & 7 deletions src/plugins/column.auto-size.plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ import each from 'lodash/each';
import reduce from 'lodash/reduce';

import { BasePlugin } from './base.plugin';
import ColumnDataProvider, {
ColumnCollection,
} from '../services/column.data.provider';
import { ColumnItems } from '../services/dimension.provider';
import { getSourceItem, columnTypes } from '@store';
import {
DimensionCols,
Expand All @@ -21,7 +17,7 @@ import {
BeforeSaveDataDetails,
BeforeRangeSaveDataDetails,
} from '@type';
import { PluginProviders } from '../';
import { ColumnCollection, getColumnType, PluginProviders } from '../';

interface Column extends ColumnRegular {
index: number;
Expand Down Expand Up @@ -106,7 +102,7 @@ export default class AutoSizeColumnPlugin extends BasePlugin {
this.columnSet(columns);
};
const headerDblClick = ({ detail }: CustomEvent<InitialHeaderClick>) => {
const type = ColumnDataProvider.getColumnType(detail.column);
const type = getColumnType(detail.column);
const size = this.getColumnSize(detail.index, type);
if (size) {
this.providers.dimension.setCustomSizes(
Expand Down Expand Up @@ -263,7 +259,7 @@ export default class AutoSizeColumnPlugin extends BasePlugin {
);
}

columnSet(columns: ColumnItems) {
columnSet(columns: Record<DimensionCols, ColumnRegular[]>) {
for (let t of columnTypes) {
const type = t as DimensionCols;
const cols = columns[type];
Expand Down
9 changes: 3 additions & 6 deletions src/plugins/column.stretch.plugin.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import each from 'lodash/each';
import { calculateRowHeaderSize } from '../utils/row-header-utils';
import { ColumnCollection } from '../services/column.data.provider';
import { ColumnItems } from '../services/dimension.provider';
import { getScrollbarSize } from '../utils';
import { BasePlugin } from './base.plugin';
import { DimensionCols, DimensionType } from '..';
import { PluginBaseComponent } from '../';
import { PluginProviders } from '../';
import { DimensionCols, DimensionType, PluginBaseComponent, PluginProviders, ColumnRegular } from '@type';
import { ColumnCollection } from '../utils/column.utils';

/**
* This plugin serves to recalculate columns initially
Expand Down Expand Up @@ -86,7 +83,7 @@ export default class StretchColumn extends BasePlugin {
/**
* Apply stretch changes
*/
applyStretch(columns: ColumnItems) {
applyStretch(columns: Record<DimensionCols, ColumnRegular[]>) {
// unsubscribe from all events
this.dropChanges();
// calculate grid size
Expand Down
60 changes: 0 additions & 60 deletions src/plugins/groupingColumn/grouping.col.plugin.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/plugins/groupingRow/grouping.row.plugin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { ColumnCollection } from '../../services/column.data.provider';
import { getPhysical, setItems, columnTypes, TrimmedEntity, DSourceState } from '@store';
import { BasePlugin } from '../base.plugin';
import { FILTER_TRIMMED_TYPE } from '../filter/filter.plugin';
Expand Down Expand Up @@ -28,6 +27,7 @@ import {
} from './grouping.trimmed.service';
import { BeforeSaveDataDetails, ColumnRegular, DataType, DimensionRows, PluginProviders } from '@type';
import { Observable } from '../../utils/store.utils';
import { ColumnCollection } from '../../utils/column.utils';

export default class GroupingRowPlugin extends BasePlugin {
private options: GroupingOptions | undefined;
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/moveColumn/column.drag.plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import { getItemByPosition } from '@store';
import { BasePlugin } from '../base.plugin';
import { ColumnOrderHandler } from './order-column.handler';
import { dispatch } from '../dispatcher';
import { isColGrouping } from '../groupingColumn/grouping.col.plugin';
import { ColumnPropProp, ColumnRegular, DimensionSettingsState, PositionItem, DimensionCols, MultiDimensionType, PluginProviders } from '@type';
import { ON_COLUMN_CLICK } from '../../components/header/header-cell-renderer';
import { isColGrouping } from '../../utils/column.utils';

const COLUMN_CLICK = ON_COLUMN_CLICK;
const MOVE = 'columndragmousemove';
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/sorting/sorting.plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import debounce from 'lodash/debounce';
import range from 'lodash/range';

import { setStore } from '../../utils/store.utils';
import ColumnDataProvider from '../../services/column.data.provider';
import { BasePlugin } from '../base.plugin';
import {
ColumnProp,
Expand All @@ -15,6 +14,7 @@ import {
DimensionRows,
PluginProviders,
} from '@type';
import { getColumnByProp } from '../../utils/column.utils';

export type SortingOrder = Record<ColumnProp, Order>;
type SortingOrderFunction = Record<ColumnProp, CellCompareFunc | undefined>;
Expand Down Expand Up @@ -83,7 +83,7 @@ export default class SortingPlugin extends BasePlugin {

for (let prop in order) {
const cmp = this.getComparer(
ColumnDataProvider.getColumnByProp(columns, prop),
getColumnByProp(columns, prop),
order[prop],
);
sortingFunc[prop] = cmp;
Expand Down
Loading

0 comments on commit 684eab3

Please sign in to comment.