Skip to content

Commit

Permalink
Improving download filename of ZIP archive of solution source files.
Browse files Browse the repository at this point in the history
  • Loading branch information
krulis-martin committed Jul 25, 2022
1 parent 9b8df02 commit 71c7669
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/components/Solutions/SolutionDetail/SolutionDetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ class SolutionDetail extends Component {
<Col xl={6}>
<SolutionFiles
solutionId={id}
attemptIndex={attemptIndex}
files={files}
authorId={authorId}
openFile={this.openFile}
Expand Down
3 changes: 3 additions & 0 deletions src/components/Solutions/SolutionFiles/SolutionFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const preprocessFiles = defaultMemoize(files =>

const SolutionFiles = ({
solutionId,
attemptIndex,
files,
authorId,
isReference = false,
Expand Down Expand Up @@ -181,6 +182,7 @@ const SolutionFiles = ({
<td className="text-nowrap shrink-col text-right">
<DownloadSolutionArchiveContainer
solutionId={solutionId}
attemptIndex={attemptIndex}
authorId={authorId}
isReference={isReference}
size="xs"
Expand All @@ -199,6 +201,7 @@ const SolutionFiles = ({
);
SolutionFiles.propTypes = {
solutionId: PropTypes.string.isRequired,
attemptIndex: PropTypes.number,
files: ImmutablePropTypes.map,
authorId: PropTypes.string.isRequired,
isReference: PropTypes.bool,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@ import OptionalTooltipWrapper from '../../components/widgets/OptionalTooltipWrap
import ResourceRenderer from '../../components/helpers/ResourceRenderer';
import { toPlainAscii } from '../../helpers/common';

const solutionArchiveFileName = (solutionId, user) => {
const name = toPlainAscii(`${user.name.lastName}-${user.name.firstName}`);
return `${name}_${solutionId}.zip`;
const solutionArchiveFileName = (solutionId, user, index = null) => {
const components = [user.name.lastName, user.name.firstName];
if (index) {
components.push(String(index).padStart(3, '0'));
}
components.push(solutionId);
const name = toPlainAscii(components.join('_').replaceAll(' ', '-'));
return `${name}.zip`;
};

const DownloadSolutionArchiveContainer = ({
Expand Down Expand Up @@ -50,6 +55,8 @@ const DownloadSolutionArchiveContainer = ({
);

DownloadSolutionArchiveContainer.propTypes = {
solutionId: PropTypes.string.isRequired,
attemptIndex: PropTypes.number,
authorId: PropTypes.string.isRequired,
isReference: PropTypes.bool,
iconOnly: PropTypes.bool,
Expand All @@ -64,10 +71,10 @@ export default connect(
(state, { authorId }) => ({
authorUser: getUser(authorId)(state),
}),
(dispatch, { solutionId }) => ({
(dispatch, { solutionId, attemptIndex }) => ({
downloadSolutionArchive: user => e => {
e.preventDefault();
dispatch(downloadSolutionArchive(solutionId, solutionArchiveFileName(solutionId, user)));
dispatch(downloadSolutionArchive(solutionId, solutionArchiveFileName(solutionId, user, attemptIndex)));
},
downloadRefSolutionArchive: user => e => {
e.preventDefault();
Expand Down

0 comments on commit 71c7669

Please sign in to comment.