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

Account for localization.isrequired with field.isRequired #4721

Draft
wants to merge 2 commits into
base: production
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -342,7 +342,7 @@ export class BusinessRuleManager<SCHEMA extends AnySchema> {
return true;
if (
field !== undefined &&
!(field.isRequired || field.localization.isrequired) &&
!field.isRequired &&
(value === undefined || value === null)
) {
return false;
Expand Down
Expand Up @@ -131,19 +131,19 @@ export abstract class FieldBase {
this.isReadOnly =
globalFieldOverride === 'readOnly' || fieldDefinition.readOnly === true;

this.localization =
Copy link
Member

@maxpatiiuk maxpatiiuk Apr 3, 2024

Choose a reason for hiding this comment

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

could you please add the test case that ensures schema config setting impacts the isRequired prop?

describe('isRequired', () => {
test('not-required field', () =>
expect(tables.CollectionObject.getField('catalogNumber')?.isRequired).toBe(
false
));
test('field required by schema', () =>
expect(tables.Accession.getField('accessionNumber')?.isRequired).toBe(
true
));
test('field required by front-end override', () =>
expect(tables.Taxon.getField('parent')?.isRequired).toBe(true));
test('field made optional by front-end override', () =>
expect(tables.Attachment.getField('tableID')?.isRequired).toBe(false));
});

this.table.localization.items[this.name.toLowerCase()] ?? {};

this.isRequired =
globalFieldOverride === 'required'
? true
: globalFieldOverride === 'optional'
? false
: fieldDefinition.required;
: fieldDefinition.required || (this.localization?.isrequired ?? false);
this.type = fieldDefinition.type;
this.length = fieldDefinition.length;
this.databaseColumn = fieldDefinition.column;

this.localization =
this.table.localization.items[this.name.toLowerCase()] ?? {};

this.label =
typeof this.localization.name === 'string' &&
this.localization.name.length > 0
Expand Down