Skip to content

Commit

Permalink
fixes image upload to take unknown image category id
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrea-Papaleo committed Apr 11, 2024
1 parent 151bbba commit 6878e39
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 7 deletions.
8 changes: 6 additions & 2 deletions src/components/dialogs/ImageShapeDialog/ImageShapeDialog.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useState } from "react";
import { useDispatch } from "react-redux";
import { useDispatch, useSelector } from "react-redux";
import { useHotkeys } from "hooks";

import { Alert, Box } from "@mui/material";
Expand All @@ -13,6 +13,7 @@ import { dataSlice } from "store/data/dataSlice";
import { uploadImages } from "utils/file-io/helpers";
import { ImageShapeInfo } from "utils/file-io/types";
import { ImageShapeEnum } from "utils/file-io/enums";
import { selectUnknownImageCategory } from "store/data/selectors";

type ImageShapeDialogProps = {
files: FileList;
Expand All @@ -38,6 +39,8 @@ export const ImageShapeDialog = ({
const [frames, setFrames] = useState<number>(-1);
const [invalidImageShape, setInvalidImageShape] = useState<boolean>(false);

const unknownImageCategory = useSelector(selectUnknownImageCategory);

const handleChannelsChange = async (channels: number) => {
setChannels(channels);
};
Expand Down Expand Up @@ -65,7 +68,8 @@ export const ImageShapeDialog = ({
files,
channels,
slices,
referenceImageShape
referenceImageShape,
unknownImageCategory
);
//HACK: Future plans to re-work error messages
if (res.warning) {
Expand Down
22 changes: 18 additions & 4 deletions src/hooks/useUpload/useUpload.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { useCallback } from "react";
import { useDispatch } from "react-redux";
import { useDispatch, useSelector } from "react-redux";
import { applicationSettingsSlice } from "store/applicationSettings";

import { dataSlice } from "store/data/dataSlice";
import { selectUnknownImageCategory } from "store/data/selectors";
import { ImageShapeEnum } from "utils/file-io/enums";
import { getImageFileInformation, uploadImages } from "utils/file-io/helpers";

export const useUpload = (
setOpenDimensionsDialogBox: (flag: boolean) => void
) => {
const dispatch = useDispatch();
const unknownImageCategory = useSelector(selectUnknownImageCategory);

return useCallback(
async (files: FileList) => {
Expand All @@ -20,7 +22,13 @@ export const useUpload = (
case ImageShapeEnum.GreyScale: {
const channels =
imageShapeInfo.shape === ImageShapeEnum.GreyScale ? 1 : 3;
const res = await uploadImages(files, channels, 1, imageShapeInfo);
const res = await uploadImages(
files,
channels,
1,
imageShapeInfo,
unknownImageCategory
);
//HACK: Future plans to re-work error messages
if (res.warning) {
dispatch(
Expand All @@ -45,7 +53,13 @@ export const useUpload = (
break;
}
case ImageShapeEnum.DicomImage: {
const res = await uploadImages(files, 1, 1, imageShapeInfo);
const res = await uploadImages(
files,
1,
1,
imageShapeInfo,
unknownImageCategory
);
//HACK: Future plans to re-work error messages
if (res.warning) {
dispatch(
Expand Down Expand Up @@ -85,6 +99,6 @@ export const useUpload = (

return imageShapeInfo;
},
[dispatch, setOpenDimensionsDialogBox]
[dispatch, setOpenDimensionsDialogBox, unknownImageCategory]
);
};
7 changes: 7 additions & 0 deletions src/store/data/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,13 @@ export const selectAllImageCategories = createSelector(
}
);

export const selectUnknownImageCategory = createSelector(
selectKindDictionary,
(kinds) => {
return kinds["Image"].unknownCategoryId;
}
);

export const selectAllObjectCategories = createSelector(
selectAllCategories,
(categories) => {
Expand Down
4 changes: 3 additions & 1 deletion src/utils/file-io/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ export const uploadImages = async (
files: FileList,
channels: number,
slices: number,
referenceShape: ImageShapeInfo
referenceShape: ImageShapeInfo,
categoryId: string
): Promise<{
imagesToUpload: ImageObject[];
warning: any;
Expand Down Expand Up @@ -125,6 +126,7 @@ export const uploadImages = async (
channels
);
imageToUpload.kind = "Image";
imageToUpload.categoryId = categoryId;
imageToUpload.containing = [];

imagesToUpload.push(imageToUpload as ImageObject);
Expand Down

0 comments on commit 6878e39

Please sign in to comment.