Skip to content

Commit

Permalink
fix: make equipment type values match domain values
Browse files Browse the repository at this point in the history
  • Loading branch information
stdavis committed Nov 6, 2024
1 parent 3434842 commit 3b93f10
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
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
25 changes: 13 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 @@ -242,7 +243,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 +272,8 @@ const reducer = (draft, action) => {
getNewFish(
draft[config.tableNames.samplingEvents].attributes[config.fieldNames.samplingEvents.EVENT_ID],
newPass,
null
)
null,
),
);

break;
Expand All @@ -283,32 +284,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 +320,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

0 comments on commit 3b93f10

Please sign in to comment.