From 29837ec8381ed07a0c24f4e26c41fff6ddf3fcbe Mon Sep 17 00:00:00 2001 From: Tim Down <158919+timdown@users.noreply.github.com> Date: Thu, 6 Jun 2024 16:37:47 +0100 Subject: [PATCH] Merge pull request #18733 from overleaf/td-bs5-button-props Simplify handling of BS3 props in button wrapper component GitOrigin-RevId: 12a6b1374da5084e075775f3cef23f0b24d098fc --- .../make-primary/confirmation-modal.tsx | 10 +---- .../actions/make-primary/primary-button.tsx | 4 -- .../add-email/add-another-email-btn.tsx | 1 - .../email-affiliated-with-institution.tsx | 1 - .../emails/add-email/university-name.tsx | 7 +--- .../components/emails/reconfirmation-info.tsx | 6 --- .../resend-confirmation-email-button.tsx | 1 - .../components/leave/modal-content.tsx | 7 +--- .../components/linking/enable-widget.tsx | 6 --- .../components/linking/integration-widget.tsx | 28 ++------------ .../components/linking/sso-widget.tsx | 38 +++---------------- .../settings/components/security-section.tsx | 1 - .../features/ui/components/ol/ol-button.tsx | 31 +++++++-------- .../ui/components/ol/ol-icon-button.tsx | 16 ++------ .../shared/components/copy-to-clipboard.tsx | 7 +--- 15 files changed, 32 insertions(+), 132 deletions(-) diff --git a/services/web/frontend/js/features/settings/components/emails/actions/make-primary/confirmation-modal.tsx b/services/web/frontend/js/features/settings/components/emails/actions/make-primary/confirmation-modal.tsx index b06a622c66..dd19daf317 100644 --- a/services/web/frontend/js/features/settings/components/emails/actions/make-primary/confirmation-modal.tsx +++ b/services/web/frontend/js/features/settings/components/emails/actions/make-primary/confirmation-modal.tsx @@ -46,21 +46,13 @@ function ConfirmationModal({

{t('log_in_with_primary_email_address')}

