Skip to content
6 changes: 3 additions & 3 deletions packages/qgrid-core/src/format/format.service.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export declare class FormatService {
static number(x: number, format: string): string;
static date(x: Date, format: string): string;
static currency(x: number, format: string): string;
static number(x: number, format: string): string | null;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets discuss to use Nullable instead of string | null

static date(x: Date, format: string): string | null;
static currency(x: number, format: string): string | null;
}
10 changes: 5 additions & 5 deletions packages/qgrid-core/src/plugin/grid.plugin.d.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { Model } from '../model/model';
import { Table } from '../dom/table';
import { GridLet } from '../grid/grid.let';
import { ObservableLike } from '../rx/rx';
import { Event } from '../event/event';
import { GridLet } from '../grid/grid.let';
import { GridService } from '../grid/grid.service';
import { Model } from '../model/model';
import { ObservableEvent, ObservableReplyEvent } from '../rx/rx';

export interface GridPlugin {
readonly model: Model;
readonly table: Table;
readonly view: GridLet;
readonly service: GridService;

observe<TState>(event: Event<TState>): ObservableLike<TState>;
observeReply<TState>(event: Event<TState>): ObservableLike<TState>;
observe<TState>(event: Event<TState>): ObservableEvent<TState>;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why we change it to ObservableEvent? it should return the minimal required interface

observeReply<TState>(event: Event<TState>): ObservableReplyEvent<TState>;
}
2 changes: 1 addition & 1 deletion packages/qgrid-core/src/scene/render/render.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { RenderStrategy } from './render.strategy';

export declare class Renderer {
defaultStrategy: RenderStrategy;
readonly rows: { left: any[]; right: any[]; mid: any[] };
readonly rows: Record<string, any>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd create an interface for left, right, mid object and use it here.

export interface RowsPosition {
  left: any[];
  mid: any[];
  right: any[];
}
....
readonly rows: RowsPosition;

Because Record<string, ...> could accept any string as a key;


constructor(plugin: GridPlugin);

Expand Down
14 changes: 7 additions & 7 deletions packages/qgrid-ngx/src/lib/body/body-core.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ export class BodyCoreComponent implements OnInit {
scrollSettings,
));

disposable.add(listener.on('wheel', e => host.wheel(e)));
disposable.add(listener.on('mouseleave', e => host.mouseLeave(e)));
disposable.add(listener.on('wheel', (e: WheelEvent) => host.wheel(e)));
disposable.add(listener.on('mouseleave', (e: WheelEvent) => host.mouseLeave(e)));
});

