OpnForm icon indicating copy to clipboard operation
OpnForm copied to clipboard

Partial submissions

Open chiragchhatrala opened this issue 11 months ago • 3 comments

Summary by CodeRabbit

  • New Features

    • Introduced support for partial form submissions, allowing users to save incomplete forms and resume later.
    • Added a new toggle in form settings to enable/disable partial submissions.
    • Enhanced submission interfaces with a new status column and filtering options for “In Progress” versus “Submitted” entries.
    • Updated form statistics to display data on partial submissions for improved engagement insights.
    • Implemented a new composable function for managing synchronization of partial submissions to the server.
    • Added a dropdown for filtering form submissions based on their status.
    • Integrated partial submission handling in the form submission logic and user interface components.
    • Enhanced the form submission settings with a new toggle switch for capturing partial submissions.
    • Introduced a new method for handling submission hashes to support partial submissions.
  • Bug Fixes

    • Improved validation logic to bypass rules for partial submissions.
  • Documentation

    • Updated help text for the partial submissions toggle to clarify its purpose.

chiragchhatrala avatar Feb 20 '25 04:02 chiragchhatrala

Walkthrough

This pull request introduces functionality for handling partial form submissions. Backend components, including controllers, jobs, models, requests, and database migrations, are updated to differentiate between complete and partial submissions. Validation rules are adjusted to bypass validation for partial submissions, and new status constants are added. Frontend components integrate logic for managing and synchronizing partial submission data, including UI elements for toggling and filtering partial submissions. A new composable manages debounced synchronization of partial data to the server. Overall, the changes improve the tracking, validation, storage, and presentation of forms with partial data, ensuring partial submissions are processed and displayed appropriately.

Changes

File(s) Change Summary
api/app/Http/Controllers/Forms/FormStatsController.php Added partial_submissions to stats; updated logic to count only completed submissions and track partial ones separately.
api/app/Http/Controllers/Forms/PublicFormController.php Added private methods to handle partial submissions and process submission identifiers; updated answer method to support partial submissions and submission hashes.
api/app/Http/Requests/AnswerFormRequest.php
api/app/Http/Requests/UserFormRequest.php
Skipped validation rules for partial submissions in AnswerFormRequest; added boolean validation for enable_partial_submissions in UserFormRequest.
api/app/Http/Resources/FormSubmissionResource.php Included status field in resource output when accessed non-publicly.
api/app/Jobs/Form/StoreFormSubmissionJob.php Changed submissionId type to int; added properties for completionTime and isPartial; extracted metadata from submission data; updated event dispatching to exclude partial submissions; refined submission storing logic to handle status.
api/app/Models/Forms/Form.php
api/app/Models/Forms/FormSubmission.php
Added enable_partial_submissions attribute with boolean cast in Form; added STATUS_PARTIAL and STATUS_COMPLETED constants and status fillable in FormSubmission; updated submission count to consider only completed submissions.
api/database/migrations/2025_02_14_073642_add_partial_submissions_to_form_submissions.php Added status enum column to form_submissions (default STATUS_COMPLETED) and enable_partial_submissions boolean column to forms.
client/components/open/forms/OpenCompleteForm.vue
client/components/open/forms/OpenForm.vue
Imported and integrated usePartialSubmission composable; added reactive properties and watchers to manage partial submission synchronization and submission hashes; refactored payment and submission flow in OpenForm.vue.
client/components/open/forms/components/FormStats.vue
client/components/open/forms/components/FormSubmissions.vue
client/components/open/forms/components/form-components/FormSubmissionSettings.vue
client/components/open/tables/OpenTable.vue
Updated UI to conditionally display partial submissions dataset; added dropdown filter for submission status; added toggle switch for enabling partial submissions with Pro tag; added "Status" column with badges in tables.
client/composables/forms/pendingSubmission.js
client/composables/forms/usePartialSubmission.js
Added setSubmissionHash and getSubmissionHash functions and exposed formPendingSubmissionKey; introduced usePartialSubmission composable to handle debounced partial submission sync with server and event listeners.
api/app/Service/Forms/FormCleaner.php Added default setting and cleaning message for enable_partial_submissions.
api/app/Http/Controllers/Forms/FormSubmissionController.php Updated update method to pass submission_id within submission data to StoreFormSubmissionJob and removed separate setSubmissionId call.
api/app/Service/Forms/FormLogicConditionChecker.php Excluded partial submissions from existence checks in previous submissions by filtering out STATUS_PARTIAL.
api/tests/Feature/Submissions/PartialSubmissionTest.php Added comprehensive tests covering partial submission creation, updating, completing, file handling, validation, and behavior when partial submissions are disabled or user is non-pro.
client/pages/settings/connections/callback/[service].vue Removed debug console.log statements related to autoClose flag handling in callback logic.

