Skip to content

Conversation

@shahzadaziz
Copy link
Collaborator

@shahzadaziz shahzadaziz commented Jan 7, 2026

  • ContentSidebar.js: Added minimalFile prop that allows the sidebar to render its shell immediately using minimal file data from EUA's Redux store, while showing a loading state until the full file data is fetched.
  • ContentSidebar.test.js: Added 5 tests covering the minimalFile behavior - verifying sidebar renders with minimal data when full file is unavailable, uses full file when available, and correctly sets loading states.

Summary by CodeRabbit

  • New Features

    • Content sidebar now shows a minimal placeholder immediately while full content loads, improving perceived responsiveness and allowing the sidebar to render earlier.
    • Loading indicator behavior updated so the sidebar reflects a loading state until full content is available.
  • Tests

    • Added comprehensive tests covering rendering with minimal data, transition to full data, loading-state behavior, and non-rendering when no data is present.

✏️ Tip: You can customize this high-level summary in your review settings.

@shahzadaziz shahzadaziz requested review from a team as code owners January 7, 2026 20:13
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 7, 2026

Walkthrough

ContentSidebar now accepts an optional minimalFile prop (type BoxItem) and uses a computed displayFile (either file or minimalFile) to decide rendering and loading state. displayFile is passed to the Sidebar; loading treats absence of full file as loading.

Changes

