Skip to content

feat(docgen-sidebar): support new types for pdf template#4513

Open
myu-box wants to merge 3 commits intobox:masterfrom
myu-box:support-pdf-tag-type
Open

feat(docgen-sidebar): support new types for pdf template#4513
myu-box wants to merge 3 commits intobox:masterfrom
myu-box:support-pdf-tag-type

Conversation

@myu-box
Copy link
Copy Markdown
Contributor

@myu-box myu-box commented Apr 22, 2026

This PR adds support for new PDF form field types: checkbox, radiobutton, and dropdown.

Previously, all PDF form fields were grouped under the text tags section. This update introduces new sections for these new field types.

Changes

  • Added support for checkbox, radiobutton and dropdown field type
  • Followed existing UI patterns for consistency
Before After
Screenshot 2026-04-21 at 11 43 18 Screenshot 2026-04-21 at 11 26 21

Summary by CodeRabbit

Release Notes

  • New Features

    • Added support for checkbox, radiobutton, and dropdown PDF form field types in the document generation sidebar.
    • Form fields can now be marked as required or optional.
    • Form field tags are now organized into dedicated sidebar sections with localized labels for each type.
  • Tests

    • Enhanced test coverage for form field tag rendering and empty-state scenarios.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 22, 2026

Walkthrough

The PR extends the DocGenSidebar component to support PDF form field tags (checkbox, radiobutton, dropdown) by refactoring the sidebar to dynamically organize tags into sections. The component now groups tags by category—text, image, and per-field type—instead of using hardcoded sections. Type definitions are extended with new tag types, a required field, and helper functions. Mock data and localization messages are added to support testing and rendering.

Changes

Cohort / File(s) Summary
Component Logic
src/elements/content-sidebar/DocGenSidebar/DocGenSidebar.tsx
Refactored to use dynamic sections: DocGenSection[] state instead of separate text and image tag tracking. Introduces DocGenSection and helper functions to build a nested JsonPathsMap from incoming tags, grouping them into text, image, and PDF form field type sections. Render logic updated to map over sections instead of two hardcoded TagsSection components. Empty-state condition adjusted accordingly.
Type Definitions & Constants
src/elements/content-sidebar/DocGenSidebar/types.ts
Extended DocGenTag.tag_type union to include 'checkbox' | 'radiobutton' | 'dropdown'. Added required: boolean field to DocGenTag. Introduced PDF_FIELD_TAG_TYPES constant and isPdfFormFieldTagType() helper function.
Mock Data
src/elements/content-sidebar/__mocks__/DocGenSidebar.mock.ts
Added required: true field to all existing mockData tag entries. Exported new mockPdfTemplateData array with PDF template tags (text, checkbox, radiobutton, dropdown) including explicit required flags per entry.
Localization
src/elements/content-sidebar/DocGenSidebar/messages.tsx
Added three new message definitions: checkboxTags, radiobuttonTags, and dropdownTags for section header localization.
Storybook Stories
src/elements/content-sidebar/DocGenSidebar/stories/DocGenSidebar.stories.tsx
Imported mockPdfTemplateData and added two new story exports: pdfTemplate and pdfTemplateWithModernizedBlueprint, demonstrating PDF form field tag rendering with optional modernized components.
Test Suite
src/elements/content-sidebar/__tests__/DocGenSidebar.test.tsx
Updated tests to verify section-based organization (e.g., Text tags, Image tags labels). Removed generic tag count assertions. Added coverage for multiple form-field tag categories from mockPdfTemplateData, empty-state rendering, and fallback rendering of unknown tag types to the text section.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • #4392 — Modifies DocGenSidebar Storybook stories and modernized-blueprint UI variants.

Suggested labels

ready-to-merge

Suggested reviewers

  • tjiang-box
  • tjuanitas
  • jpan-box

Poem

