-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from WorldHealthOrganization/feature/find721-s…
…ample-search-base-implementation FIND-721 INSDC Samples Search: Baseline page implementation.
- Loading branch information
Showing
21 changed files
with
345 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"rules": { | ||
"max-len": ["error", { "code": 120 }] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
181 changes: 181 additions & 0 deletions
181
src/features/TableView/components/GenotypeResistanceView/GenotypeResistanceView.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
/** @jsxImportSource @emotion/react */ | ||
import React, { | ||
useEffect, useState, SyntheticEvent, useRef, | ||
} from 'react'; | ||
import { CSVLink } from 'react-csv'; | ||
|
||
import { useGetDrugsDataQuery } from '../../../../services/drugsApi/drugsApi'; | ||
import { useGetTableDataQuery, useGetExportTableLazyQuery } from '../../../../services/genotypeResistanceApi/genotypeResistanceApi'; | ||
import { DEFAULT_PAGE_SIZE, useTableData } from '../../hooks/useTableData'; | ||
import { useDebounce } from '../../../../hooks/useDebounce'; | ||
import { useExportTable } from '../../../../hooks/useExportTable'; | ||
|
||
import H1 from '../../../../components/typography/H1'; | ||
import AppPaper from '../../../../components/AppPaper/AppPaper'; | ||
import H3 from '../../../../components/typography/H3'; | ||
|
||
import AutocompleteInputSearch from '../../../../components/AutocompleteInputSearch/AutocompleteInputSearch'; | ||
import LoadingWrapper from '../../../../components/LoadingWrapper/LoadingWrapper'; | ||
import AppButton from '../../../../components/AppButton/AppButton'; | ||
|
||
import DataGrid from '../../../../components/DataGrid'; | ||
import { pagination } from '../../../../components/DataGrid/styles'; | ||
import Pagination from '../../../drugsView/componets/Pagination/Pagination'; | ||
import { | ||
GenotypeResistance, GridType, IColumn, | ||
} from '../../../../components/DataGrid/models'; | ||
|
||
import { | ||
header, | ||
wrapper, | ||
paperWrapper, | ||
paper, | ||
dataGrid, | ||
viewStyles, | ||
buttonUploadWrapper, | ||
addStyle, | ||
} from './styles'; | ||
|
||
export const columns: IColumn<GenotypeResistance>[] = [ | ||
{ name: 'drugName', header: 'Drug' }, | ||
{ name: 'variant', header: 'Variant' }, | ||
{ name: 'sampleAliasesName', header: 'Sample Alias Name' }, | ||
{ name: 'resistanceFlag', header: 'Genotype Resistance' }, | ||
]; | ||
|
||
const GenotypeResistanceView = () => { | ||
// react-scv lib doesn't have types for ref | ||
const csvRef = useRef<any>(null); | ||
|
||
const [inputSampleValue, setInputSampleValue] = useState<boolean | string>(false); | ||
const debouncedSampleValue = useDebounce<boolean | string>(inputSampleValue, 500); | ||
|
||
const { | ||
data: drugsData = [], | ||
} = useGetDrugsDataQuery({ isAssociated: 1 }); | ||
|
||
const getDrugIds = () => { | ||
let drugsIds = ''; | ||
drugsData.forEach((drugItem) => { | ||
drugsIds += `,${drugItem.drugId}`; | ||
}); | ||
return drugsIds.substring(1); | ||
}; | ||
|
||
const { | ||
rowsCount, | ||
tableData = [], | ||
isTableDataLoading, | ||
sortState, | ||
filters, | ||
page, | ||
updateSort, | ||
updateFilters, | ||
updatePaging, | ||
} = useTableData({ | ||
drugID: getDrugIds(), | ||
useGetDataQuery: useGetTableDataQuery, | ||
}); | ||
|
||
const { | ||
response, | ||
fetchData, | ||
} = useExportTable(useGetExportTableLazyQuery, { filters }); | ||
|
||
const handleSampleChange = (e: SyntheticEvent, value: string) => { | ||
setInputSampleValue(value); | ||
}; | ||
|
||
useEffect(() => { | ||
if (csvRef?.current && response.data?.length && response.status === 'fulfilled') { | ||
csvRef.current.link.click(); | ||
} | ||
}, [response]); | ||
|
||
useEffect(() => { | ||
if (typeof debouncedSampleValue === 'boolean') { | ||
// eslint-disable-line | ||
} else { | ||
updateFilters([{ id: 'sampleAliasesName', value: debouncedSampleValue }]); | ||
} | ||
// eslint-disable-line | ||
}, [debouncedSampleValue]); | ||
|
||
if (!tableData.length && isTableDataLoading) { | ||
return ( | ||
<div css={wrapper}> | ||
<H1 style={header}>Sample Alias Search</H1> | ||
<LoadingWrapper centered isLoading> | ||
<span /> | ||
</LoadingWrapper> | ||
</div> | ||
); | ||
} | ||
|
||
return ( | ||
<div css={wrapper}> | ||
<H1 style={header}>Sample Alias Search</H1> | ||
<div css={dataGrid}> | ||
<DataGrid<GenotypeResistance> | ||
isLoading={isTableDataLoading} | ||
columns={columns} | ||
dataSource={tableData} | ||
filterValues={filters} | ||
onFilterChange={updateFilters} | ||
onSortingChange={updateSort} | ||
selectedDropdownItem={{}} | ||
sortState={sortState} | ||
type={GridType.Drug} | ||
addStyle={addStyle} | ||
> | ||
<div css={paperWrapper}> | ||
<AppPaper style={paper}> | ||
<div css={viewStyles.autoCompleteContainer}> | ||
<H3 | ||
style={viewStyles.autoCompleteInputLabel} | ||
> | ||
Sample Alias | ||
</H3> | ||
<AutocompleteInputSearch | ||
isLoading={isTableDataLoading} | ||
onSelectionChanged={(e, value) => { console.log(e, value); }} | ||
selectedValue={null} | ||
onChange={handleSampleChange} | ||
value={`${debouncedSampleValue}`} | ||
options={[]} | ||
style={viewStyles.sxAutoComplete} | ||
placeholder="Search by Sample Alias Name" | ||
/> | ||
</div> | ||
<div css={buttonUploadWrapper}> | ||
<H3 style={viewStyles.autoCompleteInputLabel}>Export CSV Data</H3> | ||
<AppButton | ||
onClick={fetchData} | ||
variant="outlined" | ||
size="medium" | ||
startIconName="file_download" | ||
> | ||
{response.isLoading ? 'Loading...' : 'Download'} | ||
</AppButton> | ||
<CSVLink | ||
ref={csvRef} | ||
data={response.data || []} | ||
filename="GenotypeResistanceSearch" | ||
/> | ||
</div> | ||
</AppPaper> | ||
</div> | ||
</DataGrid> | ||
<div css={pagination.wrapper}> | ||
<Pagination | ||
page={page} | ||
pageCount={Math.ceil(rowsCount / DEFAULT_PAGE_SIZE)} | ||
onPageClick={updatePaging} | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default GenotypeResistanceView; |
23 changes: 23 additions & 0 deletions
23
src/features/TableView/components/GenotypeResistanceView/styles.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { | ||
wrapper, | ||
header, | ||
dataGrid, | ||
paperWrapper, | ||
paper, | ||
iconStyles, | ||
viewStyles, | ||
buttonUploadWrapper, | ||
addStyle, | ||
} from '../../styles'; | ||
|
||
export { | ||
wrapper, | ||
header, | ||
dataGrid, | ||
paperWrapper, | ||
paper, | ||
iconStyles, | ||
viewStyles, | ||
buttonUploadWrapper, | ||
addStyle, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { | ||
wrapper, | ||
header, | ||
dataGrid, | ||
paperWrapper, | ||
paper, | ||
iconStyles, | ||
viewStyles, | ||
buttonUploadWrapper, | ||
addStyle, | ||
} from '../../styles'; | ||
|
||
export { | ||
wrapper, | ||
header, | ||
dataGrid, | ||
paperWrapper, | ||
paper, | ||
iconStyles, | ||
viewStyles, | ||
buttonUploadWrapper, | ||
addStyle, | ||
}; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.