From f701f8d05f64843f7921a95f0b710da0f323d0f5 Mon Sep 17 00:00:00 2001 From: Philip Molares Date: Mon, 30 Oct 2023 12:23:24 +0100 Subject: [PATCH] refactor: remove show-if in favour of conditionals This prevents a problem where show-if can trigger an error if a value is checked to exist with it. Signed-off-by: Philip Molares --- frontend/src/app/(editor)/profile/page.tsx | 5 +- .../loading-screen/loading-screen.tsx | 7 +- .../copyable-field/copyable-field.tsx | 7 +- .../copyable/hooks/use-copy-overlay.tsx | 11 +-- .../hedge-doc-logo-horizontal-grey.tsx | 5 +- .../common/icon-button/icon-button.tsx | 7 +- .../components/common/modals/common-modal.tsx | 41 ++++++----- .../create-non-existing-note-hint.tsx | 5 +- .../note-loading-boundary.tsx | 5 +- .../common/pagination/pager-pagination.tsx | 23 +++--- .../renderer-iframe/renderer-iframe.tsx | 7 +- .../__snapshots__/show-if.spec.tsx.snap | 9 --- .../common/show-if/show-if.spec.tsx | 19 ----- .../src/components/common/show-if/show-if.tsx | 21 ------ .../common/user-avatar/user-avatar.tsx | 5 +- .../document-infobar.tsx | 17 ++--- .../editor-pane/tool-bar/tool-bar.tsx | 73 ++++++++++--------- .../upload-image-button.tsx | 5 +- .../sidebar/sidebar-button/sidebar-button.tsx | 5 +- .../sidebar-menu-info-entry.tsx | 5 +- .../aliases-modal/aliases-list-entry.tsx | 9 +-- .../import-markdown-sidebar-entry.tsx | 5 +- .../note-info-line-word-count.tsx | 9 +-- .../permission-entry-user.tsx | 6 +- .../revisions-modal/revision-list-entry.tsx | 7 +- .../share-modal/share-modal.tsx | 21 +++--- .../user-line/user-line.tsx | 5 +- .../editor-page/splitter/splitter.tsx | 7 +- .../table-of-contents/table-of-contents.tsx | 7 +- .../use-build-react-dom-from-toc-ast.tsx | 11 +-- .../error-pages/common-error-page.tsx | 5 +- .../shortcuts-modal/shortcut-line.tsx | 21 +++--- .../version-info-modal/version-info-modal.tsx | 9 +-- .../history-page/entry-menu/entry-menu.tsx | 19 ++--- .../history-toolbar/history-toolbar.tsx | 5 +- .../intro-page/intro-custom-content.tsx | 4 +- .../navigation/sign-in-button.tsx | 17 +++-- .../help-dropdown/submenues/legal-submenu.tsx | 13 ++-- .../translated-dropdown-item.tsx | 5 +- .../note-title-element/note-title-element.tsx | 5 +- .../login-page/guest/guest-card.tsx | 5 +- .../local-login/local-login-card.tsx | 11 +-- .../click-shield/click-shield.tsx | 28 ++++--- .../notifications/ui-notification-toast.tsx | 5 +- .../access-tokens/profile-access-tokens.tsx | 11 +-- .../register-page/register-infos.tsx | 17 +++-- .../document/document-toc-sidebar.tsx | 7 +- .../abcjs/abc-frame.tsx | 7 +- .../flowchart/flowchart.tsx | 7 +- .../graphviz/graphviz-frame.tsx | 7 +- .../mermaid/mermaid-chart.tsx | 7 +- .../vega-lite/vega-lite-chart.tsx | 7 +- 52 files changed, 239 insertions(+), 352 deletions(-) delete mode 100644 frontend/src/components/common/show-if/__snapshots__/show-if.spec.tsx.snap delete mode 100644 frontend/src/components/common/show-if/show-if.spec.tsx delete mode 100644 frontend/src/components/common/show-if/show-if.tsx diff --git a/frontend/src/app/(editor)/profile/page.tsx b/frontend/src/app/(editor)/profile/page.tsx index 428ebb6eb..14a1c5ad6 100644 --- a/frontend/src/app/(editor)/profile/page.tsx +++ b/frontend/src/app/(editor)/profile/page.tsx @@ -7,7 +7,6 @@ */ import { AuthProviderType } from '../../../api/config/types' import { Redirect } from '../../../components/common/redirect' -import { ShowIf } from '../../../components/common/show-if/show-if' import { LandingLayout } from '../../../components/landing-layout/landing-layout' import { ProfileAccessTokens } from '../../../components/profile-page/access-tokens/profile-access-tokens' import { ProfileAccountManagement } from '../../../components/profile-page/account-management/profile-account-management' @@ -35,9 +34,7 @@ const ProfilePage: NextPage = () => { - - - + {userProvider === (AuthProviderType.LOCAL as string) && } diff --git a/frontend/src/components/application-loader/loading-screen/loading-screen.tsx b/frontend/src/components/application-loader/loading-screen/loading-screen.tsx index c19944370..424e7b24d 100644 --- a/frontend/src/components/application-loader/loading-screen/loading-screen.tsx +++ b/frontend/src/components/application-loader/loading-screen/loading-screen.tsx @@ -1,9 +1,8 @@ /* - * SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file) + * SPDX-FileCopyrightText: 2023 The HedgeDoc developers (see AUTHORS file) * * SPDX-License-Identifier: AGPL-3.0-only */ -import { ShowIf } from '../../common/show-if/show-if' import styles from '../application-loader.module.scss' import { LoadingAnimation } from './loading-animation' import type { ReactElement } from 'react' @@ -27,9 +26,7 @@ export const LoadingScreen: React.FC = ({ errorMessage }) => - - {errorMessage} - + {errorMessage !== undefined && {errorMessage}} ) } diff --git a/frontend/src/components/common/copyable/copyable-field/copyable-field.tsx b/frontend/src/components/common/copyable/copyable-field/copyable-field.tsx index f458b29e0..6244807f1 100644 --- a/frontend/src/components/common/copyable/copyable-field/copyable-field.tsx +++ b/frontend/src/components/common/copyable/copyable-field/copyable-field.tsx @@ -1,11 +1,10 @@ /* - * SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file) + * SPDX-FileCopyrightText: 2023 The HedgeDoc developers (see AUTHORS file) * * SPDX-License-Identifier: AGPL-3.0-only */ import { Logger } from '../../../../utils/logger' import { UiIcon } from '../../icons/ui-icon' -import { ShowIf } from '../../show-if/show-if' import { CopyToClipboardButton } from '../copy-to-clipboard-button/copy-to-clipboard-button' import React, { useCallback, useMemo } from 'react' import { Button, FormControl, InputGroup } from 'react-bootstrap' @@ -54,13 +53,13 @@ export const CopyableField: React.FC = ({ content, shareOrig - + {sharingSupported && ( - + )} ) } diff --git a/frontend/src/components/common/copyable/hooks/use-copy-overlay.tsx b/frontend/src/components/common/copyable/hooks/use-copy-overlay.tsx index 9a22fd812..f6b6659d5 100644 --- a/frontend/src/components/common/copyable/hooks/use-copy-overlay.tsx +++ b/frontend/src/components/common/copyable/hooks/use-copy-overlay.tsx @@ -1,10 +1,9 @@ /* - * SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file) + * SPDX-FileCopyrightText: 2023 The HedgeDoc developers (see AUTHORS file) * * SPDX-License-Identifier: AGPL-3.0-only */ import { Logger } from '../../../../utils/logger' -import { ShowIf } from '../../show-if/show-if' import type { ReactElement, RefObject } from 'react' import React, { useCallback, useEffect, useMemo, useState } from 'react' import { Overlay, Tooltip } from 'react-bootstrap' @@ -64,12 +63,8 @@ export const useCopyOverlay = ( {(props) => ( - - - - - - + {showState === SHOW_STATE.ERROR && } + {showState === SHOW_STATE.SUCCESS && } )} diff --git a/frontend/src/components/common/hedge-doc-logo/hedge-doc-logo-horizontal-grey.tsx b/frontend/src/components/common/hedge-doc-logo/hedge-doc-logo-horizontal-grey.tsx index b22f50004..7c3f83e9b 100644 --- a/frontend/src/components/common/hedge-doc-logo/hedge-doc-logo-horizontal-grey.tsx +++ b/frontend/src/components/common/hedge-doc-logo/hedge-doc-logo-horizontal-grey.tsx @@ -5,7 +5,6 @@ */ import { LogoSize } from './logo-size' import React from 'react' -import { ShowIf } from '../show-if/show-if' interface HedgeDocLogoHorizontalGreyProps { color: 'dark' | 'light' @@ -68,13 +67,13 @@ export const HedgeDocLogoHorizontalGrey: React.FC - + {showText && ( - + )} ) diff --git a/frontend/src/components/common/icon-button/icon-button.tsx b/frontend/src/components/common/icon-button/icon-button.tsx index 046d36c6e..744f4c478 100644 --- a/frontend/src/components/common/icon-button/icon-button.tsx +++ b/frontend/src/components/common/icon-button/icon-button.tsx @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file) + * SPDX-FileCopyrightText: 2023 The HedgeDoc developers (see AUTHORS file) * * SPDX-License-Identifier: AGPL-3.0-only */ @@ -7,7 +7,6 @@ import { concatCssClasses } from '../../../utils/concat-css-classes' import type { PropsWithDataTestId } from '../../../utils/test-id' import { testId } from '../../../utils/test-id' import { UiIcon } from '../icons/ui-icon' -import { ShowIf } from '../show-if/show-if' import styles from './icon-button.module.scss' import React, { useMemo } from 'react' import type { ButtonProps } from 'react-bootstrap' @@ -52,9 +51,7 @@ export const IconButton: React.FC = ({ - - {children} - + {children !== undefined && {children}} ) } diff --git a/frontend/src/components/common/modals/common-modal.tsx b/frontend/src/components/common/modals/common-modal.tsx index 9bab6992e..84f618b15 100644 --- a/frontend/src/components/common/modals/common-modal.tsx +++ b/frontend/src/components/common/modals/common-modal.tsx @@ -8,7 +8,6 @@ import type { PropsWithDataCypressId } from '../../../utils/cypress-attribute' import { cypressId } from '../../../utils/cypress-attribute' import { testId } from '../../../utils/test-id' import { UiIcon } from '../icons/ui-icon' -import { ShowIf } from '../show-if/show-if' import type { PropsWithChildren, ReactElement } from 'react' import React, { Fragment, useMemo } from 'react' import { Modal } from 'react-bootstrap' @@ -66,25 +65,27 @@ export const CommonModal: React.FC> = ({ return titleI18nKey !== undefined ? : {title} }, [titleI18nKey, title]) + if (!show) { + return null + } + return ( - - - - - - {titleElement} - - {additionalTitleElement ?? } - - {children} - - + + + + + {titleElement} + + {additionalTitleElement ?? } + + {children} + ) } diff --git a/frontend/src/components/common/note-loading-boundary/create-non-existing-note-hint.tsx b/frontend/src/components/common/note-loading-boundary/create-non-existing-note-hint.tsx index 991efc2e5..f898e5ac8 100644 --- a/frontend/src/components/common/note-loading-boundary/create-non-existing-note-hint.tsx +++ b/frontend/src/components/common/note-loading-boundary/create-non-existing-note-hint.tsx @@ -6,7 +6,6 @@ import { createNoteWithPrimaryAlias } from '../../../api/notes' import { testId } from '../../../utils/test-id' import { UiIcon } from '../icons/ui-icon' -import { ShowIf } from '../show-if/show-if' import React, { useCallback, useEffect } from 'react' import { Alert, Button } from 'react-bootstrap' import { @@ -85,9 +84,7 @@ export const CreateNonExistingNoteHint: React.FC className='mx-2' onClick={onClickHandler} {...testId('createNoteButton')}> - - - + {returnState.loading && } diff --git a/frontend/src/components/common/note-loading-boundary/note-loading-boundary.tsx b/frontend/src/components/common/note-loading-boundary/note-loading-boundary.tsx index 37891660f..87b2807be 100644 --- a/frontend/src/components/common/note-loading-boundary/note-loading-boundary.tsx +++ b/frontend/src/components/common/note-loading-boundary/note-loading-boundary.tsx @@ -10,7 +10,6 @@ import { Logger } from '../../../utils/logger' import { LoadingScreen } from '../../application-loader/loading-screen/loading-screen' import { CommonErrorPage } from '../../error-pages/common-error-page' import { CustomAsyncLoadingBoundary } from '../async-loading-boundary/custom-async-loading-boundary' -import { ShowIf } from '../show-if/show-if' import { CreateNonExistingNoteHint } from './create-non-existing-note-hint' import { useLoadNoteFromServer } from './hooks/use-load-note-from-server' import type { PropsWithChildren } from 'react' @@ -59,9 +58,9 @@ export const NoteLoadingBoundary: React.FC> = ({ - + {error instanceof ApiError && error.statusCode === 404 && ( - + )} ) }, [error, loadNoteFromServer, noteId]) diff --git a/frontend/src/components/common/pagination/pager-pagination.tsx b/frontend/src/components/common/pagination/pager-pagination.tsx index 97b9d77b4..dafbefc21 100644 --- a/frontend/src/components/common/pagination/pager-pagination.tsx +++ b/frontend/src/components/common/pagination/pager-pagination.tsx @@ -1,9 +1,8 @@ /* - * SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file) + * SPDX-FileCopyrightText: 2023 The HedgeDoc developers (see AUTHORS file) * * SPDX-License-Identifier: AGPL-3.0-only */ -import { ShowIf } from '../show-if/show-if' import { PagerItem } from './pager-item' import React, { useEffect, useMemo, useState } from 'react' import { Pagination } from 'react-bootstrap' @@ -70,17 +69,21 @@ export const PagerPagination: React.FC = ({ return ( - 0}> - - - + {correctedLowerPageIndex > 0 && ( + <> + + + + )} {paginationItemsBefore} {correctedPageIndex + 1} {paginationItemsAfter} - - - - + {correctedUpperPageIndex < lastPageIndex && ( + <> + + + + )} ) } diff --git a/frontend/src/components/common/renderer-iframe/renderer-iframe.tsx b/frontend/src/components/common/renderer-iframe/renderer-iframe.tsx index abe822be6..cf8fe8409 100644 --- a/frontend/src/components/common/renderer-iframe/renderer-iframe.tsx +++ b/frontend/src/components/common/renderer-iframe/renderer-iframe.tsx @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file) + * SPDX-FileCopyrightText: 2023 The HedgeDoc developers (see AUTHORS file) * * SPDX-License-Identifier: AGPL-3.0-only */ @@ -19,7 +19,6 @@ import type { SetScrollStateMessage } from '../../render-page/window-post-message-communicator/rendering-message' import { CommunicationMessageType } from '../../render-page/window-post-message-communicator/rendering-message' -import { ShowIf } from '../show-if/show-if' import { WaitSpinner } from '../wait-spinner/wait-spinner' import { useEffectOnRenderTypeChange } from './hooks/use-effect-on-render-type-change' import { useForceRenderPageUrlOnIframeLoadCallback } from './hooks/use-force-render-page-url-on-iframe-load-callback' @@ -176,9 +175,7 @@ export const RendererIframe: React.FC = ({ return ( - - - + {!rendererReady && showWaitSpinner && }