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

✨ Add Duplicate Archetype action #1371

Merged
merged 3 commits into from
Sep 18, 2023
Merged

Conversation

mturley
Copy link
Collaborator

@mturley mturley commented Sep 15, 2023

Part of #1264, see checklist here.

The Duplicate action is a cross between create and edit: a "create new archetype" form is opened, but its fields are all prefilled as if we are editing an existing archetype. The prefilled name has an appended " (duplicate)" suffix on it.

Just for fun, in case a user duplicates the same archetype multiple times without touching the default name, we check to see if the new default name is taken and use " (duplicate N)" as the suffix, with N incrementing until we get a name that isn't taken. This is probably unnecessary, but I found it annoying that the "name must be unique" error didn't appear until I touched the field, so this makes sure that case never comes up.

Because ArchetypeForm already had the logic for prefilling the form for editing, all we needed to do was pass in an archetype and an isDuplicating boolean which slightly changes the behavior:

  • When validating that the name is unique, we don't treat the archetype being duplicated as the "current item", so it is not an exception to that validation like it needs to be when editing (if you input the same name of the item you're editing that's valid, but not so for duplicating).
  • We have the default name behavior with the suffix as described above.
  • Normally the submit button is disabled if the form isn't dirty, but the prefilled form with a generated name is valid for submission, so we allow a non-dirty form to be submitted when isDuplicating is true. This way you can rapid-fire duplicating things without touching the form if you so desire (useful for testing the pagination in ✨ Add client-side pagination to Archetypes table #1370 😄)
  • The submit button says "Create", and on submit we create instead of updating.

Signed-off-by: Mike Turley <mike.turley@alum.cs.umass.edu>
@mturley mturley changed the title ✨ Duplicate Archetype action ✨ Add Duplicate Archetype action Sep 15, 2023
Signed-off-by: Mike Turley <mike.turley@alum.cs.umass.edu>
@codecov
Copy link

codecov bot commented Sep 15, 2023

Codecov Report

Patch and project coverage have no change.

Comparison is base (a93733f) 41.43% compared to head (5f678ca) 41.43%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1371   +/-   ##
=======================================
  Coverage   41.43%   41.43%           
=======================================
  Files         137      137           
  Lines        4279     4279           
  Branches     1026     1026           
=======================================
  Hits         1773     1773           
  Misses       2418     2418           
  Partials       88       88           
Flag Coverage Δ
client 41.43% <ø> (ø)
server ∅ <ø> (∅)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@sjd78 sjd78 left a comment

Choose a reason for hiding this comment

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

LGTM.

The getDefaultName() function was a bit jarring but after reading it slowly makes sense.

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