Skip to content

Conversation

@melton-jason
Copy link
Contributor

@melton-jason melton-jason commented Dec 3, 2024

Fixes #5232, #5233
See #5234

⚠️ Note: This PR affects database migrations. See migration testing instructions.

Aside from implementing #5232 and #5233, there are some other improvements in this PR!

Schema Config

  • When selecting a Field Format in the Schema Configuration tool, Specify now groups field formatters for the field they selected (Field Formats that explicitly reference the field in fieldName=fieldname) above the rest
Screenshot 2024-12-03 at 3 08 19 PM

Migrations
There were some bugs in other migrations which used the functions defined in specifyweb/specify/update_schema_config.py. These bugs have been fixed in this PR, and a migration has been written to fix these bugs for databases already affected: specify/0017_schemaconfig_fixes.py

UIFormatter picklists for Collection -> catalogNumFormatName and CollectionObjectType -> catalogNumberFormatName

  • Everywhere in the application*, these fields will now appear as a picklist whose items are the names of CO -> catalogNumber Field Formatters
Screenshot 2024-12-03 at 3 21 02 PM

*on the DataEntry Form, they will only appear as a PickList if uitype="combobox" is used on the form definition

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

  • Define a Field Format for Collection Object -> catalogNumber which is different than the current Collection -> Catalog Num Format Name
    • An example field format called Rocks is provided below:
<format system="false" name="Rocks" class="edu.ku.brc.specify.datamodel.CollectionObject" fieldname="catalogNumber" default="false">
	<autonumber>edu.ku.brc.af.core.db.AutoNumberGeneric</autonumber>
	<field type="constant" size="4" value="ROCK"/>
	<field type="separator" size="1" value="-"/>
	<field type="numeric" size="6" inc="true"/>
</format>
  • Go to the Data Entry form to create a new Collection Object Type
  • Ensure the Catalog Number Format Name picklist shows all Catalog Number Field Formats
  • Save the Collection Object Type with a Catalog Number Format Name that is different than the Collection -> catalogNumFormatName
  • Make sure collectionObjectType is on the Collection Object form
  • Go to the Data Entry form to create a new Collection Object
  • Change the Collection Object Type of the Collection Object to be that which you previously saved
  • Ensure the Catalog Number of the Collection Object is replaced with the pattern of the new
  • (If needed) Modify the Catalog Number so that it matches the format of formatter
  • Save the Collection Object with the new format

@melton-jason melton-jason changed the title Allow CollectionObjects to be autonumbered by CollectionObjectType Allow catalogNumber format to be determined by CollectionObjectType Dec 3, 2024
@melton-jason melton-jason requested review from a team December 4, 2024 16:15
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 instructions

  • Define a Field Format for Collection Object -> catalogNumber which is different than the current Collection -> Catalog Num Format Name
    • An example field format called Rocks is provided below:
  • Go to the Data Entry form to create a new Collection Object Type
  • Ensure the Catalog Number Format Name picklist shows all Catalog Number Field Formats
  • Save the Collection Object Type with a Catalog Number Format Name that is different than the Collection -> catalogNumFormatName
  • Make sure collectionObjectType is on the Collection Object form
  • Go to the Data Entry form to create a new Collection Object
  • Change the Collection Object Type of the Collection Object to be that which you previously saved
  • Ensure the Catalog Number of the Collection Object is replaced with the pattern of the new
  • (If needed) Modify the Catalog Number so that it matches the format of formatter
  • Save the Collection Object with the new format

Functionality wise it seems to be working 👍👍

On the CO form it looks like the form needs an extra update in order to be okay with the new format.
Clicking the save button twice does the trick, or typing in the new catalog number manually.

chrome_9hLjzWdtpV.mp4

The issue also persists if you switch to a different CO of a different type in the same tab.

@alesan99 alesan99 requested a review from a team December 5, 2024 15:50
@CarolineDenis
Copy link
Contributor

@alesan99
for

On the CO form it looks like the form needs an extra update in order to be okay with the new format.
Clicking the save button twice does the trick, or typing in the new catalog number manually.

That is good for this pr 👍

@alesan99 alesan99 requested a review from a team December 5, 2024 16:14
@grantfitzsimmons grantfitzsimmons self-requested a review December 5, 2024 16:21
Copy link

@bronwyncombs bronwyncombs left a comment

Choose a reason for hiding this comment

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

  • Define a Field Format for Collection Object -> catalogNumber which is different than the current Collection -> Catalog Num Format Name
    • An example field format called Rocks is provided below:
  • Go to the Data Entry form to create a new Collection Object Type
  • Ensure the Catalog Number Format Name picklist shows all Catalog Number Field Formats
  • Save the Collection Object Type with a Catalog Number Format Name that is different than the Collection -> catalogNumFormatName
  • Make sure collectionObjectType is on the Collection Object form
  • Go to the Data Entry form to create a new Collection Object
  • Change the Collection Object Type of the Collection Object to be that which you previously saved
  • ** Ensure the Catalog Number of the Collection Object is replaced with the pattern of the new
  • (If needed) Modify the Catalog Number so that it matches the format of formatter
  • Save the Collection Object with the new format

