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

feat: implement specific API for duplicating form fields #1907

Merged
merged 30 commits into from
May 20, 2021

Conversation

chowyiyin
Copy link
Contributor

@chowyiyin chowyiyin commented May 17, 2021

Problem

This PR creates a new endpoint POST /api/v3/admin/forms/:formId/fields/:fieldId/duplicate and extracts the functionality to duplicate form fields from the existing endpoint PUT /:formId/adminform.

Closes #1483

Solution

  • admin-forms.form.routes.ts: Added new endpoint
  • admin-form.controller.ts: Added handleDuplicateFormField controller
  • admin-form.service.ts: Added duplicateFormField service
  • form-server-model.ts: Added duplicateFormFieldById
    • Duplication of the existing field is done here
  • UPDATE_FORM_TYPES: Added DuplicateField
  • admin-form.client.controller.js: Added another case for duplication to call new API and update view

Tests

Unit Tests

  • admin-form.controller.specs.ts: add unit tests handleDuplicateFormField
  • admin-form.service.specs.ts: add unit tests for duplicateFormField
  • admin-forms.form.routes.spec.ts: add unit tests forPOST /:formId/fields/:fieldId/duplicate
  • form.server.model.spec.ts: add unit tests for duplicateFormFieldById instance method

Manual Tests

  • Create random field in storage mode and duplicate it. Check that contents of field are duplicated correctly.
  • Create random field in email mode and duplicate it. Check that contents of field are duplicated correctly.
  • Create myinfo field (with dropdown options) and duplicate it. Check that duplicated field has the correct options and is also uneditable if it has a pre-filled value.

@chowyiyin chowyiyin marked this pull request as draft May 17, 2021 09:02
@chowyiyin chowyiyin changed the title Refactor/field duplication refactor/field duplication May 17, 2021
@chowyiyin chowyiyin changed the title refactor/field duplication refactor(field duplication) May 17, 2021
@chowyiyin chowyiyin marked this pull request as ready for review May 18, 2021 08:24
Copy link
Contributor

@seaerchin seaerchin left a comment

Choose a reason for hiding this comment

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

looks good! but add docs cos some stuff abit confusing

@mantariksh mantariksh requested a review from karrui May 19, 2021 02:44
Copy link
Contributor

@mantariksh mantariksh left a comment

Choose a reason for hiding this comment

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

lgtm, to test on staging before approval. also requesting @karrui and @tshuli to take another look if you have time!

@mantariksh mantariksh requested a review from tshuli May 19, 2021 02:45
Copy link
Contributor

@karrui karrui left a comment

Choose a reason for hiding this comment

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

lgtm after fixing typos

@karrui karrui changed the title refactor(field duplication) feat: implement specific API for duplication form fields May 19, 2021
@karrui karrui changed the title feat: implement specific API for duplication form fields feat: implement specific API for duplicating form fields May 19, 2021
@chowyiyin chowyiyin merged commit 62441f2 into develop May 20, 2021
@karrui karrui deleted the refactor/fieldDuplication branch August 17, 2021 02:45
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.

[API] Extract form field duplication endpoint from PUT /:formId/adminform
4 participants