-
Notifications
You must be signed in to change notification settings - Fork 673
DataGrid - Summary - Refactor getSummaryOptions() #34864
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Tucchhaa
wants to merge
9
commits into
DevExpress:main
Choose a base branch
from
Tucchhaa:refactor_summary_optiobs_26_2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f9399e7
move getSummaryOptions to utils
e5231b9
move getSummaryOptions to adapterExtender
156f7aa
add test for find_summary_item
1906059
fix datasource tests
ba0ad31
add jest tests
e23a95d
add type for default options
258f0e8
apply copilot's review
1a422e6
apply review
5705536
fix ts error
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,11 +3,13 @@ import dataQuery from '@js/common/data/query'; | |
| import storeHelper from '@js/common/data/store_helper'; | ||
| import { normalizeSortingInfo } from '@js/common/data/utils'; | ||
| import $ from '@js/core/renderer'; | ||
| import { noop } from '@js/core/utils/common'; | ||
| import { extend } from '@js/core/utils/extend'; | ||
| import { each } from '@js/core/utils/iterator'; | ||
| import { isDefined, isFunction, isPlainObject } from '@js/core/utils/type'; | ||
| import { isDefined, isPlainObject } from '@js/core/utils/type'; | ||
| import type { DataSource } from '@ts/data/data_source/types'; | ||
| import type { ColumnsController } from '@ts/grids/grid_core/columns_controller/m_columns_controller'; | ||
| import type DataSourceAdapter from '@ts/grids/grid_core/data_source_adapter/m_data_source_adapter'; | ||
| import type { RemoteOperationsOptions } from '@ts/grids/grid_core/data_source_adapter/types'; | ||
| import type { EditingControllerRequired, ModuleType } from '@ts/grids/grid_core/m_types'; | ||
| import { ColumnsView } from '@ts/grids/grid_core/views/m_columns_view'; | ||
|
|
||
|
|
@@ -27,6 +29,8 @@ import { | |
| DATAGRID_TOTAL_FOOTER_CLASS, | ||
| DATAGRID_TOTAL_FOOTER_ROW_TYPE, | ||
| } from './const'; | ||
| import type { SummaryOptions } from './types'; | ||
| import { getSummaryOptions } from './utils/get_summary_options'; | ||
|
|
||
| export const renderSummaryCell = function (cell, options, setAria) { | ||
| const $cell = $(cell); | ||
|
|
@@ -149,7 +153,7 @@ const calculateAggregates = function (that: EditingControllerRequired, summary, | |
| let calculator; | ||
|
|
||
| if ((that as any).option('summary.recalculateWhileEditing')) { | ||
| const editingController = that._editingController; | ||
| const { editingController } = that; | ||
| if (editingController) { | ||
| const insertedData = editingController.getInsertedData(); | ||
| if (insertedData.length) { | ||
|
|
@@ -284,42 +288,44 @@ export class FooterView extends ColumnsView { | |
| export const dataSourceAdapterExtender = (Base: ModuleType<DataSourceAdapter>) => class SummaryDataSourceAdapterExtender extends Base implements EditingControllerRequired { | ||
| private _totalAggregates: any; | ||
|
|
||
| private _summaryGetter: any; | ||
| private columnsController!: ColumnsController; | ||
|
|
||
| public _editingController!: EditingController; | ||
| public editingController!: EditingController; | ||
|
|
||
| public init() { | ||
| super.init.apply(this, arguments as any); | ||
| public init(dataSource?: DataSource): void { | ||
| super.init(dataSource); | ||
|
|
||
| this._editingController = this.getController('editing'); | ||
| this.columnsController = this.getController('columns'); | ||
| this.editingController = this.getController('editing'); | ||
| this._totalAggregates = []; | ||
| this._summaryGetter = noop; | ||
| } | ||
|
|
||
| private summaryGetter(summaryGetter?) { | ||
| if (!arguments.length) { | ||
| return this._summaryGetter; | ||
| } | ||
| private getSummary(remoteOperations?: RemoteOperationsOptions): SummaryOptions | undefined { | ||
| const summary = this.option('summary'); | ||
|
|
||
| if (isFunction(summaryGetter)) { | ||
| this._summaryGetter = summaryGetter; | ||
| if (!summary) { | ||
| return undefined; | ||
| } | ||
| } | ||
|
|
||
| private summary(summary?) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was used as setter only in QUnit |
||
| if (!arguments.length) { | ||
| return this._summaryGetter(); | ||
| } | ||
| const result = getSummaryOptions({ | ||
| summary, | ||
| sortByGroupSummaryInfo: this.option('sortByGroupSummaryInfo'), | ||
| remoteOperations: remoteOperations ?? this.remoteOperations(), | ||
| getUpdatedItemData: (data) => this.editingController.getUpdatedData(data), | ||
| columnOption: (id) => this.columnsController.columnOption(id), | ||
| groupColumns: this.columnsController.getGroupColumns(), | ||
| component: this.component as any, | ||
| }); | ||
|
|
||
| this._summaryGetter = function () { return summary; }; | ||
| return result; | ||
| } | ||
|
|
||
| private totalAggregates() { | ||
| return this._totalAggregates; | ||
| } | ||
|
|
||
| private isLastLevelGroupItemsPagingLocal() { | ||
| const summary = this.summary(); | ||
| const summary = this.getSummary(); | ||
| const sortByGroupsInfo = summary?.sortByGroups(); | ||
|
|
||
| return sortByGroupsInfo?.length; | ||
|
|
@@ -342,7 +348,7 @@ export const dataSourceAdapterExtender = (Base: ModuleType<DataSourceAdapter>) = | |
| } | ||
|
|
||
| protected _customizeRemoteOperations(options) { | ||
| const summary = this.summary(); | ||
| const summary = this.getSummary(); | ||
|
|
||
| if (summary) { | ||
| if (options.remoteOperations.summary) { | ||
|
|
@@ -372,7 +378,7 @@ export const dataSourceAdapterExtender = (Base: ModuleType<DataSourceAdapter>) = | |
| protected customizeLoadResultHandlerCore(options) { | ||
| const groups = normalizeSortingInfo(options.storeLoadOptions.group || options.loadOptions.group || []); | ||
| const remoteOperations = options.remoteOperations || {}; | ||
| const summary = this.summaryGetter()(remoteOperations); | ||
| const summary = this.getSummary(remoteOperations); | ||
|
|
||
| if (!options.isCustomLoading || options.storeLoadOptions.isLoadingAll) { | ||
| if (remoteOperations.summary) { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
replaced this function by a simple getter in summaryDataSourceAdapterExtender:
https://github.com/DevExpress/DevExtreme/pull/34864/changes#diff-d57264845ac30f8d19ae92cce36b829978453305efb72ed33d907e6208d7f112R303