Skip to content
This repository was archived by the owner on Jun 1, 2025. It is now read-only.

Commit ffee51e

Browse files
authored
Merge pull request #1355 from ghiscoding/perf/decreate-translate-calls
perf: decrease number of calls to translate all extensions only once
2 parents 6b18b14 + b51eef4 commit ffee51e

File tree

4 files changed

+383
-371
lines changed

4 files changed

+383
-371
lines changed

package.json

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -50,57 +50,57 @@
5050
},
5151
"dependencies": {
5252
"@ngx-translate/core": "^15.0.0",
53-
"@slickgrid-universal/common": "~4.3.0",
54-
"@slickgrid-universal/custom-footer-component": "~4.3.0",
55-
"@slickgrid-universal/empty-warning-component": "~4.3.0",
53+
"@slickgrid-universal/common": "~4.3.1",
54+
"@slickgrid-universal/custom-footer-component": "~4.3.1",
55+
"@slickgrid-universal/empty-warning-component": "~4.3.1",
5656
"@slickgrid-universal/event-pub-sub": "~4.3.0",
57-
"@slickgrid-universal/pagination-component": "~4.3.0",
58-
"@slickgrid-universal/row-detail-view-plugin": "~4.3.0",
59-
"@slickgrid-universal/rxjs-observable": "~4.3.0",
57+
"@slickgrid-universal/pagination-component": "~4.3.1",
58+
"@slickgrid-universal/row-detail-view-plugin": "~4.3.1",
59+
"@slickgrid-universal/rxjs-observable": "~4.3.1",
6060
"dequal": "^2.0.3",
6161
"dompurify": "^3.0.8",
6262
"rxjs": "^7.8.1",
6363
"sortablejs": "^1.15.2"
6464
},
6565
"devDependencies": {
6666
"@4tw/cypress-drag-drop": "^2.2.5",
67-
"@angular-devkit/build-angular": "^17.1.0",
67+
"@angular-devkit/build-angular": "^17.1.1",
6868
"@angular-eslint/builder": "^17.2.1",
6969
"@angular-eslint/eslint-plugin": "^17.2.1",
7070
"@angular-eslint/eslint-plugin-template": "^17.2.1",
7171
"@angular-eslint/schematics": "^17.2.1",
7272
"@angular-eslint/template-parser": "^17.2.1",
73-
"@angular/animations": "^17.1.0",
74-
"@angular/cli": "^17.1.0",
75-
"@angular/common": "^17.1.0",
76-
"@angular/compiler": "^17.1.0",
77-
"@angular/compiler-cli": "^17.1.0",
78-
"@angular/core": "^17.1.0",
79-
"@angular/forms": "^17.1.0",
80-
"@angular/language-service": "^17.1.0",
81-
"@angular/platform-browser": "^17.1.0",
82-
"@angular/platform-browser-dynamic": "^17.1.0",
83-
"@angular/router": "^17.1.0",
84-
"@faker-js/faker": "^8.3.1",
73+
"@angular/animations": "^17.1.1",
74+
"@angular/cli": "^17.1.1",
75+
"@angular/common": "^17.1.1",
76+
"@angular/compiler": "^17.1.1",
77+
"@angular/compiler-cli": "^17.1.1",
78+
"@angular/core": "^17.1.1",
79+
"@angular/forms": "^17.1.1",
80+
"@angular/language-service": "^17.1.1",
81+
"@angular/platform-browser": "^17.1.1",
82+
"@angular/platform-browser-dynamic": "^17.1.1",
83+
"@angular/router": "^17.1.1",
84+
"@faker-js/faker": "^8.4.0",
8585
"@fnando/sparkline": "^0.3.10",
8686
"@ng-select/ng-select": "^12.0.6",
8787
"@ngx-translate/http-loader": "^8.0.0",
8888
"@popperjs/core": "^2.11.8",
8989
"@release-it/conventional-changelog": "^8.0.1",
90-
"@slickgrid-universal/composite-editor-component": "~4.3.0",
91-
"@slickgrid-universal/custom-tooltip-plugin": "~4.3.0",
92-
"@slickgrid-universal/excel-export": "~4.3.0",
93-
"@slickgrid-universal/graphql": "~4.3.0",
94-
"@slickgrid-universal/odata": "~4.3.0",
95-
"@slickgrid-universal/text-export": "~4.3.0",
90+
"@slickgrid-universal/composite-editor-component": "~4.3.1",
91+
"@slickgrid-universal/custom-tooltip-plugin": "~4.3.1",
92+
"@slickgrid-universal/excel-export": "~4.3.1",
93+
"@slickgrid-universal/graphql": "~4.3.1",
94+
"@slickgrid-universal/odata": "~4.3.1",
95+
"@slickgrid-universal/text-export": "~4.3.1",
9696
"@types/dompurify": "^3.0.5",
9797
"@types/flatpickr": "^3.1.2",
9898
"@types/fnando__sparkline": "^0.3.7",
9999
"@types/jest": "^29.5.11",
100-
"@types/node": "^20.11.5",
100+
"@types/node": "^20.11.8",
101101
"@types/sortablejs": "^1.15.7",
102-
"@typescript-eslint/eslint-plugin": "^6.19.0",
103-
"@typescript-eslint/parser": "^6.19.0",
102+
"@typescript-eslint/eslint-plugin": "^6.19.1",
103+
"@typescript-eslint/parser": "^6.19.1",
104104
"bootstrap": "^5.3.2",
105105
"copyfiles": "^2.4.1",
106106
"custom-event-polyfill": "^1.0.7",
@@ -112,10 +112,10 @@
112112
"jest-extended": "^4.0.2",
113113
"jest-preset-angular": "^14.0.0",
114114
"moment-mini": "^2.29.4",
115-
"ng-packagr": "^17.1.0",
115+
"ng-packagr": "^17.1.2",
116116
"ngx-bootstrap": "^12.0.0",
117117
"npm-run-all2": "^6.1.1",
118-
"release-it": "^17.0.1",
118+
"release-it": "^17.0.3",
119119
"rimraf": "^5.0.5",
120120
"rxjs": "^7.8.1",
121121
"sass": "^1.70.0",

src/app/modules/angular-slickgrid/components/__tests__/angular-slickgrid.component.spec.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,11 +1042,12 @@ describe('Angular-Slickgrid Custom Component instantiated via Constructor', () =
10421042
const refreshSpy = jest.spyOn(component, 'refreshGridData');
10431043

10441044
const mockData = [{ firstName: 'John', lastName: 'Doe' }, { firstName: 'Jane', lastName: 'Smith' }];
1045-
jest.spyOn(mockDataView, 'getItems').mockReturnValue(mockData);
1045+
jest.spyOn(mockDataView, 'getItems').mockReturnValueOnce(mockData);
10461046
component.gridOptions = {
10471047
enablePagination: true,
10481048
presets: { pagination: { pageSize: 2, pageNumber: expectedPageNumber } }
10491049
};
1050+
component.paginationOptions = undefined;
10501051
component.paginationOptions = { pageSize: 2, pageNumber: 2, pageSizes: [2, 10, 25, 50], totalItems: 100 };
10511052

10521053
component.dataset = mockData;
@@ -1163,7 +1164,7 @@ describe('Angular-Slickgrid Custom Component instantiated via Constructor', () =
11631164
component.gridOptions.backendServiceApi!.internalPostProcess!({ data: { notUsers: { nodes: [{ firstName: 'John' }], totalCount: 2 } } } as GraphqlPaginatedResult);
11641165

11651166
expect(spy).not.toHaveBeenCalled();
1166-
// expect(component.dataset).toEqual([]);
1167+
expect(component.dataset).toEqual([]);
11671168
});
11681169

11691170
it('should invoke "updateFilters" method with filters returned from "getColumnFilters" of the Filter Service when there is no Presets defined', () => {
@@ -1949,8 +1950,7 @@ describe('Angular-Slickgrid Custom Component instantiated via Constructor', () =
19491950
expect(footerSpy).toHaveBeenCalledWith(expectation);
19501951
});
19511952

1952-
it.skip('should have custom footer with metrics when the DataView "onSetItemsCalled" event is triggered', () => {
1953-
const invalidateSpy = jest.spyOn(mockGrid, 'invalidate');
1953+
it('should have custom footer with metrics when the DataView "onSetItemsCalled" event is triggered', () => {
19541954
const expectation = {
19551955
startTime: expect.toBeDate(),
19561956
endTime: expect.toBeDate(),
@@ -1964,7 +1964,6 @@ describe('Angular-Slickgrid Custom Component instantiated via Constructor', () =
19641964
const footerSpy = jest.spyOn(component.slickFooter!, 'metrics', 'set');
19651965
mockDataView.onSetItemsCalled.notify({ idProperty: 'id', itemCount: 0 });
19661966

1967-
expect(invalidateSpy).toHaveBeenCalled();
19681967
expect(footerSpy).toHaveBeenCalledWith(expectation);
19691968
expect(component.metrics).toEqual(expectation);
19701969
});

src/app/modules/angular-slickgrid/components/angular-slickgrid.component.ts

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ import { ContainerService } from '../services/container.service';
9595
]
9696
})
9797
export class AngularSlickgridComponent<TData = any> implements AfterViewInit, OnDestroy {
98-
protected _dataset?: any[] | null;
98+
protected _dataset?: TData[] | null;
9999
protected _columnDefinitions!: Column[];
100100
protected _currentDatasetLength = 0;
101101
protected _eventHandler: SlickEventHandler = new SlickEventHandler();
@@ -358,7 +358,7 @@ export class AngularSlickgridComponent<TData = any> implements AfterViewInit, On
358358
this._isGridInitialized = true;
359359

360360
// recheck the empty warning message after grid is shown so that it works in every use case
361-
if (this.gridOptions && this.gridOptions.enableEmptyDataWarningMessage && Array.isArray(this.dataset)) {
361+
if (this.gridOptions?.enableEmptyDataWarningMessage && Array.isArray(this.dataset)) {
362362
const finalTotalCount = this.dataset.length;
363363
this.displayEmptyDataWarning(finalTotalCount < 1);
364364
}
@@ -789,7 +789,7 @@ export class AngularSlickgridComponent<TData = any> implements AfterViewInit, On
789789
newColumnDefinitions = this.swapInternalEditorToSlickGridFactoryEditor(newColumnDefinitions);
790790

791791
if (this.gridOptions.enableTranslate) {
792-
this.extensionService.translateColumnHeaders(false, newColumnDefinitions);
792+
this.extensionService.translateColumnHeaders(undefined, newColumnDefinitions);
793793
} else {
794794
this.extensionService.renderColumnHeaders(newColumnDefinitions, true);
795795
}
@@ -835,19 +835,15 @@ export class AngularSlickgridComponent<TData = any> implements AfterViewInit, On
835835
// translate some of them on first load, then on each language change
836836
if (gridOptions.enableTranslate) {
837837
this.extensionService.translateAllExtensions();
838-
this.translateColumnHeaderTitleKeys();
839-
this.translateColumnGroupKeys();
840838
}
841839

842840
this.subscriptions.push(
843-
this.translate.onLangChange.subscribe(() => {
841+
this.translate.onLangChange.subscribe(({ lang }) => {
844842
// publish event of the same name that Slickgrid-Universal uses on a language change event
845843
this._eventPubSubService.publish('onLanguageChange');
846844

847845
if (gridOptions.enableTranslate) {
848-
this.extensionService.translateAllExtensions();
849-
this.translateColumnHeaderTitleKeys();
850-
this.translateColumnGroupKeys();
846+
this.extensionService.translateAllExtensions(lang);
851847
if (gridOptions.createPreHeaderPanel && !gridOptions.enableDraggableGrouping) {
852848
this.groupingService.translateGroupingAndColSpan();
853849
}
@@ -1407,16 +1403,6 @@ export class AngularSlickgridComponent<TData = any> implements AfterViewInit, On
14071403
});
14081404
}
14091405

1410-
protected translateColumnHeaderTitleKeys() {
1411-
// translate all columns (including hidden columns)
1412-
this.extensionUtility.translateItems(this.sharedService.allColumns, 'nameKey', 'name');
1413-
}
1414-
1415-
protected translateColumnGroupKeys() {
1416-
// translate all column groups (including hidden columns)
1417-
this.extensionUtility.translateItems(this.sharedService.allColumns, 'columnGroupKey', 'columnGroup');
1418-
}
1419-
14201406
/**
14211407
* Update the "internalColumnEditor.collection" property.
14221408
* Since this is called after the async call resolves, the pointer will not be the same as the "column" argument passed.

0 commit comments

Comments
 (0)