Skip to content

Commit e25e0e1

Browse files
feat(router): optional router in SidebarNavigation (#4194)
* feat(router): optional router in SidebarNavigation * feat(router): Flow errors fix * feat(router): Fixes after review * feat(router): optional router in PreviewNavigation
1 parent dd19958 commit e25e0e1

File tree

7 files changed

+314
-441
lines changed

7 files changed

+314
-441
lines changed

src/elements/common/types/SidebarNavigation.js.flow

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55

66
export const ViewType = Object.freeze({
77
BOXAI: 'boxai',
8-
SKILLS: 'skills',
9-
ACTIVITY: 'activity',
108
DETAILS: 'details',
119
METADATA: 'metadata',
10+
METADATA_REDESIGN: 'metadata_redesign',
11+
SKILLS: 'skills',
12+
ACTIVITY: 'activity',
13+
VERSIONS: 'versions',
1214
DOCGEN: 'docgen',
1315
});
1416

@@ -22,11 +24,12 @@ export type ViewTypeValues = $Values<typeof ViewType>;
2224
export type FeedEntryTypeValues = $Values<typeof FeedEntryType>;
2325

2426
export type SidebarNavigation = {
25-
sidebar: ViewTypeValues,
26-
versionId?: string,
2727
activeFeedEntryType?: FeedEntryTypeValues,
2828
activeFeedEntryId?: string,
2929
fileVersionId?: string,
30+
filteredTemplateIds?: string,
31+
sidebar: ViewTypeValues,
32+
versionId?: string,
3033
};
3134

3235
export type InternalSidebarNavigation = SidebarNavigation & {

src/elements/common/types/SidebarNavigation.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
export enum ViewType {
2-
BOXAI = 'boxai',
32
SKILLS = 'skills',
4-
ACTIVITY = 'activity',
53
DETAILS = 'details',
64
METADATA = 'metadata',
5+
METADATA_REDESIGN = 'metadata_redesign',
6+
BOXAI = 'boxai',
7+
ACTIVITY = 'activity',
8+
VERSIONS = 'versions',
79
DOCGEN = 'docgen',
810
}
911

@@ -18,6 +20,11 @@ type VersionSidebarView = {
1820
versionId: string;
1921
};
2022

23+
export type MetadataSidebarView = {
24+
sidebar: ViewType.METADATA | ViewType.METADATA_REDESIGN;
25+
filteredTemplateIds?: string;
26+
};
27+
2128
export type ActivityAnnotationsSidebarView = {
2229
sidebar: ViewType.ACTIVITY;
2330
activeFeedEntryType: FeedEntryType.ANNOTATIONS;
@@ -35,6 +42,7 @@ export type SidebarNavigation =
3542
sidebar: ViewType;
3643
}
3744
| VersionSidebarView
45+
| MetadataSidebarView
3846
| ActivityCommentsSidebarView
3947
| ActivityAnnotationsSidebarView;
4048

src/elements/content-preview/PreviewNavigation.js

Lines changed: 86 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,26 @@ import PlainButton from '../../components/plain-button/PlainButton';
1414
import messages from '../common/messages';
1515
import type { BoxItem } from '../../common/types/core';
1616
import { SIDEBAR_VIEW_METADATA } from '../../constants';
17+
import type { InternalSidebarNavigation, InternalSidebarNavigationHandler } from '../common/types/SidebarNavigation';
1718

1819
type Props = {
1920
collection: Array<string | BoxItem>,
2021
currentIndex: number,
2122
intl: IntlShape,
23+
internalSidebarNavigation?: InternalSidebarNavigation,
24+
internalSidebarNavigationHandler?: InternalSidebarNavigationHandler,
2225
onNavigateLeft: Function,
2326
onNavigateRight: Function,
27+
routerDisabled?: boolean,
2428
};
2529

26-
const PreviewNavigation = ({ collection = [], currentIndex, intl, onNavigateLeft, onNavigateRight }: Props) => {
30+
const PreviewNavigationWithRouter = ({
31+
collection = [],
32+
currentIndex,
33+
intl,
34+
onNavigateLeft,
35+
onNavigateRight,
36+
}: Props) => {
2737
const hasLeftNavigation = collection.length > 1 && currentIndex > 0 && currentIndex < collection.length;
2838
const hasRightNavigation = collection.length > 1 && currentIndex > -1 && currentIndex < collection.length - 1;
2939

@@ -48,6 +58,7 @@ const PreviewNavigation = ({ collection = [], currentIndex, intl, onNavigateLeft
4858
{hasLeftNavigation && (
4959
<PlainButton
5060
className="bcpr-navigate-left"
61+
data-testid="preview-navigation-left"
5162
onClick={() => {
5263
goToActiveSidebarTab(match.params, history);
5364
onNavigateLeft();
@@ -61,6 +72,7 @@ const PreviewNavigation = ({ collection = [], currentIndex, intl, onNavigateLeft
6172
{hasRightNavigation && (
6273
<PlainButton
6374
className="bcpr-navigate-right"
75+
data-testid="preview-navigation-right"
6476
onClick={() => {
6577
goToActiveSidebarTab(match.params, history);
6678
onNavigateRight();
@@ -77,5 +89,77 @@ const PreviewNavigation = ({ collection = [], currentIndex, intl, onNavigateLeft
7789
);
7890
};
7991

80-
export { PreviewNavigation as PreviewNavigationComponent };
92+
const PreviewNavigationWithoutRouter = ({
93+
collection = [],
94+
currentIndex,
95+
intl,
96+
internalSidebarNavigation,
97+
internalSidebarNavigationHandler,
98+
onNavigateLeft,
99+
onNavigateRight,
100+
}: Props) => {
101+
const hasLeftNavigation = collection.length > 1 && currentIndex > 0 && currentIndex < collection.length;
102+
const hasRightNavigation = collection.length > 1 && currentIndex > -1 && currentIndex < collection.length - 1;
103+
104+
if (!hasLeftNavigation && !hasRightNavigation) {
105+
return null;
106+
}
107+
108+
const handleInternalNavigation = () => {
109+
if (internalSidebarNavigationHandler && internalSidebarNavigation && internalSidebarNavigation.sidebar) {
110+
const { sidebar, ...rest } = internalSidebarNavigation;
111+
const hasDeeplink = Object.keys(rest).length > 0;
112+
113+
if (hasDeeplink && sidebar === SIDEBAR_VIEW_METADATA) {
114+
internalSidebarNavigationHandler(internalSidebarNavigation);
115+
} else {
116+
internalSidebarNavigationHandler({ sidebar });
117+
}
118+
}
119+
};
120+
121+
return (
122+
<>
123+
{hasLeftNavigation && (
124+
<PlainButton
125+
className="bcpr-navigate-left"
126+
data-testid="preview-navigation-left"
127+
onClick={() => {
128+
handleInternalNavigation();
129+
onNavigateLeft();
130+
}}
131+
title={intl.formatMessage(messages.previousFile)}
132+
type="button"
133+
>
134+
<IconNavigateLeft />
135+
</PlainButton>
136+
)}
137+
{hasRightNavigation && (
138+
<PlainButton
139+
className="bcpr-navigate-right"
140+
data-testid="preview-navigation-right"
141+
onClick={() => {
142+
handleInternalNavigation();
143+
onNavigateRight();
144+
}}
145+
title={intl.formatMessage(messages.nextFile)}
146+
type="button"
147+
>
148+
<IconNavigateRight />
149+
</PlainButton>
150+
)}
151+
</>
152+
);
153+
};
154+
155+
const PreviewNavigation = (props: Props) => {
156+
const { routerDisabled = false } = props;
157+
158+
if (routerDisabled) {
159+
return <PreviewNavigationWithoutRouter {...props} />;
160+
}
161+
162+
return <PreviewNavigationWithRouter {...props} />;
163+
};
164+
81165
export default injectIntl(PreviewNavigation);

0 commit comments

Comments
 (0)