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

CRDCDH-1843 Remove size from Batch #518

Open
wants to merge 2 commits into
base: 3.2.0
Choose a base branch
from
Open
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
18 changes: 11 additions & 7 deletions src/components/DataSubmissions/MetadataUpload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,17 @@ import { isEqual } from "lodash";
import { VariantType } from "notistack";
import { Button, Stack, Typography, styled } from "@mui/material";
import Tooltip from "../Tooltip";
import { CREATE_BATCH, CreateBatchResp, UPDATE_BATCH, UpdateBatchResp } from "../../graphql";
import {
CREATE_BATCH,
CreateBatchInput,
CreateBatchResp,
UPDATE_BATCH,
UpdateBatchResp,
} from "../../graphql";
import { useAuthContext } from "../Contexts/AuthContext";
import FlowWrapper from "./FlowWrapper";
import { canUploadMetadataRoles } from "../../config/AuthRoles";
import { Logger } from "../../utils";

const StyledUploadTypeText = styled(Typography)(() => ({
color: "#083A50",
Expand Down Expand Up @@ -113,7 +120,7 @@ const MetadataUpload = ({ submission, readOnly, onCreateBatch, onUpload }: Props
collaborator.permission === "Can Edit");
const acceptedExtensions = [".tsv", ".txt"];

const [createBatch] = useMutation<CreateBatchResp>(CREATE_BATCH, {
const [createBatch] = useMutation<CreateBatchResp, CreateBatchInput>(CREATE_BATCH, {
context: { clientName: "backend" },
fetchPolicy: "no-cache",
});
Expand Down Expand Up @@ -185,15 +192,11 @@ const MetadataUpload = ({ submission, readOnly, onCreateBatch, onUpload }: Props
}

try {
const formattedFiles: FileInput[] = Array.from(selectedFiles)?.map((file) => ({
fileName: file.name,
size: file.size,
}));
const { data: batch, errors } = await createBatch({
variables: {
submissionID: submissionId,
type: "metadata",
files: formattedFiles,
files: Array.from(selectedFiles)?.map((file) => file.name),
},
});

Expand All @@ -204,6 +207,7 @@ const MetadataUpload = ({ submission, readOnly, onCreateBatch, onUpload }: Props
return batch?.createBatch;
} catch (err) {
// Unable to initiate upload process so all failed
Logger.error("Error creating new batch", err);
onUploadFail(selectedFiles?.length);
return null;
}
Expand Down
3 changes: 1 addition & 2 deletions src/components/FileListDialog/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ const baseBatch: Batch = {
const baseBatchFileInfo: BatchFileInfo = {
filePrefix: "",
fileName: "",
size: 0,
nodeType: "",
status: "",
status: "New",
errors: [],
createdAt: "",
updatedAt: "",
Expand Down
8 changes: 7 additions & 1 deletion src/graphql/createBatch.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import gql from "graphql-tag";

export const mutation = gql`
mutation createBatch($submissionID: ID!, $type: String, $files: [FileInput]) {
mutation createBatch($submissionID: ID!, $type: String, $files: [String!]!) {
createBatch(submissionID: $submissionID, type: $type, files: $files) {
_id
submissionID
Expand All @@ -20,6 +20,12 @@ export const mutation = gql`
}
`;

export type Input = {
submissionID: string;
type: UploadType;
files: string[];
};

export type Response = {
createBatch: NewBatch;
};
2 changes: 1 addition & 1 deletion src/graphql/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export { mutation as SUBMISSION_ACTION } from "./submissionAction";
export type { Response as SubmissionActionResp } from "./submissionAction";

export { mutation as CREATE_BATCH } from "./createBatch";
export type { Response as CreateBatchResp } from "./createBatch";
export type { Input as CreateBatchInput, Response as CreateBatchResp } from "./createBatch";

export { mutation as UPDATE_BATCH } from "./updateBatch";
export type { Response as UpdateBatchResp } from "./updateBatch";
Expand Down
1 change: 0 additions & 1 deletion src/graphql/listBatches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ const FullBatchFragment = gql`
nodeType
filePrefix
fileName
size
status
errors
createdAt
Expand Down
8 changes: 1 addition & 7 deletions src/types/Submissions.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,6 @@ type SubmissionIntention = "New/Update" | "Delete";

type SubmissionDataType = "Metadata Only" | "Metadata and Data Files";

type FileInput = {
fileName: string;
size: number;
};

type FileURL = {
fileName: string;
signedURL: string;
Expand All @@ -146,9 +141,8 @@ type UploadResult = {
type BatchFileInfo = {
filePrefix: string; // prefix/path within S3 bucket
fileName: string;
size: number;
nodeType: string;
status: string; // [New, Uploaded, Failed]
status: "New" | "Uploaded" | "Failed";
errors: string[];
createdAt: string; // ISO 8601 date time format with UTC or offset e.g., 2023-05-01T09:23:30Z
updatedAt: string; // ISO 8601 date time format with UTC or offset e.g., 2023-05-01T09:23:30Z
Expand Down