Closed egordidenko closed 1 month ago
The changes introduce a centralized ValidationManager
for handling file and collection validations within the uploader block. This refactor simplifies the code by removing multiple individual validator functions and replacing them with a unified validation system. Configuration settings are updated to support the new validators, and type definitions are enhanced to reflect these changes. Additionally, demo files are updated to showcase the new validation functionality.
Files / Groups | Change Summary |
---|---|
abstract/UploaderBlock.js |
Removed old validators, added ValidationManager , updated logic to use the new manager. |
abstract/ValidationManager.js |
Introduced ValidationManager class for handling file and collection validations. |
blocks/Config/Config.js |
Added fileValidators and collectionValidators to complexConfigKeys . |
blocks/Config/initialConfig.js |
Added fileValidators and collectionValidators properties to initialConfig . |
blocks/Config/normalizeConfigValue.js |
Introduced asArray function and updated mapping object for new validators. |
demo/raw-regular.html |
Added a script tag to reference index.js as a module. |
abstract/CTX.js |
Updated type annotation for collectionErrors to use types from ValidationManager . |
abstract/buildOutputCollectionState.js |
Updated return type annotation for errors function. |
types/exported.d.ts |
Added FileValidator and CollectionValidator types. |
utils/validators/collection/index.js |
Exported validateCollectionUploadError and validateMultiple functions. |
utils/validators/collection/validateCollectionUploadError.js |
Introduced validateCollectionUploadError function. |
utils/validators/collection/validateMultiple.js |
Introduced validateMultiple function. |
utils/validators/file/index.js |
Exported validateIsImage , validateFileType , validateMaxSizeLimit , and validateUploadError functions. |
utils/validators/file/validateFileType.js |
Introduced validateFileType function. |
utils/validators/file/validateIsImage.js |
Introduced validateIsImage function. |
utils/validators/file/validateMaxSizeLimit.js |
Introduced validateMaxSizeLimit function. |
utils/validators/file/validateUploadError.js |
Introduced validateUploadError function. |
demo/validators.html |
Added new validation functions and updated configuration in demo HTML. |
sequenceDiagram
participant User
participant UploaderBlock
participant ValidationManager
participant FileValidator
participant CollectionValidator
User->>UploaderBlock: Upload File/Collection
UploaderBlock->>ValidationManager: Run Validators
ValidationManager->>FileValidator: Validate File
FileValidator-->>ValidationManager: Return Validation Result
ValidationManager->>CollectionValidator: Validate Collection
CollectionValidator-->>ValidationManager: Return Validation Result
ValidationManager-->>UploaderBlock: Return Validation Results
UploaderBlock-->>User: Display Validation Results
In the code, a change so grand,
Validators now take a stand.
With a manager to guide the way,
Errors and files kept at bay.
Configuration set just right,
Uploads now a smoother flight.
🎉✨
block
argument to the ctx
or or
(like lr-upload-ctx-provider
)(this._blockInstance.cfg.fileValidators ?? []).map(fn => (...args) => ({...fn(...args), type: 'CUSTOM_TYPE'}))
Description
Checklist
Summary by CodeRabbit
New Features
ValidationManager
to handle file and collection validation, improving the validation process.Bug Fixes
Documentation
Refactor
ValidationManager
, removing redundant code.Style