Skip to content

Commit cbf2ac3

Browse files
committed
refactor(preview): use signConfig from primary props instead of feature props
1 parent 6f979d2 commit cbf2ac3

10 files changed

+47
-51
lines changed

i18n/en-US.properties

-2
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,6 @@ be.contentSidebar.boxSignRequestSignature = Request Signature
356356
be.contentSidebar.boxSignSecurityBlockedTooltip = This action is unavailable due to a security policy.
357357
# One of the dropdown options that opens a Box Sign sign myself experience
358358
be.contentSidebar.boxSignSignMyself = Sign Myself
359-
# label for button that opens a Box Sign signature fulfillment experience
360-
be.contentSidebar.boxSignSignature = Sign
361359
# Tooltip text for when Box Sign is blocked due to an item being watermarked
362360
be.contentSidebar.boxSignWatermarkBlockedTooltip = This action is unavailable, because the file is watermarked.
363361
# title for when editing an existing approval task

src/elements/content-sidebar/ContentSidebar.js

+4
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import type { DetailsSidebarProps } from './DetailsSidebar';
3434
import type { DocGenSidebarProps } from './DocGenSidebar/DocGenSidebar';
3535
import type { MetadataSidebarProps } from './MetadataSidebar';
3636
import type { VersionsSidebarProps } from './versions';
37+
import type { SignSideBarProps } from './SidebarNavSign';
3738
import type { WithLoggerProps } from '../../common/types/logging';
3839
import type { ElementsXhrError, RequestOptions, ErrorContextProps } from '../../common/types/api';
3940
import type { MetadataEditor } from '../../common/types/metadata';
@@ -84,6 +85,7 @@ type Props = {
8485
responseInterceptor?: Function,
8586
sharedLink?: string,
8687
sharedLinkPassword?: string,
88+
signSidebarProps: SignSideBarProps,
8789
token: Token,
8890
versionsSidebarProps: VersionsSidebarProps,
8991
} & ErrorContextProps &
@@ -364,6 +366,7 @@ class ContentSidebar extends React.Component<Props, State> {
364366
onVersionChange,
365367
onVersionHistoryClick,
366368
versionsSidebarProps,
369+
signSidebarProps,
367370
}: Props = this.props;
368371
const { file, isLoading, metadataEditors }: State = this.state;
369372
const initialPath = defaultView.charAt(0) === '/' ? defaultView : `/${defaultView}`;
@@ -405,6 +408,7 @@ class ContentSidebar extends React.Component<Props, State> {
405408
onVersionChange={onVersionChange}
406409
onVersionHistoryClick={onVersionHistoryClick}
407410
versionsSidebarProps={versionsSidebarProps}
411+
signSidebarProps={signSidebarProps}
408412
wrappedComponentRef={ref => {
409413
this.sidebarRef = ref;
410414
}}

src/elements/content-sidebar/Sidebar.js

+4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import type { VersionsSidebarProps } from './versions';
2929
import type { AdditionalSidebarTab } from './flowTypes';
3030
import type { MetadataEditor } from '../../common/types/metadata';
3131
import type { BoxItem, User } from '../../common/types/core';
32+
import type { SignSideBarProps } from './SidebarNavSign';
3233
import type { Errors } from '../common/flowTypes';
3334
import { SIDEBAR_VIEW_DOCGEN } from '../../constants';
3435
import API from '../../api';
@@ -66,6 +67,7 @@ type Props = {
6667
onVersionChange?: Function,
6768
onVersionHistoryClick?: Function,
6869
versionsSidebarProps: VersionsSidebarProps,
70+
signSidebarProps: SignSideBarProps,
6971
};
7072

7173
type State = {
@@ -305,6 +307,7 @@ class Sidebar extends React.Component<Props, State> {
305307
onAnnotationSelect,
306308
onVersionChange,
307309
versionsSidebarProps,
310+
signSidebarProps,
308311
}: Props = this.props;
309312
const isOpen = this.isOpen();
310313
const hasBoxAI = SidebarUtils.canHaveBoxAISidebar(this.props);
@@ -339,6 +342,7 @@ class Sidebar extends React.Component<Props, State> {
339342
hasMetadata={hasMetadata}
340343
hasSkills={hasSkills}
341344
hasDocGen={docGenSidebarProps.isDocGenTemplate}
345+
signSideBarProps={signSidebarProps}
342346
isOpen={isOpen}
343347
onPanelChange={this.handlePanelChange}
344348
/>

src/elements/content-sidebar/SidebarNav.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {
3333
import { useFeatureConfig } from '../common/feature-checking';
3434
import type { NavigateOptions, AdditionalSidebarTab } from './flowTypes';
3535
import './SidebarNav.scss';
36+
import type { SignSideBarProps } from './SidebarNavSign';
3637

3738
type Props = {
3839
additionalTabs?: Array<AdditionalSidebarTab>,
@@ -49,6 +50,7 @@ type Props = {
4950
isOpen?: boolean,
5051
onNavigate?: (SyntheticEvent<>, NavigateOptions) => void,
5152
onPanelChange?: (name: string, isInitialState: boolean) => void,
53+
signSideBarProps: SignSideBarProps,
5254
};
5355

5456
const SidebarNav = ({
@@ -66,8 +68,9 @@ const SidebarNav = ({
6668
isOpen,
6769
onNavigate,
6870
onPanelChange = noop,
71+
signSideBarProps,
6972
}: Props) => {
70-
const { enabled: hasBoxSign } = useFeatureConfig('boxSign');
73+
const { enabled: hasBoxSign } = signSideBarProps || {};
7174
const { disabledTooltip: boxAIDisabledTooltip, showOnlyNavButton: showOnlyBoxAINavButton } =
7275
useFeatureConfig('boxai.sidebar');
7376

@@ -159,7 +162,7 @@ const SidebarNav = ({
159162

160163
{hasBoxSign && (
161164
<div className="bcs-SidebarNav-secondary">
162-
<SidebarNavSign />
165+
<SidebarNavSign {...signSideBarProps} />
163166
</div>
164167
)}
165168

src/elements/content-sidebar/SidebarNavSign.tsx

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import * as React from 'react';
22
import { FormattedMessage } from 'react-intl';
33

4-
// @ts-ignore Module is written in Flow
5-
import { useFeatureConfig } from '../common/feature-checking';
64
// @ts-ignore Module is written in Flow
75
import { SIDEBAR_NAV_TARGETS } from '../common/interactionTargets';
86

@@ -17,21 +15,29 @@ import { Menu, MenuItem } from '../../components/menu';
1715
import messages from './messages';
1816

1917
import './SidebarNavSign.scss';
18+
// @ts-ignore Module is written in Flow
19+
import type { TargetingApi } from '../../features/targeting/types';
20+
21+
export interface SignSideBarProps {
22+
blockedReason: string;
23+
enabled: boolean;
24+
onClick: () => void;
25+
onClickSignMyself: () => void;
26+
targetingApi: TargetingApi | null;
27+
}
2028

21-
export function SidebarNavSign() {
29+
export function SidebarNavSign(signSideBarProps: SignSideBarProps) {
2230
const {
2331
blockedReason: boxSignBlockedReason,
2432
onClick: onBoxClickRequestSignature,
2533
onClickSignMyself: onBoxClickSignMyself,
26-
status: boxSignStatus,
2734
targetingApi: boxSignTargetingApi,
28-
} = useFeatureConfig('boxSign');
35+
} = signSideBarProps;
2936

3037
return (
3138
<DropdownMenu isResponsive constrainToWindow isRightAligned>
3239
<SidebarNavSignButton
3340
blockedReason={boxSignBlockedReason}
34-
status={boxSignStatus}
3541
targetingApi={boxSignTargetingApi}
3642
data-resin-target={SIDEBAR_NAV_TARGETS.SIGN}
3743
/>

src/elements/content-sidebar/SidebarNavSignButton.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ export type Props = PlainButtonProps & {
2525

2626
export const PlaceholderTooltip = ({ children }: { children: React.ReactNode }) => children;
2727

28-
export function SidebarNavSignButton({ blockedReason, intl, status, targetingApi, ...rest }: Props) {
28+
export function SidebarNavSignButton({ blockedReason, intl, targetingApi, ...rest }: Props) {
2929
const isSignDisabled = !!blockedReason;
30-
const isTargeted = targetingApi && targetingApi.canShow;
30+
const isTargeted = targetingApi?.canShow;
3131
const FtuxTooltip = !isSignDisabled && isTargeted ? TargetedClickThroughGuideTooltip : PlaceholderTooltip;
32-
const label = intl.formatMessage(status === 'active' ? messages.boxSignSignature : messages.boxSignRequest);
32+
const label = intl.formatMessage(messages.boxSignRequest);
3333
const buttonClassName = classnames('bcs-SidebarNavSignButton', { 'bdl-is-disabled': isSignDisabled });
3434

3535
let tooltipMessage = label;

src/elements/content-sidebar/__tests__/SidebarNav.test.js

+4-8
Original file line numberDiff line numberDiff line change
@@ -166,19 +166,15 @@ describe('elements/content-sidebar/SidebarNav', () => {
166166
});
167167

168168
test('should render the Box Sign entry point if its feature is enabled', () => {
169-
const features = {
170-
boxSign: {
169+
const props = {
170+
signSideBarProps: {
171171
enabled: true,
172172
onClick: () => {},
173173
},
174174
};
175-
const wrapper = getWrapper({}, 'activity', features);
176-
expect(wrapper.exists(SidebarNavSignButton)).toBe(true);
177-
});
175+
const wrapper = getWrapper(props);
178176

179-
test('should not render the Box Sign entry point if its feature is not enabled', () => {
180-
const wrapper = getWrapper();
181-
expect(wrapper.exists(SidebarNavSignButton)).toBe(false);
177+
expect(wrapper.exists(SidebarNavSignButton)).toBe(true);
182178
});
183179
test('should render docgen tab', () => {
184180
const props = {

src/elements/content-sidebar/__tests__/SidebarNavSign.test.tsx

+11-16
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,15 @@ describe('elements/content-sidebar/SidebarNavSign', () => {
88
const onClickRequestSignature = jest.fn();
99
const onClickSignMyself = jest.fn();
1010

11-
const renderComponent = (props = {}, features = {}) =>
12-
render(<SidebarNavSign {...props} />, {
13-
wrapperProps: { features },
14-
});
11+
const defaultSignSideBarProps = {
12+
blockedReason: '',
13+
enabled: true,
14+
onClick: onClickRequestSignature,
15+
onClickSignMyself,
16+
targetingApi: null,
17+
};
18+
19+
const renderComponent = () => render(<SidebarNavSign {...defaultSignSideBarProps} />, {});
1520

1621
test('should render sign button', async () => {
1722
renderComponent();
@@ -29,12 +34,7 @@ describe('elements/content-sidebar/SidebarNavSign', () => {
2934
});
3035

3136
test('should call correct handler when request signature option is clicked', async () => {
32-
const features = {
33-
boxSign: {
34-
onClick: onClickRequestSignature,
35-
},
36-
};
37-
renderComponent({}, features);
37+
renderComponent();
3838

3939
await userEvent.click(screen.getByRole('button', { name: 'Request Signature' }));
4040
await userEvent.click(screen.getByRole('menuitem', { name: 'Request Signature' }));
@@ -43,12 +43,7 @@ describe('elements/content-sidebar/SidebarNavSign', () => {
4343
});
4444

4545
test('should call correct handler when sign myself option is clicked', async () => {
46-
const features = {
47-
boxSign: {
48-
onClickSignMyself,
49-
},
50-
};
51-
renderComponent({}, features);
46+
renderComponent();
5247

5348
await userEvent.click(screen.getByRole('button', { name: 'Request Signature' }));
5449
await userEvent.click(screen.getByRole('menuitem', { name: 'Sign Myself' }));

src/elements/content-sidebar/__tests__/SidebarNavSignButton.test.tsx

+4-9
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,11 @@ import Tooltip from '../../../components/tooltip';
1010
describe('elements/content-sidebar/SidebarNavSignButton', () => {
1111
const getWrapper = (props = {}) => shallow(<SidebarNavSignButton {...props} />).dive();
1212

13-
test.each`
14-
status | label
15-
${undefined} | ${'Request Signature'}
16-
${'random'} | ${'Request Signature'}
17-
${'active'} | ${'Sign'}
18-
`('should render the correct label based on the current signature status', ({ label, status }) => {
19-
const wrapper = getWrapper({ status });
13+
test('should render the correct label', () => {
14+
const wrapper = getWrapper();
2015

21-
expect(wrapper.find(Tooltip).prop('text')).toBe(label);
22-
expect(wrapper.find(PlainButton).prop('aria-label')).toBe(label);
16+
expect(wrapper.find(Tooltip).prop('text')).toBe('Request Signature');
17+
expect(wrapper.find(PlainButton).prop('aria-label')).toBe('Request Signature');
2318
expect(wrapper.exists(BoxSign28)).toBe(true);
2419
});
2520

src/elements/content-sidebar/messages.js

-5
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,6 @@ const messages = defineMessages({
5757
defaultMessage: 'Sign Myself',
5858
description: 'One of the dropdown options that opens a Box Sign sign myself experience',
5959
},
60-
boxSignSignature: {
61-
id: 'be.contentSidebar.boxSignSignature',
62-
defaultMessage: 'Sign',
63-
description: 'label for button that opens a Box Sign signature fulfillment experience',
64-
},
6560
boxSignSecurityBlockedTooltip: {
6661
defaultMessage: 'This action is unavailable due to a security policy.',
6762
description: 'Tooltip text for when Box Sign is blocked due to a security policy',

0 commit comments

Comments
 (0)