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

Conversation

melton-jason
Copy link
Contributor

Fixes #4720

Currently the field.localization.isrequired is not present in field.isRequired. The fieldDefinition only contains information from the specify_datamodel.xml (https://files.specifysoftware.org/schema/version/2.10/), and does not contain any information on the splocalecontaineritem which represents the disclipline's configuration for the field.

Consider the two CollectionObject fields uniqueIdentifier and totalValue. In the currently logged in discipline, totalValue is marked as required and uniqueIdentifier is not required.

The following code is added to the constructor of FieldBase

if (
      table.name === 'CollectionObject' &&
      ['totalvalue', 'uniqueidentifier'].includes(
        fieldDefinition.name.toLowerCase()
      )
    )
      console.log(
        table.name,
        fieldDefinition.name,
        table.localization.items[fieldDefinition.name.toLowerCase()]
          ?.isrequired,
        fieldDefinition.required,
        this.isRequired
      );

which outputs:

Screenshot 2024-04-01 at 9 22 48 AM I agree it would make sense to include the `field.localization.isrequired` with the `field.isRequired`.

#4703 (comment)

Checklist

  • Self-review the PR after opening it to make sure the changes look good
    and self-explanatory (or properly documented)
  • Add automated tests
  • Add relevant issue to release milestone

Testing instructions

Copy link
Member

@maxpatiiuk maxpatiiuk left a comment

Choose a reason for hiding this comment

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

need a test as this is a critical file
otherwise, all good

@@ -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));
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 📋Back Log
Development

Successfully merging this pull request may close these issues.

Schemaconfig isRequired not being respected to field.isRequired
3 participants