Skip to content

Commit

Permalink
file upload error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
CiaranMn committed Dec 4, 2024
1 parent 82edc9a commit 41b1a6a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ export const FilePreviewSection = () => {
const [showSearch, setShowSearch] = useState(false);
const [showThumbnails, setShowThumbnails] = useState(true);

const { isDirty, readonly, entitySubgraph } = useEntityEditor();
const { isDirty, readonly, closedMultiEntityType, entitySubgraph } =
useEntityEditor();

const entity = getRoots(entitySubgraph)[0]!;

Expand All @@ -184,7 +185,8 @@ export const FilePreviewSection = () => {
entity.properties as FileProperties,
);

const title = displayName ?? generateEntityLabel(entitySubgraph, entity);
const title =
displayName ?? generateEntityLabel(closedMultiEntityType, entity);

const alt = description ?? title;

Expand Down
18 changes: 11 additions & 7 deletions apps/hash-frontend/src/shared/file-upload-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ export const FileUploadsProvider = ({ children }: PropsWithChildren) => {

const newRequestId = requestId ? undefined : uuid();

const upload =
let upload: FileUpload =
existingUpload ??
({
fileData,
Expand Down Expand Up @@ -359,13 +359,13 @@ export const FileUploadsProvider = ({ children }: PropsWithChildren) => {

presignedPut = data.requestFileUpload.presignedPut;

const updatedUpload: FileUpload = {
upload = {
...upload,
createdEntities: { fileEntity },
presignedPut,
status: "uploading-file-locally",
};
updateUpload(updatedUpload);
updateUpload(upload);
}

if (!presignedPut) {
Expand Down Expand Up @@ -423,6 +423,7 @@ export const FileUploadsProvider = ({ children }: PropsWithChildren) => {
const updatedUpload: FileUpload = {
...upload,
...(fileEntity ? { createdEntities: { fileEntity } } : {}),
presignedPut,
status: "error",
failedStep: "uploading-file-locally",
errorMessage,
Expand Down Expand Up @@ -463,13 +464,14 @@ export const FileUploadsProvider = ({ children }: PropsWithChildren) => {
linkEntityIdToDelete &&
existingUpload?.failedStep !== "creating-link-entity"
) {
updateUpload({
upload = {
...upload,
createdEntities: {
fileEntity,
},
status: "archiving-link-entity",
});
};
updateUpload(upload);

try {
const { data: archiveData, errors: archiveErrors } =
Expand Down Expand Up @@ -500,13 +502,15 @@ export const FileUploadsProvider = ({ children }: PropsWithChildren) => {
}
}

updateUpload({
upload = {
...upload,
createdEntities: {
fileEntity,
},
status: "creating-link-entity",
});
};

updateUpload(upload);

try {
const { data, errors } = await createEntity({
Expand Down

0 comments on commit 41b1a6a

Please sign in to comment.