From de9c4702764905b62cd2c49b803f367bb34a1f86 Mon Sep 17 00:00:00 2001 From: IRBorisov <8611739+IRBorisov@users.noreply.github.com> Date: Mon, 27 Nov 2023 11:33:34 +0300 Subject: [PATCH] Refactoring: replace shortcurctuit with conditionals --- rsconcept/frontend/src/App.tsx | 49 +++--- .../frontend/src/components/BackendError.tsx | 4 +- .../frontend/src/components/Common/Button.tsx | 4 +- .../src/components/Common/Checkbox.tsx | 13 +- .../src/components/Common/ConceptSearch.tsx | 2 +- .../src/components/Common/DropdownButton.tsx | 4 +- .../components/Common/DropdownCheckbox.tsx | 2 +- .../frontend/src/components/Common/Form.tsx | 2 +- .../frontend/src/components/Common/Modal.tsx | 16 +- .../src/components/Common/SelectorButton.tsx | 9 +- .../src/components/Common/SubmitButton.tsx | 4 +- .../src/components/Common/SwitchButton.tsx | 2 +- .../src/components/Common/TextInput.tsx | 7 +- .../src/components/Common/Tristate.tsx | 11 +- .../src/components/DataTable/DataTable.tsx | 36 ++--- .../components/DataTable/PaginationTools.tsx | 20 +-- .../src/components/DataTable/SelectAll.tsx | 19 ++- .../src/components/DataTable/SelectRow.tsx | 10 +- .../src/components/DataTable/SortingIcon.tsx | 3 +- .../frontend/src/components/ErrorFallback.tsx | 2 +- rsconcept/frontend/src/components/Footer.tsx | 3 +- .../src/components/Help/InfoConstituenta.tsx | 35 ++-- .../src/components/Help/InfoCstClass.tsx | 39 +++-- .../src/components/Help/InfoCstStatus.tsx | 45 +++--- .../src/components/Navigation/Logo.tsx | 16 +- .../src/components/Navigation/Navigation.tsx | 28 ++-- .../Navigation/NavigationButton.tsx | 8 +- .../components/Navigation/ThemeSwitcher.tsx | 21 ++- .../src/components/Navigation/UserMenu.tsx | 14 +- .../src/components/RSInput/RSInput.tsx | 4 +- .../src/components/RefsInput/RefsInput.tsx | 16 +- .../frontend/src/components/RequireAuth.tsx | 24 ++- .../components/Shared/ConstituentaBadge.tsx | 10 +- .../DlgConstituentaTemplate/ArgumentsTab.tsx | 1 - .../frontend/src/dialogs/DlgCreateCst.tsx | 2 +- .../frontend/src/dialogs/DlgDeleteCst.tsx | 10 +- .../DlgEditReference/DlgEditReference.tsx | 28 ++-- .../DlgEditReference/WordformButton.tsx | 4 +- .../frontend/src/dialogs/DlgEditWordForms.tsx | 14 +- .../frontend/src/dialogs/DlgGraphOptions.tsx | 27 ++-- .../frontend/src/dialogs/DlgRenameCst.tsx | 14 +- rsconcept/frontend/src/dialogs/DlgShowAST.tsx | 14 +- .../frontend/src/dialogs/DlgUploadRSForm.tsx | 43 +++-- .../frontend/src/pages/CreateRSFormPage.tsx | 31 ++-- rsconcept/frontend/src/pages/HomePage.tsx | 10 +- .../src/pages/LibraryPage/LibraryPage.tsx | 42 +++-- .../src/pages/LibraryPage/PickerStrategy.tsx | 10 +- .../src/pages/LibraryPage/SearchPanel.tsx | 44 +++-- .../src/pages/LibraryPage/ViewLibrary.tsx | 100 ++++++------ rsconcept/frontend/src/pages/LoginPage.tsx | 114 +++++++------ .../src/pages/ManualsPage/ManualsPage.tsx | 20 +-- .../src/pages/ManualsPage/TopicsList.tsx | 7 +- .../src/pages/ManualsPage/ViewTopic.tsx | 27 ++-- rsconcept/frontend/src/pages/NotFoundPage.tsx | 11 +- .../pages/RSFormPage/EditorConstituenta.tsx | 34 ++-- .../src/pages/RSFormPage/EditorItems.tsx | 6 +- .../pages/RSFormPage/EditorRSExpression.tsx | 20 ++- .../src/pages/RSFormPage/EditorRSForm.tsx | 4 +- .../src/pages/RSFormPage/EditorTermGraph.tsx | 5 +- .../frontend/src/pages/RSFormPage/RSTabs.tsx | 40 ++--- .../RSFormPage/elements/ParsingResult.tsx | 33 ++-- .../pages/RSFormPage/elements/RSFormStats.tsx | 153 +++++++++--------- .../RSFormPage/elements/RSLocalButton.tsx | 19 +-- .../pages/RSFormPage/elements/RSTabsMenu.tsx | 39 ++--- .../RSFormPage/elements/RSTokenButton.tsx | 19 +-- .../elements/ViewSideConstituents.tsx | 20 +-- rsconcept/frontend/src/pages/RegisterPage.tsx | 123 +++++++------- .../pages/UserProfilePage/EditorPassword.tsx | 88 +++++----- .../pages/UserProfilePage/EditorProfile.tsx | 67 ++++---- .../src/pages/UserProfilePage/UserTabs.tsx | 58 ++++--- .../UserProfilePage/ViewSubscriptions.tsx | 32 ++-- rsconcept/frontend/src/utils/constants.ts | 1 + 72 files changed, 906 insertions(+), 910 deletions(-) diff --git a/rsconcept/frontend/src/App.tsx b/rsconcept/frontend/src/App.tsx index 69dc1016..0d604983 100644 --- a/rsconcept/frontend/src/App.tsx +++ b/rsconcept/frontend/src/App.tsx @@ -20,32 +20,33 @@ import { globalIDs } from './utils/constants'; function Root() { const { noNavigation, noFooter, viewportHeight, mainHeight, showScroll } = useConceptTheme(); return ( - -
+ +
+ + + + + +
+
+ +
- - - -
-
- -
- {!noNavigation && !noFooter &&
} -
+ {(!noNavigation && !noFooter) ?
: null}
- - ); +
+
); } const router = createBrowserRouter([ diff --git a/rsconcept/frontend/src/components/BackendError.tsx b/rsconcept/frontend/src/components/BackendError.tsx index cbcb2af7..894df4b1 100644 --- a/rsconcept/frontend/src/components/BackendError.tsx +++ b/rsconcept/frontend/src/components/BackendError.tsx @@ -50,8 +50,8 @@ function DescribeError(error: ErrorInfo) {

{error.message}

{error.response.data && (<>

Описание

- { isHtml &&
} - { !isHtml && } + {isHtml ?
: null} + {!isHtml ? : null} )}
); diff --git a/rsconcept/frontend/src/components/Common/Button.tsx b/rsconcept/frontend/src/components/Common/Button.tsx index e5a95a2c..94c3ae70 100644 --- a/rsconcept/frontend/src/components/Common/Button.tsx +++ b/rsconcept/frontend/src/components/Common/Button.tsx @@ -28,8 +28,8 @@ function Button({ className={`inline-flex items-center gap-2 align-middle justify-center select-none ${padding} ${colors} ${outlineClass} ${borderClass} ${dimensions} ${cursor}`} {...props} > - {icon && icon} - {text && {text}} + {icon ? icon : null} + {text ? {text} : null} ); } diff --git a/rsconcept/frontend/src/components/Common/Checkbox.tsx b/rsconcept/frontend/src/components/Common/Checkbox.tsx index ba20f94f..4190b763 100644 --- a/rsconcept/frontend/src/components/Common/Checkbox.tsx +++ b/rsconcept/frontend/src/components/Common/Checkbox.tsx @@ -5,7 +5,6 @@ import Label from './Label'; export interface CheckboxProps extends Omit, 'className' | 'children' | 'title' | 'value' | 'onClick' > { - id?: string label?: string disabled?: boolean dimensions?: string @@ -43,8 +42,7 @@ function Checkbox({ } return ( - ); } diff --git a/rsconcept/frontend/src/components/Common/ConceptSearch.tsx b/rsconcept/frontend/src/components/Common/ConceptSearch.tsx index f023da6f..a12f3435 100644 --- a/rsconcept/frontend/src/components/Common/ConceptSearch.tsx +++ b/rsconcept/frontend/src/components/Common/ConceptSearch.tsx @@ -20,7 +20,7 @@ function ConceptSearch({ value, onChange, dense }: ConceptSearchProps) { noOutline noBorder={dense} value={value} - onChange={event => onChange && onChange(event.target.value)} + onChange={event => (onChange ? onChange(event.target.value) : undefined)} />
); } diff --git a/rsconcept/frontend/src/components/Common/DropdownButton.tsx b/rsconcept/frontend/src/components/Common/DropdownButton.tsx index fbb54e65..60999f63 100644 --- a/rsconcept/frontend/src/components/Common/DropdownButton.tsx +++ b/rsconcept/frontend/src/components/Common/DropdownButton.tsx @@ -6,10 +6,10 @@ interface DropdownButtonProps { } function DropdownButton({ tooltip, onClick, disabled, children }: DropdownButtonProps) { - const behavior = (onClick ? 'cursor-pointer disabled:cursor-not-allowed clr-hover' : 'cursor-default'); + const behavior = onClick ? 'cursor-pointer disabled:cursor-not-allowed clr-hover' : 'cursor-default'; const text = disabled ? 'text-controls' : ''; return ( - ); } diff --git a/rsconcept/frontend/src/components/Common/SubmitButton.tsx b/rsconcept/frontend/src/components/Common/SubmitButton.tsx index 52bd23d8..5b8f52c3 100644 --- a/rsconcept/frontend/src/components/Common/SubmitButton.tsx +++ b/rsconcept/frontend/src/components/Common/SubmitButton.tsx @@ -17,8 +17,8 @@ function SubmitButton({ className={`px-4 py-2 inline-flex items-center gap-2 align-middle justify-center font-semibold select-none disabled:cursor-not-allowed border rounded clr-btn-primary ${dimensions} ${loading ? ' cursor-progress' : ''}`} disabled={disabled ?? loading} > - {icon && {icon}} - {text && {text}} + {icon ? {icon} : null} + {text ? {text} : null} ); } diff --git a/rsconcept/frontend/src/components/Common/SwitchButton.tsx b/rsconcept/frontend/src/components/Common/SwitchButton.tsx index 1489c189..703bb677 100644 --- a/rsconcept/frontend/src/components/Common/SwitchButton.tsx +++ b/rsconcept/frontend/src/components/Common/SwitchButton.tsx @@ -22,7 +22,7 @@ function SwitchButton({ className={`px-2 py-1 border font-semibold small-caps rounded-none cursor-pointer clr-btn-clear clr-hover ${dimensions} ${isSelected ? 'clr-selected': ''}`} {...props} > - {icon && icon} + {icon ? icon : null} {label} ); } diff --git a/rsconcept/frontend/src/components/Common/TextInput.tsx b/rsconcept/frontend/src/components/Common/TextInput.tsx index 956588e5..0210d663 100644 --- a/rsconcept/frontend/src/components/Common/TextInput.tsx +++ b/rsconcept/frontend/src/components/Common/TextInput.tsx @@ -23,15 +23,14 @@ function TextInput({ const outlineClass = noOutline ? '' : 'clr-outline'; return (
- {label && + {label ?