Skip to content

Commit

Permalink
fix eslint warning/errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ricopella committed Oct 28, 2023
1 parent 39936e5 commit 8ad07f9
Show file tree
Hide file tree
Showing 24 changed files with 182 additions and 157 deletions.
4 changes: 2 additions & 2 deletions src/renderer/src/Sections/Directories/ActionsRow.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { insertScan, openFilesDirectoryDialog, removeDirectories } from '@renderer/actions/ipc'
import ErrorMessage from '@renderer/components/ErrorMessage'
import PreviousResults from '@renderer/components/PreviousResults'
import { useMain } from '@renderer/context/MainContext'
import { useTableContext } from '@renderer/context/TableContext'
import useMain from '@renderer/context/hooks/useMain'
import useTableContext from '@renderer/context/hooks/useTableContext'
import { transformScan } from '@renderer/utils/transformScan'
import { ADD_NEW_SCAN, REMOVE_DIRECTORIES, UPDATE_ACTIVE_TAB } from '@src/constants'
import { useQueryClient } from '@tanstack/react-query'
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/src/Sections/Directories/ConfigurationPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useMain } from '@renderer/context/MainContext'
import useMain from '@renderer/context/hooks/useMain'
import { useEffect } from 'react'

const classNames = {
Expand Down Expand Up @@ -74,7 +74,7 @@ export default function ConfigurationPanel(): JSX.Element {
}
})
}
}, [type, scanConfiguration.scanType, dispatch])
}, [type, scanConfiguration.scanType, dispatch, scanType, includeCrates])

