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

161 Add API calls UUID Seed lIst #162

Merged
merged 9 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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 package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "nachet-frontend",
"private": true,
"version": "0.8.4",
"version": "0.8.5",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down
50 changes: 38 additions & 12 deletions src/App.tsx
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
height: window.innerHeight,
});
const [uuid, setUuid] = useState<string>("");
const [container_uuid, setContainerUuid] = useState<string>("");
const [creativeCommonsPopupOpen, setCreativeCommonsPopupOpen] =
useState<boolean>(false);
const [switchLanguage, setSwitchLanguage] = useState<boolean>(false);
Expand Down Expand Up @@ -47,29 +48,50 @@
}
}, []);

const createUuid = useCallback((): void => {
const createContainerUuid = useCallback((): void => {
// create a new uuid for user and set a cookie to remember it for 10 years (it is used to identify user container in azure storage)
const newUuid = uuidv4();
setUuid(newUuid);
Cookies.set("user-uuid", newUuid, { expires: 365 * 10 });
setContainerUuid(newUuid);
Cookies.set("container-uuid", newUuid, { expires: 365 * 10 });
Fixed Show fixed Hide fixed
}, []);

const getUuid = useCallback((): void => {
const getContainerUuid = useCallback((): void => {
// check if the user has already a uuid (cookie)
const existingUuid = Cookies.get("user-uuid") as string;
const existingUuid = Cookies.get("container-uuid") as string;
if (existingUuid !== undefined) {
setUuid(existingUuid);
console.log("Existing UUID: " + existingUuid);
setContainerUuid(existingUuid);
console.log("Existing Container UUID: " + existingUuid);
} else {
console.log("Creating new UUID");
createUuid();
console.log("Creating new Container UUID");
createContainerUuid();
}
}, [createUuid]);
}, [createContainerUuid]);

// const handleSignIn = (): void => {
// setSignedIn(true);
// };

// // uuid will check if an email is already stored in the cookie, if not setsignup open
// const getUuid = useCallback((): void => {
// // check if the user has email stored in the cookie
// const email: string | undefined = Cookies.get("user-email");
// if (email == null || !email.includes("@") || !signedIn) {
// setSignUpOpen(true);
// } else {
// requestUUID(email)
// .then((response) => {
// setUuid(response.data.uuid);
// Cookies.set("user-uuid", response.data.uuid, { expires: 30 });
// }
// setUuid(uuid);
// Cookies.set("user-uuid", uuid, { expires: 30 });
// }
// }, [signedIn]);

useEffect(() => {
getUuid();
getContainerUuid();
getCreativeCommonsAgreement();
}, [getUuid, getCreativeCommonsAgreement]);
}, [getContainerUuid, getCreativeCommonsAgreement]);

useEffect(() => {
// update window size on resize
Expand Down Expand Up @@ -107,11 +129,15 @@
<Body
windowSize={windowSize}
uuid={uuid}
container_uuid={container_uuid}
creativeCommonsPopupOpen={creativeCommonsPopupOpen}
setCreativeCommonsPopupOpen={setCreativeCommonsPopupOpen}
handleCreativeCommonsAgreement={handleCreativeCommonsAgreement}
setSignUpOpen={setSignUpOpen}
signUpOpen={signUpOpen}
signedIn={signedIn}
setSignedIn={setSignedIn}
setUuid={setUuid}
/>
}
/>
Expand Down
8 changes: 4 additions & 4 deletions src/_versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ export interface TsAppVersion {
gitTag?: string;
};
export const versions: TsAppVersion = {
version: '0.8.4',
version: '0.8.5',
name: 'nachet-frontend',
versionDate: '2024-05-30T04:19:03.983Z',
gitCommitHash: 'd019904',
versionLong: '0.8.4-d019904',
versionDate: '2024-06-05T14:39:44.056Z',
gitCommitHash: '9074593',
versionLong: '0.8.5-9074593',
};
export default versions;
59 changes: 56 additions & 3 deletions src/common/api.ts
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import axios from "axios";
import { AzureAPIError, ValueError } from "./error";
import {
ApiInferenceData,
ApiSpeciesData,
FeedbackDataNegative,
FeedbackDataPositive,
Images,
Expand Down Expand Up @@ -128,7 +129,8 @@ export const inferenceRequest = async (
imageObject: Images,
curDir: string,
uuid: string,
): Promise<ApiInferenceData[]> => {
container_uuid: string,
): Promise<ApiInferenceData> => {
if (backendUrl === "" || backendUrl == null) {
throw new ValueError("Backend URL is null or empty");
}
Expand Down Expand Up @@ -156,10 +158,11 @@ export const inferenceRequest = async (
image: imageObject.src,
imageDims: imageObject.imageDims,
folder_name: curDir,
container_name: uuid,
user_id: uuid,
container_name: container_uuid,
},
};
return handleAxios<ApiInferenceData[]>(request);
return handleAxios<ApiInferenceData>(request);
};

export const fetchModelMetadata = async (
Expand Down Expand Up @@ -236,3 +239,53 @@ export const sendNegativeFeedback = async (
};
return handleAxios(request);
};

export const requestUUID = async (
backendUrl: string,
email: string,
): Promise<{
user_id: string;
}> => {
if (backendUrl === "" || backendUrl == null) {
throw new ValueError("Backend URL is null or empty");
}
const request = {
method: "post",
url: `${backendUrl}/get-user-id`,
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
},
data: {
email: email,
},
};
return handleAxios<{
user_id: string;
}>(request);
};

