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

Exp fix upload files error #14488

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
f506f10
redoing exp fix branch
WeatherfordAaron Dec 30, 2024
7e35c13
corrected circle ci config.yaml
WeatherfordAaron Dec 30, 2024
2fe4052
Revert "corrected circle ci config.yaml"
WeatherfordAaron Dec 30, 2024
80faf1d
Revert "redoing exp fix branch"
WeatherfordAaron Dec 30, 2024
a5fd52a
ran DEPLOY_ENV=exp make nonato_deploy_prepare
WeatherfordAaron Dec 30, 2024
2ace395
added experimental fix
WeatherfordAaron Dec 31, 2024
bcb67df
changed the error string we look for
WeatherfordAaron Dec 31, 2024
f537d7d
removed showing of link
WeatherfordAaron Dec 31, 2024
458c7c8
changed to ammended orders section
WeatherfordAaron Dec 31, 2024
5251a28
changed front end to try local before storage
WeatherfordAaron Dec 31, 2024
f75649f
trying a different HEAD check
WeatherfordAaron Dec 31, 2024
08292cf
added a check every second to see if files are available
WeatherfordAaron Dec 31, 2024
db9f7d8
Revert "added a check every second to see if files are available"
WeatherfordAaron Dec 31, 2024
09e1732
Revert "trying a different HEAD check"
WeatherfordAaron Dec 31, 2024
77e7d0e
Revert "changed front end to try local before storage"
WeatherfordAaron Dec 31, 2024
13d94f0
Revert "changed to ammended orders section"
WeatherfordAaron Dec 31, 2024
d48e1c9
Revert "removed showing of link"
WeatherfordAaron Dec 31, 2024
6b50016
Revert "changed the error string we look for"
WeatherfordAaron Dec 31, 2024
c4436ce
Revert "added experimental fix"
WeatherfordAaron Dec 31, 2024
0b90a62
James fix
WeatherfordAaron Dec 31, 2024
62ef496
another fix
WeatherfordAaron Dec 31, 2024
73451bb
new fix
WeatherfordAaron Jan 2, 2025
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
12 changes: 6 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,30 +40,30 @@ references:

# In addition, it's common practice to disable acceptance tests and
# ignore tests for dp3 deploys. See the branch settings below.
dp3-branch: &dp3-branch placeholder_branch_name
dp3-branch: &dp3-branch exp-fix-upload-files-error
# MUST BE ONE OF: loadtest, demo, exp.
# These are used to pull in env vars so the spelling matters!
dp3-env: &dp3-env placeholder_env
dp3-env: &dp3-env exp

# set integration-ignore-branch to the branch if you want to IGNORE
# integration tests, or `placeholder_branch_name` if you do want to
# run them
integration-ignore-branch: &integration-ignore-branch placeholder_branch_name
integration-ignore-branch: &integration-ignore-branch exp-fix-upload-files-error

# set integration-mtls-ignore-branch to the branch if you want to
# IGNORE mtls integration tests, or `placeholder_branch_name` if you
# do want to run them
integration-mtls-ignore-branch: &integration-mtls-ignore-branch placeholder_branch_name
integration-mtls-ignore-branch: &integration-mtls-ignore-branch exp-fix-upload-files-error

# set client-ignore-branch to the branch if you want to IGNORE
# client tests, or `placeholder_branch_name` if you do want to run
# them
client-ignore-branch: &client-ignore-branch placeholder_branch_name
client-ignore-branch: &client-ignore-branch exp-fix-upload-files-error

# set server-ignore-branch to the branch if you want to IGNORE
# server tests, or `placeholder_branch_name` if you do want to run
# them
server-ignore-branch: &server-ignore-branch placeholder_branch_name
server-ignore-branch: &server-ignore-branch exp-fix-upload-files-error

executors:
base_small:
Expand Down
61 changes: 51 additions & 10 deletions src/components/UploadsTable/UploadsTable.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useState, useEffect } from 'react';
import PropTypes from 'prop-types';
import bytes from 'bytes';
import moment from 'moment';
Expand All @@ -12,6 +12,9 @@ import SectionWrapper from 'components/Customer/SectionWrapper';
import { ExistingUploadsShape } from 'types/uploads';

const UploadsTable = ({ className, uploads, onDelete, showDeleteButton, showDownloadLink = false }) => {
const [fileAvailable, setFileAvailable] = useState({});
const pollingInterval = 5000; // Poll every 5 seconds

const getIcon = (fileType) => {
switch (fileType) {
case 'application/pdf':
Expand All @@ -27,6 +30,52 @@ const UploadsTable = ({ className, uploads, onDelete, showDeleteButton, showDown
}
};

const checkFileAvailability = async (url, fileId) => {
try {
const response = await fetch(url, { method: 'GET', headers: { Range: 'bytes=0-0' } }); // Try to fetch just a byte
if (response.ok) {
setFileAvailable((prev) => ({ ...prev, [fileId]: true })); // Mark as available
} else {
setFileAvailable((prev) => ({ ...prev, [fileId]: false })); // Mark as unavailable
}
} catch (error) {
setFileAvailable((prev) => ({ ...prev, [fileId]: false })); // Mark as unavailable if error occurs
}
};

useEffect(() => {
const intervalIds = {}; // Store interval IDs for each file to clear later

uploads.forEach((upload) => {
if (upload.url && !Object.hasOwn(fileAvailable, upload.id)) {
// Start polling if the file URL is available and polling isn't already in progress
intervalIds[upload.id] = setInterval(() => {
checkFileAvailability(upload.url, upload.id);
}, pollingInterval);
}
});

// Cleanup polling on component unmount
return () => {
Object.values(intervalIds).forEach(clearInterval); // Clear all intervals
};
}, [uploads, fileAvailable]);

const renderFileContent = (upload) => {
if (showDownloadLink && upload.url) {
// If the file is available, show a link; otherwise, just the filename as plain text
return fileAvailable[upload.id] ? (
<a href={upload.url} download>
{upload.filename}
</a>
) : (
upload.filename // Plain text filename if file is not available
);
}

return upload.filename; // Plain text filename if download link is not shown
};

return (
uploads?.length > 0 && (
<SectionWrapper className={classnames(styles.uploadsTableContainer, className)} data-testid="uploads-table">
Expand All @@ -37,15 +86,7 @@ const UploadsTable = ({ className, uploads, onDelete, showDeleteButton, showDown
<div className={styles.fileInfoContainer}>
<FontAwesomeIcon size="lg" icon={getIcon(upload.contentType)} className={styles.faIcon} />
<div className={styles.fileInfo}>
<p>
{showDownloadLink ? (
<a href={upload.url} download>
{upload.filename}
</a>
) : (
upload.filename
)}
</p>
<p>{renderFileContent(upload)}</p>
<p className={styles.fileSizeAndTime}>
<span className={styles.uploadFileSize}>{bytes(upload.bytes)}</span>
<span>Uploaded {moment(upload.createdAt).format('DD MMM YYYY h:mm A')}</span>
Expand Down
Loading