Skip to content

Commit

Permalink
refactor(ngrid): terminology, change from 'table' to 'grid'
Browse files Browse the repository at this point in the history
This is part of the prep's for the 1.0.0 release.

BREAKING CHANGE:
This refacor changes the terminology used by the library from legacy "table" references to "grid" references.
This refactor addressed filenames and property names but did not include literal string names, and property names of configuration objects (e.g. configs...)  so functions that accepted 'table' will still accept it.
Filenames change should not have any effect unless you are extending the types using TS augmentaion so any `declare module '@pebula/ngrid/lib/table/...` will have to change.
For property names, all private/protected references to `table` are now `grid` and also all public references, however is most public ref's a getter was added to support the `table` property, with a `@deprecated` JSDoc annotation
  • Loading branch information
shlomiassaf committed Nov 22, 2019
1 parent e14382d commit 4ca1a1e
Show file tree
Hide file tree
Showing 100 changed files with 494 additions and 458 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const COUNTRY_GETTER = {
data: undefined as any
}

declare module '@pebula/ngrid/lib/table/columns/types' {
declare module '@pebula/ngrid/lib/grid/columns/types' {
interface PblColumnTypeDefinitionDataMap {
currencyFn: (row: Person) => string;
countryNameDynamic: (row: Person) => string;
Expand Down
14 changes: 7 additions & 7 deletions apps/ngrid-demo-app/content/extending-ngrid/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ By itself, an angular directive is the perfect plugin host, allowing immediate a
```typescript
export const PLUGIN_KEY: 'myCustomPlugin' = 'myCustomPlugin';

@TablePlugin({ id: PLUGIN_KEY })
@NgridPlugin({ id: PLUGIN_KEY })
@Directive({ selector: 'pbl-ngrid[myCustomPlugin]', exportAs: 'myCustomPlugin' })
export class MyCustomPlugin {
constructor(private grid: PblNgridComponent, private pluginCtrl: PblNgridPluginController) {
Expand All @@ -118,7 +118,7 @@ To use it:

Since it's an angular directive it can also get input, emit output, exportAs and get queried by angular (`ViewChild`).

I> The `PLUGIN_KEY` is a unique identifier used to register the plugin together with `@TablePlugin()`. This is not mandatory, directive style plugin
I> The `PLUGIN_KEY` is a unique identifier used to register the plugin together with `@NgridPlugin()`. This is not mandatory, directive style plugin
does not require registration as it is template driven and created by the angular runtime. However, registration provide better control and inter-plugin communication.

### Grid Extension Registry
Expand All @@ -133,7 +133,7 @@ We will use the same example:
```typescript
export const PLUGIN_KEY: 'myCustomPlugin' = 'myCustomPlugin';

@TablePlugin({ id: PLUGIN_KEY })
@NgridPlugin({ id: PLUGIN_KEY })
export class MyCustomPlugin { }
```

Expand Down Expand Up @@ -165,7 +165,7 @@ declare module '@pebula/ngrid/lib/ext/types' {

export const PLUGIN_KEY: 'myCustomPlugin' = 'myCustomPlugin';

@TablePlugin({ id: PLUGIN_KEY, factory: 'create' })
@NgridPlugin({ id: PLUGIN_KEY, factory: 'create' })
export class MyCustomPlugin {
static create(grid: PblNgridComponent, injector: Injector): MyCustomPlugin {
const pluginCtrl = PblNgridPluginController.find(grid);
Expand All @@ -178,7 +178,7 @@ export class MyCustomPlugin {

Let's explain:

We added another metadata property to `@TablePlugin()` called `factory`. `factory` is the name of a **static** function on out plugin class
We added another metadata property to `@NgridPlugin()` called `factory`. `factory` is the name of a **static** function on out plugin class
that we can use as a factory for creating new instances of the plugin.

The factory method must accept 2 parameters, the grid and an angular `Injector` and in it can create a new instance and return it.
Expand Down Expand Up @@ -224,7 +224,7 @@ declare module '@pebula/ngrid/lib/ext/types' {
Because this is a simple example, we will use the same class for the plugin and directive, you can split them in more complex scenarios.

```typescript
@TablePlugin({ id: PLUGIN_KEY, factory: 'create' })
@NgridPlugin({ id: PLUGIN_KEY, factory: 'create' })
@Directive({ selector: 'pbl-ngrid[clipboard]', exportAs: 'pblNgridClipboard' })
@UnRx()
export class PblNgridClipboardPlugin implements OnDestroy {
Expand Down Expand Up @@ -386,7 +386,7 @@ We will add a new settings group, specific to our plugin, allowing the user to t
The first step is enrich the global settings type with the new settings:

```typescript
declare module '@pebula/ngrid/lib/table/services/config' {
declare module '@pebula/ngrid/lib/grid/services/config' {
interface PblNgridConfig {
clipboard?: {
/** When set to true will enable the clipboard plugin on all grid instances by default. */
Expand Down
4 changes: 2 additions & 2 deletions dev_docs/tsconfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ we need to point to the exact location (file) that the type is declared in.
For example:

```ts
declare module '@pebula/ngrid/lib/table/columns/types' {
declare module '@pebula/ngrid/lib/grid/columns/types' {
interface PblColumnTypeDefinitionDataMap {
currencyFn: (row: Person) => string;
countryNameDynamic: (row: Person) => string;
}
}
```

Notice the path we reference: `declare module '@pebula/ngrid/lib/table/columns/types'`
Notice the path we reference: `declare module '@pebula/ngrid/lib/grid/columns/types'`

We point to `@pebula/ngrid/lib` but the file is actually in `@pebula/ngrid/src/lib`.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ import { Platform} from '@angular/cdk/platform';
import { TooltipPosition, MatTooltipDefaultOptions, MatTooltip, MAT_TOOLTIP_SCROLL_STRATEGY, MAT_TOOLTIP_DEFAULT_OPTIONS } from '@angular/material/tooltip';

import { UnRx } from '@pebula/utils';
import { PblNgridComponent, PblNgridPluginController, TablePlugin, PblNgridConfigService } from '@pebula/ngrid';
import { PblNgridComponent, PblNgridPluginController, NgridPlugin, PblNgridConfigService } from '@pebula/ngrid';
import { PblNgridCellEvent } from '@pebula/ngrid/target-events';

declare module '@pebula/ngrid/lib/table/services/config' {
declare module '@pebula/ngrid/lib/grid/services/config' {
interface PblNgridConfig {
cellTooltip?: CellTooltipOptions & {
/** When set to true will apply the default cell tooltip to ALL tables */
Expand Down Expand Up @@ -55,7 +55,7 @@ export interface CellTooltipOptions {
message?: (event: PblNgridCellEvent<any>) => string;
}

@TablePlugin({ id: PLUGIN_KEY, factory: 'create' })
@NgridPlugin({ id: PLUGIN_KEY, factory: 'create' })
@Directive({ selector: '[cellTooltip]', exportAs: 'pblOverflowTooltip' })
@UnRx()
export class PblNgridCellTooltipDirective<T> implements CellTooltipOptions, OnDestroy {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Directive, Input } from '@angular/core';
import { PblNgridPluginController, TablePlugin } from '@pebula/ngrid';
import { PblNgridPluginController, NgridPlugin } from '@pebula/ngrid';
import { PblNgridOverlayPanelFactory, PblNgridOverlayPanel, PblNgridOverlayPanelConfig } from '@pebula/ngrid/overlay-panel';

declare module '@pebula/ngrid/lib/ext/types' {
Expand All @@ -11,7 +11,7 @@ declare module '@pebula/ngrid/lib/ext/types' {
const PLUGIN_KEY: 'matHeaderContextMenu' = 'matHeaderContextMenu';

@Directive({ selector: 'pbl-ngrid[matHeaderContextMenu]' })
@TablePlugin({ id: PLUGIN_KEY })
@NgridPlugin({ id: PLUGIN_KEY })
export class PblNgridMatHeaderContextMenuPlugin {

@Input('matHeaderContextMenu') style: any;
Expand All @@ -21,7 +21,7 @@ export class PblNgridMatHeaderContextMenuPlugin {

constructor(overlayPanelFactory: PblNgridOverlayPanelFactory,
public readonly pluginCtrl: PblNgridPluginController) {
this.overlayPanel = overlayPanelFactory.create(pluginCtrl.extApi.table);
this.overlayPanel = overlayPanelFactory.create(pluginCtrl.extApi.grid);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class MatExcelStyleHeaderMenu {

constructor(private ref: PblNgridOverlayPanelRef<PblNgridDataHeaderExtensionContext>, private vcRef: ViewContainerRef) {
this.column = ref.data.col;
this.grid = ref.data.table;
this.grid = ref.data.grid;

if (this.grid.ds.sort.column === this.column) {
this.currentSort = this.grid.ds.sort.sort.order;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Directive, Injector, Input, OnDestroy, ComponentFactoryResolver, ComponentRef, DoCheck } from '@angular/core';
import { coerceBooleanProperty } from '@angular/cdk/coercion';
import { PblNgridComponent, PblNgridPluginController, TablePlugin } from '@pebula/ngrid';
import { PblNgridComponent, PblNgridPluginController, NgridPlugin } from '@pebula/ngrid';

import { PblPaginatorComponent } from './table-paginator.component';

Expand All @@ -12,7 +12,7 @@ declare module '@pebula/ngrid/lib/ext/types' {

const PLUGIN_KEY: 'matPaginator' = 'matPaginator';

@TablePlugin({ id: PLUGIN_KEY })
@NgridPlugin({ id: PLUGIN_KEY })
@Directive({ selector: 'pbl-ngrid[matPaginator]' })
export class PblNgridMatPaginatorDirective implements OnDestroy, DoCheck {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Directive, Injector, Input, OnDestroy, ComponentFactoryResolver, Compon
import { ThemePalette } from '@angular/material/core';

import { UnRx } from '@pebula/utils';
import { PblNgridComponent, PblNgridPluginController, TablePlugin } from '@pebula/ngrid';
import { PblNgridComponent, PblNgridPluginController, NgridPlugin } from '@pebula/ngrid';

import { PblNgridCheckboxComponent } from './table-checkbox.component';

Expand All @@ -14,7 +14,7 @@ declare module '@pebula/ngrid/lib/ext/types' {

const PLUGIN_KEY: 'matCheckboxSelection' = 'matCheckboxSelection';

@TablePlugin({ id: PLUGIN_KEY })
@NgridPlugin({ id: PLUGIN_KEY })
@Directive({ selector: 'pbl-ngrid[matCheckboxSelection]' })
@UnRx()
export class PblNgridMatCheckboxSelectionDirective implements OnDestroy {
Expand Down
4 changes: 2 additions & 2 deletions libs/ngrid-material/sort/src/lib/mat-sort.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Directive, OnDestroy } from '@angular/core';
import { Sort, MatSort, MatSortHeader, SortDirection } from '@angular/material/sort';

import { UnRx } from '@pebula/utils';
import { PblNgridComponent, PblNgridPluginController, TablePlugin, PblNgridSortDefinition, PblDataSource } from '@pebula/ngrid';
import { PblNgridComponent, PblNgridPluginController, NgridPlugin, PblNgridSortDefinition, PblDataSource } from '@pebula/ngrid';

declare module '@pebula/ngrid/lib/ext/types' {
interface PblNgridPluginExtension {
Expand All @@ -11,7 +11,7 @@ declare module '@pebula/ngrid/lib/ext/types' {
}
const PLUGIN_KEY: 'matSort' = 'matSort';

@TablePlugin({ id: PLUGIN_KEY })
@NgridPlugin({ id: PLUGIN_KEY })
@Directive({ selector: 'pbl-ngrid[matSort]', exportAs: 'pblMatSort' })
@UnRx()
export class PblNgridMatSortDirective implements OnDestroy {
Expand Down
18 changes: 9 additions & 9 deletions libs/ngrid/block-ui/src/lib/block-ui/block-ui-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Directive, EmbeddedViewRef, Input, OnDestroy } from '@angular/core';
import { coerceBooleanProperty } from '@angular/cdk/coercion';

import { UnRx } from '@pebula/utils';
import { PblNgridComponent, PblNgridPluginController, TablePlugin } from '@pebula/ngrid';
import { PblNgridComponent, PblNgridPluginController, NgridPlugin } from '@pebula/ngrid';

declare module '@pebula/ngrid/lib/ext/types' {
interface PblNgridPluginExtension {
Expand All @@ -13,7 +13,7 @@ declare module '@pebula/ngrid/lib/ext/types' {

const PLUGIN_KEY: 'blockUi' = 'blockUi';

@TablePlugin({ id: PLUGIN_KEY })
@NgridPlugin({ id: PLUGIN_KEY })
@Directive({ selector: 'pbl-ngrid[blockUi]', exportAs: 'blockUi' })
@UnRx()
export class PblNgridBlockUiPluginDirective<T> implements OnDestroy {
Expand Down Expand Up @@ -72,12 +72,12 @@ export class PblNgridBlockUiPluginDirective<T> implements OnDestroy {
private _blockInProgress: boolean = false;
private _blockUi: boolean | 'auto' | Observable<boolean>;
private _blockerEmbeddedVRef: EmbeddedViewRef<any>;
private _removePlugin: (table: PblNgridComponent<any>) => void;
private _removePlugin: (grid: PblNgridComponent<any>) => void;

constructor(private table: PblNgridComponent<any>, pluginCtrl: PblNgridPluginController<T>) {
constructor(private grid: PblNgridComponent<any>, pluginCtrl: PblNgridPluginController<T>) {
this._removePlugin = pluginCtrl.setPlugin(PLUGIN_KEY, this);

table.registry.changes.subscribe( changes => {
grid.registry.changes.subscribe( changes => {
for (const c of changes) {
switch (c.type) {
case 'blocker':
Expand Down Expand Up @@ -116,21 +116,21 @@ export class PblNgridBlockUiPluginDirective<T> implements OnDestroy {


ngOnDestroy(): void {
this._removePlugin(this.table);
this._removePlugin(this.grid);
}

private setupBlocker(): void {
const state = this._blockInProgress;
if (state) {
if (!this._blockerEmbeddedVRef) {
const blockerTemplate = this.table.registry.getSingle('blocker');
const blockerTemplate = this.grid.registry.getSingle('blocker');
if (blockerTemplate) {
this._blockerEmbeddedVRef = this.table.createView('afterContent', blockerTemplate.tRef, { $implicit: this.table });
this._blockerEmbeddedVRef = this.grid.createView('afterContent', blockerTemplate.tRef, { $implicit: this.grid });
this._blockerEmbeddedVRef.detectChanges();
}
}
} else if (this._blockerEmbeddedVRef) {
this.table.removeView(this._blockerEmbeddedVRef, 'afterContent');
this.grid.removeView(this._blockerEmbeddedVRef, 'afterContent');
this._blockerEmbeddedVRef = undefined;
}
}
Expand Down
2 changes: 1 addition & 1 deletion libs/ngrid/block-ui/src/lib/block-ui/directives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { Directive, TemplateRef } from '@angular/core';
import { PblNgridComponent, PblNgridRegistryService, PblNgridSingleTemplateRegistry } from '@pebula/ngrid';

declare module '@pebula/ngrid/lib/table/services/table-registry.service' {
declare module '@pebula/ngrid/lib/grid/services/grid-registry.service' {
interface PblNgridSingleRegistryMap {
blocker?: PblNgridBlockUiDefDirective;
}
Expand Down
6 changes: 3 additions & 3 deletions libs/ngrid/clipboard/src/lib/clipboard.plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Directive, Injector, OnDestroy, Input } from '@angular/core';
import { Clipboard } from './clipboard.service';

import { UnRx } from '@pebula/utils';
import { PblNgridComponent, PblNgridPluginController, TablePlugin, PblNgridConfigService } from '@pebula/ngrid';
import { PblNgridComponent, PblNgridPluginController, NgridPlugin, PblNgridConfigService } from '@pebula/ngrid';

declare module '@pebula/ngrid/lib/ext/types' {
interface PblNgridPluginExtension {
Expand All @@ -17,7 +17,7 @@ declare module '@pebula/ngrid/lib/ext/types' {
}
}

declare module '@pebula/ngrid/lib/table/services/config' {
declare module '@pebula/ngrid/lib/grid/services/config' {
interface PblNgridConfig {
clipboard?: {
/** When set to true will enable the clipboard plugin on all grid instances by default. */
Expand All @@ -42,7 +42,7 @@ const DEFAULT_ROW_SEP = '\n';

export const PLUGIN_KEY: 'clipboard' = 'clipboard';

@TablePlugin({ id: PLUGIN_KEY, factory: 'create' })
@NgridPlugin({ id: PLUGIN_KEY, factory: 'create' })
@Directive({ selector: 'pbl-ngrid[clipboard]', exportAs: 'pblNgridClipboard' })
@UnRx()
export class PblNgridClipboardPlugin implements OnDestroy {
Expand Down
Loading

0 comments on commit 4ca1a1e

Please sign in to comment.