export const requestClassList = async (
backendUrl: string,
// uuid: string,
): Promise<ApiSpeciesData> => {
if (backendUrl === "" || backendUrl == null) {
throw new ValueError("Backend URL is null or empty");
}
// if (uuid === "" || uuid == null) {
// throw new ValueError("UUID is null or empty");
// }
const request = {
method: "get",
url: `${backendUrl}/seeds`,
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
},
data: {},
// data: {
// uuid: uuid,
// },
};
return handleAxios<ApiSpeciesData>(request);
};
6 changes: 3 additions & 3 deletions src/common/cacheutils.ts
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -369,9 +369,9 @@ export const loadResultsToCache = (
boxes: inferenceData.boxes.map((box) => {
return {
...box.box,
inferenceId: inferenceData.inferenceId,
boxId: box.boxId,
classId: box.classId,
inferenceId: inferenceData.inference_id,
boxId: box.box_id,
classId: box.object_type_id,
label: box.label,
};
}),
Expand Down
12 changes: 7 additions & 5 deletions src/common/types.d.ts
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
export interface ApiInferenceData {
filename: string;
imageId: string;
inferenceId: string;
inference_id: string;
boxes: Array<{
topN: Array<{ score: number; label: string }>;
score: number;
label: string;
classId: string;
boxId: string;
object_type_id: string;
box_id: string;
box: BoxCoordinates;
overlapping: boolean;
overlappingIndices: number;
Expand Down Expand Up @@ -79,16 +80,17 @@ export interface LabelOccurrences {
[label: string]: number;
}

// TODO: Redefine when the backend is updated
interface ClassData {
id: number;
classId: string;
label: string;
}

interface ApiSpeciesData {
classId: string;
label: string;
seeds: Array<{
seed_id: string;
seed_name: string;
}>;
}

export interface ModelMetadata {
Expand Down
7 changes: 6 additions & 1 deletion src/components/body/authentication/signup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ import {
} from "@mui/material";
import CloseIcon from "@mui/icons-material/Close";
import { colours } from "../../../styles/colours";
import Cookies from "js-cookie";

interface params {
setSignUpOpen: React.Dispatch<React.SetStateAction<boolean>>;
onSignIn: () => void;
}

const SignUp: React.FC<params> = (props): JSX.Element => {
Expand All @@ -27,8 +29,11 @@ const SignUp: React.FC<params> = (props): JSX.Element => {
const data = new FormData(event.currentTarget);
console.log({
email: data.get("email"),
password: data.get("password"),
// password: data.get("password"),
});
Cookies.set("user-email", String(data.get("email") ?? ""), { expires: 30 });
props.onSignIn();
handleClose();
};

return (
Expand Down
25 changes: 2 additions & 23 deletions src/components/body/feedback_form/FeedbackForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@ import { SyntheticEvent, useEffect, useMemo, useState } from "react";
import { BoxCSS, ClassData, FeedbackDataNegative } from "../../../common/types";
import Draggable from "react-draggable";

// import styled from "styled-components";
// const FeedbackPopover = styled(Popover)`
// .MuiPopover-paper {
// padding: 10px;
// }
// `;

interface SimpleFeedbackFormProps {
anchorEl: HTMLButtonElement | null;
onClose: () => void;
Expand Down Expand Up @@ -101,6 +94,7 @@ export const SimpleFeedbackForm = (
interface NegativeFeedbackFormProps {
inference: FeedbackDataNegative;
position: BoxCSS;
classList: ClassData[];
onCancel: () => void;
onSubmit: (feedbackDataNegative: FeedbackDataNegative) => void;
}
Expand All @@ -110,21 +104,6 @@ export const NegativeFeedbackForm = (
): JSX.Element => {
/* TODO: update when backend is defined Section stub convert to prop or use state when backend defined */

const classList = useMemo(() => {
return [
{
id: 1,
classId: "1",
label: "Species stub 1",
},
{
id: 2,
classId: "2",
label: "Species stub 2",
},
];
}, []);

const reasons = useMemo(() => {
return ["No Seed", "Multi Seed", "Wrong Seed", "Wrong Seed not in List"];
}, []);
Expand All @@ -138,7 +117,7 @@ export const NegativeFeedbackForm = (
};
}, []);

const { inference, position, onCancel, onSubmit } = props;
const { inference, position, classList, onCancel, onSubmit } = props;
const [selectedClass, setSelectedClass] = useState<ClassData>(defaultClass);
const [comment, setComment] = useState<string>(reasons[2]);

Expand Down
Loading
Loading