Skip to content

Commit c51d1f6

Browse files
authored
feat(content-explorer): migrate empty state to blueprint (#3931)
* feat(content-explorer): migrate empty state to blueprint * fix: add unit tests * fix: flow type * fix: e2e test * fix: update apostrophe
1 parent 9e8065e commit c51d1f6

File tree

17 files changed

+159
-246
lines changed

17 files changed

+159
-246
lines changed

i18n/en-US.properties

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,20 @@ be.drawAnnotation = Drawing annotation mode
432432
be.editLabel = Edit
433433
# Message to the user when there are no Open With integrations
434434
be.emptyOpenWithDescription = No integrations are available for this file
435+
# Text shown in the empty state when there is an error
436+
be.emptyView.errorState = A network error has occurred while trying to load.
437+
# Text shown in the empty state when there are no folder items
438+
be.emptyView.folderState = There are no items in this folder.
439+
# Text shown in the empty state when the folder items are loading
440+
be.emptyView.loadingState = Please wait while the items load...
441+
# Text shown in the empty state when there are no items for the metadata query
442+
be.emptyView.metadataState = There are no items in this folder.
443+
# Text shown in the empty state when there are no recent items
444+
be.emptyView.recentsState = There are no recent items yet.
445+
# Text shown in the empty state when there no results for the search query
446+
be.emptyView.searchState = Sorry, we couldn't find what you're looking for.
447+
# Text shown in the empty state when there are no selected items
448+
be.emptyView.selectedState = You haven't selected any items yet.
435449
# Generic error label.
436450
be.error = Error
437451
# Default label for signifying error in the sub header.
@@ -440,8 +454,6 @@ be.errorBreadcrumb = Error
440454
be.errorOccured = An error occurred
441455
# Message to the user when the open with element errors
442456
be.errorOpenWithDescription = Opening this file with other services is currently unavailable
443-
# Message shown when there is an error.
444-
be.errorState = A network error has occurred while trying to load.
445457
# Header message to the user when an Open With integration fails to execute
446458
be.executeIntegrationOpenWithErrorHeader = We’re sorry, this integration is currently unavailable.
447459
# Sub header message to the user when an Open With integration fails to execute
@@ -468,8 +480,6 @@ be.fileDescriptionInlineErrorTitleMessage = Something went wrong when saving the
468480
be.fileRequestDisplayName = File Request
469481
# Icon title for a Box item of type folder
470482
be.folder = Folder
471-
# Message shown when there are no folder items.
472-
be.folderState = There are no items in this folder.
473483
# Aria label for button to get information about a file’s versions
474484
be.getVersionInfo = Get version information
475485
# Label for switching to grid view
@@ -534,8 +544,6 @@ be.keywordsList = Keywords: {words}
534544
be.listView = Switch to List View
535545
# Label for loading state.
536546
be.loading = Loading
537-
# Message shown when folder items are still fetching.
538-
be.loadingState = Please wait while the items load...
539547
# Placeholder for a logo.
540548
be.logo = Logo
541549
# Indicator on the footer that max items have been selected.
@@ -556,8 +564,6 @@ be.messageCenter.previewError = Sorry, we're having trouble showing this image.
556564
be.messageCenter.product = Product
557565
# Title for the message center modal
558566
be.messageCenter.title = What's New
559-
# Message shown when there are no items for provided metadata query.
560-
be.metadataState = There are no items in this folder.
561567
# Text for modified date with modified prefix.
562568
be.modifiedDate = Modified {date}
563569
# Text for modified date with user with modified prefix.
@@ -612,8 +618,6 @@ be.print = Print
612618
be.priorCollaborator = A Prior Collaborator
613619
# Shown as the title in the sub header when showing recents.
614620
be.recentsBreadcrumb = Recents
615-
# Message shown when there are no recent items.
616-
be.recentsState = There are no recent items yet.
617621
# Label for reload button.
618622
be.reload = Reload
619623
# Label for remove action.
@@ -644,14 +648,10 @@ be.save = Save
644648
be.searchBreadcrumb = Search Results
645649
# Shown as a placeholder in the search box.
646650
be.searchPlaceholder = Search files and folders
647-
# Message shown when there are no search results.
648-
be.searchState = Sorry, we couldn’t find what you’re looking for.
649651
# Default label for selected items list in the footer.
650652
be.selected = {count} Selected
651653
# Shown as the title in the sub header while showing selected items.
652654
be.selectedBreadcrumb = Selected Items
653-
# Message shown when there are no selected items.
654-
be.selectedState = You haven’t selected any items yet.
655655
# Label for share action.
656656
be.share = Share
657657
# Dropdown select option for collaborator share access.

src/elements/common/empty-state/EmptyState.js.flow

Lines changed: 0 additions & 53 deletions
This file was deleted.

src/elements/common/empty-state/EmptyState.scss

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/elements/common/empty-state/EmptyState.tsx

Lines changed: 0 additions & 48 deletions
This file was deleted.

src/elements/common/empty-state/index.js.flow

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/elements/common/empty-state/index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import React from 'react';
2+
import { useIntl } from 'react-intl';
3+
4+
import { EmptyState, Text } from '@box/blueprint-web';
5+
import { Files, FolderFloat, HatWand, OpenBook } from '@box/blueprint-web-assets/illustrations/Medium';
6+
7+
import { VIEW_ERROR, VIEW_FOLDER, VIEW_METADATA, VIEW_SEARCH, VIEW_SELECTED } from '../../../constants';
8+
9+
import messages from './messages';
10+
11+
import type { View } from '../../../common/types/core';
12+
13+
export interface EmptyViewProps {
14+
isLoading: boolean;
15+
view: View;
16+
}
17+
18+
const EmptyView = ({ isLoading, view }: EmptyViewProps) => {
19+
const { formatMessage } = useIntl();
20+
21+
let icon;
22+
let text = formatMessage(messages[`${view}State`]);
23+
24+
if (isLoading && (view === VIEW_FOLDER || view === VIEW_METADATA)) {
25+
text = formatMessage(messages.loadingState);
26+
}
27+
28+
switch (view) {
29+
case VIEW_ERROR:
30+
icon = HatWand;
31+
break;
32+
case VIEW_SELECTED:
33+
icon = Files;
34+
break;
35+
case VIEW_SEARCH:
36+
icon = OpenBook;
37+
break;
38+
default:
39+
icon = FolderFloat;
40+
break;
41+
}
42+
43+
return <EmptyState body={<Text as="p">{text}</Text>} illustration={icon} />;
44+
};
45+
46+
export default EmptyView;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import React from 'react';
2+
import { render, screen } from '../../../../test-utils/testing-library';
3+
import EmptyView from '../EmptyView';
4+
5+
describe('elements/common/empty-view/EmptyView', () => {
6+
const renderComponent = (props = {}) => {
7+
const defaultProps = {
8+
isLoading: false,
9+
view: 'folder',
10+
};
11+
render(<EmptyView {...defaultProps} {...props} />);
12+
};
13+
14+
test.each`
15+
view | text
16+
${'error'} | ${'A network error has occurred while trying to load.'}
17+
${'folder'} | ${'There are no items in this folder.'}
18+
${'metadata'} | ${'There are no items in this folder.'}
19+
${'recents'} | ${'There are no recent items yet.'}
20+
${'search'} | ${"Sorry, we couldn't find what you're looking for."}
21+
${'selected'} | ${"You haven't selected any items yet."}
22+
`('renders component correctly when the view is `$view`', ({ text, view }) => {
23+
renderComponent({ view });
24+
expect(screen.getByRole('paragraph')).toHaveTextContent(text);
25+
});
26+
27+
test('renders component correctly when items are being fetched', () => {
28+
renderComponent({ isLoading: true });
29+
expect(screen.getByRole('paragraph')).toHaveTextContent('Please wait while the items load...');
30+
});
31+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from './EmptyView';
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { defineMessages } from 'react-intl';
2+
3+
const messages = defineMessages({
4+
errorState: {
5+
id: 'be.emptyView.errorState',
6+
description: 'Text shown in the empty state when there is an error',
7+
defaultMessage: 'A network error has occurred while trying to load.',
8+
},
9+
folderState: {
10+
id: 'be.emptyView.folderState',
11+
description: 'Text shown in the empty state when there are no folder items',
12+
defaultMessage: 'There are no items in this folder.',
13+
},
14+
loadingState: {
15+
id: 'be.emptyView.loadingState',
16+
description: 'Text shown in the empty state when the folder items are loading',
17+
defaultMessage: 'Please wait while the items load...',
18+
},
19+
metadataState: {
20+
id: 'be.emptyView.metadataState',
21+
description: 'Text shown in the empty state when there are no items for the metadata query',
22+
defaultMessage: 'There are no items in this folder.',
23+
},
24+
recentsState: {
25+
id: 'be.emptyView.recentsState',
26+
description: 'Text shown in the empty state when there are no recent items',
27+
defaultMessage: 'There are no recent items yet.',
28+
},
29+
searchState: {
30+
id: 'be.emptyView.searchState',
31+
description: 'Text shown in the empty state when there no results for the search query',
32+
defaultMessage: "Sorry, we couldn't find what you're looking for.",
33+
},
34+
selectedState: {
35+
id: 'be.emptyView.selectedState',
36+
description: 'Text shown in the empty state when there are no selected items',
37+
defaultMessage: "You haven't selected any items yet.",
38+
},
39+
});
40+
41+
export default messages;

0 commit comments

Comments
 (0)