return (
<div className="rounded-t bg-base-200 p-4 border-b-2 border-base-content border-opacity-5">
Expand Down
105 changes: 105 additions & 0 deletions src/renderer/src/Sections/Directories/List.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import { FilesDirectory } from '@prisma/client'
import Loader from '@renderer/components/Loader'
import Body from '@renderer/components/Table/Body'
import TableHeader from '@renderer/components/Table/Header'
import IndeterminateCheckbox from '@renderer/components/Table/InderminateCheckbox'
import useMain from '@renderer/context/hooks/useMain'
import useTableContext from '@renderer/context/hooks/useTableContext'
import useFetchDirectories from '@renderer/hooks/useDirectoriesList'
import { createColumnHelper, getCoreRowModel, useReactTable } from '@tanstack/react-table'
import { useMemo } from 'react'
import { fuzzyFilter } from '../Results/utils'

const classNames = {
table: 'table table-xs padding-sm w-full'
}
const columnHelper = createColumnHelper<FilesDirectory>()

const List = (): JSX.Element => {
const { state } = useMain()
const { rowSelection, setRowSelection } = useTableContext()

const { status } = useFetchDirectories()

const directories = state.directorySrcs

const columns = useMemo(
() => [
columnHelper.display({
id: 'select',
size: 16,
header: ({ table }) => (
<IndeterminateCheckbox
{...{
checked: table.getIsAllRowsSelected(),
indeterminate: table.getIsSomeRowsSelected(),
onChange: table.getToggleAllRowsSelectedHandler()
}}
/>
),
cell: ({ row }) => (
<div>
<IndeterminateCheckbox
{...{
checked: row.getIsSelected(),
disabled: !row.getCanSelect(),
indeterminate: row.getIsSomeSelected(),
onChange: row.getToggleSelectedHandler()
}}
/>
</div>
)
}),
columnHelper.accessor('id', {
id: 'id'
}),
columnHelper.accessor('path', {
id: 'path',
cell: (info) => info.getValue(),
header: () => <span>Path</span>
})
],
[]
)

const table = useReactTable({
data: directories ?? [],
columns,
getCoreRowModel: getCoreRowModel(),
state: {
columnVisibility: {
id: false
},
rowSelection
},
filterFns: {
fuzzy: fuzzyFilter
},
enableRowSelection: true,
onRowSelectionChange: setRowSelection
})

const renderList = (): JSX.Element => {
if (status === 'pending') {
return (
<div className="h-full w-full flex justify-center items-center">
<Loader />
</div>
)
}

return (
<table className={classNames.table}>
<TableHeader<FilesDirectory> headerGroups={table.getHeaderGroups()} />
<Body<FilesDirectory>
table={table}
noResultsMessage="No directories selected. Use the buttons below to add/remove directories to scan."
/>
</table>
)
}

return <div className="overflow-x-auto">{renderList()}</div>
}

export default List
110 changes: 7 additions & 103 deletions src/renderer/src/Sections/Directories/index.tsx
Original file line number Diff line number Diff line change
@@ -1,111 +1,13 @@
import { FilesDirectory } from '@prisma/client'
import Loader from '@renderer/components/Loader'
import Body from '@renderer/components/Table/Body'
import TableHeader from '@renderer/components/Table/Header'
import IndeterminateCheckbox from '@renderer/components/Table/InderminateCheckbox'
import { useMain } from '@renderer/context/MainContext'
import { TableProvider, useTableContext } from '@renderer/context/TableContext'
import useFetchDirectories from '@renderer/hooks/useDirectoriesList'
import { createColumnHelper, getCoreRowModel, useReactTable } from '@tanstack/react-table'
import { memo, useMemo } from 'react'
import { fuzzyFilter } from '../Results/utils'
import { TableProvider } from '@renderer/context/TableContext'
import ActionsRow from './ActionsRow'
import ConfigurationPanel from './ConfigurationPanel'
import List from './List'

const classNames = {
container: 'h-full w-full grid grid-rows-max-1fr-max',
table: 'table table-xs padding-sm w-full'
container: 'h-full w-full grid grid-rows-max-1fr-max'
}
const columnHelper = createColumnHelper<FilesDirectory>()

const List = (): JSX.Element => {
const { state } = useMain()
const { rowSelection, setRowSelection } = useTableContext()

const { status } = useFetchDirectories()

const directories = state.directorySrcs

const columns = useMemo(
() => [
columnHelper.display({
id: 'select',
size: 16,
header: ({ table }) => (
<IndeterminateCheckbox
{...{
checked: table.getIsAllRowsSelected(),
indeterminate: table.getIsSomeRowsSelected(),
onChange: table.getToggleAllRowsSelectedHandler()
}}
/>
),
cell: ({ row }) => (
<div>
<IndeterminateCheckbox
{...{
checked: row.getIsSelected(),
disabled: !row.getCanSelect(),
indeterminate: row.getIsSomeSelected(),
onChange: row.getToggleSelectedHandler()
}}
/>
</div>
)
}),
columnHelper.accessor('id', {
id: 'id'
}),
columnHelper.accessor('path', {
id: 'path',
cell: (info) => info.getValue(),
header: () => <span>Path</span>
})
],
[]
)

const table = useReactTable({
data: directories ?? [],
columns,
getCoreRowModel: getCoreRowModel(),
state: {
columnVisibility: {
id: false
},
rowSelection
},
filterFns: {
fuzzy: fuzzyFilter
},
enableRowSelection: true,
onRowSelectionChange: setRowSelection
})

const renderList = (): JSX.Element => {
if (status === 'pending') {
return (
<div className="h-full w-full flex justify-center items-center">
<Loader />
</div>
)
}

return (
<table className={classNames.table}>
<TableHeader<FilesDirectory> headerGroups={table.getHeaderGroups()} />
<Body<FilesDirectory>
table={table}
noResultsMessage="No directories selected. Use the buttons below to add/remove directories to scan."
/>
</table>
)
}

return <div className="overflow-x-auto">{renderList()}</div>
}

export default memo(function Directories(): JSX.Element {
function Directories(): JSX.Element {
return (
<TableProvider>
<div className={classNames.container}>
Expand All @@ -115,4 +17,6 @@ export default memo(function Directories(): JSX.Element {
</div>
</TableProvider>
)
})
}

export default Directories
4 changes: 2 additions & 2 deletions src/renderer/src/Sections/Results/ActionsRow.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import ErrorMessage from '@renderer/components/ErrorMessage'
import { useMain } from '@renderer/context/MainContext'
import { useTableContext } from '@renderer/context/TableContext'
import useMain from '@renderer/context/hooks/useMain'
import useTableContext from '@renderer/context/hooks/useTableContext'
import { useMemo } from 'react'

const classNames = {
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/src/Sections/Results/ConfigurationPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import DebouncedInput from '@renderer/components/DebouncedInput'
import ColumnSelection from '@renderer/components/Table/ColumnSelection'
import { useMain } from '@renderer/context/MainContext'
import { useTableContext } from '@renderer/context/TableContext'
import useMain from '@renderer/context/hooks/useMain'
import useTableContext from '@renderer/context/hooks/useTableContext'
import { values } from 'ramda'
import { useMemo } from 'react'
import ErrorIcon from '../../assets/error.svg?react'
Expand Down
6 changes: 4 additions & 2 deletions src/renderer/src/Sections/Results/DeleteConfirmModal.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { deleteFiles } from '@renderer/actions/ipc'
import { useMain } from '@renderer/context/MainContext'
import useMain from '@renderer/context/hooks/useMain'
import { ADD_TRACKING_DELETE_ID } from '@src/constants'
import { DuplicateData, NotCratedData, ResultsData } from '@src/types'
import { memo } from 'react'
Expand All @@ -13,7 +13,7 @@ type Props = {
selected: Record<string, boolean>
}

export default memo(function deleteWarningModal({
const DeleteModal = memo(function DeleteWarningModal({
data,
id,
selected,
Expand Down Expand Up @@ -79,3 +79,5 @@ export default memo(function deleteWarningModal({
</dialog>
)
})

export default DeleteModal
4 changes: 2 additions & 2 deletions src/renderer/src/Sections/Results/columns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export const duplicatesColumns: ColumnDef<ResultsData>[] = [
header: 'Crates',
accessorFn: (row): number => {
if ((row as DuplicateData)?.files?.length === 0) {
// @ts-ignore
// @ts-ignore row type is incorrect
return (row.crates || []).length
}

Expand All @@ -175,7 +175,7 @@ export const duplicatesColumns: ColumnDef<ResultsData>[] = [
cell: (info): JSX.Element | number | string => {
if (info.row.depth === 0) {
const count = info.row.subRows.reduce((acc, row) => {
// @ts-ignore
// @ts-ignore row type is incorrect
return acc + row.original?.crates?.length ?? 0
}, 0)

Expand Down
7 changes: 4 additions & 3 deletions src/renderer/src/Sections/Results/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import Loader from '@renderer/components/Loader'
import Body from '@renderer/components/Table/Body'
import { useMain } from '@renderer/context/MainContext'
import { TableProvider, useTableContext } from '@renderer/context/TableContext'
import { TableProvider } from '@renderer/context/TableContext'
import useMain from '@renderer/context/hooks/useMain'
import useTableContext from '@renderer/context/hooks/useTableContext'
import { ResultsData, ScanResults } from '@src/types'
import { RankingInfo } from '@tanstack/match-sorter-utils'
import {
Expand Down Expand Up @@ -50,7 +51,7 @@ const Table = ({ id }: { id: string }): JSX.Element => {
setRowSelection
} = useTableContext()
const scan = state.scans[id]
const results: ScanResults = scan.results ?? { files: {} }
const results: ScanResults = useMemo(() => scan.results ?? { files: {} }, [scan])
const [sorted, setSorting] = useState<SortingState>([])
const data: ResultsData[] = useMemo(() => {
return transformScanResultsToRows(results, scan)
Expand Down
6 changes: 4 additions & 2 deletions src/renderer/src/components/DebouncedInput.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { InputHTMLAttributes, memo, useEffect, useState } from 'react'

export default memo(function DebouncedInput({
const Input = memo(function DebouncedInput({
value: initialValue,
onChange,
debounce = 500,
Expand All @@ -24,7 +24,7 @@ export default memo(function DebouncedInput({
}, debounce)

return (): void => clearTimeout(timeout)
}, [value])
}, [debounce, onChange, value])

return (
<input
Expand All @@ -35,3 +35,5 @@ export default memo(function DebouncedInput({
/>
)
})

export default Input
2 changes: 1 addition & 1 deletion src/renderer/src/components/PreviousResults.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useMain } from '@renderer/context/MainContext'
import useMain from '@renderer/context/hooks/useMain'
import useScansList from '@renderer/hooks/useScansList'
import { UPDATE_ACTIVE_TAB } from '@src/constants'
import { format } from 'date-fns'
Expand Down
8 changes: 4 additions & 4 deletions src/renderer/src/components/SectionTabs.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Directories from '@renderer/Sections/Directories'
import { useMain } from '@renderer/context/MainContext'
import useMain from '@renderer/context/hooks/useMain'
import { REMOVE_SCAN, UPDATE_ACTIVE_TAB } from '@src/constants'
import { keys } from 'ramda'
import { Suspense, lazy, memo, useMemo } from 'react'
Expand All @@ -15,7 +15,7 @@ const classNames = {
contentContainer: 'bg-base-300 h-full w-full rounded-t-none rounded-b overflow-hidden p-4'
}

function SectionTabs(): JSX.Element {
const Tabs = memo(function SectionTabs(): JSX.Element {
const { state, dispatch } = useMain()

const handleTabClick = (tabId: string): void => {
Expand Down Expand Up @@ -101,6 +101,6 @@ function SectionTabs(): JSX.Element {
</Suspense>
</div>
)
}
})

export default memo(SectionTabs)
export default Tabs
Loading

0 comments on commit 8ad07f9

Please sign in to comment.