Skip to content

Commit

Permalink
refactor: streamline firestore operations and improve readability
Browse files Browse the repository at this point in the history
This commit significantly refines and optimizes the firestore.js file, enhancing the efficiency and legibility of the firestore operations. Major changes include the simplification of database queries, the consolidation of similar functions into a single reusable function, and the removal of redundant code.

Key changes made:
- Streamlined `getArthropodLabels`, `getSitesForProject`, `getArraysForSite`, `getTrapStatuses`, `getFenceTraps`, and `getSexes` functions by introducing a generic `getAnswerSetOptions` function.
- Optimized `getDocsFromCollection` and `deleteDocFromCollection` functions for clearer, more concise logic.
- Refactored `editSessionAndItsEntries` and `deleteSessionAndItsEntries` to efficiently utilize batch operations and promise handling.
- Cleaned up `uploadNewEntry` to prevent unnecessary checks and streamline the handling of Arthropod-specific logic.
- Improved code styling consistency across the file, including the usage of template literals and arrow functions, and applying proper spacing for readability.

Files and directories affected:
- Modified `src/utils/firestore.js` for optimizations and refactoring.
- Minor styling and consistency adjustments in `src/tools/DataManager.jsx`.
  • Loading branch information
IanSkelskey committed May 21, 2024
1 parent 82b4f7c commit c1b0350
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 295 deletions.
8 changes: 4 additions & 4 deletions src/tools/DataManager.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import ColumnSelectorButton from '../components/ColumnSelectorButton';
import { Table } from '../components/Table';
import { useState, useEffect, useCallback } from 'react';
import { getValue } from '../components/TableEntry';
import {SearchField} from '../components/FormFields';
import { SearchField } from '../components/FormFields';
import { CSVLink } from 'react-csv';
import { getKey } from '../const/tableLabels';
import { notify, Type } from '../components/Notifier';
Expand Down Expand Up @@ -57,8 +57,8 @@ export default function DataManager({ name, labels = [], entries = [], setEntrie
}
const collectionName = getCollectionNameFromDoc(entry);
const dateTime = new Date().toLocaleString();
if(name === 'Session') {
return collectionName + ' ' + dateTime;
if (name === 'Session') {
return collectionName + ' ' + dateTime;
} else {
return collectionName.slice(0, -4) + name + ' ' + dateTime;
}
Expand Down Expand Up @@ -99,7 +99,7 @@ export default function DataManager({ name, labels = [], entries = [], setEntrie
data={generateCSV(labels, entries)}
filename={getCSVName(entries[0]) + '.csv'}
onClick={() => {
if(generateCSV(labels, entries).length === 0) {
if (generateCSV(labels, entries).length === 0) {
notify(Type.error, 'No data to export');
} else {
notify(Type.success, 'Exported data to CSV');
Expand Down
Loading

0 comments on commit c1b0350

Please sign in to comment.