Skip to content
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
6 changes: 3 additions & 3 deletions src/components/Catalogue/catalogueItemView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ const CatalogueItemView = ({ isOpen, onClose, title, sectionId, items, setDialog
gap={2}
>
<Text
fontSize="lg"
fontSize="md"
fontWeight="bold"
>
{item.title}
Expand Down Expand Up @@ -491,8 +491,8 @@ const CatalogueItemView = ({ isOpen, onClose, title, sectionId, items, setDialog
>
<Text
fontSize={{
md: "lg",
lg: "xl",
md: "md",
lg: "lg",
}}
fontWeight="bold"
mr={4}
Expand Down
2 changes: 1 addition & 1 deletion src/components/Catalogue/metadataDisplay.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ function MetadataDisplay({ currentItem, isOpen }) {
lineClamp={1}
title={metadata.figureInfo[id]}
>
{metadata.figureInfo[id] || "No Label"}
{metadata.figureInfo[id] && metadata.figureInfo[id].length <= 20 ? metadata.figureInfo[id] : "No Label"}
</Text>
</Box>
))}
Expand Down
10 changes: 9 additions & 1 deletion src/components/DataImport/ArtefactUploadView.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Button, Flex, Box, Text, Field, Input } from "@chakra-ui/react";
import { useEffect, useRef, useState } from "react";
import { HiUpload } from "react-icons/hi";
import server from "../../networking";
import server, { JSONResponse } from "../../networking";
import ToastWizard from "../toastWizard";
import FileItem from "./FileItem";
import { IoArrowBackCircleSharp } from "react-icons/io5";
Expand Down Expand Up @@ -101,6 +101,14 @@ function ArtefactUploadView({ batch, setBatchID, fetchBatches, onBackToPending }
);
} catch (err) {
console.log(`Non-success response in file upload to batch ${batchID || 'New Batch'}`, err)

if (err.response && err.response.data instanceof JSONResponse) {
if (err.response.data.userErrorType()) {
ToastWizard.standard("error", "Upload Failed", err.response.data.message);
return;
}
}

const updates = err?.response?.data?.raw?.updates;
if (updates) {
setFileStatuses(updates);
Expand Down
5 changes: 1 addition & 4 deletions src/components/DataImport/BatchCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,10 @@ function BatchCard({ batchData, formatTimestamp, fetchBatches }) {
}
}

console.log(batchData)

useEffect(() => {
if (batchData) {
var newContent = { ...content };
newContent.name = batchData.name || "No name";
if (batchData.stage === "upload_pending") {
newContent.displayMessage = `${batchData.artefactSummary.total || 0} Uploaded (Upload more if you wish)`
// newContent.progress = Math.round((batchData.artefactSummary.unprocessed || 0) / (batchData.artefactSummary.total || 1) * 100);
Expand Down Expand Up @@ -184,8 +183,6 @@ function BatchCard({ batchData, formatTimestamp, fetchBatches }) {
}
}, [batchData]);

console.log(content);

return (
<Card.Root w="full" bg="white" boxShadow="md" borderRadius="lg" _hover={{ boxShadow: "md", transform: "translateY(-1px)" }}>
<Card.Body p={{ base: "3", md: "4" }}>
Expand Down
2 changes: 1 addition & 1 deletion src/components/DataStudio/figureDisplay.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ function FigureDisplaySection({ artefactId, figureInfo, getArtefactData, isEditi
fontSize={10}
lineClamp={1}
>
{figureInfo[id] || "No Label"}
{figureInfo[id] && figureInfo[id].length <= 20 ? figureInfo[id] : "No Label"}
</Text>
</Flex>
))}
Expand Down
6 changes: 5 additions & 1 deletion src/components/Navbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ function Navbar() {
const { username, accountID } = useSelector(state => state.auth);

const handleLogoClick = () => {
navigate('/');
if (username) {
navigate('/catalogue')
} else {
navigate('/');
}
}

const handleProfileClick = () => {
Expand Down
85 changes: 71 additions & 14 deletions src/pages/ArtefactEditor.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Box, Flex, Text, Image, useBreakpointValue } from "@chakra-ui/react";
import { Box, Flex, Text, Image, useBreakpointValue, Button, Spacer } from "@chakra-ui/react";
import { useParams, useNavigate } from 'react-router-dom';
import { useEffect, useState } from "react";
import { useSelector } from "react-redux";
Expand All @@ -16,6 +16,8 @@ function ArtefactEditor() {
const { loaded } = useSelector(state => state.auth);
const navigate = useNavigate();
const [isInvalid, setIsInvalid] = useState(false);
const [vetted, setVetted] = useState(true);
const [markingVetted, setMarkingVetted] = useState(false);

// Responsive layout values
const isMobile = useBreakpointValue({ base: true, md: false });
Expand Down Expand Up @@ -120,7 +122,7 @@ function ArtefactEditor() {
// Metadata fetching function
const fetchMetadata = async () => {
try {
const response = await server.get(`/cdn/artefactMetadata/${artID}`);
const response = await server.get(`/cdn/artefactMetadata/${artID}?colID=${colID}`);

if (response.data instanceof JSONResponse) {
if (response.data.isErrorStatus()) {
Expand All @@ -137,6 +139,10 @@ function ArtefactEditor() {
...response.data.raw.data,
figureInfo: response.data.raw.figureInfo || {}
});
console.log("New vetted info:", response.data.raw.vetted);
if (response.data.raw.vetted !== null && response.data.raw.vetted !== undefined) {
setVetted(response.data.raw.vetted);
}
} else {
throw new Error("Unexpected response format");
}
Expand Down Expand Up @@ -211,6 +217,53 @@ function ArtefactEditor() {
}
}, [collection, metadata, artID]);

const handleMarkVetted = async () => {
if (vetted) {
ToastWizard.standard("error", "Already vetted", "This artefact has already been marked as vetted.");
return;
}

setMarkingVetted(true);

try {
const response = await server.post('/dataImport/vetting/confirm', {
batchID: colID,
artefactID: artID
})

if (response.data instanceof JSONResponse) {
if (response.data.isErrorStatus()) {
const errObject = {
response: {
data: response.data
}
};
throw new Error(errObject);
}

// Success case
fetchMetadata();
ToastWizard.standard("success", "Marked as vetted", "Artefact marked as vetted successfully!");
} else {
throw new Error("Unexpected response format");
}
} catch (err) {
if (err.response && err.response.data instanceof JSONResponse) {
console.log("Error response in mark vetted request:", err.response.data.fullMessage());
if (err.response.data.userErrorType()) {
ToastWizard.standard("error", "Login failed.", err.response.data.message);
} else {
ToastWizard.standard("error", "Something went wrong", "Couldn't mark artefact as vetted. Please try again.")
}
} else {
console.log("Unexpected error in mark vetted request:", err);
ToastWizard.standard("error", "Something went wrong", "Couldn't mark artefact as vetted. Please try again.");
}
} finally {
setMarkingVetted(false);
}
}

// Show loading spinner while data is being fetched
if (!metadata || !collection || isInvalid) {
return <CentredSpinner />
Expand All @@ -223,24 +276,28 @@ function ArtefactEditor() {
<Flex mt={6} flexDirection="row">
<FaCircleArrowLeft cursor={"pointer"} onClick={() => navigate(-1)} size={40} color='darkBlue' />
<Box ml={6}>
<Text fontSize="2xl" fontWeight="bold">Data Studio</Text>
<Text fontSize="md" mt={1} mb={2}>{metadata.name}</Text>
<Text fontSize="xl" fontWeight="bold">Data Studio</Text>
<Text fontSize="md" mt={1} mb={2} maxW={{ base: '100px', md: 'fit-content' }} lineClamp={1}>{metadata.name}</Text>
</Box>

<Spacer />

{!vetted && <Button variant={'ArchPrimary'} onClick={handleMarkVetted} loading={markingVetted} loadingText={'Marking...'}>Mark as Vetted</Button>}
</Flex>

{isMobile ? (
<Flex flexDirection="column" h={"calc(79vh - 80px)"} overflowY="auto">
<Flex width="100%" position="relative" justifyContent="center" alignItems="center">
<Box position="absolute" left={0} zIndex={1} bg={"white"} p={2} border={"solid"} borderWidth={"2px"} borderRadius={"full"}>
<FaChevronLeft
size={30}
<FaChevronLeft
size={30}
cursor={isFirst ? "not-allowed" : "pointer"}
color={isFirst ? "gray" : "inherit"}
opacity={isFirst ? 0.4 : 1}
onClick={!isFirst ? navigateToPrevious : undefined}
/>
</Box>

<Box width={imageWidth} p={3}>
<Image
src={`${import.meta.env.VITE_BACKEND_URL}/cdn/artefacts/${artID}`}
Expand All @@ -251,9 +308,9 @@ function ArtefactEditor() {
borderRadius={15}
/>
</Box>

<Box position="absolute" right={0} zIndex={1} bg={"white"} p={2} border={"solid"} borderWidth={"2px"} borderRadius={"full"}>
<FaChevronRight
<FaChevronRight
size={30}
cursor={isLast ? "not-allowed" : "pointer"}
color={isLast ? "gray" : "inherit"}
Expand All @@ -264,14 +321,14 @@ function ArtefactEditor() {
</Flex>

<Box width={editorWidth} p={3}>
<EditorCard metadata={metadata} artefactId={artID} refreshArtefactData={fetchMetadata}/>
<EditorCard metadata={metadata} artefactId={artID} refreshArtefactData={fetchMetadata} />
</Box>
</Flex>
) : (
<Flex h={"calc(79vh - 80px)"}>
<Flex width={chevronWidth} display="flex" alignItems="center" justifyContent="flex-start" >
<FaChevronLeft
size={30}
<FaChevronLeft
size={30}
cursor={isFirst ? "not-allowed" : "pointer"}
color={isFirst ? "gray" : "inherit"}
opacity={isFirst ? 0.4 : 1}
Expand All @@ -290,11 +347,11 @@ function ArtefactEditor() {
</Box>

<Box width={editorWidth} p={3}>
<EditorCard metadata={metadata} artefactId={artID} refreshArtefactData={fetchMetadata}/>
<EditorCard metadata={metadata} artefactId={artID} refreshArtefactData={fetchMetadata} />
</Box>

<Flex width={chevronWidth} display="flex" alignItems="center" justifyContent="flex-end">
<FaChevronRight
<FaChevronRight
size={30}
cursor={isLast ? "not-allowed" : "pointer"}
color={isLast ? "gray" : "inherit"}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function Login() {
navigate("/catalogue");
ToastWizard.standard(
"success",
(res.data.raw.fname && res.data.raw.lname) ? `Welcome back, ${res.data.raw.fname} ${res.data.raw.lname}!` : `Welcome back, ${res.data.raw.username}!`,
(res.data.raw.fname && res.data.raw.lname) ? `Welcome back, ${res.data.raw.fname} ${res.data.raw.lname}!` : `Welcome back, ${res.data.raw.username || 'User'}!`,
"Login successful.",
5000,
true
Expand Down