Cohort / File(s) Summary
ContentSidebar component
src/elements/content-sidebar/ContentSidebar.js
Added public prop minimalFile?: BoxItem. Introduced displayFile selection (prefer file, fallback minimalFile), updated render gating to use displayFile, passed displayFile to Sidebar, and adjusted loading logic to `isLoading
Test suite
src/elements/content-sidebar/__tests__/ContentSidebar.test.js
Added tests for minimalFile scenarios: renders with minimalFile pre-fetch, swaps to full file after fetch success, returns null when neither present, and verifies isLoading behavior before/after fetch.
Manifest
package.json
(Touched by diff analyzer; no API or production behavior changes reported.)

Sequence Diagram(s)

(omitted — change is focused within component rendering logic and tests; no multi-component sequential flow requiring visualization)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

ready-to-merge

Suggested reviewers

  • greg-in-a-box
  • jmcbgaston
  • bfoxx1906

Poem

🐰 I brought a minimal file to play,
A tiny shell to light the way,
While full data hops along the track,
The sidebar smiles and holds its stack. 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Description check ❓ Inconclusive The description clearly explains what was changed (minimalFile prop added) and the test coverage, but lacks important context like motivation, technical details, or potential impacts. Enhance the description with the rationale for the change, how it impacts user experience, any trade-offs, and whether there are any breaking changes or dependencies.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding a minimalFile prop to enable faster rendering of the content sidebar.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ 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

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

Copy link
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: 0

🧹 Nitpick comments (1)
src/elements/content-sidebar/__tests__/ContentSidebar.test.js (1)

356-382: Remove duplicate test cases.

Tests 4 and 5 (lines 356-382) are functionally identical to test 1 (lines 310-324). All three tests:

  • Set up a wrapper with fileId and minimalFile
  • Set state to { file: undefined, isLoading: true }
  • Assert that isLoading is true

Test 1 already comprehensively covers this scenario by verifying that the sidebar renders, receives the correct file prop, and has isLoading set to true.

♻️ Consolidate duplicate tests

Remove tests 4 and 5, as test 1 already validates the same behavior:

-        test('should pass isLoading as true when using minimalFile without full file data', () => {
-            const wrapper = getWrapper({
-                fileId: 'test_id',
-                minimalFile,
-            });
-
-            act(() => {
-                wrapper.setState({ file: undefined, isLoading: true });
-            });
-            wrapper.update();
-
-            expect(wrapper.find('sidebar').prop('isLoading')).toBe(true);
-        });
-
-        test('should pass isLoading as true when file is loading even with minimalFile', () => {
-            const wrapper = getWrapper({
-                fileId: 'test_id',
-                minimalFile,
-            });
-
-            act(() => {
-                wrapper.setState({ file: undefined, isLoading: true });
-            });
-            wrapper.update();
-
-            expect(wrapper.find('sidebar').prop('isLoading')).toBe(true);
-        });
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 69be418 and a91a9ba.

📒 Files selected for processing (2)
  • src/elements/content-sidebar/ContentSidebar.js
  • src/elements/content-sidebar/__tests__/ContentSidebar.test.js
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: rafalmaksymiuk
Repo: box/box-ui-elements PR: 4136
File: src/elements/common/types/SidebarNavigation.ts:16-26
Timestamp: 2025-06-11T16:30:10.431Z
Learning: `VersionSidebarView` intentionally uses the `versionId` field to stay consistent with current URL parameter naming; a potential rename to `fileVersionId` is deferred until React Router is removed.
Learnt from: fpan225
Repo: box/box-ui-elements PR: 4239
File: src/elements/content-sidebar/SidebarPanels.js:0-0
Timestamp: 2025-09-03T18:30:44.447Z
Learning: In the CustomSidebarPanel type, the component field is required (React.ComponentType<any>), so runtime checks for component existence are unnecessary since Flow will catch missing components at compile time. User fpan225 prefers to rely on the type system rather than adding redundant runtime checks.
📚 Learning: 2025-06-11T16:30:10.431Z
Learnt from: rafalmaksymiuk
Repo: box/box-ui-elements PR: 4136
File: src/elements/common/types/SidebarNavigation.ts:16-26
Timestamp: 2025-06-11T16:30:10.431Z
Learning: `VersionSidebarView` intentionally uses the `versionId` field to stay consistent with current URL parameter naming; a potential rename to `fileVersionId` is deferred until React Router is removed.

Applied to files:

  • src/elements/content-sidebar/ContentSidebar.js
📚 Learning: 2025-06-17T13:30:02.172Z
Learnt from: rafalmaksymiuk
Repo: box/box-ui-elements PR: 4144
File: src/elements/content-sidebar/versions/VersionsList.js:24-33
Timestamp: 2025-06-17T13:30:02.172Z
Learning: In the box-ui-elements codebase, Flow components use .flow.js type definition files, not TypeScript .ts files. The InternalSidebarNavigation type is a union type where different variants may have different properties like versionId, and proper type safety is ensured through conditional checks in methods like getSelectedVersionId.

Applied to files:

  • src/elements/content-sidebar/ContentSidebar.js
🧬 Code graph analysis (1)
src/elements/content-sidebar/__tests__/ContentSidebar.test.js (2)
src/elements/content-sidebar/__tests__/SidebarFileProperties.test.js (1)
  • getWrapper (10-10)
src/elements/content-sidebar/__tests__/DetailsSidebar.test.js (2)
  • getWrapper (26-36)
  • file (15-18)
🪛 Biome (2.1.2)
src/elements/content-sidebar/ContentSidebar.js

[error] 389-389: type annotation are a TypeScript only feature. Convert your file to a TypeScript file or remove the syntax.

TypeScript only syntax

(parse)


[error] 390-390: type annotation are a TypeScript only feature. Convert your file to a TypeScript file or remove the syntax.

TypeScript only syntax

(parse)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: lint_test_build
  • GitHub Check: Summary
🔇 Additional comments (5)
src/elements/content-sidebar/ContentSidebar.js (5)

99-100: LGTM!

The minimalFile prop is well-documented and correctly typed as an optional BoxItem. The JSDoc clearly explains its purpose for rendering an immediate shell while full data loads.


388-393: LGTM!

The displayFile logic correctly implements the fallback pattern, prioritizing full file data over minimal file data. This ensures the sidebar uses the most complete data available.


424-424: LGTM!

The isLoading logic correctly ensures that the loading state is true whenever full file data is unavailable, even when minimalFile is present. This provides accurate feedback to users that complete data is still being fetched.


395-397: No issues found. The implementation safely handles minimal file data through lodash/get (getProp) which uses default values for missing paths. The hasSkillsData function accesses nested properties like metadata.global.boxSkillsCards.cards with a fallback to an empty array, so minimalFile objects lacking these properties simply return false without errors. Existing test coverage (line 310-324 of ContentSidebar.test.js) validates this behavior.


413-413: BoxAISidebar may receive undefined fileExtension when rendering with minimalFile.

The BoxAISidebar component requires a non-optional fileExtension: string prop (line 21 of BoxAISidebar.tsx), but minimalFile lacks an extension property. When displayFile is set to minimalFile (line 393 of ContentSidebar.js), the code at line 284 of SidebarPanels.js passes fileExtension={file.extension} which evaluates to undefined, creating a type mismatch.

Ensure minimalFile includes an extension property, or add a defensive fallback like fileExtension={file.extension || ''} when passing it to BoxAISidebar.

⛔ Skipped due to learnings
Learnt from: rafalmaksymiuk
Repo: box/box-ui-elements PR: 4136
File: src/elements/common/types/SidebarNavigation.ts:16-26
Timestamp: 2025-06-11T16:30:10.431Z
Learning: `VersionSidebarView` intentionally uses the `versionId` field to stay consistent with current URL parameter naming; a potential rename to `fileVersionId` is deferred until React Router is removed.
Learnt from: fpan225
Repo: box/box-ui-elements PR: 4239
File: src/elements/content-sidebar/SidebarPanels.js:0-0
Timestamp: 2025-09-03T18:30:44.447Z
Learning: In the CustomSidebarPanel type, the component field is required (React.ComponentType<any>), so runtime checks for component existence are unnecessary since Flow will catch missing components at compile time. User fpan225 prefers to rely on the type system rather than adding redundant runtime checks.
Learnt from: rafalmaksymiuk
Repo: box/box-ui-elements PR: 4144
File: src/elements/content-sidebar/versions/VersionsList.js:24-33
Timestamp: 2025-06-17T13:30:02.172Z
Learning: In the box-ui-elements codebase, Flow components use .flow.js type definition files, not TypeScript .ts files. The InternalSidebarNavigation type is a union type where different variants may have different properties like versionId, and proper type safety is ensured through conditional checks in methods like getSelectedVersionId.

Copy link
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: 0

🧹 Nitpick comments (2)
src/elements/content-sidebar/__tests__/ContentSidebar.test.js (2)

343-350: Remove redundant mock setup.

Line 344 redundantly sets SidebarUtils.shouldRenderSidebar when it's already configured in the beforeEach at line 307.

♻️ Proposed refactor
     test('should return null when neither file nor minimalFile is available', () => {
-        SidebarUtils.shouldRenderSidebar = jest.fn().mockReturnValue(true);
         const wrapper = getWrapper({
             fileId: 'test_id',
         });

352-376: Consider consolidating duplicate test coverage.

Tests 4 and 5 duplicate assertions already covered in tests 1 and 2:

  • Test 4 checks isLoading with minimalFile (already verified at line 321)
  • Test 5 checks isLoading after fetch completes (already verified at line 340)

Consider removing these tests to reduce maintenance overhead.

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a91a9ba and 6c5da06.

📒 Files selected for processing (1)
  • src/elements/content-sidebar/__tests__/ContentSidebar.test.js
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: rafalmaksymiuk
Repo: box/box-ui-elements PR: 4136
File: src/elements/common/types/SidebarNavigation.ts:16-26
Timestamp: 2025-06-11T16:30:10.431Z
Learning: `VersionSidebarView` intentionally uses the `versionId` field to stay consistent with current URL parameter naming; a potential rename to `fileVersionId` is deferred until React Router is removed.
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: lint_test_build
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: Summary
🔇 Additional comments (2)
src/elements/content-sidebar/__tests__/ContentSidebar.test.js (2)

298-308: LGTM! Clean test suite setup.

The minimalFile fixture and mock setup are appropriate for testing the minimal file rendering scenarios.


310-341: LGTM! Core transition logic is well-tested.

Tests 1 and 2 correctly verify the minimalFile → full file transition and the corresponding loading state changes.

Copy link
Contributor

@tjuanitas tjuanitas left a comment

Choose a reason for hiding this comment

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

lgtm

@mergify mergify bot added the queued label Jan 8, 2026
@mergify mergify bot merged commit 70e2846 into box:master Jan 8, 2026
9 checks passed
@mergify
Copy link
Contributor

mergify bot commented Jan 8, 2026

Merge Queue Status

✅ The pull request has been merged at 6c5da06

This pull request spent 5 seconds in the queue, with no time running CI.
The checks were run in-place.

Required conditions to merge

@mergify mergify bot removed the queued label Jan 8, 2026
shahzadaziz added a commit that referenced this pull request Jan 8, 2026
…ter (#4412)

* feat(preview): add minimalFile prop for content sidebar to render faster

* feat(preview): add minimalFile prop for content sidebar to render faster

* fix: address comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants