-
Notifications
You must be signed in to change notification settings - Fork 673
Grids: move _validatingController definition from base dataController #34761
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
Merged
bit-byte0
merged 6 commits into
DevExpress:main
from
bit-byte0:refactor/gridcore-relocate-validating-controller-26_2
Aug 14, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
67f15a0
refactor(grids): relocate validating data extender out of base DataCo…
bit-byte0 4faddf9
refactor(grids): extract validating constants into const module
bit-byte0 562cf0c
refactor(grids): expose validating getValidationData accessor for rea…
bit-byte0 91bbd4d
refactor(grids): name validating data extender export to match module
bit-byte0 3680479
refactor(grids): type validating data extender and split _isCellChanged
bit-byte0 20cea4d
refactor(grids): make validationResultIsValid a type guard and tidy v…
bit-byte0 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
2 changes: 1 addition & 1 deletion
2
packages/devextreme/js/__internal/grids/data_grid/module_not_extended/validating.ts
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
22 changes: 22 additions & 0 deletions
22
packages/devextreme/js/__internal/grids/grid_core/validating/const.ts
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 |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import { isDefined } from '@js/core/utils/type'; | ||
|
|
||
| export const INVALIDATE_CLASS = 'invalid'; | ||
|
|
||
| export const VALIDATION_STATUS = { | ||
| valid: 'valid', | ||
| invalid: 'invalid', | ||
| pending: 'pending', | ||
| } as const; | ||
|
|
||
| export type ValidationStatus = typeof VALIDATION_STATUS[keyof typeof VALIDATION_STATUS]; | ||
|
|
||
| export const VALIDATION_CANCELLED = 'cancel'; | ||
|
|
||
| export interface CellValidationResult { | ||
| status?: ValidationStatus; | ||
| disabledPendingId?: unknown; | ||
| } | ||
|
|
||
| export const validationResultIsValid = ( | ||
| result: unknown, | ||
| ): result is CellValidationResult => isDefined(result) && result !== VALIDATION_CANCELLED; |
104 changes: 104 additions & 0 deletions
104
...vextreme/js/__internal/grids/grid_core/validating/extenders/validating_data_controller.ts
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 |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| import $ from '@js/core/renderer'; | ||
| import type { DataController } from '@ts/grids/grid_core/data_controller/data_controller'; | ||
| import type { Cell, ProcessedItem } from '@ts/grids/grid_core/data_controller/types'; | ||
| import type { ModuleType } from '@ts/grids/grid_core/m_types'; | ||
|
|
||
| import type { CellValidationResult, ValidationStatus } from '../const'; | ||
| import { | ||
| INVALIDATE_CLASS, | ||
| VALIDATION_STATUS, | ||
| validationResultIsValid, | ||
| } from '../const'; | ||
|
|
||
| type ValidationResult = CellValidationResult | string | undefined; | ||
|
|
||
| interface ValidationData { | ||
| isValid?: boolean; | ||
| } | ||
|
|
||
| type ValidatedCell = Cell & { | ||
| validationStatus?: ValidationStatus; | ||
| cellElement?: Element; | ||
| }; | ||
|
|
||
| interface ValidatingControllerReader { | ||
| getCellValidationResult: (options: { rowKey: unknown; columnIndex: number }) => ValidationResult; | ||
| getValidationData: (key: unknown) => ValidationData | undefined; | ||
| } | ||
|
|
||
| export const validatingDataControllerExtender = ( | ||
| Base: ModuleType<DataController>, | ||
| ): ModuleType<DataController> => class ValidatingDataControllerExtender extends Base { | ||
| protected _validatingController!: ValidatingControllerReader; | ||
|
|
||
| public init(): void { | ||
| this._validatingController = this.getController('validating'); | ||
| super.init(); | ||
| } | ||
|
|
||
| private _getValidationStatus(validationResult: ValidationResult): string { | ||
| if (!validationResultIsValid(validationResult)) { | ||
| return validationResult ?? VALIDATION_STATUS.valid; | ||
| } | ||
|
|
||
| return validationResult.status ?? VALIDATION_STATUS.valid; | ||
| } | ||
|
|
||
| private _isRowEditStateChanged( | ||
| oldRow: ProcessedItem, | ||
| newRow: ProcessedItem, | ||
| columnIndex: number, | ||
| ): boolean { | ||
| const cell = oldRow.cells?.[columnIndex]; | ||
| const hasValidationRules = !!cell?.column?.validationRules?.length; | ||
|
|
||
| return oldRow.isEditing !== newRow.isEditing && hasValidationRules; | ||
| } | ||
|
|
||
| private _isCellValidationStateChanged( | ||
| oldRow: ProcessedItem, | ||
| newRow: ProcessedItem, | ||
| columnIndex: number, | ||
| ): boolean { | ||
| const cell = oldRow.cells?.[columnIndex] as ValidatedCell | undefined; | ||
|
|
||
| const oldValidationStatus = this._getValidationStatus({ status: cell?.validationStatus }); | ||
| const newValidationStatus = this._getValidationStatus( | ||
| this._validatingController.getCellValidationResult({ rowKey: oldRow.key, columnIndex }), | ||
| ); | ||
| const rowIsModified = JSON.stringify(newRow.modifiedValues) | ||
| !== JSON.stringify(oldRow.modifiedValues); | ||
| const validationStatusChanged = oldValidationStatus !== newValidationStatus && rowIsModified; | ||
|
|
||
| if (validationStatusChanged) { | ||
| return true; | ||
| } | ||
|
|
||
| const validationData = this._validatingController.getValidationData(oldRow.key); | ||
| const cellIsMarkedAsInvalid = $(cell?.cellElement) | ||
| .hasClass(this.addWidgetPrefix(INVALIDATE_CLASS)); | ||
|
|
||
| return !!validationData?.isValid && cellIsMarkedAsInvalid; | ||
| } | ||
|
|
||
| protected _isCellChanged( | ||
| oldRow: ProcessedItem, | ||
| newRow: ProcessedItem, | ||
| visibleRowIndex: number, | ||
| columnIndex: number, | ||
| isLiveUpdate?: boolean, | ||
| ): boolean { | ||
| const rowEditStateChanged = this._isRowEditStateChanged(oldRow, newRow, columnIndex); | ||
| const cellValidationStateChanged = this._isCellValidationStateChanged( | ||
| oldRow, | ||
| newRow, | ||
| columnIndex, | ||
| ); | ||
|
|
||
| if (rowEditStateChanged || cellValidationStateChanged) { | ||
| return true; | ||
| } | ||
|
|
||
| return super._isCellChanged(oldRow, newRow, visibleRowIndex, columnIndex, isLiveUpdate); | ||
| } | ||
| }; | ||
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
39 changes: 39 additions & 0 deletions
39
packages/devextreme/js/__internal/grids/grid_core/validating/validating_module.ts
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 |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import messageLocalization from '@js/common/core/localization/message'; | ||
| import type { EditingTextsBase } from '@js/common/grids'; | ||
|
|
||
| import { validatingDataControllerExtender } from './extenders/validating_data_controller'; | ||
| import { | ||
| ValidatingController, | ||
| validatingEditingExtender, | ||
| validatingEditorFactoryExtender, | ||
| validatingRowsViewExtender, | ||
| } from './m_validating'; | ||
|
|
||
| interface ValidatingModuleOptions { | ||
| editing: { texts: Pick<EditingTextsBase, 'validationCancelChanges'> }; | ||
| } | ||
|
|
||
| export const validatingModule = { | ||
| defaultOptions(): ValidatingModuleOptions { | ||
| return { | ||
| editing: { | ||
| texts: { | ||
| validationCancelChanges: messageLocalization.format('dxDataGrid-validationCancelChanges'), | ||
| }, | ||
| }, | ||
| }; | ||
| }, | ||
| controllers: { | ||
| validating: ValidatingController, | ||
| }, | ||
| extenders: { | ||
| controllers: { | ||
| editing: validatingEditingExtender, | ||
| editorFactory: validatingEditorFactoryExtender, | ||
| data: validatingDataControllerExtender, | ||
| }, | ||
| views: { | ||
| rowsView: validatingRowsViewExtender, | ||
| }, | ||
| }, | ||
| }; |
2 changes: 1 addition & 1 deletion
2
packages/devextreme/js/__internal/grids/tree_list/m_validating.ts
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.
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.