Skip to content
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

Rework quickMARC records validation #560

Merged
merged 21 commits into from
Dec 18, 2023
Merged

Conversation

BogdanDenis
Copy link
Contributor

@BogdanDenis BogdanDenis commented Jun 29, 2023

Description

Rework MARC record validation by breaking up validateMarcRecord function into smaller re-usable functions

Approach

Validation will now be a useValidation hook. The hook accepts data that is needed for validation (initial values, marc type, action, locations etc) and returns a validate function.

File validators.js contains small mostly re-usable functions that check for one specific rule (tag length, leader length, leader non-editable bytes not touched, a field has a subfield etc.)

Then in rules.js there are contstants that define for each marc type and action which rules should be applied to which fields.

Issues

UIQM-526

@github-actions
Copy link

github-actions bot commented Jun 29, 2023

Jest Unit Test Statistics

    1 files  ±  0    41 suites  +2   2m 18s ⏱️ -4s
348 tests +24  348 ✔️ +24  0 💤 ±0  0 ±0 
349 runs  +24  349 ✔️ +24  0 💤 ±0  0 ±0 

Results for commit 6880cfe. ± Comparison against base commit cf34440.

♻️ This comment has been updated with latest results.

}, null);

return errorMessage;
}, [context]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Context is always a new object and will trigger the useCallback continuously. Let's spread it. The rest looks cool.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this hook doesn't need to know what is in the context - only tests need to know what properties there are if they need some additional data for validation.
If we add some property in our component, but forget to add it to dependencies here it could cause a bug, so I'll just remove useCallback

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should have written more clearly, I meant [...context]. All context data will be cached as soon as all responses are retrieved (for example for the linkingRules).

@BogdanDenis BogdanDenis force-pushed the poc-improve-validation branch from 51a4b01 to cb4fc25 Compare December 13, 2023 10:47
@BogdanDenis BogdanDenis requested review from Dmytro-Melnyshyn and a team December 13, 2023 10:47
@BogdanDenis BogdanDenis marked this pull request as ready for review December 13, 2023 10:48
@BogdanDenis BogdanDenis changed the title WIP: Rework quickMARC records validation Rework quickMARC records validation Dec 13, 2023
@BogdanDenis BogdanDenis force-pushed the poc-improve-validation branch from cb4fc25 to 85f5600 Compare December 13, 2023 11:23
@BogdanDenis BogdanDenis force-pushed the poc-improve-validation branch from 85f5600 to c556940 Compare December 13, 2023 11:28
return undefined;
}, [initialValues, locations, marcType, linkableBibFields, linkingRules, prepareForSubmit]);
return validate(formValuesForValidation.records);
}, [validate, prepareForSubmit]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

validate function is not cached

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not cached, but we need to include it in dependencies - if context values change but we don't have it here, then validation will be performed with old values

});

it('should not return an error for a not linkable field', () => {
const record = cloneDeep(initialValues);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove variables that are never used.

expect(utils.validateLocationSubfield({}, locations)).toBe(false);
});
});

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove eslint warnings.

TAG_LENGTH,
} from '../../QuickMarcEditor/constants';

const uncontrolledSubfieldGroups = ['uncontrolledAlpha', 'uncontrolledNumber'];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use the UNCONTROLLED_SUBFIELDS constant.

@BogdanDenis BogdanDenis force-pushed the poc-improve-validation branch from 91d63d9 to 6880cfe Compare December 14, 2023 10:37
Copy link

@Dmytro-Melnyshyn Dmytro-Melnyshyn merged commit 1b07a49 into master Dec 18, 2023
4 checks passed
@Dmytro-Melnyshyn Dmytro-Melnyshyn deleted the poc-improve-validation branch December 18, 2023 09:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants