Skip to content

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

Closed
myu-box wants to merge 1 commit intobox:masterfrom
myu-box:DOCGEN-10007
Closed

feat(docgen-sidebar): support new types for pdf template#4508
myu-box wants to merge 1 commit intobox:masterfrom
myu-box:DOCGEN-10007

Conversation

@myu-box
Copy link
Copy Markdown
Contributor

@myu-box myu-box commented Apr 21, 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

  • New Features

    • Sidebar now groups tags into dynamic sections and displays PDF form fields (checkbox, radiobutton, dropdown) as separate tag sections.
  • Localization

    • Added user-facing labels for Checkbox tags, Radiobutton tags, and Dropdown tags.
  • Tests

    • Added test coverage verifying PDF-template rendering and form-field tag display.
  • Chores

    • Storybook examples and mock PDF template data added to showcase PDF form-field scenarios.

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 21, 2026

CLA assistant check
All committers have signed the CLA.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 21, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 34a6d44a-7ef1-40d7-b545-5f7731c77b80

📥 Commits

Reviewing files that changed from the base of the PR and between 6ef0e87 and ce9e0e1.

📒 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
✅ Files skipped from review due to trivial changes (1)
  • src/elements/content-sidebar/DocGenSidebar/messages.tsx
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/elements/content-sidebar/mocks/DocGenSidebar.mock.ts
  • src/elements/content-sidebar/DocGenSidebar/stories/DocGenSidebar.stories.tsx
  • src/elements/content-sidebar/DocGenSidebar/types.ts

Walkthrough

Replaces DocGenSidebar's fixed text/image state with a unified sections: DocGenSection[] built from tag types (text, image, and PDF form-field types); adds PDF field tag types, i18n messages, mock PDF template data, tests, and Storybook stories; rendering and empty/loading logic now operate on sections.

Changes

Cohort / File(s) Summary
DocGenSidebar component
src/elements/content-sidebar/DocGenSidebar/DocGenSidebar.tsx
Replaced separate text/image tag arrays and JSON trees with a single sections: DocGenSection[]. Build logic groups tags into text, image, and per-PDF-field sections. Loading handler sets sections; rendering maps sections to TagsSection; empty-state check uses sections.length.
Types & helpers
src/elements/content-sidebar/DocGenSidebar/types.ts
Expanded DocGenTag['tag_type'] to include `'checkbox'
i18n messages
src/elements/content-sidebar/DocGenSidebar/messages.tsx
Added checkboxTags, radiobuttonTags, and dropdownTags react-intl messages for new PDF field sections.
Mocks
src/elements/content-sidebar/__mocks__/DocGenSidebar.mock.ts
Added named mockPdfTemplateData array containing PDF form-field tag descriptors (text, checkbox, radiobutton, dropdown) for Storybook/tests.
Tests
src/elements/content-sidebar/__tests__/DocGenSidebar.test.tsx
Added test using mockPdfTemplateData that asserts rendering of four bcs-TagsSection elements and presence of Text/Checkbox/Radiobutton/Dropdown labels.
Storybook
src/elements/content-sidebar/DocGenSidebar/stories/DocGenSidebar.stories.tsx
Added pdfTemplate and pdfTemplateWithModernizedBlueprint stories which override getDocGenTags to return mockPdfTemplateData; existing stories unchanged.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

ready-to-merge

Suggested reviewers

  • tjuanitas
  • tjiang-box
  • jfox-box

Poem

🐇 I hopped through tags both new and old,
Grouped sections tidy, neat, and bold.
Checkboxes, radios, dropdowns hop in line,
The sidebar hums — organized design! 🥕

🚥 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 'feat(docgen-sidebar): support new types for pdf template' is concise and clearly summarizes the main feature addition of supporting new PDF form field types.
Description check ✅ Passed The PR description adequately explains the changes, including what was added (checkbox, radiobutton, dropdown support), why (to group fields by type), and includes before/after visual comparisons. However, it uses the default template structure rather than providing a customized description.
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 21, 2026 09:58
@myu-box myu-box requested review from a team as code owners April 21, 2026 09:58
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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/elements/content-sidebar/__tests__/DocGenSidebar.test.tsx (1)

63-80: Strengthen the test to assert per-section tag placement.

The new test confirms the four headers render, but not that NameField, SubscribeCheckbox, Gender, and CountryDropdown are grouped under their matching sections. Adding scoped tag assertions would better protect the core behavior of this PR.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/elements/content-sidebar/__tests__/DocGenSidebar.test.tsx` around lines
63 - 80, Update the test 'should render PDF template tags in separate sections'
to assert that each tag appears inside its correct section: after rendering with
mocked getDocGenTags and awaiting screen.findAllByTestId('bcs-TagsSection'), use
the testing-library within(...) on each returned section element to assert that
'NameField' exists in the Text tags section, 'SubscribeCheckbox' exists in the
Checkbox tags section, 'Gender' exists in the Radiobutton tags section, and
'CountryDropdown' exists in the Dropdown tags section (use renderComponent,
mockPdfTemplateData and within from `@testing-library/react` to scope the
queries).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/elements/content-sidebar/DocGenSidebar/DocGenSidebar.tsx`:
- Around line 70-103: buildDocGenSections currently creates sections when tags
exist but doesn't ensure those tags have non-empty json_paths, causing empty
sections to render; modify the logic in buildDocGenSections to only push a
DocGenSection when tagsToJsonPaths(...) returns a non-empty tree (or when at
least one tag has non-empty json_paths) for textTags, imageTags and each
fieldTags inside PDF_FIELD_TAG_TYPES, e.g., compute const tree =
tagsToJsonPaths(tags) and push the section only if tree.length > 0, using the
existing id/message/ tree shape for the section so isEmpty (which checks
sections.length) will behave correctly.

---

Nitpick comments:
In `@src/elements/content-sidebar/__tests__/DocGenSidebar.test.tsx`:
- Around line 63-80: Update the test 'should render PDF template tags in
separate sections' to assert that each tag appears inside its correct section:
after rendering with mocked getDocGenTags and awaiting
screen.findAllByTestId('bcs-TagsSection'), use the testing-library within(...)
on each returned section element to assert that 'NameField' exists in the Text
tags section, 'SubscribeCheckbox' exists in the Checkbox tags section, 'Gender'
exists in the Radiobutton tags section, and 'CountryDropdown' exists in the
Dropdown tags section (use renderComponent, mockPdfTemplateData and within from
`@testing-library/react` to scope the queries).
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 04fd271f-3544-4d82-a12c-b10ccca526d5

📥 Commits

Reviewing files that changed from the base of the PR and between 61dab4e and 1cc4246.

📒 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

Comment thread src/elements/content-sidebar/DocGenSidebar/DocGenSidebar.tsx
Copy link
Copy Markdown
Contributor

@pyaromchyk-stack pyaromchyk-stack 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 docgen side

),
});

const tagList = await screen.findAllByTestId('bcs-TagsSection');
Copy link
Copy Markdown
Collaborator

@jpan-box jpan-box Apr 22, 2026

Choose a reason for hiding this comment

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

is it completely necessary to use testIds? our general practice is to use semantic queries when possible like getByRole. just want to double check here - trusting your judgement.

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.

Correct. I followed the existing test style at first, but the behavior we care about is the rendered labels, so findByText (and getByRole when it applies) fit better than testid.

https://github.com/box/box-ui-elements/pull/4513/changes#diff-2d5f346ca4d1e1ac53d9b83c2f0a69cfcd5ab5cda77a5935932897048d3072e3

I removed the toHaveLength(4) . Besides, also added a new test that an unknown tag_type appears under text tag section.

tag_type: 'text',
tag_content: '{{NameField::optional}}',
json_paths: ['NameField'],
required: false,
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.

I notice all the other objects in this page have tag_type, tag_content, and json_paths. where does required come from?

I am guessing the type for this object is defined here: https://github.com/box/box-ui-elements/blob/master/src/elements/content-sidebar/DocGenSidebar/types.ts#L2

which also does not have required. just want to make sure the types match up correctly here

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.

dropdown: messages.dropdownTags,
};

const createNestedObject = (base: JsonPathsMap, paths: string[]) => {
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.

naming nitpick: this function is called createNestedObject, but as I understand it .reduce doesn't so much create a new object as much as it modifies an existing one.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce

I feel like something like populateNestedPaths or addNestedPaths would better communicate the mutation to future readers. What do you think?

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.

combined these logic into one buildJsonPathTree function

src/elements/content-sidebar/DocGenSidebar/DocGenSidebar.tsx

return obj[path];
}, base);
};
const tagsToJsonPaths = (docGenTags: DocGenTag[]): JsonPathsMap => {
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.

wondering if this function will need to be used as a util in a future pr? ie should this be factored out into a utils file?

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.

combined these logic into one buildJsonPathTree function

src/elements/content-sidebar/DocGenSidebar/DocGenSidebar.tsx

});

const tagList = await screen.findAllByTestId('bcs-TagsSection');
expect(tagList).toHaveLength(4);
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.

I don't know how important this is, but since you have checked to see if there is a length of 4 with specific mock data, are there cases where it should return 3,2,1, or even 0 or invalid tag types? I have little to no context on what the api shape is like, i'm only thinking from a testing depth perspective. maybe some sort of parameterized test to cover all the cases.

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.

Correct. I followed the existing test style at first, but the behavior we care about is the rendered labels, so findByText (and getByRole when it applies) fit better than testid.

https://github.com/box/box-ui-elements/pull/4513/changes#diff-2d5f346ca4d1e1ac53d9b83c2f0a69cfcd5ab5cda77a5935932897048d3072e3

I removed the toHaveLength(4) . Besides, also added a new test that an unknown tag_type appears under text tag section.

loadTags.call(this, attempts - 1);
} else if (response?.data) {
const { data } = response;
// anything that is not an image tag for this view is treated as a text tag
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.

is this comment still helpful to keep?

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.

thanks for reminder! I moved to this line

src/elements/content-sidebar/DocGenSidebar/DocGenSidebar.tsx

Screenshot 2026-04-22 at 23 18 46

@myu-box
Copy link
Copy Markdown
Contributor Author

myu-box commented Apr 22, 2026

Closing this PR in favor of a new one with the correct branch name.

Please continue review here: #4513

@myu-box myu-box closed this Apr 22, 2026
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.

4 participants