Skip to content

Commit

Permalink
refactor(src/modals/ExportModal.jsx): modernize data export functiona…
Browse files Browse the repository at this point in the history
…lity

This commit updates the `ExportModal.jsx` component to better handle the export of data based on different application modes (test and live) and cleans up unused code.

Changes include:
- Removed the unused import `getArthropodLabels` from `../utils/firestore`, streamlining the component's dependencies.
- Deleted unnecessary blank lines and the invocation of `getArthropodLabels()` within `DataForm`, simplifying the data preparation process for CSV export.
- Added `environment` detection within `SessionForm` to dynamically set the collection name based on whether the application is in live or test mode. This makes the export process more adaptable to the application's current state.

This refactor improves code readability and maintenance while ensuring the export functionality is more robust and context-aware.
  • Loading branch information
IanSkelskey committed May 20, 2024
1 parent 5df8507 commit 07735c3
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/modals/ExportModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { collection, getDocs, where, query } from "firebase/firestore";
import { db } from "../utils/firebase";
import { useAtomValue } from "jotai";
import { appMode, currentProjectName } from "../utils/jotai";
import { getArthropodLabels } from "../utils/firestore";
import InnerModalWrapper from "./InnerModalWrapper";
import { _ } from "lodash";
import { TABLE_LABELS, dynamicArthropodLabels, getKey } from "../const/tableLabels";
Expand Down Expand Up @@ -128,9 +127,6 @@ const DataForm = () => {

let tempCsvData = [];


const arthropodLabels = await getArthropodLabels();

entries.sort((a, b) => {
const dateA = new Date(a.dateTime).getTime();
const dateB = new Date(b.dateTime).getTime();
Expand Down Expand Up @@ -214,6 +210,7 @@ const DataForm = () => {
}

const SessionForm = () => {
const environment = useAtomValue(appMode);
const project = useAtomValue(currentProjectName);
const [buttonText, setButtonText] = useState('Generate CSV');
const [csvData, setCsvData] = useState([]);
Expand All @@ -228,7 +225,8 @@ const SessionForm = () => {
const generateCSV = async () => {
setButtonText('Generating CSV Data...')
const entries = []
const collectionName = `Test${project}Session`
let collectionName = `Test${project}Session`
if (environment === 'live') collectionName = `${project}Session`
const collectionSnapshot = await getDocs(
collection(db, collectionName)
)
Expand Down

0 comments on commit 07735c3

Please sign in to comment.