- + {t('cancel')} {t('confirm')} diff --git a/services/web/frontend/js/features/settings/components/emails/actions/make-primary/primary-button.tsx b/services/web/frontend/js/features/settings/components/emails/actions/make-primary/primary-button.tsx index 9a0f69998b..f68dfb633e 100644 --- a/services/web/frontend/js/features/settings/components/emails/actions/make-primary/primary-button.tsx +++ b/services/web/frontend/js/features/settings/components/emails/actions/make-primary/primary-button.tsx @@ -13,10 +13,6 @@ function PrimaryButton({ isLoading={isLoading} onClick={onClick} variant="secondary" - bs3Props={{ - bsStyle: null, - className: 'btn-secondary btn-secondary-info', - }} > {children} diff --git a/services/web/frontend/js/features/settings/components/emails/add-email/add-another-email-btn.tsx b/services/web/frontend/js/features/settings/components/emails/add-email/add-another-email-btn.tsx index 8be3693b81..cb0573c2c3 100644 --- a/services/web/frontend/js/features/settings/components/emails/add-email/add-another-email-btn.tsx +++ b/services/web/frontend/js/features/settings/components/emails/add-email/add-another-email-btn.tsx @@ -9,7 +9,6 @@ function AddAnotherEmailBtn({ onClick, ...props }: OLButtonProps) { variant="link" onClick={onClick} className="btn-inline-link" - bs3Props={{ bsStyle: null }} {...props} > {t('add_another_email')} diff --git a/services/web/frontend/js/features/settings/components/emails/add-email/email-affiliated-with-institution.tsx b/services/web/frontend/js/features/settings/components/emails/add-email/email-affiliated-with-institution.tsx index 1ad1950b2d..113201a911 100644 --- a/services/web/frontend/js/features/settings/components/emails/add-email/email-affiliated-with-institution.tsx +++ b/services/web/frontend/js/features/settings/components/emails/add-email/email-affiliated-with-institution.tsx @@ -11,7 +11,6 @@ function EmailAffiliatedWithInstitution({ onClick, ...props }: OLButtonProps) { variant="link" onClick={onClick} className="btn-inline-link" - bs3Props={{ bsStyle: null }} {...props} > {t('let_us_know')} diff --git a/services/web/frontend/js/features/settings/components/emails/add-email/university-name.tsx b/services/web/frontend/js/features/settings/components/emails/add-email/university-name.tsx index 1032666856..32fc0166d2 100644 --- a/services/web/frontend/js/features/settings/components/emails/add-email/university-name.tsx +++ b/services/web/frontend/js/features/settings/components/emails/add-email/university-name.tsx @@ -14,12 +14,7 @@ function UniversityName({ name, onClick }: UniversityNameProps) { {name} {' '} - + {t('change')} diff --git a/services/web/frontend/js/features/settings/components/emails/reconfirmation-info.tsx b/services/web/frontend/js/features/settings/components/emails/reconfirmation-info.tsx index b99c8f14a7..4970602559 100644 --- a/services/web/frontend/js/features/settings/components/emails/reconfirmation-info.tsx +++ b/services/web/frontend/js/features/settings/components/emails/reconfirmation-info.tsx @@ -150,9 +150,6 @@ function ReconfirmationInfo({ userEmailData }: ReconfirmationInfoProps) { disabled={state.isLoading} onClick={handleRequestReconfirmation} className="btn-inline-link" - bs3Props={{ - bsStyle: null, - }} > {t('resend_confirmation_email')} @@ -164,7 +161,6 @@ function ReconfirmationInfo({ userEmailData }: ReconfirmationInfoProps) { disabled={isPending} isLoading={isLoading} onClick={handleRequestReconfirmation} - bs3Props={{ bsStyle: 'info' }} > {isLoading ? ( <> @@ -209,7 +205,6 @@ function ReconfirmationInfo({ userEmailData }: ReconfirmationInfoProps) { disabled={state.isLoading} onClick={handleRequestReconfirmation} className="btn-inline-link" - bs3Props={{ bsStyle: null }} > {t('resend_confirmation_email')} @@ -241,7 +236,6 @@ function ReconfirmationInfo({ userEmailData }: ReconfirmationInfoProps) { variant="secondary" disabled={state.isLoading || isPending} onClick={handleRequestReconfirmation} - bs3Props={{ bsStyle: 'info' }} > {isLoading ? ( <> diff --git a/services/web/frontend/js/features/settings/components/emails/resend-confirmation-email-button.tsx b/services/web/frontend/js/features/settings/components/emails/resend-confirmation-email-button.tsx index a42c45d330..e4696cfd72 100644 --- a/services/web/frontend/js/features/settings/components/emails/resend-confirmation-email-button.tsx +++ b/services/web/frontend/js/features/settings/components/emails/resend-confirmation-email-button.tsx @@ -52,7 +52,6 @@ function ResendConfirmationEmailButton({ disabled={state.isLoading || isLoading} onClick={handleResendConfirmationEmail} className="btn-inline-link" - bs3Props={{ bsStyle: null }} > {t('resend_confirmation_email')} diff --git a/services/web/frontend/js/features/settings/components/leave/modal-content.tsx b/services/web/frontend/js/features/settings/components/leave/modal-content.tsx index bb6dcdd6b6..97177430ef 100644 --- a/services/web/frontend/js/features/settings/components/leave/modal-content.tsx +++ b/services/web/frontend/js/features/settings/components/leave/modal-content.tsx @@ -74,12 +74,7 @@ function LeaveModalContent({ - + {t('cancel')} diff --git a/services/web/frontend/js/features/settings/components/linking/enable-widget.tsx b/services/web/frontend/js/features/settings/components/linking/enable-widget.tsx index ddd230d854..23ad1f0ad6 100644 --- a/services/web/frontend/js/features/settings/components/linking/enable-widget.tsx +++ b/services/web/frontend/js/features/settings/components/linking/enable-widget.tsx @@ -96,7 +96,6 @@ function ActionButton({ variant="primary" href="/user/subscription/plans" onClick={trackUpgradeClick} - bs3Props={{ bsStyle: null, className: 'btn-primary' }} > {t('upgrade')} @@ -107,7 +106,6 @@ function ActionButton({ variant="danger-ghost" onClick={handleUnlinkClick} disabled={disabled} - bs3Props={{ bsStyle: null, className: 'btn-danger-ghost' }} > {t('turn_off')} @@ -118,10 +116,6 @@ function ActionButton({ variant="secondary" disabled={disabled} onClick={handleLinkClick} - bs3Props={{ - bsStyle: null, - className: 'btn btn-secondary-info btn-secondary', - }} > {t('turn_on')} diff --git a/services/web/frontend/js/features/settings/components/linking/integration-widget.tsx b/services/web/frontend/js/features/settings/components/linking/integration-widget.tsx index 8c0990a248..def60625a2 100644 --- a/services/web/frontend/js/features/settings/components/linking/integration-widget.tsx +++ b/services/web/frontend/js/features/settings/components/linking/integration-widget.tsx @@ -4,7 +4,6 @@ import OLBadge from '@/features/ui/components/ol/ol-badge' import getMeta from '../../../../utils/meta' import { sendMB } from '../../../../infrastructure/event-tracking' import OLButton from '@/features/ui/components/ol/ol-button' -import { bsVersion } from '@/features/utils/bootstrap-5' import OLModal, { OLModalBody, OLModalFooter, @@ -123,7 +122,6 @@ function ActionButton({ variant="primary" href="/user/subscription/plans" onClick={() => trackUpgradeClick(integration)} - bs3Props={{ bsStyle: null, className: 'btn-primary' }} > {t('upgrade')} @@ -134,7 +132,6 @@ function ActionButton({ variant="danger-ghost" onClick={handleUnlinkClick} disabled={disabled} - bs3Props={{ bsStyle: null, className: 'btn-danger-ghost' }} > {t('unlink')} @@ -143,25 +140,14 @@ function ActionButton({ return ( <> {disabled ? ( - + {t('link')} ) : ( trackLinkingClick(integration)} > {t('link')} @@ -215,20 +201,12 @@ function UnlinkConfirmationModal({
- + {t('cancel')} {t('unlink')} diff --git a/services/web/frontend/js/features/settings/components/linking/sso-widget.tsx b/services/web/frontend/js/features/settings/components/linking/sso-widget.tsx index 3d3f44c520..8d5bc169d1 100644 --- a/services/web/frontend/js/features/settings/components/linking/sso-widget.tsx +++ b/services/web/frontend/js/features/settings/components/linking/sso-widget.tsx @@ -6,7 +6,6 @@ import GoogleLogo from '../../../../shared/svgs/google-logo' import OrcidLogo from '../../../../shared/svgs/orcid-logo' import LinkingStatus from './status' import OLButton from '@/features/ui/components/ol/ol-button' -import { bsVersion } from '@/features/utils/bootstrap-5' import OLModal, { OLModalBody, OLModalFooter, @@ -118,35 +117,19 @@ function ActionButton({ const { t } = useTranslation() if (unlinkRequestInflight) { return ( - + {t('unlinking')} ) } else if (accountIsLinked) { return ( - + {t('unlink')} ) } else { return ( - + {t('link')} ) @@ -181,21 +164,10 @@ function UnlinkConfirmModal({ - + {t('cancel')} - + {t('unlink')} diff --git a/services/web/frontend/js/features/settings/components/security-section.tsx b/services/web/frontend/js/features/settings/components/security-section.tsx index 9e5dc098db..fba217ccb6 100644 --- a/services/web/frontend/js/features/settings/components/security-section.tsx +++ b/services/web/frontend/js/features/settings/components/security-section.tsx @@ -87,7 +87,6 @@ function SecuritySection() {
{t('set_up_sso')} diff --git a/services/web/frontend/js/features/ui/components/ol/ol-button.tsx b/services/web/frontend/js/features/ui/components/ol/ol-button.tsx index 4e5a0d48af..5979792c24 100644 --- a/services/web/frontend/js/features/ui/components/ol/ol-button.tsx +++ b/services/web/frontend/js/features/ui/components/ol/ol-button.tsx @@ -3,13 +3,12 @@ import { Button as BS3Button } from 'react-bootstrap' import type { ButtonProps } from '@/features/ui/components/types/button-props' import type { ButtonProps as BS3ButtonPropsBase } from 'react-bootstrap' import Button from '../bootstrap-5/button' +import classnames from 'classnames' export type BS3ButtonSize = 'xsmall' | 'sm' | 'medium' | 'lg' export type OLButtonProps = ButtonProps & { bs3Props?: { - bsStyle?: string | null - className?: string loading?: React.ReactNode bsSize?: BS3ButtonSize } @@ -20,6 +19,20 @@ export type BS3ButtonProps = Omit & { onClick?: React.MouseEventHandler } +export function bs3ButtonProps(props: ButtonProps) { + const bs3ButtonProps: BS3ButtonProps = { + bsStyle: null, + bsSize: mapBsButtonSizes(props.size), + className: classnames(`btn-${props.variant || 'primary'}`, props.className), + disabled: props.isLoading || props.disabled, + form: props.form, + href: props.href, + onClick: props.onClick, + type: props.type, + } + return bs3ButtonProps +} + // maps Bootstrap 5 sizes to Bootstrap 3 sizes export const mapBsButtonSizes = ( size: ButtonProps['size'] @@ -29,22 +42,10 @@ export const mapBsButtonSizes = ( export default function OLButton(props: OLButtonProps) { const { bs3Props, ...rest } = props - const bs3ButtonProps: BS3ButtonProps = { - bsStyle: rest.variant === 'secondary' ? 'default' : rest.variant, - bsSize: mapBsButtonSizes(rest.size), - className: rest.className, - disabled: rest.isLoading || rest.disabled, - form: rest.form, - href: rest.href, - onClick: rest.onClick, - type: rest.type, - ...bs3Props, - } - return ( + {bs3Props?.loading || rest.children} } diff --git a/services/web/frontend/js/features/ui/components/ol/ol-icon-button.tsx b/services/web/frontend/js/features/ui/components/ol/ol-icon-button.tsx index ea87d902c4..a0e19e90af 100644 --- a/services/web/frontend/js/features/ui/components/ol/ol-icon-button.tsx +++ b/services/web/frontend/js/features/ui/components/ol/ol-icon-button.tsx @@ -1,4 +1,4 @@ -import { BS3ButtonProps, BS3ButtonSize, mapBsButtonSizes } from './ol-button' +import { bs3ButtonProps, BS3ButtonSize } from './ol-button' import { Button as BS3Button } from 'react-bootstrap' import type { IconButtonProps } from '@/features/ui/components/types/icon-button-props' import BootstrapVersionSwitcher from '../bootstrap-5/bootstrap-version-switcher' @@ -17,22 +17,12 @@ export type OLIconButtonProps = IconButtonProps & { export default function OLIconButton(props: OLIconButtonProps) { const { bs3Props, ...rest } = props - const { fw, ...filterBs3Props } = bs3Props || {} - - const bs3ButtonProps: BS3ButtonProps = { - bsStyle: rest.variant === 'secondary' ? 'default' : rest.variant, - bsSize: mapBsButtonSizes(rest.size), - disabled: rest.isLoading || rest.disabled, - form: rest.form, - onClick: rest.onClick, - type: rest.type, - ...filterBs3Props, - } + const { fw, ...bs3Rest } = bs3Props || {} return ( + {bs3Props?.loading} {t('copy')}