Skip to content

Commit

Permalink
default loading of tables implemented for genomes and genes.
Browse files Browse the repository at this point in the history
  • Loading branch information
vikasguptaebi committed Nov 13, 2024
1 parent baec646 commit d89e8e9
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 134 deletions.
27 changes: 27 additions & 0 deletions dataportal-app/src/components/interfaces/Genome.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
export interface Contig {
seq_id: string;
length: number;
}

export interface Genome {
species: string;
id: number;
common_name: string;
isolate_name: string;
assembly_name: string;
assembly_accession: string | null;
fasta_file: string;
gff_file: string;
fasta_url: string;
gff_url: string;
contigs: Contig[];
}

export interface GenomeResponse {
results: Genome[];
page_number: number;
num_pages: number;
has_previous: boolean;
has_next: boolean;
total_results: number;
}
126 changes: 52 additions & 74 deletions dataportal-app/src/components/organisms/GeneSearch/GeneSearchForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,83 +110,61 @@ const GeneSearchForm: React.FC<GeneSearchFormProps> = ({

// Fetch search results based on the query, selected species, page, sort field, and sort order
const fetchSearchResults = useCallback(
async (page = 1, sortField = currentSortField, sortOrder = currentSortOrder) => {
async (page = 1, sortField = currentSortField, sortOrder = currentSortOrder) => {
const params = new URLSearchParams({
'query': query.trim() || '',
'page': String(page),
'per_page': String(pageSize),
'sortField': sortField,
'sortOrder': sortOrder,
});

if (selectedGeneId) {
try {
const response = await fetchGeneById(selectedGeneId);
if (response) {
setResults([response]);
setCurrentPage(1);
setTotalPages(1);
setHasPrevious(false);
setHasNext(false);
} else {
setResults([]);
setCurrentPage(1);
setTotalPages(1);
setHasPrevious(false);
setHasNext(false);
}
} catch (error) {
console.error('Error fetching data:', error);
setResults([]);
setCurrentPage(1);
setTotalPages(1);
setHasPrevious(false);
setHasNext(false);
}
} else {
const gene = geneName.trim() || query.trim();
if (gene) {
// Build the query parameters dynamically
const params = new URLSearchParams({
'query': gene,
'page': String(page),
'per_page': String(pageSize),
'sortField': sortField,
'sortOrder': sortOrder,
});

// Add genome IDs if available
if (selectedGenomes && selectedGenomes.length > 0) {
params.append('genome_ids', selectedGenomes.map((genome: {
id: number;
name: string
}) => genome.id).join(','));
}
// Ensure genomeFilter is an array of objects with id and name
const genomeFilter = selectedGenomes && selectedGenomes.length > 0
? selectedGenomes.map((genome) => ({ id: genome.id, name: genome.name }))
: undefined;

try {
const response = await fetchGeneSearchResults(
gene, page, pageSize, sortField, sortOrder, selectedGenomes, selectedSpecies
);

if (response && response.results) {
setResults(response.results);
setCurrentPage(response.page_number);
setTotalPages(response.num_pages);
setHasPrevious(response.has_previous);
setHasNext(response.has_next);
} else {
setResults([]);
setCurrentPage(1);
setTotalPages(1);
setHasPrevious(false);
setHasNext(false);
}
} catch (error) {
console.error('Error fetching data:', error);
setResults([]);
setCurrentPage(1);
setTotalPages(1);
setHasPrevious(false);
setHasNext(false);
}
}
// Use selectedSpecies directly if only one species is selected, or undefined otherwise
const speciesFilter = selectedSpecies && selectedSpecies.length === 1
? selectedSpecies
: undefined;

try {
const response = await fetchGeneSearchResults(
query, page, pageSize, sortField, sortOrder, genomeFilter, speciesFilter
);

if (response && response.results) {
setResults(response.results);
setCurrentPage(response.page_number);
setTotalPages(response.num_pages);
setHasPrevious(response.has_previous);
setHasNext(response.has_next);
} else {
setResults([]);
setCurrentPage(1);
setTotalPages(1);
setHasPrevious(false);
setHasNext(false);
}
},
[selectedGeneId, geneName, query, selectedSpecies, selectedGenomes, currentSortField, currentSortOrder, pageSize]
);
} catch (error) {
console.error('Error fetching data:', error);
setResults([]);
setCurrentPage(1);
setTotalPages(1);
setHasPrevious(false);
setHasNext(false);
}
},
[query, selectedSpecies, selectedGenomes, currentSortField, currentSortOrder, pageSize]
);




useEffect(() => {
fetchSearchResults();
}, [selectedSpecies, selectedGenomes, pageSize]);


const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,74 +96,40 @@ const GenomeSearchForm: React.FC<SearchGenomeFormProps> = ({
// Fetch search results based on the query, selected species, page, sort field, and sort order
const fetchSearchResults = useCallback(
async (page: number = 1, sortField: string = currentSortField, sortOrder: string = currentSortOrder) => {
if (selectedStrainId) {
try {
const response = await fetchGenomeByStrainId(selectedStrainId);
console.log("response: " + response)
if (response) {
setResults([response]);
setCurrentPage(1);
setTotalPages(1);
setHasPrevious(false);
setHasNext(false);
} else {
setResults([]);
setCurrentPage(1);
setTotalPages(1);
setHasPrevious(false);
setHasNext(false);
}
} catch (error) {
console.error('Error fetching data:', error);
const isolate = isolateName.trim() || query.trim();
const speciesFilter = selectedSpecies.length ? selectedSpecies : [];
try {
const response = await fetchGenomeSearchResults(isolate, page, pageSize, sortField, sortOrder, speciesFilter);

if (response && response.results) {
setResults(response.results);
setCurrentPage(response.page_number);
setTotalPages(response.num_pages);
setHasPrevious(response.has_previous);
setHasNext(response.has_next);
} else {
setResults([]);
setCurrentPage(1);
setTotalPages(1);
setHasPrevious(false);
setHasNext(false);
}
} else {
const isolate = isolateName.trim() || query.trim();
if (isolate) {
const queryString = new URLSearchParams({
'query': isolate,
'page': String(page),
'per_page': String(pageSize),
'sortField': sortField,
'sortOrder': sortOrder
}).toString();

try {
const response = await fetchGenomeSearchResults(isolate, page, pageSize, sortField, sortOrder, selectedSpecies);


if (response && response.results) {
setResults(response.results);
setCurrentPage(response.page_number);
setTotalPages(response.num_pages);
setHasPrevious(response.has_previous);
setHasNext(response.has_next);
} else {
setResults([]);
setCurrentPage(1);
setTotalPages(1);
setHasPrevious(false);
setHasNext(false);
}
} catch (error) {
console.error('Error fetching data:', error);
setResults([]);
setCurrentPage(1);
setTotalPages(1);
setHasPrevious(false);
setHasNext(false);
}
}

} catch (error) {
console.error('Error fetching data:', error);
setResults([]);
setCurrentPage(1);
setTotalPages(1);
setHasPrevious(false);
setHasNext(false);
}
},
[selectedStrainId, isolateName, query, selectedSpecies, currentSortField, currentSortOrder, pageSize]
[query, selectedSpecies, currentSortField, currentSortOrder, pageSize]
);

useEffect(() => {
fetchSearchResults(); // Trigger fetch when component mounts or species selection changes
}, [selectedSpecies, pageSize]);


const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>) => {
const newQuery = event.target.value;
Expand Down
2 changes: 1 addition & 1 deletion k8s-hl/dev/mett-dataportal-api-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ spec:
runAsUser: 7123
runAsGroup: 1347
containers:
- image: quay.io/microbiome-informatics/mett-dataportal-api:v0.0.20
- image: quay.io/microbiome-informatics/mett-dataportal-api:v0.0.22
imagePullPolicy: Always
name: mett-dataportal-api-dev
env:
Expand Down
2 changes: 1 addition & 1 deletion k8s-hl/dev/mett-dataportal-app-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ spec:
app: mett-dataportal-react-app-dev
spec:
containers:
- image: quay.io/microbiome-informatics/mett-dataportal-react-app:v0.0.20
- image: quay.io/microbiome-informatics/mett-dataportal-react-app:v0.0.22
imagePullPolicy: Always
name: mett-dataportal-react-app-dev
env:
Expand Down

0 comments on commit d89e8e9

Please sign in to comment.