Skip to content
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

Replace defaultProps with default parameters #5278

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
186 changes: 73 additions & 113 deletions packages/api/src/hooks/Composer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,23 +141,23 @@ function createCardActionContext({
getSignInUrl:
cardAction.type === 'signin'
? () => {
const { value } = cardAction;

if (directLine.getSessionId) {
/**
* @todo TODO: [P3] We should change this one to async/await.
* This is the first place in this project to use async.
* Thus, we need to add @babel/plugin-transform-runtime and @babel/runtime.
*/
return observableToPromise(directLine.getSessionId(), ponyfill).then(
sessionId => `${value}${encodeURIComponent(`&code_challenge=${sessionId}`)}`
);
}

console.warn('botframework-webchat: OAuth is not supported on this Direct Line adapter.');

return value;
const { value } = cardAction;

if (directLine.getSessionId) {
/**
* @todo TODO: [P3] We should change this one to async/await.
* This is the first place in this project to use async.
* Thus, we need to add @babel/plugin-transform-runtime and @babel/runtime.
*/
return observableToPromise(directLine.getSessionId(), ponyfill).then(
sessionId => `${value}${encodeURIComponent(`&code_challenge=${sessionId}`)}`
);
}

console.warn('botframework-webchat: OAuth is not supported on this Direct Line adapter.');

return value;
}
: null,
target
});
Expand Down Expand Up @@ -252,34 +252,34 @@ type ComposerCoreProps = Readonly<{
}>;

