Skip to content

feat(FormBuilder): morph action button label with TextMorph#118

Merged
harshtandiya merged 4 commits into
developfrom
feat/torph
May 1, 2026
Merged

feat(FormBuilder): morph action button label with TextMorph#118
harshtandiya merged 4 commits into
developfrom
feat/torph

Conversation

@harshtandiya

@harshtandiya harshtandiya commented May 1, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Adds torph dep and integrates TextMorph for animated action button label transitions
  • Fixes button label flickering through incorrect intermediate states on click (root cause: frappe-ui's setValue.submit mutates doc optimistically before originalDoc syncs, causing a brief isDirty=true window that triggers extra reactive renders)
  • Exposes isSaving from the edit form store and makes togglePublish return a promise so consumers can await settled state

How the fix works

On click, the button config is snapshotted before the handler mutates doc state. The snapshot is held until the setValue.submit promise resolves and Vue's deep isDirty watcher has had a tick to settle — then the live config takes over. Double-clicks are ignored while frozen.

Test plan

  • Click Save — label stays "Save" until save completes, then shows "Publish"
  • Click Publish — label stays "Publish" until complete, then shows "Unpublish"
  • Click Unpublish — label stays "Unpublish" until complete, then shows "Publish"
  • Click Save and publish — label stays "Save and publish" until complete, then shows "Unpublish"
  • Save with duplicate fieldnames — dialog appears, label unchanged after dismiss
  • Network error on publish — toast fires, label returns to pre-click state

Summary by CodeRabbit

Bug Fixes

  • Enhanced form save and publish state management to prevent action conflicts and improve overall reliability during form submission operations
  • Improved form header layout with refined tooltip interactions providing clearer visual feedback and guidance to users
  • Optimized form loading state tracking for more accurate representation of background save and publish operations

…lish

Consumers need to await the publish toggle to freeze UI state
until the server response settles. isSaving surfaces setValue.loading
so components don't reach into formResource internals.
frappe-ui's setValue.submit mutates doc optimistically, making
isDirty briefly true before originalDoc syncs — causing two reactive
renders and two TextMorph transitions per click. Freeze the button
config on click and release only after the settled state is stable.

Also integrates TextMorph for animated label transitions and fixes
the :loading binding to reflect setValue state (not just fetch state).
@coderabbitai

coderabbitai Bot commented May 1, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@harshtandiya has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 50 minutes and 54 seconds before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9c86896c-f10a-4ff0-a41e-daf023f797af

📥 Commits

Reviewing files that changed from the base of the PR and between 201d202 and 2306af1.

📒 Files selected for processing (1)
  • frontend/src/components/FormBuilderHeader.vue
📝 Walkthrough

Walkthrough

Frontend dependency management updated with addition of torph. FormBuilderHeader component refactored to use configuration-driven action button logic with a frozen config mechanism for capturing state at click time. editForm store enhanced with new isSaving computed property and improved togglePublish handler.

Changes

Cohort / File(s) Summary
Dependency Management
frontend/package.json
Added torph@^0.0.9 to dependencies.
Store State & Actions
frontend/src/stores/editForm.ts
Introduced isSaving computed flag derived from setValue.loading. Refactored togglePublish to return early when doc is absent. Restructured setValue.submit invocation with separate payload and callback arguments.
Component Header Logic
frontend/src/components/FormBuilderHeader.vue
Consolidated header action button into configuration-driven flow via new computeConfig() method. Added frozenConfig mechanism to capture action configuration at click time and prevent state changes from affecting in-flight actions. Updated loading control from editFormStore.formResource?.loading to editFormStore.isSaving || editFormStore.isLoading. Switched button label rendering to TextMorph component. Updated route resolution with constant name and regex-based path parameter replacement. Simplified tooltip conditional logic and adjusted header layout by removing transition classes and adding m-auto centering.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 A button that knows what to do,
Frozen in time, tried and true,
With isSaving flags held tight,
State captured just right—
Our form header hops through the night! 🌙✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately reflects the main change: integrating TextMorph for animating the action button label, which is the primary visible feature of this PR.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed The PR description is comprehensive and covers all required template sections with detailed technical context.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/torph

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
Review rate limit: 0/1 reviews remaining, refill in 50 minutes and 54 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@frontend/src/stores/editForm.ts`:
- Around line 172-186: Compute the intended new publish state before calling
formResource.value.setValue.submit (e.g. const newIsPublished =
!formResource.value.doc.is_published) and use that flag in both onSuccess and
onError handlers instead of reading formResource.value.doc inside those
callbacks; update the success toast to show "Form published successfully" or
"Form unpublished successfully" based on newIsPublished and update the error
toast to "Failed to publish form" or "Failed to unpublish form" accordingly
(refer to setValue.submit and formResource.value.doc.is_published to locate the
code).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 32f67d7f-b06c-46d3-81be-a5bb3a5a9ab8

📥 Commits

Reviewing files that changed from the base of the PR and between 638777b and 201d202.

⛔ Files ignored due to path filters (1)
  • frontend/yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (3)
  • frontend/package.json
  • frontend/src/components/FormBuilderHeader.vue
  • frontend/src/stores/editForm.ts

Comment on lines +172 to +186
return formResource.value.setValue.submit(
{
is_published: !formResource.value.doc.is_published,
},
{
onSuccess: () => {
if (formResource.value.doc.is_published) {
toast.success("Form published successfully");
} else {
toast.info("Form unpublished successfully");
}
},
{
onSuccess: () => {
if (formResource.value.doc.is_published) {
toast.success("Form published successfully");
} else {
toast.info("Form unpublished successfully");
}
},
onError: () => {
toast.error("Failed to publish form");
},
}
);
}
onError: () => {
toast.error("Failed to publish form");
},

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Use action-specific failure text in togglePublish.

On Line 185, the error toast always says “Failed to publish form”, even when the attempted action was unpublish.

Suggested fix
 function togglePublish() {
   if (!formResource.value?.doc) return Promise.resolve();
+  const willPublish = !formResource.value.doc.is_published;
   return formResource.value.setValue.submit(
     {
-      is_published: !formResource.value.doc.is_published,
+      is_published: willPublish,
     },
     {
       onSuccess: () => {
-        if (formResource.value.doc.is_published) {
+        if (willPublish) {
           toast.success("Form published successfully");
         } else {
           toast.info("Form unpublished successfully");
         }
       },
       onError: () => {
-        toast.error("Failed to publish form");
+        toast.error(
+          willPublish ? "Failed to publish form" : "Failed to unpublish form"
+        );
       },
     }
   );
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
return formResource.value.setValue.submit(
{
is_published: !formResource.value.doc.is_published,
},
{
onSuccess: () => {
if (formResource.value.doc.is_published) {
toast.success("Form published successfully");
} else {
toast.info("Form unpublished successfully");
}
},
{
onSuccess: () => {
if (formResource.value.doc.is_published) {
toast.success("Form published successfully");
} else {
toast.info("Form unpublished successfully");
}
},
onError: () => {
toast.error("Failed to publish form");
},
}
);
}
onError: () => {
toast.error("Failed to publish form");
},
function togglePublish() {
if (!formResource.value?.doc) return Promise.resolve();
const willPublish = !formResource.value.doc.is_published;
return formResource.value.setValue.submit(
{
is_published: willPublish,
},
{
onSuccess: () => {
if (willPublish) {
toast.success("Form published successfully");
} else {
toast.info("Form unpublished successfully");
}
},
onError: () => {
toast.error(
willPublish ? "Failed to publish form" : "Failed to unpublish form"
);
},
}
);
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@frontend/src/stores/editForm.ts` around lines 172 - 186, Compute the intended
new publish state before calling formResource.value.setValue.submit (e.g. const
newIsPublished = !formResource.value.doc.is_published) and use that flag in both
onSuccess and onError handlers instead of reading formResource.value.doc inside
those callbacks; update the success toast to show "Form published successfully"
or "Form unpublished successfully" based on newIsPublished and update the error
toast to "Failed to publish form" or "Failed to unpublish form" accordingly
(refer to setValue.submit and formResource.value.doc.is_published to locate the
code).

…t compatibility

TextMorph keeps exiting chars in DOM during animation, so Playwright
resolves the button's accessible name as merged old+new text. aria-label
bypasses inner text entirely, giving tests a stable selector.
@harshtandiya harshtandiya merged commit fd7acea into develop May 1, 2026
7 checks passed
@harshtandiya harshtandiya deleted the feat/torph branch May 1, 2026 15:21
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.

1 participant