🐰 A sidebar grows with forms anew,
PDF fields of every hue—
Checkboxes, dropdowns, radio rounds,
Grouped in sections, neatly bound!

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is incomplete and does not follow the template structure. It contains only template instructions and a brief change summary, lacking organized sections for context, motivation, and implementation details. Replace the template instructions with actual PR description content. Include sections explaining what changed, why it was needed, and any implementation notes or testing information.
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 (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat(docgen-sidebar): support new types for pdf template' accurately describes the main change: adding support for new PDF form field types (checkbox, radiobutton, dropdown) to the DocGen sidebar.
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.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

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

@myu-box myu-box marked this pull request as ready for review April 22, 2026 21:31
@myu-box myu-box requested review from a team as code owners April 22, 2026 21:31
Copy link
Copy Markdown
Contributor

@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.

🧹 Nitpick comments (1)
src/elements/content-sidebar/DocGenSidebar/types.ts (1)

4-13: Model unknown API tag types instead of casting around the union.

The sidebar and tests intentionally support unknown tag_type values falling back to Text tags, but DocGenTag['tag_type'] currently excludes them. That forces as unknown as DocGenTag in tests and makes the API contract narrower than the runtime behavior.

Suggested type adjustment
+export const KNOWN_DOC_GEN_TAG_TYPES = [
+    'text',
+    'arithmetic',
+    'conditional',
+    'for-loop',
+    'table-loop',
+    'image',
+    'checkbox',
+    'radiobutton',
+    'dropdown',
+] as const;
+
+export type KnownDocGenTagType = (typeof KNOWN_DOC_GEN_TAG_TYPES)[number];
+
 // our apis are in snake case
 export type DocGenTag = {
     /* eslint-disable-next-line camelcase */
-    tag_type:
-        | 'text'
-        | 'arithmetic'
-        | 'conditional'
-        | 'for-loop'
-        | 'table-loop'
-        | 'image'
-        | 'checkbox'
-        | 'radiobutton'
-        | 'dropdown';
+    tag_type: KnownDocGenTagType | (string & {});
     /* eslint-disable-next-line camelcase */
     tag_content: string;
     /* eslint-disable-next-line camelcase */
     json_paths: Array<string>;
     required: boolean;
@@
 /** PDF template control tags that render in their own sidebar section. */
 export const PDF_FIELD_TAG_TYPES = ['checkbox', 'radiobutton', 'dropdown'] as const;
+export type PdfFieldTagType = (typeof PDF_FIELD_TAG_TYPES)[number];
 
-export function isPdfFormFieldTagType(tagType: DocGenTag['tag_type']): boolean {
-    return (PDF_FIELD_TAG_TYPES as readonly DocGenTag['tag_type'][]).includes(tagType);
+export function isPdfFormFieldTagType(tagType: DocGenTag['tag_type']): tagType is PdfFieldTagType {
+    return (PDF_FIELD_TAG_TYPES as readonly string[]).includes(tagType);
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/elements/content-sidebar/DocGenSidebar/types.ts` around lines 4 - 13,
DocGenTag['tag_type'] currently lists only known literals, which prevents
representing unknown API tag types and forces casts in tests; update the union
in types.ts (the tag_type definition) to allow arbitrary strings (e.g., append |
string to the existing union) so unknown tag_type values are accepted and
code/tests can rely on runtime fallback to text without using as unknown as
DocGenTag casts.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/elements/content-sidebar/DocGenSidebar/types.ts`:
- Around line 4-13: DocGenTag['tag_type'] currently lists only known literals,
which prevents representing unknown API tag types and forces casts in tests;
update the union in types.ts (the tag_type definition) to allow arbitrary
strings (e.g., append | string to the existing union) so unknown tag_type values
are accepted and code/tests can rely on runtime fallback to text without using
as unknown as DocGenTag casts.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a4a727c1-b8ec-41f8-a27b-17a20fd824c4

📥 Commits

Reviewing files that changed from the base of the PR and between 4326560 and e846aee.

📒 Files selected for processing (6)
  • src/elements/content-sidebar/DocGenSidebar/DocGenSidebar.tsx
  • src/elements/content-sidebar/DocGenSidebar/messages.tsx
  • src/elements/content-sidebar/DocGenSidebar/stories/DocGenSidebar.stories.tsx
  • src/elements/content-sidebar/DocGenSidebar/types.ts
  • src/elements/content-sidebar/__mocks__/DocGenSidebar.mock.ts
  • src/elements/content-sidebar/__tests__/DocGenSidebar.test.tsx

tag_content: string;
/* eslint-disable-next-line camelcase */
json_paths: Array<string>;
required: boolean;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

thanks for adding :) but since required is a required type property now, does that cause any sort of breaking changes? just want to check and raise - trust you and polina on the logic of all things docgen.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The required property follows the DocGen tag type format to keep consistency with the type definition. At the moment, we are not using this required field in the DocGen Sidebar for any UI behavior changes.

return (
<SidebarContent sidebarView={SIDEBAR_VIEW_DOCGEN} title={formatMessage(messages.docGenTags)}>
<div className={classNames('bcs-DocGenSidebar', { center: isEmpty || hasError || isLoading })}>
{hasError && <Error onClick={() => loadTags(DEFAULT_RETRIES)} />}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Unrelated to your PR, but reading the additions at
https://github.com/box/box-ui-elements/pull/4513/changes#diff-89a3e1cb69853b3b87f5751630234d05ffc288ba9c9e3cb35f918ced1f435db3R115-R117

made me think of this.

It looks like it is theoretically possible to be in both an error state and a loading state and have both show up? it may not be possible (i dont know for sure!) and don't address in this PR, but... if your project leads you back to this file in the future might be something to look at.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch. I’ll watch for it in preview. If it shows up in practice We need to put up a follow-up PR. Thanks for calling it out

Copy link
Copy Markdown
Collaborator

@jpan-box jpan-box left a comment

Choose a reason for hiding this comment

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

LGTM from structural perspective (no significant changes to buie framework or cross element interactions) and general BUIE/box coding practices.

rely on you and teammate +1 for specific code logic! thank you so much for your work and revisions!

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.

2 participants