const ComposerCore = ({
activityMiddleware,
activityStatusMiddleware,
attachmentForScreenReaderMiddleware,
attachmentMiddleware,
avatarMiddleware,
cardActionMiddleware,
children,
dir,
activityMiddleware = undefined,
activityStatusMiddleware = undefined,
attachmentForScreenReaderMiddleware = undefined,
attachmentMiddleware = undefined,
avatarMiddleware = undefined,
cardActionMiddleware = undefined,
children = undefined,
dir = 'auto',
directLine,
disabled,
downscaleImageToDataURL,
grammars,
groupActivitiesMiddleware,
internalErrorBoxClass,
locale,
onTelemetry,
overrideLocalizedStrings,
renderMarkdown,
scrollToEndButtonMiddleware,
selectVoice,
disabled = false,
downscaleImageToDataURL = undefined,
grammars = [],
groupActivitiesMiddleware = undefined,
internalErrorBoxClass = undefined,
locale = window.navigator.language || 'en-US',
onTelemetry = undefined,
overrideLocalizedStrings = undefined,
renderMarkdown = undefined,
scrollToEndButtonMiddleware = undefined,
selectVoice = undefined,
sendBoxMiddleware,
sendBoxToolbarMiddleware,
sendTypingIndicator,
styleOptions,
toastMiddleware,
typingIndicatorMiddleware,
userID,
username
sendTypingIndicator = false,
styleOptions = {},
toastMiddleware = undefined,
typingIndicatorMiddleware = undefined,
userID = '',
username = ''
}: ComposerCoreProps) => {
const [ponyfill] = usePonyfill();
const dispatch = useDispatch();
Expand Down Expand Up @@ -398,13 +398,13 @@ const ComposerCore = ({
...singleToArray(activityMiddleware),
() =>
() =>
({ activity }) => {
if (activity) {
throw new Error(`No renderer for activity of type "${activity.type}"`);
} else {
throw new Error('No activity to render');
({ activity }) => {
if (activity) {
throw new Error(`No renderer for activity of type "${activity.type}"`);
} else {
throw new Error('No activity to render');
}
}
}
)({}),
[activityMiddleware]
);
Expand All @@ -428,19 +428,19 @@ const ComposerCore = ({
...singleToArray(attachmentForScreenReaderMiddleware),
() =>
() =>
({ attachment }) => {
if (attachment) {
console.warn(`No renderer for attachment for screen reader of type "${attachment.contentType}"`);
return false;
}
({ attachment }) => {
if (attachment) {
console.warn(`No renderer for attachment for screen reader of type "${attachment.contentType}"`);
return false;
}

return () => {
/**
* @todo TODO: [P4] Might be able to throw without returning a function -- investigate and possibly fix
*/
throw new Error('No attachment to render');
};
}
return () => {
/**
* @todo TODO: [P4] Might be able to throw without returning a function -- investigate and possibly fix
*/
throw new Error('No attachment to render');
};
}
)({}),
[attachmentForScreenReaderMiddleware]
);
Expand All @@ -452,13 +452,13 @@ const ComposerCore = ({
...singleToArray(attachmentMiddleware),
() =>
() =>
({ attachment }) => {
if (attachment) {
throw new Error(`No renderer for attachment of type "${attachment.contentType}"`);
} else {
throw new Error('No attachment to render');
({ attachment }) => {
if (attachment) {
throw new Error(`No renderer for attachment of type "${attachment.contentType}"`);
} else {
throw new Error('No attachment to render');
}
}
}
)({}),
[attachmentMiddleware]
);
Expand All @@ -482,13 +482,13 @@ const ComposerCore = ({
...singleToArray(toastMiddleware),
() =>
() =>
({ notification }) => {
if (notification) {
throw new Error(`No renderer for notification of type "${notification.contentType}"`);
} else {
throw new Error('No notification to render');
({ notification }) => {
if (notification) {
throw new Error(`No renderer for notification of type "${notification.contentType}"`);
} else {
throw new Error('No notification to render');
}
}
}
)({}),
[toastMiddleware]
);
Expand Down Expand Up @@ -616,34 +616,6 @@ const ComposerCore = ({
* we should clean up the responsibility between Context and Redux store
* We should decide which data is needed for React but not in other environment such as CLI/VSCode
*/
ComposerCore.defaultProps = {
activityMiddleware: undefined,
activityStatusMiddleware: undefined,
attachmentForScreenReaderMiddleware: undefined,
attachmentMiddleware: undefined,
avatarMiddleware: undefined,
cardActionMiddleware: undefined,
children: undefined,
dir: 'auto',
disabled: false,
downscaleImageToDataURL: undefined,
grammars: [],
groupActivitiesMiddleware: undefined,
internalErrorBoxClass: undefined,
locale: window.navigator.language || 'en-US',
onTelemetry: undefined,
overrideLocalizedStrings: undefined,
renderMarkdown: undefined,
scrollToEndButtonMiddleware: undefined,
selectVoice: undefined,
sendTypingIndicator: false,
styleOptions: {},
toastMiddleware: undefined,
typingIndicatorMiddleware: undefined,
userID: '',
username: ''
};

ComposerCore.propTypes = {
activityMiddleware: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.func), PropTypes.func]),
activityStatusMiddleware: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.func), PropTypes.func]),
Expand Down Expand Up @@ -708,7 +680,7 @@ type ComposerProps = ComposerWithStoreProps & {
};

// We will create a Redux store if it was not passed in
const ComposerWithStore = ({ onTelemetry, store, ...props }: ComposerWithStoreProps) => {
const ComposerWithStore = ({ onTelemetry = undefined, store = undefined, ...props }: ComposerWithStoreProps) => {
const [ponyfill] = usePonyfill();

const memoizedStore = useMemo(() => {
Expand Down Expand Up @@ -757,17 +729,12 @@ const ComposerWithStore = ({ onTelemetry, store, ...props }: ComposerWithStorePr
);
};

ComposerWithStore.defaultProps = {
onTelemetry: undefined,
store: undefined
};

ComposerWithStore.propTypes = {
onTelemetry: PropTypes.func,
store: PropTypes.any
};

const Composer = ({ internalRenderErrorBox, onTelemetry, ponyfill, ...props }: ComposerProps) => {
const Composer = ({ internalRenderErrorBox = undefined, onTelemetry = undefined, ponyfill = undefined, ...props }: ComposerProps) => {
const [error, setError] = useState();

const handleError = useCallback(
Expand All @@ -792,13 +759,6 @@ const Composer = ({ internalRenderErrorBox, onTelemetry, ponyfill, ...props }: C
);
};

Composer.defaultProps = {
...ComposerWithStore.defaultProps,
internalRenderErrorBox: undefined,
onTelemetry: undefined,
ponyfill: undefined
};

Composer.propTypes = {
...ComposerWithStore.propTypes,
internalRenderErrorBox: PropTypes.any,
Expand Down
6 changes: 1 addition & 5 deletions packages/api/src/hooks/internal/ErrorBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import PropTypes from 'prop-types';
import useErrorBoxClass from './useErrorBoxClass';
import useTrackException from '../useTrackException';

const ErrorBox = ({ error, type }) => {
const ErrorBox = ({ error, type = undefined }) => {
const [errorBoxClass] = useErrorBoxClass();
const trackException = useTrackException();

Expand All @@ -22,10 +22,6 @@ const ErrorBox = ({ error, type }) => {
return !!errorBoxClass && createElement(errorBoxClass, { error, type });
};

ErrorBox.defaultProps = {
type: undefined
};

ErrorBox.propTypes = {
error: PropTypes.any.isRequired,
type: PropTypes.string
Expand Down
7 changes: 1 addition & 6 deletions packages/api/src/hooks/middleware/UserlandBoundary.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React, { useCallback, useState } from 'react';
import ErrorBoundary from '../utils/ErrorBoundary';
import ErrorBox from '../internal/ErrorBox';

const UserlandBoundary = ({ children, type }) => {
const UserlandBoundary = ({ children = undefined, type = undefined }) => {
const [error, setError] = useState();

const handleError = useCallback(error => setError(error), []);
Expand All @@ -16,11 +16,6 @@ const UserlandBoundary = ({ children, type }) => {
);
};

UserlandBoundary.defaultProps = {
children: undefined,
type: undefined
};

UserlandBoundary.propTypes = {
children: PropTypes.any,
type: PropTypes.string
Expand Down
7 changes: 1 addition & 6 deletions packages/api/src/hooks/utils/ErrorBoundary.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ErrorBoundary extends Component {

this.setState({ hasError: true });

onError(error);
onError && onError(error);
}

render() {
Expand All @@ -26,11 +26,6 @@ class ErrorBoundary extends Component {
}
}

ErrorBoundary.defaultProps = {
children: undefined,
onError: undefined
};

ErrorBoundary.propTypes = {
children: PropTypes.any,
onError: PropTypes.func
Expand Down
6 changes: 1 addition & 5 deletions packages/api/src/providers/Ponyfill/PonyfillComposer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type Props = PropsWithChildren<{
ponyfill?: Partial<GlobalScopePonyfill>;
}>;

const PonyfillComposer = ({ children, ponyfill: partialPonyfill }: Props) => {
const PonyfillComposer = ({ children, ponyfill: partialPonyfill = undefined }: Props) => {
// Note: `useRef(value)` always return the initial value that was called with.
if (useRef(partialPonyfill).current !== partialPonyfill) {
// We does not support changing ponyfill.
Expand Down Expand Up @@ -85,10 +85,6 @@ const PonyfillComposer = ({ children, ponyfill: partialPonyfill }: Props) => {
return <PonyfillContext.Provider value={contextValue}>{children}</PonyfillContext.Provider>;
};

PonyfillComposer.defaultProps = {
ponyfill: undefined
};

PonyfillComposer.propTypes = {
ponyfill: PropTypes.any
};
Expand Down
6 changes: 3 additions & 3 deletions packages/bundle/src/AddFullBundle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ const adaptiveCardHostConfigDeprecation = warnOnce(

const AddFullBundle = ({
adaptiveCardHostConfig,
adaptiveCardsHostConfig,
adaptiveCardsPackage,
adaptiveCardsHostConfig = undefined,
adaptiveCardsPackage = undefined,
attachmentForScreenReaderMiddleware,
attachmentMiddleware,
children,
children = undefined,
renderMarkdown,
styleOptions,
styleSet
Expand Down
7 changes: 0 additions & 7 deletions packages/bundle/src/FullComposer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,6 @@ const FullComposer = (props: FullComposerProps) => (
</AddFullBundle>
);

FullComposer.defaultProps = {
...Composer.defaultProps,
adaptiveCardsHostConfig: undefined,
adaptiveCardsPackage: undefined,
children: undefined
};

FullComposer.propTypes = {
...Composer.propTypes,
adaptiveCardsHostConfig: PropTypes.any,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,12 @@ type AdaptiveCardAttachmentProps = {
disabled?: boolean;
};

const AdaptiveCardAttachment: FC<AdaptiveCardAttachmentProps> = ({ attachment: { content }, disabled }) => (
const AdaptiveCardAttachment: FC<AdaptiveCardAttachmentProps> = ({ attachment: { content }, disabled = undefined }) => (
<AdaptiveCardContent content={content} disabled={disabled} />
);

export default AdaptiveCardAttachment;

AdaptiveCardAttachment.defaultProps = {
disabled: undefined
};

AdaptiveCardAttachment.propTypes = {
// PropTypes cannot fully capture TypeScript types.
// @ts-ignore
Expand Down
Loading