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

MOTs business logic: Clear CO form when CO Type changes #5100

Merged
merged 18 commits into from
Aug 1, 2024

Conversation

sharadsw
Copy link
Contributor

@sharadsw sharadsw commented Jul 15, 2024

Fixes #5088

Using business rules to clear CO values when COType changes. Needs #5098 to be fixed to test with configuring a pick list in Schema Config. Until then, it can be tested with CoType as a QCBX.

The following fields are ignored when clearing for better UX or based on backend restrictions (for eg: backend needs a non-null value for version)

const fieldsToIgnore = [
'cataloger',
'catalogNumber',
'collection',
'collectionObjectType',
'version',
];

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

Set up a QCBX for CollectionObjectType (like in #5127):

Ideally, COType would be set as a picklist. However, until #5098 is fixed, it is not possible to configure one for COType. Instead for this PR, COType can be set up as a QCBX.

  • Go to App Resources > Type Searches (found under Global Resources)
  • Add the following line in the XML editor:
<typesearch tableid="1015"  name="CollectionObjectType" searchfield="name" displaycols="name" format="%s" uifieldformatter="" dataobjformatter="" system="true"/>
  • Click on the Form Definition tab
  • Select the correct .views file for the collection you are in
  • Go the the Collection Object form definition
  • Add the following lines inside an existing <row>:
<cell type="label" labelfor="111"/>
<cell type="field" id="111" name="collectionObjectType" uitype="querycbx" />

Your CO form should look something like this
image

Testing the PR

  • Go to Data Entry -> Collection Object
  • Enter some determinations
  • Enter data in different basic fields (text/number fields)
  • Change CollectionObjectType value
  • Verify all simple fields are cleared
  • Verify any added determinations are deleted
  • Re-run the test for an already existing Collection Object

@sharadsw sharadsw added this to the 7.9.7 milestone Jul 15, 2024
@CarolineDenis
Copy link
Contributor

TODO:

  • Refresh after type change when form is already saved

@sharadsw sharadsw changed the title MOTs business logic: Refresh CO form when CO Type changes MOTs business logic: Clear CO form when CO Type changes Jul 16, 2024
Copy link
Contributor

@melton-jason melton-jason left a comment

Choose a reason for hiding this comment

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

Are we clearing all fields on the CollectionObject?

What I gathered from #4640 (comment) is that only the CollectionObjectAttribute fields should be cleared.
Other fields on CollectionObject can remain untouched.
Is this misunderstanding the requirements, or have the requirements changed?

(If we go with a businessrule approach for determing the Taxon tree to search on for the Determination -> QueryComboBox and the current implementation style of #5127, then Determinations should be cleared as well).

@sharadsw
Copy link
Contributor Author

Hmm, looks like #4640 mentions only clearing determinations and collectionObjectAttribute fields - which would make this a lot simpler. However, I think we discussed in a meeting that we should clear all fields as we don't know what fields are gonna be conditionally rendered - which should handle all possibilities.

Thoughts on this? @grantfitzsimmons

@CarolineDenis
Copy link
Contributor

@sharadsw

However, I think we discussed in a meeting that we should clear all fields as we don't know what fields are gonna be conditionally rendered - which should handle all possibilities.

Yes that is correct

@grantfitzsimmons
Copy link
Member

@sharadsw The decision for now is to clear everything– I just spoke with Aimee and it seems like the simplest solution for the MVP.

I feel that we should only clear fields not visible on the form (in case of conditionals) and the determination, but maybe that is something we revisit later.

@sharadsw
Copy link
Contributor Author

Trying to clear all to-many dependent fields with the simple resource.set(fieldName, []) results in an infinite loop. So the only other way to clear to-many fields is to individually remove every record of each to-many relation in the CO form - which could theoretically be an expensive/slow operation for large data.

Right now this PR will clear all simple fields and independent relations and also delete all determinations added in the CO form whenever CollectionObjectType changes. Does this sound good? @grantfitzsimmons

@sharadsw sharadsw marked this pull request as ready for review July 30, 2024 18:20
@sharadsw sharadsw requested a review from a team July 30, 2024 18:31
Copy link
Collaborator

@emenslin emenslin left a comment

Choose a reason for hiding this comment

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

Testing the PR

  • Go to Data Entry -> Collection Object
  • Enter some determinations
  • Enter data in different basic fields (text/number fields)
  • Change CollectionObjectType value
  • Verify all simple fields are cleared
  • Verify any added determinations are deleted
  • Re-run the test for an already existing Collection Object

Looks good, all fields expected to clear were cleared

@emenslin emenslin requested a review from a team July 31, 2024 15:55
@grantfitzsimmons
Copy link
Member

Trying to clear all to-many dependent fields with the simple resource.set(fieldName, []) results in an infinite loop. So the only other way to clear to-many fields is to individually remove every record of each to-many relation in the CO form - which could theoretically be an expensive/slow operation for large data.

Right now this PR will clear all simple fields and independent relations and also delete all determinations added in the CO form whenever CollectionObjectType changes. Does this sound good? @grantfitzsimmons

That sounds good to me.

Copy link
Contributor

@alesan99 alesan99 left a comment

Choose a reason for hiding this comment

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

Testing the PR

  • Go to Data Entry -> Collection Object
  • Enter some determinations
  • Enter data in different basic fields (text/number fields)
  • Change CollectionObjectType value
  • Verify all simple fields are cleared
  • Verify any added determinations are deleted
  • Re-run the test for an already existing Collection Object

All fields I tried were cleared 👍👍👍

chrome_uq7cIGOCjt.mp4

Copy link

@Areyes42 Areyes42 left a comment

Choose a reason for hiding this comment

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

Testing the PR

  • Go to Data Entry -> Collection Object
  • Enter some determinations
  • Enter data in different basic fields (text/number fields)
  • Change CollectionObjectType value
  • Verify all simple fields are cleared
  • Verify any added determinations are deleted
  • Re-run the test for an already existing Collection Object

Looks good, all fields cleared on new and pre-existing COs👌

Copy link
Contributor

@melton-jason melton-jason left a comment

Choose a reason for hiding this comment

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

This is fine given it is acceptable for the requirements and a temporary solution or fallback if a more robust solution can not be implemented by the deadline.

Not a fan of clearing all literal fields and some relationships here.
Either of the previously discussed solutions (only clearing fields used in a conditional panel or having separate view definitions based on CollectionObjectType) will be well worth the complexity, and far better from a resultant UX standpoint.

Complexity does take time, and that we don't have much of, so something is better than nothing.

Still, this is a fine start while we work out everything else for Geo.
Onto the next fish to fry! 👏

@sharadsw sharadsw changed the base branch from production to issue-5111 August 1, 2024 19:21
Base automatically changed from issue-5111 to production August 1, 2024 22:05
@sharadsw sharadsw merged commit 84642bc into production Aug 1, 2024
9 checks passed
@sharadsw sharadsw deleted the issue-5088b branch August 1, 2024 22:05
@specifysoftware
Copy link

This pull request has been mentioned on Specify Community Forum. There might be relevant details there:

https://discourse.specifysoftware.org/t/specify-7-9-7-release-announcement/1979/1

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

Successfully merging this pull request may close these issues.

MOTs business logic: Refresh CO form when CO Type changes
8 participants