Skip to content

Commit

Permalink
fix(ui): several code quality issues
Browse files Browse the repository at this point in the history
  • Loading branch information
bouassaba committed Oct 30, 2024
1 parent 2342187 commit 36c85e3
Show file tree
Hide file tree
Showing 13 changed files with 98 additions and 61 deletions.
29 changes: 29 additions & 0 deletions ui/qodana.yaml
Original file line number Diff line number Diff line change
@@ -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: <SomeEnabledInspectionId>

#Disable inspections
#exclude:
# - name: <SomeDisabledInspectionId>
# paths:
# - <path/where/not/run/inspection>

#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> #(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
3 changes: 0 additions & 3 deletions ui/src/api/introspection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions ui/src/components/actions/list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ const List = ({ type }: ListParams) => {
<Delete
id={actionId}
open={openDeleteDialog}
onComplete={() => {
mutate()
onComplete={async () => {
await mutate()
setOpenDeleteDialog(false)
}}
onDismiss={() => setOpenDeleteDialog(false)}
Expand Down
16 changes: 8 additions & 8 deletions ui/src/components/actions/run/clone.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const Clone = () => {
try {
setLoading(true)
await ActionAPI.runClone({ sourceConnectionId, targetConnectionId })
mutate('/actions')
mutate('/actions').then()
} finally {
setLoading(false)
}
Expand Down Expand Up @@ -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)
}
}}
>
Expand Down
6 changes: 3 additions & 3 deletions ui/src/components/actions/run/disable-constraints.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const DisableConstraints = () => {
try {
setLoading(true)
await ActionAPI.runDisableConstraints({ connectionId })
mutate('/actions')
mutate('/actions').then()
} finally {
setLoading(false)
}
Expand Down Expand Up @@ -46,10 +46,10 @@ const DisableConstraints = () => {
colorScheme="blue"
leftIcon={<IconPlayArrow />}
isDisabled={loading}
onClick={() => {
onClick={async () => {
setInvalid(!connectionId)
if (connectionId) {
handleRun(connectionId)
await handleRun(connectionId)
}
}}
>
Expand Down
6 changes: 3 additions & 3 deletions ui/src/components/actions/run/disable-triggers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const DisableTriggers = () => {
try {
setLoading(true)
await ActionAPI.runDisableTriggers({ connectionId })
mutate('/actions')
mutate('/actions').then()
} finally {
setLoading(false)
}
Expand Down Expand Up @@ -46,10 +46,10 @@ const DisableTriggers = () => {
colorScheme="blue"
leftIcon={<IconPlayArrow />}
isDisabled={loading}
onClick={() => {
onClick={async () => {
setInvalid(!connectionId)
if (connectionId) {
handleRun(connectionId)
await handleRun(connectionId)
}
}}
>
Expand Down
6 changes: 3 additions & 3 deletions ui/src/components/actions/run/drop-objects.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const DropObjects = () => {
try {
setLoading(true)
await ActionAPI.runDropObjects({ connectionId })
mutate('/actions')
mutate('/actions').then()
} finally {
setLoading(false)
}
Expand Down Expand Up @@ -46,10 +46,10 @@ const DropObjects = () => {
colorScheme="red"
leftIcon={<IconPlayArrow />}
isDisabled={loading}
onClick={() => {
onClick={async () => {
setInvalid(!connectionId)
if (connectionId) {
handleRun(connectionId)
await handleRun(connectionId)
}
}}
>
Expand Down
6 changes: 3 additions & 3 deletions ui/src/components/actions/run/enable-constraints.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const EnableConstraints = () => {
try {
setLoading(true)
await ActionAPI.runEnableConstraints({ connectionId })
mutate('/actions')
mutate('/actions').then()
} finally {
setLoading(false)
}
Expand Down Expand Up @@ -46,10 +46,10 @@ const EnableConstraints = () => {
colorScheme="blue"
leftIcon={<IconPlayArrow />}
isDisabled={loading}
onClick={() => {
onClick={async () => {
setInvalid(!connectionId)
if (connectionId) {
handleRun(connectionId)
await handleRun(connectionId)
}
}}
>
Expand Down
6 changes: 3 additions & 3 deletions ui/src/components/actions/run/enable-triggers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const EnableTriggers = () => {
try {
setLoading(true)
await ActionAPI.runEnableTriggers({ connectionId })
mutate('/actions')
mutate('/actions').then()
} finally {
setLoading(false)
}
Expand Down Expand Up @@ -46,10 +46,10 @@ const EnableTriggers = () => {
colorScheme="blue"
leftIcon={<IconPlayArrow />}
isDisabled={loading}
onClick={() => {
onClick={async () => {
setInvalid(!connectionId)
if (connectionId) {
handleRun(connectionId)
await handleRun(connectionId)
}
}}
>
Expand Down
16 changes: 8 additions & 8 deletions ui/src/components/actions/run/migrate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const Migrate = () => {
try {
setLoading(true)
await ActionAPI.runMigrate({ sourceConnectionId, targetConnectionId })
mutate('/actions')
mutate('/actions').then()
} finally {
setLoading(false)
}
Expand Down Expand Up @@ -67,17 +67,17 @@ const Migrate = () => {
leftIcon={<IconPlayArrow />}
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)
}
}}
>
Expand Down
2 changes: 1 addition & 1 deletion ui/src/components/comparison/result/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const Result = ({
}
if (!comparison) {
setIsCacheDataData(false)
handleCompare()
handleCompare().then()
} else if (isCacheData) {
setShowCacheNotice(true)
}
Expand Down
57 changes: 34 additions & 23 deletions ui/src/components/connection/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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()
Expand All @@ -45,7 +59,10 @@ const Edit = ({ id }: EditProps) => {
})

const handleSubmit = useCallback(
async (values: any, { setSubmitting }: any) => {
async (
values: FormValues,
{ setSubmitting }: FormikHelpers<FormValues>,
) => {
setSubmitting(true)
try {
await ConnectionAPI.update(id as string, {
Expand Down Expand Up @@ -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}
Expand All @@ -108,9 +125,9 @@ const Edit = ({ id }: EditProps) => {
<Stack spacing={variables.spacingLg}>
<Stack spacing={variables.spacing}>
<Field name="name">
{({ field }: FieldAttributes<any>) => (
{({ field }: FieldAttributes<FieldProps>) => (
<FormControl
isInvalid={errors.name && touched.name ? true : false}
isInvalid={Boolean(errors.name && touched.name)}
>
<FormLabel htmlFor="name">Name</FormLabel>
<Input {...field} w="400px" disabled={isSubmitting} />
Expand All @@ -119,11 +136,9 @@ const Edit = ({ id }: EditProps) => {
)}
</Field>
<Field name="jdbcUrl">
{({ field }: FieldAttributes<any>) => (
{({ field }: FieldAttributes<FieldProps>) => (
<FormControl
isInvalid={
errors.jdbcUrl && touched.jdbcUrl ? true : false
}
isInvalid={Boolean(errors.jdbcUrl && touched.jdbcUrl)}
>
<FormLabel htmlFor="jdbcUrl">JDBC URL</FormLabel>
<Input {...field} w="400px" disabled={isSubmitting} />
Expand All @@ -132,13 +147,11 @@ const Edit = ({ id }: EditProps) => {
)}
</Field>
<Field name="jdbcUsername">
{({ field }: FieldAttributes<any>) => (
{({ field }: FieldAttributes<FieldProps>) => (
<FormControl
isInvalid={
errors.jdbcUsername && touched.jdbcUsername
? true
: false
}
isInvalid={Boolean(
errors.jdbcUsername && touched.jdbcUsername,
)}
>
<FormLabel htmlFor="jdbcUsername">
JDBC username
Expand All @@ -149,13 +162,11 @@ const Edit = ({ id }: EditProps) => {
)}
</Field>
<Field name="jdbcPassword">
{({ field }: FieldAttributes<any>) => (
{({ field }: FieldAttributes<FieldProps>) => (
<FormControl
isInvalid={
errors.jdbcPassword && touched.jdbcPassword
? true
: false
}
isInvalid={Boolean(
errors.jdbcPassword && touched.jdbcPassword,
)}
>
<FormLabel htmlFor="jdbcPassword">
JDBC password
Expand Down Expand Up @@ -214,8 +225,8 @@ const Edit = ({ id }: EditProps) => {
<Delete
id={id}
open={openDeleteDialog}
onComplete={() => {
mutate()
onComplete={async () => {
await mutate()
setOpenDeleteDialog(false)
navigate('/connections')
}}
Expand Down
2 changes: 1 addition & 1 deletion ui/src/components/introspection/database-objects/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const DatabaseObjects = ({ connectionId, onDismiss }: DatabaseObjectsProps) => {
}
if (!introspection) {
setIsCacheDataData(false)
handleIntrospect()
handleIntrospect().then()
} else if (isCacheData) {
setShowCacheNotice(true)
}
Expand Down

0 comments on commit 36c85e3

Please sign in to comment.