Skip to content

Conversation

@greg-in-a-box
Copy link
Contributor

@greg-in-a-box greg-in-a-box commented Aug 29, 2025

Summary by CodeRabbit

  • New Features

    • Added explicit folder filtering support in content explorer queries.
  • Improvements

    • More accurate file-type filtering using real file extensions; extension filters applied only when relevant.
    • Query construction improved for correct combination of multiple filter conditions.
    • Metadata template lookup now derives scope/key from the query and fetches the template schema consistently.
  • Tests

    • Added/expanded tests for file-extension mapping and template schema behavior.

@greg-in-a-box greg-in-a-box requested a review from a team as a code owner August 29, 2025 20:04
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 29, 2025

Walkthrough

I pity the fool—This change replaces multi-type mapping with a single-type extension lookup, refactors mime-type filtering to use getFileExtensions, adds explicit folderType handling, removes FILE_FOLDER_TYPES_MAP, and updates tests; public function signatures remain unchanged.

Changes

Cohort / File(s) Summary
MetadataQueryBuilder refactor
src/elements/content-explorer/MetadataQueryBuilder.ts
Replaced mapFileTypes with getFileExtensions; getMimeTypeFilter now collects per-type extension arrays, flattens them, emits extension IN(...) only when extensions exist, and adds a mime_folderType='folder' sentinel for folderType.
Utils API change
src/elements/content-explorer/utils.ts
Removed mapFileTypes(BoxItemSelection); added getFileExtensions(string) that looks up extensions from NON_FOLDER_FILE_TYPES_MAP for a single non-folder type and returns [] if not found.
Constants cleanup
src/elements/content-explorer/constants.ts
Removed exported FILE_FOLDER_TYPES_MAP; retained NON_FOLDER_FILE_TYPES_MAP and NON_FOLDER_FILE_TYPES.
Tests update
src/elements/content-explorer/__tests__/MetadataQueryBuilder.test.ts
Added tests/imports for getFileExtensions covering single-type mapping and empty input; existing MetadataQueryBuilder tests unchanged.
MetadataQueryAPIHelper tests
src/elements/content-explorer/__tests__/MetadataQueryAPIHelper.test.ts
Tests updated to assert templateScope/templateKey are derived from metadataQuery.from and that schema fetch is called even when entries are null/empty.
MetadataQueryAPIHelper code
src/elements/content-explorer/MetadataQueryAPIHelper.ts
getTemplateSchemaInfo now derives templateScope/templateKey from this.metadataQuery.from and always calls getSchemaByTemplateKey with the derived key (removed early-return on empty entries).

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant UI as Filter UI
  participant MQB as MetadataQueryBuilder
  participant Utils as getFileExtensions
  participant Query as MQL Builder

  UI->>MQB: build mime-type filter (selectedType(s))
  alt element == "folderType"
    MQB->>Query: add mime_folderType = "folder"
  else non-folder element
    MQB->>Utils: getFileExtensions(type)
    Utils-->>MQB: ["ext1","ext2",...]
    MQB->>MQB: accumulate and flatten extensions
    alt flattened extensions exist
      MQB->>Query: add "extension IN (:arg1,:arg2,...)" clause
    else
      MQB->>Query: skip extension clause
    end
  end
  MQB->>Query: combine clauses with OR and parentheses as needed
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested labels

ready-to-merge

Suggested reviewers

  • jpan-box
  • tjiang-box

Poem

I pity the fool who misses this change, yo!
Extensions lined up, folder flags on show.
Map gone, lookup swift—queries tight and neat,
Tests confirm the path—no defeat.
Ship it clean, you da MVP of this dev street.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 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
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 (3)
src/elements/content-explorer/__tests__/MetadataQueryBuilder.test.ts (1)

537-547: Tight tests, but fix that test name, sucka.

The second test says “empty array input” but passes an empty string. Rename for accuracy; consider adding a case for an unknown type (e.g., 'unknownType') returning [].

Apply this minimal rename:

-        test('should handle empty array input', () => {
+        test('should handle empty string input', () => {

Optional extra test:

test('should return [] for unknown type', () => {
    expect(getFileExtensions('unknownType')).toEqual([]);
});
src/elements/content-explorer/MetadataQueryBuilder.ts (2)

141-152: Folder handling: solid, but tighten naming, fool.

Logic’s correct; only one folder clause gets added. Minor clarity win: rename loop var from “extension” to “fileType” to reflect intent.

-    for (const extension of filterValue) {
-        if (extension === 'folderType' && !hasFolder) {
+    for (const fileType of filterValue) {
+        if (fileType === 'folderType' && !hasFolder) {
             ...
-        } else {
-            extensions.push(getFileExtensions(extension));
+        } else {
+            extensions.push(getFileExtensions(fileType));
         }
     }

155-159: English, fool — and de-dupe for free.

Fix the comment and avoid duplicate IN args if types overlap.

-    // flat the array of arrays
-    const flattenExtensions = extensions.flat();
+    // flatten and de-dup the array of arrays
+    const flattenExtensions = Array.from(new Set(extensions.flat()));
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP (Model Context Protocol) integration is disabled
  • Jira integration is disabled
  • Linear integration is disabled

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between bdd6d1d and 531846f.

📒 Files selected for processing (4)
  • src/elements/content-explorer/MetadataQueryBuilder.ts (2 hunks)
  • src/elements/content-explorer/__tests__/MetadataQueryBuilder.test.ts (2 hunks)
  • src/elements/content-explorer/constants.ts (0 hunks)
  • src/elements/content-explorer/utils.ts (2 hunks)
💤 Files with no reviewable changes (1)
  • src/elements/content-explorer/constants.ts
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: greg-in-a-box
PR: box/box-ui-elements#4235
File: src/elements/content-explorer/MetadataQueryBuilder.ts:103-110
Timestamp: 2025-08-25T16:19:22.007Z
Learning: In src/elements/content-explorer/MetadataQueryBuilder.ts, the getSelectFilter function has a special case that maps 'mimetype-filter' to 'item.extension' because mimetype-filter is a multi-select field but the actual database field is 'item.extension'. This mapping is necessary and should not be removed.
📚 Learning: 2025-08-25T16:19:22.007Z
Learnt from: greg-in-a-box
PR: box/box-ui-elements#4235
File: src/elements/content-explorer/MetadataQueryBuilder.ts:103-110
Timestamp: 2025-08-25T16:19:22.007Z
Learning: In src/elements/content-explorer/MetadataQueryBuilder.ts, the getSelectFilter function has a special case that maps 'mimetype-filter' to 'item.extension' because mimetype-filter is a multi-select field but the actual database field is 'item.extension'. This mapping is necessary and should not be removed.

Applied to files:

  • src/elements/content-explorer/MetadataQueryBuilder.ts
  • src/elements/content-explorer/__tests__/MetadataQueryBuilder.test.ts
  • src/elements/content-explorer/utils.ts
🧬 Code graph analysis (3)
src/elements/content-explorer/MetadataQueryBuilder.ts (1)
src/elements/content-explorer/utils.ts (1)
  • getFileExtensions (198-203)
src/elements/content-explorer/__tests__/MetadataQueryBuilder.test.ts (1)
src/elements/content-explorer/utils.ts (1)
  • getFileExtensions (198-203)
src/elements/content-explorer/utils.ts (1)
src/elements/content-explorer/constants.ts (1)
  • NON_FOLDER_FILE_TYPES_MAP (13-46)
⏰ 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). (2)
  • GitHub Check: lint_test_build
  • GitHub Check: Summary
🔇 Additional comments (5)
src/elements/content-explorer/__tests__/MetadataQueryBuilder.test.ts (1)

9-9: Import looks clean, fool.

Path and placement are correct. No objections.

src/elements/content-explorer/MetadataQueryBuilder.ts (3)

2-2: Good swap to single-type resolver.

Importing getFileExtensions keeps concerns in utils. Solid move.


160-171: Arg naming and IN-clause gen are fine.

Building args from fieldKey and hard-coding item.extension in the query matches our mimetype behavior. Keep rollin’.


98-125: Special-case mapping intact. The mimetype-filter is still routed through getMimeTypeFilter in MetadataQueryAPIHelper.ts, producing an item.extension IN (…) clause per existing tests—no change needed. I pity the fool who doubts it!

src/elements/content-explorer/utils.ts (1)

198-203: Guard Map.get result and lock return type

-export const getFileExtensions = (selectedFileType: string) => {
-    if (NON_FOLDER_FILE_TYPES_MAP.has(selectedFileType)) {
-        return NON_FOLDER_FILE_TYPES_MAP.get(selectedFileType).flat();
-    }
-    return [];
-};
+export const getFileExtensions = (selectedFileType: string): string[] =>
+  NON_FOLDER_FILE_TYPES_MAP.get(selectedFileType)?.flat() ?? [];
  • Install missing dev type definitions (e.g. @types/jest, @types/enzyme, @types/classnames) or update your tsconfig.json to include the appropriate types entries, then rerun npm run typecheck / npx tsc -p tsconfig.json. I pity the fool who skips TS errors!

@greg-in-a-box greg-in-a-box changed the title fix(metadata-view): fix filtering file extensions fix(metadata-view): fix filtering file extensions and filters Aug 29, 2025
@greg-in-a-box greg-in-a-box changed the title fix(metadata-view): fix filtering file extensions and filters fix(metadata-view): fix filtering file extensions and filters visibility Aug 29, 2025
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 (3)
src/elements/content-explorer/MetadataQueryAPIHelper.ts (1)

177-179: Harden parsing of metadataQuery.from, fool!
I pity the fool who lets bad from values knock out the flow—use a safe split + fallback:

- const [scope, key] = this.metadataQuery.from.split('.');
- this.templateScope = scope;
- this.templateKey = key;
+ const from = this.metadataQuery?.from ?? '';
+ const [scope, key] = from.split('.', 2);
+ this.templateScope = scope || this.templateScope;
+ this.templateKey = key || this.templateKey;
src/elements/content-explorer/__tests__/MetadataQueryAPIHelper.test.ts (2)

210-212: Resetting schema mock before each—good discipline, sucka.
Optional: also reset queryMetadataFunc to avoid cross-test bleed.


313-326: From-based scope/key extraction test—ace uppercut!
Add one more case with malformed from (e.g., missing dot) to prove the guard. I pity the fool who skips edge cases!

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP (Model Context Protocol) integration is disabled
  • Jira integration is disabled
  • Linear integration is disabled

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 531846f and b877bf7.

📒 Files selected for processing (2)
  • src/elements/content-explorer/MetadataQueryAPIHelper.ts (1 hunks)
  • src/elements/content-explorer/__tests__/MetadataQueryAPIHelper.test.ts (4 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/elements/content-explorer/__tests__/MetadataQueryAPIHelper.test.ts (1)
src/features/metadata-based-view/__tests__/MetadataQueryAPIHelper.test.js (6)
  • getSchemaByTemplateKeyFunc (191-191)
  • templateSchemaResponse (66-68)
  • nextMarker (69-69)
  • metadataQueryAPIHelper (15-15)
  • mdQuery (207-218)
  • metadataQueryResponse (70-116)
⏰ 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). (2)
  • GitHub Check: lint_test_build
  • GitHub Check: Summary
🔇 Additional comments (6)
src/elements/content-explorer/__tests__/MetadataQueryAPIHelper.test.ts (6)

192-192: Parametrize from with template vars—nice jab!
Keeps tests resilient to template changes.


197-199: Parametrize metadata field paths—clean combo!
Reduces brittle string literals.


274-281: Test ensures schema fetch + instance props—tight form.
Covers the happy path after refactor.


283-291: Still fetch schema when entries are empty—smart defense.
Prevents early returns from skipping schema load.


293-301: Null entries case covered—no glass jaw here.
Ensures consistent behavior.


303-312: Undefined entries case—belt and suspenders.
Keeps behavior uniform across falsy shapes.

@mergify mergify bot merged commit 504aed7 into box:master Aug 29, 2025
10 checks passed
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