Skip to content

Commit 1107f73

Browse files
committed
Add changes for asset upload limit, after cherry-picking changes from asset-limit-with-lambda
1 parent 59fe175 commit 1107f73

File tree

10 files changed

+32
-36
lines changed

10 files changed

+32
-36
lines changed

client/modules/IDE/actions/ide.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,10 @@ export function closeNewFileModal() {
7575
};
7676
}
7777

78-
export function openUploadFileModal() {
78+
export function openUploadFileModal(parentId) {
7979
return {
80-
type: ActionTypes.OPEN_UPLOAD_FILE_MODAL
80+
type: ActionTypes.OPEN_UPLOAD_FILE_MODAL,
81+
parentId
8182
};
8283
}
8384

client/modules/IDE/components/AssetList.jsx

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ AssetListRowBase.propTypes = {
127127
url: PropTypes.string.isRequired,
128128
sketchId: PropTypes.string,
129129
sketchName: PropTypes.string,
130-
name: PropTypes.string.isRequired
130+
name: PropTypes.string.isRequired,
131+
size: PropTypes.number.isRequired
131132
}).isRequired,
132133
deleteAssetRequest: PropTypes.func.isRequired,
133134
username: PropTypes.string.isRequired
@@ -172,13 +173,9 @@ class AssetList extends React.Component {
172173
}
173174

174175
render() {
175-
const { assetList, totalSize } = this.props;
176+
const { assetList } = this.props;
176177
return (
177178
<div className="asset-table-container">
178-
{/* Eventually, this copy should be Total / 250 MB Used */}
179-
{this.hasAssets() && totalSize &&
180-
<p className="asset-table__total">{`${prettyBytes(totalSize)} Total`}</p>
181-
}
182179
<Helmet>
183180
<title>{this.getAssetsTitle()}</title>
184181
</Helmet>
@@ -188,7 +185,7 @@ class AssetList extends React.Component {
188185
<table className="asset-table">
189186
<thead>
190187
<tr>
191-
<th>Name</th>
188+
<th>Name</th>
192189
<th>Size</th>
193190
<th>Sketch</th>
194191
<th scope="col"></th>
@@ -214,20 +211,14 @@ AssetList.propTypes = {
214211
sketchName: PropTypes.string,
215212
sketchId: PropTypes.string
216213
})).isRequired,
217-
totalSize: PropTypes.number,
218214
getAssets: PropTypes.func.isRequired,
219215
loading: PropTypes.bool.isRequired
220216
};
221217

222-
AssetList.defaultProps = {
223-
totalSize: undefined
224-
};
225-
226218
function mapStateToProps(state) {
227219
return {
228220
user: state.user,
229221
assetList: state.assets.list,
230-
totalSize: state.user.totalSize,
231222
loading: state.loading
232223
};
233224
}

client/modules/IDE/components/AssetSize.jsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ import React from 'react';
33
import { connect } from 'react-redux';
44
import prettyBytes from 'pretty-bytes';
55

6-
const MB_TO_B = 1000 * 1000;
7-
const MAX_SIZE_B = 250 * MB_TO_B;
6+
const __process = (typeof global !== 'undefined' ? global : window).process;
7+
const limit = __process.env.UPLOAD_LIMIT || 250000000;
8+
const MAX_SIZE_B = limit;
89

