Skip to content

Commit

Permalink
perf: decrease number of calls to translate all extensions only once (#…
Browse files Browse the repository at this point in the history
…290)

* perf: decrease number of calls to translate all extensions only once
  • Loading branch information
ghiscoding authored Jan 27, 2024
1 parent 83646fb commit 89ddb41
Show file tree
Hide file tree
Showing 3 changed files with 344 additions and 326 deletions.
42 changes: 21 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,33 +96,33 @@
"/src/slickgrid-react"
],
"dependencies": {
"@slickgrid-universal/common": "~4.3.0",
"@slickgrid-universal/custom-footer-component": "~4.3.0",
"@slickgrid-universal/empty-warning-component": "~4.3.0",
"@slickgrid-universal/common": "~4.3.1",
"@slickgrid-universal/custom-footer-component": "~4.3.1",
"@slickgrid-universal/empty-warning-component": "~4.3.1",
"@slickgrid-universal/event-pub-sub": "~4.3.0",
"@slickgrid-universal/pagination-component": "~4.3.0",
"@slickgrid-universal/pagination-component": "~4.3.1",
"dequal": "^2.0.3",
"dompurify": "^3.0.8",
"font-awesome": "^4.7.0",
"i18next": "^23.7.18",
"i18next": "^23.7.20",
"moment-mini": "^2.29.4",
"regenerator-runtime": "^0.14.1",
"sortablejs": "^1.15.2"
},
"devDependencies": {
"@4tw/cypress-drag-drop": "^2.2.5",
"@faker-js/faker": "^8.3.1",
"@faker-js/faker": "^8.4.0",
"@fnando/sparkline": "^0.3.10",
"@popperjs/core": "^2.11.8",
"@release-it/conventional-changelog": "^8.0.1",
"@slickgrid-universal/composite-editor-component": "~4.3.0",
"@slickgrid-universal/custom-tooltip-plugin": "~4.3.0",
"@slickgrid-universal/excel-export": "~4.3.0",
"@slickgrid-universal/graphql": "~4.3.0",
"@slickgrid-universal/odata": "~4.3.0",
"@slickgrid-universal/rxjs-observable": "~4.3.0",
"@slickgrid-universal/text-export": "~4.3.0",
"@testing-library/jest-dom": "^6.2.0",
"@slickgrid-universal/composite-editor-component": "~4.3.1",
"@slickgrid-universal/custom-tooltip-plugin": "~4.3.1",
"@slickgrid-universal/excel-export": "~4.3.1",
"@slickgrid-universal/graphql": "~4.3.1",
"@slickgrid-universal/odata": "~4.3.1",
"@slickgrid-universal/rxjs-observable": "~4.3.1",
"@slickgrid-universal/text-export": "~4.3.1",
"@testing-library/jest-dom": "^6.3.0",
"@testing-library/react": "^14.1.2",
"@testing-library/user-event": "^14.5.2",
"@types/bluebird": "^3.5.42",
Expand All @@ -131,14 +131,14 @@
"@types/fnando__sparkline": "^0.3.7",
"@types/i18next-xhr-backend": "^1.4.2",
"@types/jest": "^29.5.11",
"@types/node": "^20.11.5",
"@types/node": "^20.11.8",
"@types/react": "^18.2.48",
"@types/react-dom": "^18.2.18",
"@types/sortablejs": "^1.15.7",
"@types/text-encoding-utf-8": "^1.0.5",
"@types/webpack": "^5.28.5",
"@typescript-eslint/eslint-plugin": "^6.19.0",
"@typescript-eslint/parser": "^6.19.0",
"@typescript-eslint/eslint-plugin": "^6.19.1",
"@typescript-eslint/parser": "^6.19.1",
"@webpack-cli/serve": "^2.0.5",
"bootstrap": "^5.3.2",
"clean-webpack-plugin": "^4.0.0",
Expand All @@ -148,7 +148,7 @@
"css-loader": "^6.9.1",
"custom-event-polyfill": "^1.0.7",
"cypress": "^13.6.3",
"esbuild-loader": "^4.0.2",
"esbuild-loader": "^4.0.3",
"eslint": "^8.56.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-prefer-arrow": "^1.2.3",
Expand All @@ -171,17 +171,17 @@
"react-dom": "^18.2.0",
"react-i18next": "^14.0.1",
"react-router-dom": "^6.21.3",
"release-it": "^17.0.1",
"release-it": "^17.0.3",
"rimraf": "^5.0.5",
"rxjs": "^7.8.1",
"sass": "^1.70.0",
"sass-loader": "^14.0.0",
"serve": "^14.2.1",
"style-loader": "3.3.4",
"ts-jest": "^29.1.1",
"ts-jest": "^29.1.2",
"ts-loader": "^9.5.1",
"typescript": "^5.3.3",
"webpack": "^5.89.0",
"webpack": "^5.90.0",
"webpack-cli": "^5.1.4",
"webpack-dev-server": "^4.15.1"
},
Expand Down
32 changes: 3 additions & 29 deletions src/slickgrid-react/components/slickgrid-react.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -760,19 +760,15 @@ export class SlickgridReact<TData = any> extends React.Component<SlickgridReactP
// translate some of them on first load, then on each language change
if (gridOptions.enableTranslate) {
this.extensionService.translateAllExtensions();
this.translateColumnHeaderTitleKeys();
this.translateColumnGroupKeys();
}

