From 5bfa7940e1281ea01e4be3afdcf5a04e49e80e01 Mon Sep 17 00:00:00 2001
From: Amanda Bullington <35536439+albullington@users.noreply.github.com>
Date: Wed, 16 Aug 2023 16:09:46 -0700
Subject: [PATCH] Refactor ObsDetails and show ID after agree button pressed
(#738)
---
src/components/ObsDetails/ActivityItem.js | 128 ----
src/components/ObsDetails/ActivityTab.js | 131 -----
.../{ => ActivityTab}/ActivityHeader.js | 116 ++--
.../ObsDetails/ActivityTab/ActivityItem.js | 82 +++
.../ObsDetails/ActivityTab/ActivityTab.js | 55 ++
.../ObsDetails/ActivityTab/FloatingButtons.js | 60 ++
src/components/ObsDetails/AddCommentModal.js | 165 ------
.../ObsDetails/DataQualityAssessment.js | 2 +-
.../{ => DetailsTab}/Attribution.js | 0
.../{ => DetailsTab}/DQAVoteButtons.js | 0
.../ObsDetails/{ => DetailsTab}/DetailsTab.js | 2 +-
src/components/ObsDetails/ObsDetails.js | 548 +++---------------
.../ObsDetails/ObsDetailsContainer.js | 338 +++++++++++
src/components/ObsDetails/PhotoDisplay.js | 140 +++++
.../ObsDetails/PhotoDisplayContainer.js | 90 +++
.../ObsDetails/Sheets/AgreeWithIDSheet.js | 66 +--
.../SharedComponents/DisplayTaxon.js | 4 +-
src/components/UiLibrary.js | 2 +-
src/navigation/BottomTabNavigator/index.js | 4 +-
src/sharedHooks/useLocalObservation.js | 13 +-
tests/integration/ObsDetails.test.js | 4 +-
.../ObsDetails/ActivityItem.test.js | 5 +-
.../components/ObsDetails/ActivityTab.test.js | 10 +-
.../ObsDetails/DataQualityAssessment.test.js | 4 +-
.../components/ObsDetails/DetailsTab.test.js | 15 +-
.../unit/components/ObsDetails/Flags.test.js | 2 +-
.../components/ObsDetails/ObsDetails.test.js | 19 +-
27 files changed, 958 insertions(+), 1047 deletions(-)
delete mode 100644 src/components/ObsDetails/ActivityItem.js
delete mode 100644 src/components/ObsDetails/ActivityTab.js
rename src/components/ObsDetails/{ => ActivityTab}/ActivityHeader.js (67%)
create mode 100644 src/components/ObsDetails/ActivityTab/ActivityItem.js
create mode 100644 src/components/ObsDetails/ActivityTab/ActivityTab.js
create mode 100644 src/components/ObsDetails/ActivityTab/FloatingButtons.js
delete mode 100644 src/components/ObsDetails/AddCommentModal.js
rename src/components/ObsDetails/{ => DetailsTab}/Attribution.js (100%)
rename src/components/ObsDetails/{ => DetailsTab}/DQAVoteButtons.js (100%)
rename src/components/ObsDetails/{ => DetailsTab}/DetailsTab.js (98%)
create mode 100644 src/components/ObsDetails/ObsDetailsContainer.js
create mode 100644 src/components/ObsDetails/PhotoDisplay.js
create mode 100644 src/components/ObsDetails/PhotoDisplayContainer.js
diff --git a/src/components/ObsDetails/ActivityItem.js b/src/components/ObsDetails/ActivityItem.js
deleted file mode 100644
index 2c61fd3f6..000000000
--- a/src/components/ObsDetails/ActivityItem.js
+++ /dev/null
@@ -1,128 +0,0 @@
-// @flow
-
-import ActivityHeader from "components/ObsDetails/ActivityHeader";
-import AgreeWithIDSheet from "components/ObsDetails/Sheets/AgreeWithIDSheet";
-import {
- Divider, INatIcon, UserText
-} from "components/SharedComponents";
-import DisplayTaxon from "components/SharedComponents/DisplayTaxon";
-import {
- Pressable, View
-} from "components/styledComponents";
-import { t } from "i18next";
-import _ from "lodash";
-import type { Node } from "react";
-import React, { useState } from "react";
-import { textStyles } from "styles/obsDetails/obsDetails";
-
-import AddCommentModal from "./AddCommentModal";
-
-type Props = {
- item: Object,
- navToTaxonDetails: Function,
- toggleRefetch: Function,
- refetchRemoteObservation: Function,
- onAgree: Function,
- currentUserId?: Number,
- observationUUID: string,
- userAgreedId?: string
-}
-
-const ActivityItem = ( {
- item, navToTaxonDetails, toggleRefetch, refetchRemoteObservation, onAgree, currentUserId,
- observationUUID, userAgreedId
-}: Props ): Node => {
- const { taxon, user } = item;
- const userId = currentUserId;
- const showAgreeButton = taxon && user && user.id !== userId && taxon.rank_level <= 10
- && userAgreedId !== taxon?.id;
- const [showAgreeWithIdSheet, setShowAgreeWithIdSheet] = useState( false );
- const [showCommentBox, setShowCommentBox] = useState( false );
- const [comment, setComment] = useState( "" );
-
- const isCurrent = item.current !== undefined
- ? item.current
- : undefined;
-
- const idWithdrawn = isCurrent !== undefined && !isCurrent;
-
- const onAgreePressed = () => {
- const agreeParams = {
- observation_id: observationUUID,
- taxon_id: taxon?.id,
- body: comment
- };
-
- onAgree( agreeParams );
- setShowAgreeWithIdSheet( false );
- };
-
- const openCommentBox = () => setShowCommentBox( true );
-
- const onCommentAdded = newComment => {
- setComment( newComment );
- };
-
- const agreeIdSheetDiscardChanges = () => {
- setComment( "" );
- setShowAgreeWithIdSheet( false );
- };
-
- const onIDAgreePressed = () => {
- setShowAgreeWithIdSheet( true );
- };
-
- return (
-
-
- {taxon && (
-
-
- { showAgreeButton && (
-
-
-
- )}
-
- )}
- { !_.isEmpty( item?.body ) && (
-
-
-
- )}
-
-
-
-
- );
-};
-
-export default ActivityItem;
diff --git a/src/components/ObsDetails/ActivityTab.js b/src/components/ObsDetails/ActivityTab.js
deleted file mode 100644
index b9ee78cfb..000000000
--- a/src/components/ObsDetails/ActivityTab.js
+++ /dev/null
@@ -1,131 +0,0 @@
-// @flow
-import createIdentification from "api/identifications";
-import { Text, View } from "components/styledComponents";
-import { formatISO } from "date-fns";
-import { t } from "i18next";
-import * as React from "react";
-import { useEffect, useState } from "react";
-import { Alert } from "react-native";
-import useAuthenticatedMutation from "sharedHooks/useAuthenticatedMutation";
-import useCurrentUser from "sharedHooks/useCurrentUser";
-
-import ActivityItem from "./ActivityItem";
-
-type Props = {
- observation:Object,
- comments:Array