-
Notifications
You must be signed in to change notification settings - Fork 344
feat(metadata-view): Add Subheader for Metadata View v2 #4202
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
Merged
Merged
Changes from 13 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
c674486
feat(metadata-view): Add MetadataView V2
greg-in-a-box 74b5ccb
feat: Add new subheader to ContentExplorer for MetadataViewV2
jfox16 2157dc3
fix: use Blueprint Text and i18n, remove logs
jfox16 a0bd998
fix: Show ancestor folder name if no title
jfox16 8eef9f4
fix: Add shouldDestroy to getFolderAPI()
jfox16 c889e03
fix: add tests for SubHeaderLeftMetadataViewV2
jfox16 b2addbf
fix: Move i18n from features to elements/common
jfox16 6bcf8f9
refactor: Move ancestor folder name to ContentExplorer
jfox16 5ef36fa
chore: rename classnames to match SUIT CSS
jfox16 015674e
chore: Add missed files
jfox16 a6c5da4
refactor: Rename SubHeaderLeftMetadataViewV2 to SubHeaderLeftV2
jfox16 e2c2e83
chore: Remove unused api prop
jfox16 8a3fcb5
feat(metadata-view): Add Subheader for Metadata View v2
jfox16 e3fdcb1
feat(metadata-view): Add Subheader for Metadata View v2
jfox16 2516f5a
Merge branch 'master' of github.com:box/box-ui-elements into subheade…
jfox16 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| .be-sub-header-left-v2-selected { | ||
jfox16 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| gap: 12px; | ||
jfox16 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| import React, { useMemo } from 'react'; | ||
| import { useIntl } from 'react-intl'; | ||
| import { XMark } from '@box/blueprint-web-assets/icons/Fill/index'; | ||
| import { IconButton, PageHeader, Text } from '@box/blueprint-web'; | ||
| import type { Selection } from 'react-aria-components'; | ||
| import type { Collection } from '../../../common/types/core'; | ||
| import messages from '../messages'; | ||
|
|
||
| import './SubHeaderLeftV2.scss'; | ||
|
|
||
| export interface SubHeaderLeftV2Props { | ||
| currentCollection: Collection; | ||
| onClearSelectedItemIds?: () => void; | ||
| rootName?: string; | ||
| selectedItemIds: Selection; | ||
| title?: string; | ||
| } | ||
|
|
||
| const SubHeaderLeftV2 = (props: SubHeaderLeftV2Props) => { | ||
| const { currentCollection, onClearSelectedItemIds, rootName, selectedItemIds, title } = props; | ||
| const { formatMessage } = useIntl(); | ||
|
|
||
| // Generate selected item text based on selected keys | ||
| const selectedItemText = useMemo(() => { | ||
| const selectedCount = selectedItemIds === 'all' ? currentCollection.items.length : selectedItemIds.size; | ||
|
|
||
| if (typeof selectedCount !== 'number' || selectedCount === 0) { | ||
| return ''; | ||
| } | ||
jfox16 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // Case 1: Single selected item - show item name | ||
| if (selectedCount === 1) { | ||
| const selectedKey = | ||
| selectedItemIds === 'all' ? currentCollection.items[0].id : selectedItemIds.values().next().value; | ||
| const selectedItem = currentCollection.items.find(item => item.id === selectedKey); | ||
| if (typeof selectedItem?.name === 'string') { | ||
| return selectedItem.name as string; | ||
| } | ||
| } | ||
| // Case 2: Multiple selected items - show count | ||
| if (selectedCount > 1) { | ||
| return formatMessage(messages.numFilesSelected, { numSelected: selectedCount }); | ||
| } | ||
| return ''; | ||
| }, [currentCollection.items, formatMessage, selectedItemIds]); | ||
|
|
||
| // Case 1 and 2: selected item text with X button | ||
| if (selectedItemText) { | ||
| return ( | ||
| <PageHeader.Root className="be-sub-header-left-v2-selected" variant="default"> | ||
| <PageHeader.Corner> | ||
| <IconButton | ||
| aria-label="Clear selection" | ||
jfox16 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| icon={XMark} | ||
| onClick={onClearSelectedItemIds} | ||
| variant="small-utility" | ||
| /> | ||
| </PageHeader.Corner> | ||
|
|
||
| <PageHeader.StartElements> | ||
| <Text as="p">{selectedItemText}</Text> | ||
jfox16 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| </PageHeader.StartElements> | ||
| </PageHeader.Root> | ||
| ); | ||
| } | ||
|
|
||
| // Case 3: No selected items - show title if provided, otherwise show root name | ||
| return ( | ||
| <Text as="h1" variant="titleXLarge"> | ||
| {title || rootName} | ||
jfox16 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| </Text> | ||
| ); | ||
| }; | ||
|
|
||
| export default SubHeaderLeftV2; | ||
109 changes: 109 additions & 0 deletions
109
src/elements/common/sub-header/__tests__/SubHeaderLeftV2.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| import * as React from 'react'; | ||
| import { render, screen } from '../../../../test-utils/testing-library'; | ||
| import SubHeaderLeftV2 from '../SubHeaderLeftV2'; | ||
| import type { Collection } from '../../../../common/types/core'; | ||
| import type { SubHeaderLeftV2Props } from '../SubHeaderLeftV2'; | ||
|
|
||
| const mockCollection: Collection = { | ||
| items: [ | ||
| { id: '1', name: 'file1.txt' }, | ||
| { id: '2', name: 'file2.txt' }, | ||
| { id: '3', name: 'file3.txt' }, | ||
| ], | ||
| }; | ||
|
|
||
| const defaultProps: SubHeaderLeftV2Props = { | ||
| currentCollection: mockCollection, | ||
| selectedItemIds: new Set(), | ||
| }; | ||
|
|
||
| const renderComponent = (props: Partial<SubHeaderLeftV2Props> = {}) => | ||
| render(<SubHeaderLeftV2 {...defaultProps} {...props} />); | ||
|
|
||
| describe('elements/common/sub-header/SubHeaderLeftV2', () => { | ||
| describe('when no items are selected', () => { | ||
| test('should render title if provided', () => { | ||
| renderComponent({ | ||
| rootName: 'Custom Folder', | ||
| title: 'Custom Title', | ||
| selectedItemIds: new Set(), | ||
| }); | ||
|
|
||
| expect(screen.getByText('Custom Title')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| test('should render root name if no title is provided', () => { | ||
| renderComponent({ | ||
| rootName: 'Custom Folder', | ||
| title: undefined, | ||
| selectedItemIds: new Set(), | ||
| }); | ||
|
|
||
| expect(screen.getByText('Custom Folder')).toBeInTheDocument(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('when items are selected', () => { | ||
| test('should render single selected item name', () => { | ||
| renderComponent({ | ||
| selectedItemIds: new Set(['1']), | ||
| }); | ||
|
|
||
| expect(screen.getByText('file1.txt')).toBeInTheDocument(); | ||
| expect(screen.getByRole('button')).toBeInTheDocument(); // Close button | ||
| }); | ||
|
|
||
| test('should render multiple selected items count', () => { | ||
| renderComponent({ | ||
| selectedItemIds: new Set(['1', '2']), | ||
| }); | ||
|
|
||
| expect(screen.getByText('2 files selected')).toBeInTheDocument(); | ||
| expect(screen.getByRole('button')).toBeInTheDocument(); // Close button | ||
| }); | ||
|
|
||
| test('should render all items selected count', () => { | ||
| renderComponent({ | ||
| selectedItemIds: 'all', | ||
| }); | ||
|
|
||
| expect(screen.getByText('3 files selected')).toBeInTheDocument(); | ||
| expect(screen.getByRole('button')).toBeInTheDocument(); // Close button | ||
| }); | ||
|
|
||
| test('should call onClearSelectedItemIds when close button is clicked', () => { | ||
| const mockOnClearSelectedItemIds = jest.fn(); | ||
|
|
||
| renderComponent({ | ||
| selectedItemIds: new Set(['1']), | ||
| onClearSelectedItemIds: mockOnClearSelectedItemIds, | ||
| }); | ||
|
|
||
| const closeButton = screen.getByRole('button'); | ||
| closeButton.click(); | ||
|
|
||
| expect(mockOnClearSelectedItemIds).toHaveBeenCalledTimes(1); | ||
| }); | ||
|
|
||
| test('should handle selected item not found in collection', () => { | ||
| renderComponent({ | ||
| selectedItemIds: new Set(['999']), // Non-existent ID | ||
| }); | ||
|
|
||
| // Should not crash and should not render any selected item text | ||
| expect(screen.queryByText('file1.txt')).not.toBeInTheDocument(); | ||
| expect(screen.queryByText('file2.txt')).not.toBeInTheDocument(); | ||
| expect(screen.queryByText('file3.txt')).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| test('should handle empty collection with selected items', () => { | ||
| renderComponent({ | ||
| currentCollection: { items: [] }, | ||
| selectedItemIds: new Set(['1']), | ||
| }); | ||
|
|
||
| // Should not crash and should not render any selected item text | ||
| expect(screen.queryByText('file1.txt')).not.toBeInTheDocument(); | ||
| }); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.