// on locale change, we have to manually translate the Headers, GridMenu
i18next.on('languageChanged', () => {
i18next.on('languageChanged', (lang) => {
// publish event of the same name that Slickgrid-Universal uses on a language change event
this._eventPubSubService.publish('onLanguageChange');

if (gridOptions.enableTranslate) {
this.extensionService.translateAllExtensions();
this.translateColumnHeaderTitleKeys();
this.translateColumnGroupKeys();
this.extensionService.translateAllExtensions(lang);
if (gridOptions.createPreHeaderPanel && !gridOptions.enableDraggableGrouping) {
this.groupingService.translateGroupingAndColSpan();
}
Expand Down Expand Up @@ -1064,10 +1060,6 @@ export class SlickgridReact<TData = any> extends React.Component<SlickgridReactP
this._isDatasetInitialized = true;
}

if (dataset) {
this.grid.invalidate();
}

// display the Pagination component only after calling this refresh data first, we call it here so that if we preset pagination page number it will be shown correctly
this.showPagination = (this._gridOptions && (this._gridOptions.enablePagination || (this._gridOptions.backendServiceApi && this._gridOptions.enablePagination === undefined))) ? true : false;
if (this._paginationOptions && this._gridOptions?.pagination && this._gridOptions?.backendServiceApi) {
Expand Down Expand Up @@ -1109,14 +1101,6 @@ export class SlickgridReact<TData = any> extends React.Component<SlickgridReactP
return showing;
}

setData(data: TData[], shouldAutosizeColumns = false) {
if (shouldAutosizeColumns) {
this._isAutosizeColsCalled = false;
this._currentDatasetLength = 0;
}
this.dataset = data || [];
}

/**
* Check if there's any Pagination Presets defined in the Grid Options,
* if there are then load them in the paginationOptions object
Expand Down Expand Up @@ -1145,7 +1129,7 @@ export class SlickgridReact<TData = any> extends React.Component<SlickgridReactP
}

if (this._gridOptions.enableTranslate) {
this.extensionService.translateColumnHeaders(false, newColumnDefinitions);
this.extensionService.translateColumnHeaders(undefined, newColumnDefinitions);
} else {
this.extensionService.renderColumnHeaders(newColumnDefinitions, true);
}
Expand Down Expand Up @@ -1554,16 +1538,6 @@ export class SlickgridReact<TData = any> extends React.Component<SlickgridReactP
});
}

/** translate all columns (including hidden columns) */
protected translateColumnHeaderTitleKeys() {
this.extensionUtility.translateItems(this.sharedService.allColumns, 'nameKey', 'name');
}

/** translate all column groups (including hidden columns) */
protected translateColumnGroupKeys() {
this.extensionUtility.translateItems(this.sharedService.allColumns, 'columnGroupKey', 'columnGroup');
}

/**
* Update the "internalColumnEditor.collection" property.
* Since this is called after the async call resolves, the pointer will not be the same as the "column" argument passed.
Expand Down
Loading

0 comments on commit 89ddb41

Please sign in to comment.