Possibly related PRs

  • JhumanJ/OpnForm#567: The changes in the main PR are related to those in the retrieved PR as both modify the getFormStats method in the FormStatsController class, with the main PR adding functionality for tracking partial submissions while the retrieved PR enhances input validation and reporting capabilities.

Suggested reviewers

  • chiragchhatrala

🐇 In fields of forms, we hop and play,
With partial submissions here to stay.
A toggle to catch those bits we miss,
In every hop, a little bliss!
So let’s embrace this change with cheer,
For every submission, we hold dear! 🐇


📜 Recent review details

Configuration used: CodeRabbit UI Review profile: CHILL Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6e6add3a4a7888297001bc13fc92dfeb8b178bd6 and cb49d0f604ed186be50189d7cc11355d40b7d5c5.

📒 Files selected for processing (7)
  • api/app/Http/Requests/UserFormRequest.php (1 hunks)
  • api/app/Models/Forms/Form.php (3 hunks)
  • api/app/Service/Forms/FormLogicConditionChecker.php (1 hunks)
  • client/components/open/forms/OpenForm.vue (7 hunks)
  • client/components/open/forms/components/form-components/FormSubmissionSettings.vue (2 hunks)
  • client/components/open/tables/OpenTable.vue (3 hunks)
  • client/pages/settings/connections/callback/[service].vue (0 hunks)
💤 Files with no reviewable changes (1)
  • client/pages/settings/connections/callback/[service].vue
🚧 Files skipped from review as they are similar to previous changes (5)
  • api/app/Http/Requests/UserFormRequest.php
  • api/app/Service/Forms/FormLogicConditionChecker.php
  • api/app/Models/Forms/Form.php
  • client/components/open/forms/components/form-components/FormSubmissionSettings.vue
  • client/components/open/tables/OpenTable.vue
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Build the Nuxt app
🔇 Additional comments (6)
client/components/open/forms/OpenForm.vue (6)

126-127: Good addition of partial submission functionality.

The imports for pendingSubmission and usePartialSubmission composables support the new partial form submission functionality described in the PR objectives.


195-195: Well-implemented client-side check for partial submission.

The implementation correctly uses import.meta.client to ensure server-side rendering compatibility, with appropriate fallback methods when running on the server.


208-208: Good tracking of partial submission state.

Adding the partialSubmissionStarted flag helps track the state of partial submission synchronization.


411-413: Improved payment flow management.

Calling doPayment first and returning early if it fails is a good pattern that simplifies the control flow. This also addresses one of the PR objectives related to improving the submission process.


425-428: Good implementation of partial submission hash.

The code correctly adds the submission hash from the partial submission to the form data when submissions are enabled, which addresses the PR objective of fixing duplicate submissions.


683-684: Improved payment processing busy state.

Setting the form as busy at the start of payment processing ensures the UI correctly reflects that an operation is in progress.

✨ Finishing Touches
  • [ ] 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

coderabbitai[bot] avatar Feb 20 '25 04:02 coderabbitai[bot]

  • When auto save enabled issue: when refreshing the page and finally submitting, a new record is creating instead of finalizing the pending one (creating duplicates) CleanShot 2025-03-06 at 12 39 35@2x
  • if I click fill again, then a pending submission is instantly created even though form is still empty CleanShot 2025-03-06 at 12 42 43@2x
  • still. may issues with signatures and files please check again

Done

chiragchhatrala avatar Mar 10 '25 08:03 chiragchhatrala

Great progress.

Please add some tests. Examples:

  • Test Edge Cases: Ensure automated tests cover scenarios like:
  • Submitting partially, then completing using the returned hash.
  • Submitting partially multiple times for the same submission.
  • Attempting partial submission when the feature is disabled for the form.
  • Correct stats calculation for partial vs. completed submissions.
  • File/signature handling during partial saves.

Check database feature clash Also there's a feature clash with "does not exist in submission" or "exisits in submisison". we when checking for these, we need to filter out pending submission otherwise pending submission conflicts with itself.

Done

chiragchhatrala avatar Apr 07 '25 04:04 chiragchhatrala