Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Promote Dev #444

Merged
merged 6 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{".":"2.4.5"}
{".":"2.5.0-0"}
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Changelog

## [2.5.0-0](https://github.com/agrc/electrofishing/compare/v2.4.6-0...v2.5.0-0) (2024-11-06)


### Features

* add data submitter to sampling event data ([895ca11](https://github.com/agrc/electrofishing/commit/895ca1106ea975b96c8d6864a79cd2ac5d79e7c1)), closes [#239](https://github.com/agrc/electrofishing/issues/239)

## [2.4.6-0](https://github.com/agrc/electrofishing/compare/v2.4.5...v2.4.6-0) (2024-11-05)


### Bug Fixes

* make equipment type values match domain values ([3d65a97](https://github.com/agrc/electrofishing/commit/3d65a9729f8c6d6696b21b90835293b81dc0a3ea))

## [2.4.5](https://github.com/agrc/electrofishing/compare/v2.4.4...v2.4.5) (2024-10-29)


Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "electrofishing",
"version": "2.4.5",
"version": "2.5.0-0",
"scripts": {
"build:stage": "export VITE_BUILD=stage && npm run build:sw && vite build",
"build:sw": "esbuild src/ServiceWorker.js --bundle --outfile=public/ServiceWorker.js --define:process.env.VITE_FIREBASE_CONFIG=$(npx dotenv -p VITE_FIREBASE_CONFIG)",
Expand Down
55 changes: 55 additions & 0 deletions scripts/migrations/migration_239.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/env python
# * coding: utf8 *
"""
migration_239.py

A module that adds a field for recording the submitter's email address in addition to fixing some values so that they match their associated domain values.

Ref: https://github.com/agrc/electrofishing/issues/239
"""

import arcpy

arcpy.env.workspace = r"..."


def add_field():
field_name = "SUBMITTER"
table_name = "SamplingEvents"
describe = arcpy.da.Describe(table_name)
if field_name not in [field.name for field in describe["fields"]]:
print(f"adding {field_name} field")
arcpy.management.AddField(
table_name,
field_name=field_name,
field_type="TEXT",
field_length=255,
field_alias="Submitter Email",
)
else:
print(f"{field_name} field already exists")


def fix_values():
mappings = [
("backpack", "Backpack"),
("canoebarge", "Canoe/Barge"),
("raftboat", "Raft/Boat"),
]
field_name = "TYPE"
print("fixing equipment type values...")
layer = arcpy.management.MakeFeatureLayer("Equipment", "equipment_layer")

for old_value, new_value in mappings:
print(f"fixing {old_value} to {new_value}")
arcpy.management.SelectLayerByAttribute(
layer, "NEW_SELECTION", f"{field_name} = '{old_value}'"
)
count = arcpy.management.GetCount(layer)[0]
print(f"count: {count}")
arcpy.management.CalculateField(layer, field_name, f"'{new_value}'", "PYTHON3")
arcpy.management.SelectLayerByAttribute(layer, "CLEAR_SELECTION")


add_field()
fix_values()
16 changes: 14 additions & 2 deletions src/components/location/Location.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import StartDistDirGeoDef from './StartDistDirGeoDef.jsx';
import StartEndGeoDef from './StartEndGeoDef.jsx';
import Station from './Station.jsx';
import VerifyMap from './VerifyMap.jsx';
import useAuthentication from '../../hooks/useAuthentication';

// successfullyVerifiedMsg: String
// message displayed on the verify location button after success
Expand All @@ -36,6 +37,17 @@ const Location = () => {
const [startEndParams, setStartEndParams] = useState(emptyStartEndParams);
const [startDistDirParams, setStartDistDirParams] = useState(emptyStartDistDirParams);
const [currentGeoDef, setCurrentGeoDef] = useState(START_END);
const { user } = useAuthentication();

useEffect(() => {
if (user) {
eventDispatch({
type: actionTypes.LOCATION,
meta: fieldNames.SUBMITTER,
payload: user.email,
});
}
}, [eventDispatch, user]);

const path = useRef(null);
const geometry = eventState[config.tableNames.samplingEvents].geometry;
Expand Down Expand Up @@ -198,7 +210,7 @@ const Location = () => {
paths.push(
path.map(function (c) {
return [c[1], c[0]];
})
}),
);
});
returnData.path = paths;
Expand Down Expand Up @@ -344,7 +356,7 @@ const Location = () => {
actionTypes.LOCATION,
config.tableNames.samplingEvents,
fieldName,
parser
parser,
);
};

Expand Down
8 changes: 4 additions & 4 deletions src/components/method/Equipment.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import NumericInputValidator from '../NumericInputValidator.jsx';

const ACTIVE = 'active';
export const EQUIPMENT_TYPES = {
BACKPACK: 'backpack',
CANOEBARGE: 'canoebarge',
RAFTBOAT: 'raftboat',
BACKPACK: 'Backpack',
CANOEBARGE: 'Canoe/Barge',
RAFTBOAT: 'Raft/Boat',
};
export const CATHODE_TYPES = {
BOAT: 'Boat',
Expand Down Expand Up @@ -87,7 +87,7 @@ function Equipment({ state, onChange, addNew, remove, isLast, isFirst }) {
const value = c.accessorKey === fieldNamesAN.EQUIPMENT_ID ? state.equipment[fieldNamesEQ.EQUIPMENT_ID] : null;

return [c.accessorKey, value];
})
}),
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/method/Equipment.stories.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const Default = () => {
const [state, setState] = useState({
equipment: {
[fieldNames.EVENT_ID]: getGUID(),
[fieldNames.TYPE]: 'backpack',
[fieldNames.TYPE]: 'Backpack/Canoe',
[fieldNames.EQUIPMENT_ID]: getGUID(),
[fieldNames.MODEL]: null,
[fieldNames.ARRAY_TYPE]: null,
Expand Down
3 changes: 2 additions & 1 deletion src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const fieldNames = {
WEATHER: 'WEATHER',
PURPOSE: 'SURVEY_PURPOSE',
OBSERVERS: 'OBSERVERS',
SUBMITTER: 'SUBMITTER',
},
equipment: {
EVENT_ID: fldEVENT_ID,
Expand Down Expand Up @@ -191,7 +192,7 @@ const config = {

// version: String
// The app version number.
version: '2.4.5', // x-release-please-version
version: '2.5.0-0', // x-release-please-version

// coordTypes: {key:String}
// Coordinate types as used in app/SettingsDialog
Expand Down
26 changes: 14 additions & 12 deletions src/hooks/samplingEventContext.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React from 'react';
import { useImmerReducer } from 'use-immer';
import config from '../config';
import getGUID from '../helpers/getGUID';
import { EQUIPMENT_TYPES } from '../components/method/Equipment.jsx';

const SamplingEventContext = React.createContext();
export const actionTypes = {
Expand Down Expand Up @@ -34,7 +35,7 @@ export const actionTypes = {
function getNewEquipment(eventId) {
return {
[config.fieldNames.equipment.EVENT_ID]: eventId,
[config.fieldNames.equipment.TYPE]: 'backpack',
[config.fieldNames.equipment.TYPE]: EQUIPMENT_TYPES.BACKPACK,
[config.fieldNames.equipment.EQUIPMENT_ID]: getGUID(),
[config.fieldNames.equipment.MODEL]: null,
[config.fieldNames.equipment.ARRAY_TYPE]: null,
Expand Down Expand Up @@ -152,6 +153,7 @@ const getBlankState = () => {
[config.fieldNames.samplingEvents.STATION_ID]: null,
[config.fieldNames.samplingEvents.SEGMENT_LENGTH]: null,
[config.fieldNames.samplingEvents.NUM_PASSES]: 1,
[config.fieldNames.samplingEvents.SUBMITTER]: null,
},
geometry: null,
},
Expand Down Expand Up @@ -242,7 +244,7 @@ const reducer = (draft, action) => {

case actionTypes.ADD_EQUIPMENT:
draft[config.tableNames.equipment].push(
getNewEquipment(draft[config.tableNames.samplingEvents].attributes[config.fieldNames.samplingEvents.EVENT_ID])
getNewEquipment(draft[config.tableNames.samplingEvents].attributes[config.fieldNames.samplingEvents.EVENT_ID]),
);

break;
Expand Down Expand Up @@ -271,8 +273,8 @@ const reducer = (draft, action) => {
getNewFish(
draft[config.tableNames.samplingEvents].attributes[config.fieldNames.samplingEvents.EVENT_ID],
newPass,
null
)
null,
),
);

break;
Expand All @@ -283,32 +285,32 @@ const reducer = (draft, action) => {
getNewFish(
draft[config.tableNames.samplingEvents].attributes[config.fieldNames.samplingEvents.EVENT_ID],
action.payload,
draft[config.tableNames.fish]
)
draft[config.tableNames.fish],
),
);

break;

case actionTypes.REMOVE_FISH:
draft[config.tableNames.fish] = draft[config.tableNames.fish].filter(
(fish) => fish[config.fieldNames.fish.FISH_ID] !== action.payload
(fish) => fish[config.fieldNames.fish.FISH_ID] !== action.payload,
);

draft[config.tableNames.tags] = draft[config.tableNames.tags].filter(
(tag) => tag[config.fieldNames.tags.FISH_ID] !== action.payload
(tag) => tag[config.fieldNames.tags.FISH_ID] !== action.payload,
);
draft[config.tableNames.health] = draft[config.tableNames.health].filter(
(health) => health[config.fieldNames.health.FISH_ID] !== action.payload
(health) => health[config.fieldNames.health.FISH_ID] !== action.payload,
);
draft[config.tableNames.diet] = draft[config.tableNames.diet].filter(
(diet) => diet[config.fieldNames.diet.FISH_ID] !== action.payload
(diet) => diet[config.fieldNames.diet.FISH_ID] !== action.payload,
);

break;

case actionTypes.UPDATE_FISH: {
const updateFishIndex = draft[config.tableNames.fish].findIndex(
(f) => f[config.fieldNames.fish.FISH_ID] === action.meta
(f) => f[config.fieldNames.fish.FISH_ID] === action.meta,
);
draft[config.tableNames.fish][updateFishIndex] = {
...draft[config.tableNames.fish][updateFishIndex],
Expand All @@ -319,7 +321,7 @@ const reducer = (draft, action) => {
}
case actionTypes.UPDATE_HEALTH: {
const updateHealthIndex = draft[config.tableNames.health].findIndex(
(f) => f[config.fieldNames.fish.FISH_ID] === action.meta
(f) => f[config.fieldNames.fish.FISH_ID] === action.meta,
);

if (updateHealthIndex === -1) {
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useAuthentication.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default function useAuthentication() {

initServiceWorker();

if (import.meta.env.VITE_BUILD === 'development') {
if (import.meta.env.VITE_BUILD === 'development' && !authRef.current.emulatorConfig) {
// comment out this and the auth config in firebase.json to hit utahid directly
connectAuthEmulator(authRef.current, 'http://127.0.0.1:9099');
}
Expand Down