Skip to content

refactor(portal-framework-ui): fix form autocomplete logic#477

Merged
pcfreak30 merged 1 commit intodevelopfrom
libs/portal-plugin-dashboard
Aug 30, 2025
Merged

refactor(portal-framework-ui): fix form autocomplete logic#477
pcfreak30 merged 1 commit intodevelopfrom
libs/portal-plugin-dashboard

Conversation

@pcfreak30
Copy link
Copy Markdown
Member

@pcfreak30 pcfreak30 commented Aug 30, 2025

  • Extracted autocomplete value calculation into separate utility function
  • Reordered imports and interface declarations
  • Simplified autocomplete prop passing in RegisteredComponent
  • Improved loading state styling with Tailwind classes
  • Added formConfig to FieldRenderer's context usage

Summary by CodeRabbit

  • New Features
    • More consistent and context-aware autocomplete across form fields, improving typing suggestions and form fill reliability.
  • Refactor
    • Consolidated autocomplete logic internally for uniform behavior across components without changing the public API.
  • Style
    • Minor layout class reordering for the loading spinner container; no visual changes expected.

- Extracted autocomplete value calculation into separate utility function
- Reordered imports and interface declarations
- Simplified autocomplete prop passing in RegisteredComponent
- Improved loading state styling with Tailwind classes
- Added formConfig to FieldRenderer's context usage
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Aug 30, 2025

⚠️ No Changeset found

Latest commit: a094726

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Aug 30, 2025

Walkthrough

Adds a helper to standardize autocomplete value resolution in FieldRenderer, introduces an internal props type, refactors to use useFormContext for form action, memoizes computed autocomplete, updates prop passing accordingly, adjusts import order, and makes a minor spinner container class tweak. No public API changes.

Changes

Cohort / File(s) Summary
Form rendering refactor and UI tweak
libs/portal-framework-ui/src/components/form/FormRenderer.tsx
- Added getFieldAutocompleteValue(field, formPurpose) helper to resolve autocomplete from field.autocomplete → getAutocompleteValue(...) → field.inputProps?.autocomplete
- Introduced internal FieldRendererProps type; used for FieldRenderer props
- FieldRenderer now reads formConfig via useFormContext and derives formConfig.action
- Memoizes autocomplete with useMemo([field, formConfig.action]) and passes autocomplete={autoCompleteValue}
- Reordered imports around useFormContext
- Minor layout change: spinner container class from "flex items-center justify-center h-14" to "flex h-14 items-center justify-center"
- No exported/public API signature changes

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant U as User
  participant FR as FieldRenderer
  participant FC as useFormContext
  participant GV as getAutocompleteValue
  participant C as Field Component

  U->>FR: Render field
  FR->>FC: Obtain formConfig
  FC-->>FR: { action, ... }

  note over FR: Compute autoCompleteValue
  alt field.autocomplete present
    FR-->>FR: Use field.autocomplete
  else no field.autocomplete
    FR->>GV: getAutocompleteValue(field, { formPurpose: action })
    GV-->>FR: derived value or undefined
    alt undefined
      FR-->>FR: Use field.inputProps?.autocomplete
    end
  end

  FR->>C: Render with props (autocomplete=autoCompleteValue)
  C-->>U: Field displayed
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I nibbled on forms in the moonlit night,
Found autocomplete’s path just right.
With memos snug and actions neat,
The spinner shuffles its tiny feet.
One hop, two hops—context in view—
Fields now whisper what they should do. 🥕✨

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch libs/portal-plugin-dashboard

🪧 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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit 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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
libs/portal-framework-ui/src/components/form/FormRenderer.tsx (1)

173-197: Loading state bug: stale closure makes spinner stick; cleanup missing.

if (isLoading) setIsLoading(false) checks a stale value and won’t clear loading after an async show(). Also guard against state updates after unmount.

-      if (shouldShow && field.show) {
-        try {
-          const showPromiseOrValue = field.show(currentValues);
-          if (showPromiseOrValue instanceof Promise) {
-            setIsLoading(true);
-            shouldShow = await showPromiseOrValue;
-            if (isLoading) setIsLoading(false);
-          } else {
-            shouldShow = showPromiseOrValue;
-            if (isLoading) setIsLoading(false);
-          }
-        } catch (error) {
+      if (shouldShow && field.show) {
+        const result = field.show(currentValues);
+        const isPromise =
+          result && typeof (result as any).then === "function";
+        try {
+          if (isPromise) setIsLoading(true);
+          shouldShow = await Promise.resolve(result);
+        } catch (error) {
           console.error(
             `Error checking show status for field ${String(field.name)}:`,
             error,
           );
           shouldShow = false;
-          if (isLoading) setIsLoading(false);
-        }
-      } else if (!field.show) {
-        if (isLoading) setIsLoading(false);
-      } else {
-        if (isLoading) setIsLoading(false);
+        } finally {
+          if (isPromise) setIsLoading(false);
+        }
       }

Add cancellation guard in the effect:

-  useEffect(() => {
+  useEffect(() => {
+    let cancelled = false;
     // Subscribe to form changes and check visibility when relevant fields change
     const subscription = watch((values, { name }) => {
       // Only check visibility if dependencies are empty (watch all) or changed field is in dependencies
       if (!dependencies.length || (name && dependencies.includes(name))) {
         checkVisibility();
       }
     });
@@
-    return () => subscription.unsubscribe();
+    return () => {
+      cancelled = true;
+      subscription.unsubscribe();
+    };
   }, [dependencies, field, getValues, isLoading, watch]);
🧹 Nitpick comments (2)
libs/portal-framework-ui/src/components/form/FormRenderer.tsx (2)

14-16: Keep imports contiguous; move local type below imports.

Minor style for consistency/readability.

-interface FieldRendererProps<TFieldValues extends FieldValues> {
-  field: FormFieldConfig<TFieldValues>;
-}

Re-add just after the last import:

+interface FieldRendererProps<TFieldValues extends FieldValues> {
+  field: FormFieldConfig<TFieldValues>;
+}

207-207: Effect re-subscribes on every loading toggle.

Remove isLoading from deps to avoid unnecessary subscribe/unsubscribe churn.

-  }, [dependencies, field, getValues, isLoading, watch]);
+  }, [dependencies, field, getValues, watch]);
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 6484025 and a094726.

📒 Files selected for processing (1)
  • libs/portal-framework-ui/src/components/form/FormRenderer.tsx (5 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
libs/portal-framework-ui/src/components/form/FormRenderer.tsx (3)
libs/portal-framework-ui/src/components/form/types.ts (1)
  • FormFieldConfig (121-175)
libs/portal-framework-ui/src/components/form/context.tsx (1)
  • useFormContext (35-43)
libs/portal-framework-ui/src/components/form/autocomplete/rules.ts (1)
  • getAutocompleteValue (364-378)
🔇 Additional comments (6)
libs/portal-framework-ui/src/components/form/FormRenderer.tsx (6)

25-25: Import location change looks fine.


120-120: Using formConfig from context — OK.


127-130: Good extraction + memoization of autocomplete value.


214-214: Spinner container tweak — OK.


279-288: Helper reads well; precedence is correct (explicit > derived > fallback).


256-258: Leave autocomplete prop as-is
Field components declare and accept a lowercase autocomplete prop and correctly map it to the rendered element’s autoComplete attribute; no change required.

@pcfreak30 pcfreak30 merged commit fd32c9f into develop Aug 30, 2025
1 of 2 checks passed
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