Skip to content

Commit 790c1b9

Browse files
committed
fix: address sonarqube issues
1 parent 7dbecc2 commit 790c1b9

File tree

6 files changed

+25
-39
lines changed

6 files changed

+25
-39
lines changed

src/components/data_library/LibraryDataGrid.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ import {
66
} from '@mui/x-data-grid'
77
import { Box, Typography, CircularProgress } from '@mui/material'
88
import { isEmpty } from 'lodash'
9-
import { LibraryDataGridProps, AssetType } from 'src/types/library'
9+
import { LibraryDataGridProps, AssetType, StudyAggregation } from 'src/types/library'
1010
import { DatasetTerm } from 'src/types/model'
11-
import { StudyAggregation } from 'src/types/library'
1211
import { makeDatasetColumns } from './columns/datasetColumns'
1312
import { makeStudyColumns } from './columns/studyColumns'
1413

src/components/data_library/LibraryFilters.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export const LibraryFilters: React.FC<LibraryFiltersProps> = ({
3535
}
3636

3737
const handleParticipantChange = (type: 'min' | 'max', value: string) => {
38-
const numValue = value === '' ? undefined : parseInt(value)
38+
const numValue = value === '' ? undefined : Number.parseInt(value)
3939
onChange({
4040
...filters,
4141
participantCount: {

src/hooks/useLibraryData.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,13 +331,13 @@ export const useLibraryData = (
331331
aggregations: {},
332332
}
333333
},
334-
staleTime: 5 * 60 * 1000, // 5 minutes
335-
retry: 1, // Only retry once on failure
334+
staleTime: 5 * 60 * 1000,
335+
retry: 1,
336336
// Provide default data structure on error to prevent crashes
337337
placeholderData: {
338338
items: [],
339339
total: 0,
340340
aggregations: {},
341341
},
342342
})
343-
}
343+
}

src/hooks/useLibraryUrlState.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ const parseFiltersFromUrl = (searchParams: URLSearchParams): FilterState => {
1212
dac: searchParams.get('dac')?.split(',').filter(Boolean) || [],
1313
participantCount: {
1414
min: searchParams.get('minParticipants')
15-
? parseInt(searchParams.get('minParticipants')!)
15+
? Number.parseInt(searchParams.get('minParticipants')!)
1616
: undefined,
1717
max: searchParams.get('maxParticipants')
18-
? parseInt(searchParams.get('maxParticipants')!)
18+
? Number.parseInt(searchParams.get('maxParticipants')!)
1919
: undefined,
2020
},
2121
}
@@ -57,18 +57,18 @@ const serializeFiltersToUrl = (
5757
searchParams.delete('dac')
5858
}
5959