Catalog Number Format Name list appears correctly on COT form and in schema config. COT pick list on CO also displays correctly. Format switch in field functions normally other than needing to click elsewhere on the form to dismiss initial save block.

** I noticed that the CO form header, that displays the catalog number format before a catalog number is saved to the form, does not reflect the format chosen with the COT picklist. If there are two COTs available, this header is consistently opposite of the one on the form.

Screen.Recording.2024-12-05.at.12.52.05.PM.mov

I also saw this on the catalog number field after saving:
Screenshot 2024-12-05 at 1 06 31 PM

Copy link
Collaborator

@combs-a combs-a left a comment

Choose a reason for hiding this comment

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

Testing instructions

  • Define a Field Format for Collection Object -> catalogNumber which is different than the current Collection -> Catalog Num Format Name
    • An example field format called Rocks is provided below:
  • Go to the Data Entry form to create a new Collection Object Type
  • Ensure the Catalog Number Format Name picklist shows all Catalog Number Field Formats
  • Save the Collection Object Type with a Catalog Number Format Name that is different than the Collection -> catalogNumFormatName
  • Make sure collectionObjectType is on the Collection Object form
  • Go to the Data Entry form to create a new Collection Object
  • Change the Collection Object Type of the Collection Object to be that which you previously saved
  • Ensure the Catalog Number of the Collection Object is replaced with the pattern of the new
  • (If needed) Modify the Catalog Number so that it matches the format of formatter
  • Save the Collection Object with the new format

Had a brief strange thing happen where it wasn't switching the format, but seems to have fixed itself on a reload (without clearing cache) so probably okay. Same thing as Alejandro where there's a save blocker incorrectly placed, but clicking anywhere on the form and not just the save blocker clears it.

I didn't run into Bronwyn's second issue, but I did see the same thing with the header. I do remember there being issues with the header update being a bit slow so maybe it's something like that. Will this be addressed in this PR?

Good work Jason! Everything looks good besides the small header thing. 🎉

@CarolineDenis
Copy link
Contributor

CarolineDenis commented Dec 5, 2024

@emenslin

Will this be addressed in this PR?

No it will not addressed in this pr if present in prod. Could you create an issue for it?

@CarolineDenis CarolineDenis requested a review from combs-a December 5, 2024 20:17
@melton-jason
Copy link
Contributor Author

melton-jason commented Dec 5, 2024

There may be some other bugs at play here, but at least there is an Issue already about the header being 'slow' to update: #3579.
Although it can probably be renamed, as it's not just contained to Tree forms 😅

The save blocker you briefly see after changing the CollectionObjectType is because everything is happening in the order:

  1. The parser changes for the field when the COT changes
  2. Specify checks if the current value of the field matches that of the new formatter
  3. It (often) doesn't match the formatter, so Specify sets a save blocker on the field
  4. Specify then sets the value of the field to be the pattern of the new formatter
  5. Specify only updates the save blocker when the field gains and then loses focus

We need to conceptually swap steps 3 and 4, but I have not thought of an easy way to accomplish this in the code.
@specify/developers, let me know if you can think of a way to accomplish this! The relevant sections of the code are1234

Footnotes

  1. https://github.com/specify/specify7/blob/3618ba19eb208a3f8357beec275cc50deefa8042/specifyweb/frontend/js_src/lib/hooks/useResourceValue.tsx#L65

  2. https://github.com/specify/specify7/blob/3618ba19eb208a3f8357beec275cc50deefa8042/specifyweb/frontend/js_src/lib/hooks/resource.tsx#L132-L148

  3. https://github.com/specify/specify7/blob/3618ba19eb208a3f8357beec275cc50deefa8042/specifyweb/frontend/js_src/lib/hooks/useResourceValue.tsx#L116-L144

  4. https://github.com/specify/specify7/blob/3618ba19eb208a3f8357beec275cc50deefa8042/specifyweb/frontend/js_src/lib/hooks/useResourceValue.tsx#L194-L231

combs-a
combs-a previously approved these changes Dec 5, 2024
Copy link
Collaborator

@combs-a combs-a left a comment

Choose a reason for hiding this comment

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

~~See above comments for approval reason; header lag is the separate issue that Jason linked 👍 ~~

Misread something along the way and thought that the save blocker bit was about the header lag, so I dismissed my review just in case we're going to address that save blocker issue here. If not, then I'll approve it. 🫡

@combs-a combs-a dismissed their stale review December 5, 2024 21:46

Misread comments, need to wait on dev comment to fully approve since it is an issue with the PR

@CarolineDenis CarolineDenis requested a review from combs-a December 6, 2024 14:11
@CarolineDenis CarolineDenis merged commit 18f5c15 into production Dec 10, 2024
12 checks passed
@CarolineDenis CarolineDenis deleted the issue-5232 branch December 10, 2024 17:03
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.

Implement Catalog Numbering Configurations Based on COT

7 participants