Skip to content

Commit 72e7fbf

Browse files
fix: Replace defaultProps with inline defaults (#4385)
* fix: Replace defaultProps with inline defaults * fix: Convert SidebarContent and SecurityBadge to tsx * fix: Remove () => {} * fix: unnecessary prop * fix: Fix flow for components --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent 5f46b8b commit 72e7fbf

File tree

19 files changed

+191
-65
lines changed

19 files changed

+191
-65
lines changed

src/components/media/MediaFigure.js.flow

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const MediaFigure = ({ as: Wrapper, className, children, ...rest }: Props) => (
2222
// that affects union types
2323
// https://github.com/facebook/flow/issues/5461
2424
MediaFigure.defaultProps = {
25-
as: 'figure',
25+
as: 'div',
2626
};
2727

2828
export default MediaFigure;

src/components/slide-carousel/SlideCarouselPrimitive.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// @flow
22
import classNames from 'classnames';
33
import * as React from 'react';
4+
import noop from 'lodash/noop';
45

56
import CarouselHeader from './CarouselHeader';
67
import SlideNavigator from './SlideNavigator';
@@ -19,10 +20,10 @@ type Props = {
1920

2021
const SlideCarouselPrimitive = ({
2122
children,
22-
className,
23+
className = '',
2324
contentHeight,
2425
idPrefix = '',
25-
onSelection,
26+
onSelection = noop,
2627
selectedIndex,
2728
title,
2829
}: Props) => {
@@ -54,10 +55,4 @@ const SlideCarouselPrimitive = ({
5455

5556
SlideCarouselPrimitive.displayName = 'SlideCarouselPrimitive';
5657

57-
SlideCarouselPrimitive.defaultProps = {
58-
className: '',
59-
idPrefix: '',
60-
onSelection: () => {},
61-
};
62-
6358
export default SlideCarouselPrimitive;

src/elements/content-sidebar/SidebarContent.js renamed to src/elements/content-sidebar/SidebarContent.js.flow

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,17 @@ type Props = {
1717
title?: React.Node,
1818
subheader?: React.Node,
1919
};
20-
const SidebarContent = ({ actions, children, className, elementId, sidebarView, title, subheader, ...rest }: Props) => {
20+
21+
const SidebarContent = ({
22+
actions,
23+
children,
24+
className,
25+
elementId,
26+
sidebarView,
27+
title,
28+
subheader,
29+
...rest
30+
}: Props) => {
2131
const label = `${elementId}${elementId === '' ? '' : '_'}${sidebarView}`;
2232
const id = `${label}-content`;
2333

@@ -48,3 +58,4 @@ SidebarContent.defaultProps = {
4858
};
4959

5060
export default SidebarContent;
61+
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/**
2+
* @file Preview sidebar content component
3+
* @author Box
4+
*/
5+
6+
import * as React from 'react';
7+
import classNames from 'classnames';
8+
import './SidebarContent.scss';
9+
10+
export interface SidebarContentProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'title'> {
11+
actions?: React.ReactNode;
12+
elementId?: string;
13+
sidebarView?: string;
14+
title?: React.ReactNode;
15+
subheader?: React.ReactNode;
16+
}
17+
18+
const SidebarContent = ({
19+
actions,
20+
children,
21+
className,
22+
elementId = '',
23+
sidebarView = '',
24+
title,
25+
subheader,
26+
...rest
27+
}: SidebarContentProps) => {
28+
const label = `${elementId}${elementId === '' ? '' : '_'}${sidebarView}`;
29+
const id = `${label}-content`;
30+
31+
return (
32+
<div
33+
aria-labelledby={label}
34+
className={classNames('bcs-content', className)}
35+
data-testid="bcs-content"
36+
id={id}
37+
role="tabpanel"
38+
{...rest}
39+
>
40+
<div className="bcs-content-header">
41+
{title && <h2 className="bcs-title">{title}</h2>}
42+
{actions}
43+
</div>
44+
{subheader && <div className="bcs-content-subheader">{subheader}</div>}
45+
<div className="bcs-scroll-content-wrapper">
46+
<div className="bcs-scroll-content">{children}</div>
47+
</div>
48+
</div>
49+
);
50+
};
51+
52+
export default SidebarContent;

src/elements/content-sidebar/__tests__/__snapshots__/ActivitySidebar.test.js.snap

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ exports[`elements/content-sidebar/ActivitySidebar render() should render the act
2323
</React.Fragment>
2424
}
2525
className="bcs-activity"
26-
elementId=""
2726
sidebarView="activity"
2827
title={
2928
<FormattedMessage

src/elements/content-sidebar/__tests__/__snapshots__/DetailsSidebar.test.js.snap

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
exports[`elements/content-sidebar/DetailsSidebar render() should render DetailsSidebar with access stats 1`] = `
44
<SidebarContent
55
className="bcs-details"
6-
elementId=""
76
sidebarView="details"
87
title={
98
<FormattedMessage
@@ -26,7 +25,6 @@ exports[`elements/content-sidebar/DetailsSidebar render() should render DetailsS
2625
exports[`elements/content-sidebar/DetailsSidebar render() should render DetailsSidebar with all components 1`] = `
2726
<SidebarContent
2827
className="bcs-details"
29-
elementId=""
3028
sidebarView="details"
3129
title={
3230
<FormattedMessage
@@ -107,7 +105,6 @@ exports[`elements/content-sidebar/DetailsSidebar render() should render DetailsS
107105
exports[`elements/content-sidebar/DetailsSidebar render() should render DetailsSidebar with notices 1`] = `
108106
<SidebarContent
109107
className="bcs-details"
110-
elementId=""
111108
sidebarView="details"
112109
title={
113110
<FormattedMessage
@@ -134,7 +131,6 @@ exports[`elements/content-sidebar/DetailsSidebar render() should render DetailsS
134131
exports[`elements/content-sidebar/DetailsSidebar render() should render DetailsSidebar with properties 1`] = `
135132
<SidebarContent
136133
className="bcs-details"
137-
elementId=""
138134
sidebarView="details"
139135
title={
140136
<FormattedMessage
@@ -172,7 +168,6 @@ exports[`elements/content-sidebar/DetailsSidebar render() should render DetailsS
172168
exports[`elements/content-sidebar/DetailsSidebar render() should render DetailsSidebar with versions 1`] = `
173169
<SidebarContent
174170
className="bcs-details"
175-
elementId=""
176171
sidebarView="details"
177172
title={
178173
<FormattedMessage
@@ -186,7 +181,6 @@ exports[`elements/content-sidebar/DetailsSidebar render() should render DetailsS
186181
exports[`elements/content-sidebar/DetailsSidebar render() should render an empty container if there is no file information 1`] = `
187182
<SidebarContent
188183
className="bcs-details"
189-
elementId=""
190184
sidebarView="details"
191185
title={
192186
<FormattedMessage

src/elements/content-sidebar/__tests__/__snapshots__/MetadataSidebar.test.js.snap

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ exports[`elements/content-sidebar/Metadata/MetadataSidebar should render Metadat
44
<SidebarContent
55
actions={null}
66
className="bcs-metadata"
7-
elementId=""
87
sidebarView="metadata"
98
title={
109
<FormattedMessage
@@ -35,7 +34,6 @@ exports[`elements/content-sidebar/Metadata/MetadataSidebar should render Metadat
3534
<SidebarContent
3635
actions={null}
3736
className="bcs-metadata"
38-
elementId=""
3937
sidebarView="metadata"
4038
title={
4139
<FormattedMessage
@@ -71,7 +69,6 @@ exports[`elements/content-sidebar/Metadata/MetadataSidebar should render Metadat
7169
/>
7270
}
7371
className="bcs-metadata"
74-
elementId=""
7572
sidebarView="metadata"
7673
title={
7774
<FormattedMessage
@@ -102,7 +99,6 @@ exports[`elements/content-sidebar/Metadata/MetadataSidebar should render error w
10299
<SidebarContent
103100
actions={null}
104101
className="bcs-metadata"
105-
elementId=""
106102
sidebarView="metadata"
107103
title={
108104
<FormattedMessage
@@ -128,7 +124,6 @@ exports[`elements/content-sidebar/Metadata/MetadataSidebar should render loading
128124
<SidebarContent
129125
actions={null}
130126
className="bcs-metadata"
131-
elementId=""
132127
sidebarView="metadata"
133128
title={
134129
<FormattedMessage
@@ -145,7 +140,6 @@ exports[`elements/content-sidebar/Metadata/MetadataSidebar should render loading
145140
<SidebarContent
146141
actions={null}
147142
className="bcs-metadata"
148-
elementId=""
149143
sidebarView="metadata"
150144
title={
151145
<FormattedMessage
@@ -162,7 +156,6 @@ exports[`elements/content-sidebar/Metadata/MetadataSidebar should render loading
162156
<SidebarContent
163157
actions={null}
164158
className="bcs-metadata"
165-
elementId=""
166159
sidebarView="metadata"
167160
title={
168161
<FormattedMessage

src/elements/content-sidebar/__tests__/__snapshots__/SkillsSidebar.test.js.snap

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
exports[`elements/content-sidebar/Skills/SkillsSidebar should render loading indicator component when cards are not available 1`] = `
44
<SidebarContent
55
className="bcs-skills"
6-
elementId=""
76
sidebarView="skills"
87
title={
98
<FormattedMessage
@@ -19,7 +18,6 @@ exports[`elements/content-sidebar/Skills/SkillsSidebar should render loading ind
1918
exports[`elements/content-sidebar/Skills/SkillsSidebar should render skills sidebar component when cards are available 1`] = `
2019
<SidebarContent
2120
className="bcs-skills"
22-
elementId=""
2321
sidebarView="skills"
2422
title={
2523
<FormattedMessage

src/features/classification/ClassifiedBadge.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@ type Props = {
1919

2020
const ICON_SIZE = 12;
2121

22-
const ClassifiedBadge = ({ color, name, onClick, tooltipPosition = 'bottom-center', tooltipText }: Props) => {
22+
const ClassifiedBadge = ({
23+
color = bdlYellow50,
24+
name,
25+
onClick,
26+
tooltipPosition = 'bottom-center',
27+
tooltipText,
28+
}: Props) => {
2329
const isClickable = typeof onClick === 'function';
2430
const isTooltipDisabled = !tooltipText;
2531
const badge = (
@@ -48,8 +54,4 @@ const ClassifiedBadge = ({ color, name, onClick, tooltipPosition = 'bottom-cente
4854
);
4955
};
5056

51-
ClassifiedBadge.defaultProps = {
52-
color: bdlYellow50,
53-
};
54-
5557
export default ClassifiedBadge;

src/features/classification/security-controls/SecurityControlsModal.js renamed to src/features/classification/security-controls/SecurityControlsModal.js.flow

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,4 @@ SecurityControlsModal.defaultProps = {
7272
};
7373

7474
export default SecurityControlsModal;
75+

0 commit comments

Comments
 (0)