910
const formatPercent = (percent) => {
1011
const percentUsed = percent * 100;
@@ -17,17 +18,18 @@ const formatPercent = (percent) => {
1718

1819
/* Eventually, this copy should be Total / 250 MB Used */
1920
const AssetSize = ({ totalSize }) => {
20-
if (!totalSize) {
21+
if (totalSize === undefined) {
2122
return null;
2223
}
2324

2425
const currentSize = prettyBytes(totalSize);
2526
const sizeLimit = prettyBytes(MAX_SIZE_B);
2627
const percentValue = totalSize / MAX_SIZE_B;
2728
const percent = formatPercent(percentValue);
29+
const percentSize = percentValue < 1 ? percentValue : 1;
2830

2931
return (
30-
<div className="asset-size" style={{ '--percent': percentValue }}>
32+
<div className="asset-size" style={{ '--percent': percentSize }}>
3133
<div className="asset-size-bar" />
3234
<p className="asset-current">{currentSize} ({percent})</p>
3335
<p className="asset-max">Max: {sizeLimit}</p>
@@ -42,7 +44,7 @@ AssetSize.propTypes = {
4244
function mapStateToProps(state) {
4345
return {
4446
user: state.user,
45-
totalSize: state.assets.totalSize,
47+
totalSize: state.user.totalSize || state.assets.totalSize,
4648
};
4749
}
4850

client/modules/IDE/components/FileUploader.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class FileUploader extends React.Component {
3030
thumbnailWidth: 200,
3131
thumbnailHeight: 200,
3232
acceptedFiles: fileExtensionsAndMimeTypes,
33-
dictDefaultMessage: 'Drop files here to upload or click to use the file browser',
33+
dictDefaultMessage: 'Drop files here or click to use the file browser',
3434
accept: this.props.dropzoneAcceptCallback.bind(this, userId),
3535
sending: this.props.dropzoneSendingCallback,
3636
complete: this.props.dropzoneCompleteCallback

client/modules/IDE/components/Sidebar.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ class Sidebar extends React.Component {
117117
<button
118118
aria-label="upload file"
119119
onClick={() => {
120-
this.props.openUploadFileModal();
120+
this.props.openUploadFileModal(rootFile.id);
121121
setTimeout(this.props.closeProjectOptions, 0);
122122
}}
123123
onBlur={this.onBlurComponent}

client/modules/IDE/components/UploadFileModal.jsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@ import PropTypes from 'prop-types';
33
import { connect } from 'react-redux';
44
import { Link } from 'react-router';
55
import InlineSVG from 'react-inlinesvg';
6+
import prettyBytes from 'pretty-bytes';
67
import FileUploader from './FileUploader';
78
import { getreachedTotalSizeLimit } from '../selectors/users';
8-
99
import exitUrl from '../../../images/exit.svg';
1010

11+
const __process = (typeof global !== 'undefined' ? global : window).process;
12+
const limit = __process.env.UPLOAD_LIMIT || 250000000;
13+
const limitText = prettyBytes(limit);
14+
1115
class UploadFileModal extends React.Component {
1216
propTypes = {
1317
reachedTotalSizeLimit: PropTypes.bool.isRequired,
@@ -36,12 +40,12 @@ class UploadFileModal extends React.Component {
3640
{ this.props.reachedTotalSizeLimit &&
3741
<p>
3842
{
39-
`Error: You cannot upload any more files. You have reached the total size limit of 250MB.
43+
`Error: You cannot upload any more files. You have reached the total size limit of ${limitText}.
4044
If you would like to upload more, please remove the ones you aren't using anymore by
4145
in your `
4246
}
43-
<Link to="/assets">assets</Link>
44-
{'.'}
47+
<Link to="/assets" onClick={this.props.closeModal}>assets</Link>
48+
.
4549
</p>
4650
}
4751
{ !this.props.reachedTotalSizeLimit &&

client/modules/IDE/reducers/assets.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ import * as ActionTypes from '../../../constants';
22

33
// 1,000,000 bytes in a MB. can't upload if totalSize is bigger than this.
44
const initialState = {
5-
list: []
5+
list: [],
6+
totalSize: 0
67
};
78

89
const assets = (state = initialState, action) => {
910
switch (action.type) {
1011
case ActionTypes.SET_ASSETS:
11-
return { list: action.assets };
12+
return { list: action.assets, totalSize: action.totalSize };
1213
case ActionTypes.DELETE_ASSET:
1314
return { list: state.list.filter(asset => asset.key !== action.key) };
1415
default:

client/modules/IDE/reducers/ide.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ const ide = (state = initialState, action) => {
107107
case ActionTypes.SHOW_RUNTIME_ERROR_WARNING:
108108
return Object.assign({}, state, { runtimeErrorWarningVisible: true });
109109
case ActionTypes.OPEN_UPLOAD_FILE_MODAL:
110-
return Object.assign({}, state, { uploadFileModalVisible: true });
110+
return Object.assign({}, state, { uploadFileModalVisible: true, parentId: action.parentId });
111111
case ActionTypes.CLOSE_UPLOAD_FILE_MODAL:
112112
return Object.assign({}, state, { uploadFileModalVisible: false });
113113
default:

client/styles/components/_asset-size.scss

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,12 @@
3737

3838
.asset-current {
3939
position: absolute;
40-
top: 28px;
41-
left: calc(200px * var(--percent));
42-
margin-left: -8px;
40+
top: #{28 / $base-font-size}rem;
41+
left: 0;
4342
}
4443

4544
.asset-max {
4645
position: absolute;
4746
top: 0;
48-
left: 0;
49-
transform: translate(210%); // align max label to right of asset-size-bar
50-
padding-left: #{8 / $base-font-size}rem;
47+
left: #{210 / $base-font-size}rem;
5148
}

server/views/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export function renderIndex() {
3131
window.process.env.EXAMPLES_ENABLED = ${process.env.EXAMPLES_ENABLED === 'false' ? false : true};
3232
window.process.env.UI_ACCESS_TOKEN_ENABLED = ${process.env.UI_ACCESS_TOKEN_ENABLED === 'false' ? false : true};
3333
window.process.env.UI_COLLECTIONS_ENABLED = ${process.env.UI_COLLECTIONS_ENABLED === 'false' ? false : true};
34-
window.process.env.UPLOAD_LIMIT = ${process.env.UPLOAD_LIMIT === 'false' ? false : true};
34+
window.process.env.UPLOAD_LIMIT = ${process.env.UPLOAD_LIMIT ? `${process.env.UPLOAD_LIMIT}` : undefined};
3535
</script>
3636
</head>
3737
<body>

0 commit comments

Comments
 (0)