From 36c85e37a855eb4d94a8df65f5a3712f8710f7c0 Mon Sep 17 00:00:00 2001 From: Anass Bouassaba Date: Wed, 30 Oct 2024 16:36:22 +0100 Subject: [PATCH] fix(ui): several code quality issues --- ui/qodana.yaml | 29 ++++++++++ ui/src/api/introspection.ts | 3 - ui/src/components/actions/list.tsx | 4 +- ui/src/components/actions/run/clone.tsx | 16 +++--- .../actions/run/disable-constraints.tsx | 6 +- .../actions/run/disable-triggers.tsx | 6 +- .../components/actions/run/drop-objects.tsx | 6 +- .../actions/run/enable-constraints.tsx | 6 +- .../actions/run/enable-triggers.tsx | 6 +- ui/src/components/actions/run/migrate.tsx | 16 +++--- ui/src/components/comparison/result/index.tsx | 2 +- ui/src/components/connection/edit.tsx | 57 +++++++++++-------- .../introspection/database-objects/index.tsx | 2 +- 13 files changed, 98 insertions(+), 61 deletions(-) create mode 100644 ui/qodana.yaml diff --git a/ui/qodana.yaml b/ui/qodana.yaml new file mode 100644 index 0000000..29f8f8c --- /dev/null +++ b/ui/qodana.yaml @@ -0,0 +1,29 @@ +#-------------------------------------------------------------------------------# +# Qodana analysis is configured by qodana.yaml file # +# https://www.jetbrains.com/help/qodana/qodana-yaml.html # +#-------------------------------------------------------------------------------# +version: "1.0" + +#Specify inspection profile for code analysis +profile: + name: qodana.starter + +#Enable inspections +#include: +# - name: + +#Disable inspections +#exclude: +# - name: +# paths: +# - + +#Execute shell command before Qodana execution (Applied in CI/CD pipeline) +#bootstrap: sh ./prepare-qodana.sh + +#Install IDE plugins before Qodana execution (Applied in CI/CD pipeline) +#plugins: +# - id: #(plugin id can be found at https://plugins.jetbrains.com) + +#Specify Qodana linter for analysis (Applied in CI/CD pipeline) +linter: jetbrains/qodana-js:latest diff --git a/ui/src/api/introspection.ts b/ui/src/api/introspection.ts index 5a22553..c4b3186 100644 --- a/ui/src/api/introspection.ts +++ b/ui/src/api/introspection.ts @@ -43,13 +43,10 @@ export interface Index extends DatabaseObject { status: string } -// eslint-disable-next-line @typescript-eslint/no-empty-interface export interface MaterializedView extends DatabaseObject {} -// eslint-disable-next-line @typescript-eslint/no-empty-interface export interface View extends DatabaseObject {} -// eslint-disable-next-line @typescript-eslint/no-empty-interface export interface Sequence extends DatabaseObject {} export interface Source extends DatabaseObject { diff --git a/ui/src/components/actions/list.tsx b/ui/src/components/actions/list.tsx index ee3bde8..b837e5d 100644 --- a/ui/src/components/actions/list.tsx +++ b/ui/src/components/actions/list.tsx @@ -142,8 +142,8 @@ const List = ({ type }: ListParams) => { { - mutate() + onComplete={async () => { + await mutate() setOpenDeleteDialog(false) }} onDismiss={() => setOpenDeleteDialog(false)} diff --git a/ui/src/components/actions/run/clone.tsx b/ui/src/components/actions/run/clone.tsx index 2b0308d..105a0f3 100644 --- a/ui/src/components/actions/run/clone.tsx +++ b/ui/src/components/actions/run/clone.tsx @@ -18,7 +18,7 @@ const Clone = () => { try { setLoading(true) await ActionAPI.runClone({ sourceConnectionId, targetConnectionId }) - mutate('/actions') + mutate('/actions').then() } finally { setLoading(false) } @@ -68,17 +68,17 @@ const Clone = () => { isLoading={loading} isDisabled={ loading || - (sourceConnectionId && - targetConnectionId && - sourceConnectionId === targetConnectionId) - ? true - : false + Boolean( + sourceConnectionId && + targetConnectionId && + sourceConnectionId === targetConnectionId, + ) } - onClick={() => { + onClick={async () => { setSourceInvalid(!sourceConnectionId) setTargetInvalid(!targetConnectionId) if (sourceConnectionId && targetConnectionId) { - handleClone(sourceConnectionId, targetConnectionId) + await handleClone(sourceConnectionId, targetConnectionId) } }} > diff --git a/ui/src/components/actions/run/disable-constraints.tsx b/ui/src/components/actions/run/disable-constraints.tsx index c3343fa..2d9684d 100644 --- a/ui/src/components/actions/run/disable-constraints.tsx +++ b/ui/src/components/actions/run/disable-constraints.tsx @@ -15,7 +15,7 @@ const DisableConstraints = () => { try { setLoading(true) await ActionAPI.runDisableConstraints({ connectionId }) - mutate('/actions') + mutate('/actions').then() } finally { setLoading(false) } @@ -46,10 +46,10 @@ const DisableConstraints = () => { colorScheme="blue" leftIcon={} isDisabled={loading} - onClick={() => { + onClick={async () => { setInvalid(!connectionId) if (connectionId) { - handleRun(connectionId) + await handleRun(connectionId) } }} > diff --git a/ui/src/components/actions/run/disable-triggers.tsx b/ui/src/components/actions/run/disable-triggers.tsx index 0dbd965..b2d7ece 100644 --- a/ui/src/components/actions/run/disable-triggers.tsx +++ b/ui/src/components/actions/run/disable-triggers.tsx @@ -15,7 +15,7 @@ const DisableTriggers = () => { try { setLoading(true) await ActionAPI.runDisableTriggers({ connectionId }) - mutate('/actions') + mutate('/actions').then() } finally { setLoading(false) } @@ -46,10 +46,10 @@ const DisableTriggers = () => { colorScheme="blue" leftIcon={} isDisabled={loading} - onClick={() => { + onClick={async () => { setInvalid(!connectionId) if (connectionId) { - handleRun(connectionId) + await handleRun(connectionId) } }} > diff --git a/ui/src/components/actions/run/drop-objects.tsx b/ui/src/components/actions/run/drop-objects.tsx index 3d99fbf..2fea10d 100644 --- a/ui/src/components/actions/run/drop-objects.tsx +++ b/ui/src/components/actions/run/drop-objects.tsx @@ -15,7 +15,7 @@ const DropObjects = () => { try { setLoading(true) await ActionAPI.runDropObjects({ connectionId }) - mutate('/actions') + mutate('/actions').then() } finally { setLoading(false) } @@ -46,10 +46,10 @@ const DropObjects = () => { colorScheme="red" leftIcon={} isDisabled={loading} - onClick={() => { + onClick={async () => { setInvalid(!connectionId) if (connectionId) { - handleRun(connectionId) + await handleRun(connectionId) } }} > diff --git a/ui/src/components/actions/run/enable-constraints.tsx b/ui/src/components/actions/run/enable-constraints.tsx index 56f9401..bc5f359 100644 --- a/ui/src/components/actions/run/enable-constraints.tsx +++ b/ui/src/components/actions/run/enable-constraints.tsx @@ -15,7 +15,7 @@ const EnableConstraints = () => { try { setLoading(true) await ActionAPI.runEnableConstraints({ connectionId }) - mutate('/actions') + mutate('/actions').then() } finally { setLoading(false) } @@ -46,10 +46,10 @@ const EnableConstraints = () => { colorScheme="blue" leftIcon={} isDisabled={loading} - onClick={() => { + onClick={async () => { setInvalid(!connectionId) if (connectionId) { - handleRun(connectionId) + await handleRun(connectionId) } }} > diff --git a/ui/src/components/actions/run/enable-triggers.tsx b/ui/src/components/actions/run/enable-triggers.tsx index 2c7145e..52d1401 100644 --- a/ui/src/components/actions/run/enable-triggers.tsx +++ b/ui/src/components/actions/run/enable-triggers.tsx @@ -15,7 +15,7 @@ const EnableTriggers = () => { try { setLoading(true) await ActionAPI.runEnableTriggers({ connectionId }) - mutate('/actions') + mutate('/actions').then() } finally { setLoading(false) } @@ -46,10 +46,10 @@ const EnableTriggers = () => { colorScheme="blue" leftIcon={} isDisabled={loading} - onClick={() => { + onClick={async () => { setInvalid(!connectionId) if (connectionId) { - handleRun(connectionId) + await handleRun(connectionId) } }} > diff --git a/ui/src/components/actions/run/migrate.tsx b/ui/src/components/actions/run/migrate.tsx index a35189a..017cbc0 100644 --- a/ui/src/components/actions/run/migrate.tsx +++ b/ui/src/components/actions/run/migrate.tsx @@ -18,7 +18,7 @@ const Migrate = () => { try { setLoading(true) await ActionAPI.runMigrate({ sourceConnectionId, targetConnectionId }) - mutate('/actions') + mutate('/actions').then() } finally { setLoading(false) } @@ -67,17 +67,17 @@ const Migrate = () => { leftIcon={} isDisabled={ loading || - (sourceConnectionId && - targetConnectionId && - sourceConnectionId === targetConnectionId) - ? true - : false + Boolean( + sourceConnectionId && + targetConnectionId && + sourceConnectionId === targetConnectionId, + ) } - onClick={() => { + onClick={async () => { setSourceInvalid(!sourceConnectionId) setTargetInvalid(!targetConnectionId) if (sourceConnectionId && targetConnectionId) { - handleClone(sourceConnectionId, targetConnectionId) + await handleClone(sourceConnectionId, targetConnectionId) } }} > diff --git a/ui/src/components/comparison/result/index.tsx b/ui/src/components/comparison/result/index.tsx index bbf54a6..f5d186e 100644 --- a/ui/src/components/comparison/result/index.tsx +++ b/ui/src/components/comparison/result/index.tsx @@ -79,7 +79,7 @@ const Result = ({ } if (!comparison) { setIsCacheDataData(false) - handleCompare() + handleCompare().then() } else if (isCacheData) { setShowCacheNotice(true) } diff --git a/ui/src/components/connection/edit.tsx b/ui/src/components/connection/edit.tsx index 0c22420..9b787b3 100644 --- a/ui/src/components/connection/edit.tsx +++ b/ui/src/components/connection/edit.tsx @@ -17,7 +17,14 @@ import { } from '@chakra-ui/react' import { variables } from '@koupr/ui' import { SectionSpinner } from '@koupr/ui' -import { Field, FieldAttributes, Form, Formik } from 'formik' +import { + Field, + FieldAttributes, + FieldProps, + Form, + Formik, + FormikHelpers, +} from 'formik' import * as Yup from 'yup' import { BsEye, BsEyeSlash } from 'react-icons/bs' import { FiChevronLeft } from 'react-icons/fi' @@ -30,6 +37,13 @@ type EditProps = { id: string } +type FormValues = { + name: string + jdbcUrl: string + jdbcUsername: string + jdbcPassword: string +} + const Edit = ({ id }: EditProps) => { const navigate = useNavigate() const toast = useToast() @@ -45,7 +59,10 @@ const Edit = ({ id }: EditProps) => { }) const handleSubmit = useCallback( - async (values: any, { setSubmitting }: any) => { + async ( + values: FormValues, + { setSubmitting }: FormikHelpers, + ) => { setSubmitting(true) try { await ConnectionAPI.update(id as string, { @@ -98,7 +115,7 @@ const Edit = ({ id }: EditProps) => { name: connection.name, jdbcUrl: connection.jdbcUrl, jdbcUsername: connection.jdbcUsername, - jdbcPassword: connection.jdbcPassword, + jdbcPassword: connection.jdbcPassword || '', }} validationSchema={formSchema} onSubmit={handleSubmit} @@ -108,9 +125,9 @@ const Edit = ({ id }: EditProps) => { - {({ field }: FieldAttributes) => ( + {({ field }: FieldAttributes) => ( Name @@ -119,11 +136,9 @@ const Edit = ({ id }: EditProps) => { )} - {({ field }: FieldAttributes) => ( + {({ field }: FieldAttributes) => ( JDBC URL @@ -132,13 +147,11 @@ const Edit = ({ id }: EditProps) => { )} - {({ field }: FieldAttributes) => ( + {({ field }: FieldAttributes) => ( JDBC username @@ -149,13 +162,11 @@ const Edit = ({ id }: EditProps) => { )} - {({ field }: FieldAttributes) => ( + {({ field }: FieldAttributes) => ( JDBC password @@ -214,8 +225,8 @@ const Edit = ({ id }: EditProps) => { { - mutate() + onComplete={async () => { + await mutate() setOpenDeleteDialog(false) navigate('/connections') }} diff --git a/ui/src/components/introspection/database-objects/index.tsx b/ui/src/components/introspection/database-objects/index.tsx index cae372f..23d2ac7 100644 --- a/ui/src/components/introspection/database-objects/index.tsx +++ b/ui/src/components/introspection/database-objects/index.tsx @@ -68,7 +68,7 @@ const DatabaseObjects = ({ connectionId, onDismiss }: DatabaseObjectsProps) => { } if (!introspection) { setIsCacheDataData(false) - handleIntrospect() + handleIntrospect().then() } else if (isCacheData) { setShowCacheNotice(true) }