observeReply(model.sceneChanged)
.subscribe(e => {
.subscribe((e: any) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

e: GridEventArg<SceneState>

if (model.grid().interactionMode === 'detached') {
if (e.hasChanges('status')) {
switch (e.state.status) {
Expand All @@ -86,22 +86,22 @@ export class BodyCoreComponent implements OnInit {
});

observe(model.sceneChanged)
.subscribe(e => {
.subscribe((e: any) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

e: GridEventArg<SceneState>

if (e.hasChanges('status') && e.state.status === 'push') {
this.cd.markForCheck();
}
});
}

columnId(index: number, item: ColumnView) {
columnId(index: number, item: ColumnView): string | undefined {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shorly string?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not possible. Have to specify it as a union.
image

return item.model.key;
}

rowId(index: number) {
rowId(index: number): number {
return index;
}

mapToDataIndex(viewIndex: number) {
mapToDataIndex(viewIndex: number): number {
return this.$view.scroll.y.container.position + viewIndex;
}
}
4 changes: 1 addition & 3 deletions packages/qgrid-ngx/src/lib/body/body.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ import { RowModule } from '../row/row.module';
VscrollModule,
RowModule,
],
exports: [
BodyCoreComponent,
],
exports: [BodyCoreComponent],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check indentation.
Should be as before

})
export class BodyModule {
}
4 changes: 2 additions & 2 deletions packages/qgrid-ngx/src/lib/body/td-core.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import { TrCoreDirective } from '../row/tr-core.directive';
selector: '[q-grid-core-td]',
})
export class TdCoreDirective implements DomTd, OnInit, OnDestroy, OnChanges {
@Input('q-grid-core-value') actualValue: any;
@Input('q-grid-core-label') actualLabel: any;
@Input('q-grid-core-value') actualValue: unknown;
@Input('q-grid-core-label') actualLabel: unknown;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure about that


@Input('q-grid-core-td') columnView: ColumnView;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ export class CellHandlerComponent implements OnInit, AfterViewInit {
if (e.hasChanges('status')) {
if (e.state.status === 'endBatch' && this.endBatchEdit) {
this.endBatchEdit();
this.endBatchEdit = null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check if this will break something

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should be reverted

}
}
});
Expand Down
8 changes: 4 additions & 4 deletions packages/qgrid-ngx/src/lib/cell/cell-template.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ import { Injectable, ViewContainerRef } from '@angular/core';
import { ColumnModel, GridError, noop } from '@qgrid/core';
import { TemplateService } from '../template/template.service';

function canBuild(column) {
function canBuild(column: ColumnModel) {
return column.type !== 'pad';
}

function buildId(source: string, column: ColumnModel, mode = 'view') {
const { key, type, itemType } = column as any;
const { key, type, itemType } = column;
return `${source}-${mode}-cell-${type}-of-${itemType}-the-${key}.tpl.html`;
}

function buildKeys(source: string, column: ColumnModel, mode = 'view') {
const { key, itemType } = column as any;
let { type } = column as any;
const { key, itemType } = column;
let { type } = column;

switch (mode) {
case 'view': {
Expand Down
14 changes: 7 additions & 7 deletions packages/qgrid-ngx/src/lib/column-list/column-list.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { GridPlugin } from '../plugin/grid-plugin';
@Injectable()
export class ColumnListService {
private host = new Lazy(() => {
const canCopy = (key: string, source, target) =>
const canCopy = (key: string, source: any, target: any) =>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

source, target - Partial<ColumnModel>

Object.prototype.hasOwnProperty.call(target, key) && !isUndefined(source[key]);

return new ColumnListHost(this.plugin.model, canCopy, parseFactory);
Expand All @@ -20,27 +20,27 @@ export class ColumnListService {
constructor(private plugin: GridPlugin) {
}

add(column: ColumnModel) {
add(column: ColumnModel): void {
this.host.instance.add(column);
}

copy(target, source) {
copy(target: any, source: any): void {
Copy link
Collaborator

@klumba12 klumba12 May 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any -> Partial<ColumnModel>

this.host.instance.copy(target, source);
}

generateKey(source) {
generateKey(source: any): string {
Copy link
Collaborator

@klumba12 klumba12 May 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any -> Partial<ColumnModel>

return this.host.instance.generateKey(source);
}

extract(key, type): ColumnModel {
extract(key: string, type: string): ColumnModel {
return this.host.instance.extract(key, type);
}

register(column: ColumnModel) {
register(column: ColumnModel): void {
this.host.instance.register(column);
}

delete(key: string) {
delete(key: string): void {
this.host.instance.delete(key);
}
}
20 changes: 13 additions & 7 deletions packages/qgrid-ngx/src/lib/column/column.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export class ColumnComponent implements OnInit, OnDestroy, OnChanges {
// We want to update model when ngOntInit is triggered and not in afterViewInit
// so we apply dirty hack to understand if column is cohort or not.
const element = this.elementRef.nativeElement as HTMLElement;
if (element.children.length && element.children.item(0).tagName === 'Q-GRID-COLUMN') {
if (element.children.length && element.children.item(0)?.tagName === 'Q-GRID-COLUMN') {
this.type = 'cohort';
if (!withKey) {
this.key = `$cohort-${this.title || guid()}`;
Expand Down Expand Up @@ -142,7 +142,9 @@ export class ColumnComponent implements OnInit, OnDestroy, OnChanges {

if (withKey) {
if (this.parentHost) {
this.parentHost.column.children.push(column);
if (this.parentHost.column.children) {
this.parentHost.column.children.push(column);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually you can replace these lines with
this.parentHost.column.children?.push(column);

}
} else {
this.columnList.add(column);
}
Expand All @@ -152,9 +154,9 @@ export class ColumnComponent implements OnInit, OnDestroy, OnChanges {
const settings =
Object
.keys(this)
.filter(key => !isUndefined(this[key]) && Object.prototype.hasOwnProperty.call(column, key))
.reduce((memo, key) => {
memo[key] = column[key];
.filter(key => !isUndefined(this.key) && Object.prototype.hasOwnProperty.call(column, key))
.reduce((memo: any, key: string) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

memo isn't any.
{ [key: string]: Column } if i got this right

memo[key] = column[key as keyof ColumnModel];
return memo;
}, {}) as ColumnModel;

Expand All @@ -180,8 +182,12 @@ export class ColumnComponent implements OnInit, OnDestroy, OnChanges {

ngOnDestroy() {
const { column } = this.selfHost;
if (column && column.source === 'template') {
this.columnList.delete(column.key);
if (!(column && column.source === 'template')) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!column || column.source !== 'template' is more readable, as for me.
If there's no column OR coumn source is not template.
Same thing with column.key.

Btw, why you even need to change this condition?

if (column && column.key && column.source === 'template') {
  this.columnList.delete(column.key);
}

return;
}
if(!column.key) {
return;
}
this.columnList.delete(column.key);
}
}
13 changes: 7 additions & 6 deletions packages/qgrid-ngx/src/lib/dnd/drag.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ export class DragDirective {

if (this.drag.canExecute(eventArg) === false) {
e.preventDefault();
transfer.effectAllowed = 'none';
if (transfer) {
transfer.effectAllowed = 'none';
}
return false;
}

Expand All @@ -50,8 +52,10 @@ export class DragDirective {

this.elementRef.nativeElement.classList.add(`${GRID_PREFIX}-drag`);

transfer.setData(DragService.mimeType, DragService.encode(data));
transfer.effectAllowed = this.effect || 'move';
if(transfer) {
transfer.setData(DragService.mimeType, DragService.encode(data));
transfer.effectAllowed = this.effect || 'move';
}

DragService.data = data;
DragService.area = this.area;
Expand All @@ -78,8 +82,5 @@ export class DragDirective {
this.elementRef.nativeElement.classList.remove(`${GRID_PREFIX}-drag`);

DragService.data = null;
DragService.area = null;
DragService.element = null;
DragService.startPosition = null;
}
}
12 changes: 9 additions & 3 deletions packages/qgrid-ngx/src/lib/dnd/drop.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ export class DropDirective implements OnInit {
e.preventDefault();

this.elementRef.nativeElement.classList.add(`${GRID_PREFIX}-dragover`);
e.dataTransfer.dropEffect = 'move';
if (e.dataTransfer) {
e.dataTransfer.dropEffect = 'move';
}
return false;
}

Expand All @@ -117,7 +119,9 @@ export class DropDirective implements OnInit {
}

if (this.area !== DragService.area) {
e.dataTransfer.dropEffect = 'none';
if (e.dataTransfer) {
e.dataTransfer.dropEffect = 'none';
}
return false;
}

Expand All @@ -142,7 +146,9 @@ export class DropDirective implements OnInit {
DragService.data = eventArg.dragData;
}

e.dataTransfer.dropEffect = 'move';
if(e.dataTransfer) {
e.dataTransfer.dropEffect = 'move';
}
}

return false;
Expand Down
4 changes: 2 additions & 2 deletions packages/qgrid-ngx/src/lib/foot/tf-core.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ export class TfCoreDirective implements DomTd, OnInit, OnDestroy {
@Input('q-grid-core-tf') columnView: ColumnView;

$implicit = this;
element: HTMLElement = null;
element: HTMLElement;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to remove default value, please check if there is no null checks for the element anywhere or hasOwnProperty

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I won't remove default value here also HTMLELement should be changed to Nullable


get value() {
const column = this.column;
return this.$view.foot.value(column);
}

get label() {
return this.label;
return this.value;
}

get column(): ColumnModel {
Expand Down
2 changes: 1 addition & 1 deletion packages/qgrid-ngx/src/lib/grid/grid.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export class GridComponent implements OnInit, OnChanges {
private cd: ChangeDetectorRef,
private stateAccessor: StateAccessor,
private modelBuilder: GridModelBuilder,
@Inject(DOCUMENT) private document: any,
@Inject(DOCUMENT) private document: Document,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it work? when you build it in prod?

theme: ThemeService,
) {
if (!theme.component) {
Expand Down
3 changes: 1 addition & 2 deletions packages/qgrid-ngx/src/lib/grid/grid.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { GridComponent } from './grid.component';
],
imports: [
CommonModule,

BoxModule,
LayerModule,
MarkupModule,
Expand All @@ -47,7 +46,7 @@ export class GridModule {
numberPipe: DecimalPipe,
currencyPipe: CurrencyPipe,
) {
FormatService.date = (x, format) => datePipe.transform(x, format);
FormatService.date = (x: Date, format: string) => datePipe.transform(x, format);
FormatService.number = (x, format) => numberPipe.transform(x, format);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why here there is no type?

FormatService.currency = (x, format) => currencyPipe.transform(x, format);

Expand Down
2 changes: 1 addition & 1 deletion packages/qgrid-ngx/src/lib/head/th-core.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class ThCoreDirective implements DomTd, OnInit, OnDestroy {
$implicit = this;
element: HTMLElement;
value: any;
label: any;
label: string;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in reality it can be any


get column(): ColumnModel {
return this.columnView.model;
Expand Down
2 changes: 1 addition & 1 deletion packages/qgrid-ngx/src/lib/layer/layer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class LayerService {
this.container = container;
}

create(name) {
create(name: string) {
if (this.layers.has(name)) {
return this.layers.get(name);
}
Expand Down
8 changes: 4 additions & 4 deletions packages/qgrid-ngx/src/lib/plugin/grid-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ import {
GridLet,
Lazy,
ObservableEvent,
ObservableLike,
ObservableReplyEvent,
} from '@qgrid/core';
import { DomTable } from '../dom/dom';
import { Grid, GridService } from '../grid/grid';
import { GridLet as NgxGridLet } from '../grid/grid-let';
import { GridModel } from '../grid/grid-model';
import { GridRoot } from '../grid/grid-root';
import { GridPlugin as GridPluginInterface } from '@qgrid/core';
import { Disposable } from '../infrastructure/disposable';

@Injectable()
export class GridPlugin implements OnDestroy {
export class GridPlugin implements OnDestroy, GridPluginInterface {
private serviceLazy = new Lazy(() => this.qgrid.service(this.$root.model));

readonly disposable = new Disposable();
Expand Down Expand Up @@ -45,9 +45,9 @@ export class GridPlugin implements OnDestroy {
) {
}

readonly observe = <TState>(event: Event<TState>): ObservableLike<TState> => new ObservableEvent(event, this.disposable);
readonly observe = <TState>(event: Event<TState>): ObservableEvent<TState> => new ObservableEvent(event, this.disposable);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please, revert back to ObervableLike


readonly observeReply = <TState>(event: Event<TState>): ObservableLike<TState> => new ObservableReplyEvent(event, this.disposable);
readonly observeReply = <TState>(event: Event<TState>): ObservableReplyEvent<TState> => new ObservableReplyEvent(event, this.disposable);

ngOnDestroy() {
this.disposable.finalize();
Expand Down
Loading