Skip to content

Commit f54c34c

Browse files
committed
fix(compare): reject dataset larger then 10MB, add 'reset' button
1 parent 08675b7 commit f54c34c

File tree

3 files changed

+50
-5
lines changed

3 files changed

+50
-5
lines changed

app/components/compare/Compare.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ export const CompareComponent: React.FC<CompareProps> = (props) => {
3333

3434
React.useEffect(() => {
3535
if (!params.left || !params.right) {
36+
if (data) {
37+
setData(null)
38+
}
3639
return
3740
}
3841
setLoading(true)

app/components/compare/CompareSidebar.tsx

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
import React from 'react'
22
import { remote } from 'electron'
3+
import fs from 'fs'
4+
import { Action } from 'redux'
35

46
import TextInput from '../form/TextInput'
57
import ButtonInput from '../form/ButtonInput'
68
import Icon from '../chrome/Icon'
79
import ExternalLink from '../ExternalLink'
10+
import { connect } from 'react-redux'
11+
import Store, { ToastType } from '../../models/store'
12+
13+
import {
14+
openToast
15+
} from '../../actions/ui'
16+
import classNames from 'classnames'
817

918
export interface CompareParams {
1019
left: string
@@ -14,9 +23,10 @@ export interface CompareParams {
1423
export interface CompareSidebarProps {
1524
data: CompareParams
1625
onChange: (p: CompareParams) => void
26+
openToast: (type: ToastType, name: string, message: string) => Action
1727
}
1828

19-
const CompareSidebar: React.FC<CompareSidebarProps> = ({ data, onChange }) => {
29+
export const CompareSidebarComponent: React.FC<CompareSidebarProps> = ({ data, onChange, openToast, closeToast }) => {
2030
const pathPicker = (side: string) => {
2131
const window = remote.getCurrentWindow()
2232
const filePaths: string[] | undefined = remote.dialog.showOpenDialogSync(window, {
@@ -32,12 +42,22 @@ const CompareSidebar: React.FC<CompareSidebarProps> = ({ data, onChange }) => {
3242
return
3343
}
3444

45+
let filepath = filePaths[0]
46+
47+
const stats = fs.statSync(filepath)
48+
49+
// if over 10 mb reject
50+
if (stats.size > (1024 * 1000 * 10)) {
51+
filepath = ''
52+
openToast("error", "file size", "file must be under 10MB")
53+
}
54+
3555
switch (side) {
3656
case 'left':
37-
onChange({ left: filePaths[0], right: data.right })
57+
onChange({ left: filepath, right: data.right })
3858
break
3959
case 'right':
40-
onChange({ right: filePaths[0], left: data.left })
60+
onChange({ right: filepath, left: data.left })
4161
break
4262
}
4363
}
@@ -54,8 +74,9 @@ const CompareSidebar: React.FC<CompareSidebarProps> = ({ data, onChange }) => {
5474

5575
return (
5676
<div className='compare-sidebar sidebar'>
57-
<div className='sidebar-header sidebar-padded-container'>
77+
<div className='sidebar-header sidebar-padded-container compare-sidebar-header'>
5878
<p className='pane-title'>Compare</p>
79+
<div className={classNames('reset', { disabled: !(data.left || data.right) })} onClick={() => { onChange({ right: '', left: '' }) }}>reset</div>
5980
</div>
6081
<div className='sidebar-padded-container'>
6182
<div className='picker'>
@@ -105,4 +126,11 @@ const CompareSidebar: React.FC<CompareSidebarProps> = ({ data, onChange }) => {
105126
)
106127
}
107128

108-
export default CompareSidebar
129+
const mapStateToProps = (state: Store, ownProps: CompareSidebarProps) => {
130+
return ownProps
131+
}
132+
133+
// TODO (b5) - this component doesn't need to be a container. Just feed it the right data
134+
export default connect(mapStateToProps, {
135+
openToast
136+
})(CompareSidebarComponent)

app/scss/0.4.0/compare.scss

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,20 @@
22
background: #123459;
33
height: 100%;
44

5+
.compare-sidebar-header {
6+
display: flex;
7+
justify-content: space-between;
8+
align-items: center;
9+
10+
.reset {
11+
cursor: pointer;
12+
13+
&.disabled {
14+
display: none;
15+
}
16+
}
17+
}
18+
519
.picker {
620
display: flex;
721

0 commit comments

Comments
 (0)