-
Notifications
You must be signed in to change notification settings - Fork 345
fix(metadata-view): fix filtering file extensions and filters visibility #4257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughI 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
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
✨ Finishing Touches
🧪 Generate 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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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.
📒 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.tssrc/elements/content-explorer/__tests__/MetadataQueryBuilder.test.tssrc/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. Themimetype-filteris still routed through getMimeTypeFilter in MetadataQueryAPIHelper.ts, producing anitem.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 yourtsconfig.jsonto include the appropriatetypesentries, then rerunnpm run typecheck/npx tsc -p tsconfig.json. I pity the fool who skips TS errors!
There was a problem hiding this 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 ofmetadataQuery.from, fool!
I pity the fool who lets badfromvalues 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 resetqueryMetadataFuncto avoid cross-test bleed.
313-326: From-based scope/key extraction test—ace uppercut!
Add one more case with malformedfrom(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.
📒 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: Parametrizefromwith 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.
Summary by CodeRabbit
New Features
Improvements
Tests