60-
if (filters.participantCount.min !== undefined) {
61-
searchParams.set('minParticipants', filters.participantCount.min.toString())
60+
if (filters.participantCount.min === undefined) {
61+
searchParams.delete('minParticipants')
6262
}
6363
else {
64-
searchParams.delete('minParticipants')
64+
searchParams.set('minParticipants', filters.participantCount.min.toString())
6565
}
6666

67-
if (filters.participantCount.max !== undefined) {
68-
searchParams.set('maxParticipants', filters.participantCount.max.toString())
67+
if (filters.participantCount.max === undefined) {
68+
searchParams.delete('maxParticipants')
6969
}
7070
else {
71-
searchParams.delete('maxParticipants')
71+
searchParams.set('maxParticipants', filters.participantCount.max.toString())
7272
}
7373
}
7474

@@ -84,8 +84,8 @@ export const useLibraryUrlState = () => {
8484
tab: (searchParams.get('tab') as AssetType) || AssetType.STUDIES,
8585
search: searchParams.get('search') || '',
8686
filters: parseFiltersFromUrl(searchParams),
87-
page: parseInt(searchParams.get('page') || '0'),
88-
pageSize: parseInt(searchParams.get('pageSize') || '25'),
87+
page: Number.parseInt(searchParams.get('page') || '0'),
88+
pageSize: Number.parseInt(searchParams.get('pageSize') || '25'),
8989
sortField: searchParams.get('sort') || undefined,
9090
sortOrder: (searchParams.get('order') as 'asc' | 'desc') || undefined,
9191
}
@@ -131,11 +131,11 @@ export const useLibraryUrlState = () => {
131131
}
132132

133133
if (updates.pageSize !== undefined) {
134-
if (updates.pageSize !== 25) {
135-
newParams.set('pageSize', updates.pageSize.toString())
134+
if (updates.pageSize === 25) {
135+
newParams.delete('pageSize')
136136
}
137137
else {
138-
newParams.delete('pageSize')
138+
newParams.set('pageSize', updates.pageSize.toString())
139139
}
140140
}
141141

src/pages/DataLibrary.tsx

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ export const DataLibrary: React.FC = () => {
3535
// Local selection state (dataset IDs)
3636
const [selectedDatasetIds, setSelectedDatasetIds] = useState<number[]>([])
3737

38-
// Library configuration (could be made dynamic based on urlState.library)
3938
const libraryConfig: LibraryVersion = {
4039
key: 'duos',
4140
query: null,
@@ -46,13 +45,11 @@ export const DataLibrary: React.FC = () => {
4645
order: 0,
4746
}
4847

49-
// Tab configuration
5048
const tabs: TabConfig[] = [
5149
{ key: AssetType.STUDIES, label: 'Studies' },
5250
{ key: AssetType.DATASETS, label: 'Datasets' },
5351
]
5452

55-
// Available filters (in a real app, these might come from an API)
5653
const availableFilters: AvailableFilters = {
5754
accessManagement: [
5855
{ value: 'controlled', label: 'Controlled' },
@@ -70,7 +67,7 @@ export const DataLibrary: React.FC = () => {
7067
{ value: 'Genomic', label: 'Genomic' },
7168
{ value: 'Transcriptomic', label: 'Transcriptomic' },
7269
],
73-
dac: [], // Would be populated from API
70+
dac: [],
7471
participantCountRange: {
7572
min: 0,
7673
max: 100000,
@@ -89,34 +86,29 @@ export const DataLibrary: React.FC = () => {
8986
: undefined,
9087
)
9188

92-
// Handle tab change
9389
const handleTabChange = (newAssetType: AssetType) => {
9490
updateUrlState({ tab: newAssetType })
95-
setSelectedDatasetIds([]) // Clear selection when switching tabs
91+
setSelectedDatasetIds([])
9692
}
9793

98-
// Handle search change
9994
const handleSearchChange = (searchTerm: string) => {
10095
updateUrlState({
10196
search: searchTerm,
102-
page: 0, // Reset to first page
97+
page: 0,
10398
})
10499
}
105100

106-
// Handle clear search
107101
const handleClearSearch = () => {
108102
updateUrlState({ search: '' })
109103
}
110104

111-
// Handle filter changes
112105
const handleFiltersChange = (newFilters: typeof urlState.filters) => {
113106
updateUrlState({
114107
filters: newFilters,
115-
page: 0, // Reset to first page
108+
page: 0,
116109
})
117110
}
118111

119-
// Handle clear filters
120112
const handleClearFilters = () => {
121113
updateUrlState({
122114
filters: {
@@ -130,15 +122,13 @@ export const DataLibrary: React.FC = () => {
130122
})
131123
}
132124

133-
// Convert sort model for DataGrid
134125
const sortModel = useMemo(() => {
135126
if (urlState.sortField && urlState.sortOrder) {
136127
return [{ field: urlState.sortField, sort: urlState.sortOrder }]
137128
}
138129
return []
139130
}, [urlState.sortField, urlState.sortOrder])
140131

141-
// Handle sort changes
142132
const handleSortChange = (model: Array<{ field: string, sort: 'asc' | 'desc' | null }>) => {
143133
if (model.length > 0 && model[0].sort) {
144134
updateUrlState({
@@ -154,19 +144,16 @@ export const DataLibrary: React.FC = () => {
154144
}
155145
}
156146

157-
// Handle selection changes
158147
const handleSelectionChange = (datasetIds: number[]) => {
159148
setSelectedDatasetIds(datasetIds)
160149
}
161150

162-
// Handle Apply for Access
163151
const handleApplyForAccess = () => {
164152
// Navigate to DAR Application with selected dataset IDs
165153
const datasetIdsParam = selectedDatasetIds.join(',')
166154
navigate(`/dar_application?datasetIds=${datasetIdsParam}`)
167155
}
168156

169-
// Show error state
170157
if (error) {
171158
return (
172159
<Box sx={{ px: 3, py: 4 }}>
@@ -183,7 +170,7 @@ export const DataLibrary: React.FC = () => {
183170
{/* Header */}
184171
<Box sx={{ px: 3, pt: 3 }}>
185172
<LibraryHeader
186-
icon={null} // Using MUI icon instead
173+
icon={null}
187174
title="Data Library"
188175
description="Search and browse available datasets and studies"
189176
searchTerm={urlState.search}

src/types/library.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { DatasetTerm } from './model'
88
export enum AssetType {
99
STUDIES = 'studies',
1010
DATASETS = 'datasets',
11-
AI_MODELS = 'ai-models', // Future
11+
MODELS = 'models',
1212
}
1313

1414
// Library configuration
@@ -335,7 +335,7 @@ export interface LibraryFiltersProps {
335335

336336
export interface LibraryDataGridProps {
337337
assetType: AssetType
338-
data: any[]
338+
data: unknown[]
339339
loading: boolean
340340
total: number
341341
paginationModel: {

0 commit comments

Comments
 (0)