-
Notifications
You must be signed in to change notification settings - Fork 296
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
[DDW-248] Refactor compress/download logs handling #995
Changes from all commits
ffd61bd
3f4af8c
88b9c50
c8f2a81
15c2a1e
5976494
e39f322
2d5a251
7ab1f8f
afd1343
242710e
81a444d
9a3a123
344d5d5
37d9bf5
0d42e24
74ada87
6913da9
a7af4f1
af76c11
27fc619
43a75fc
d68a724
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// @flow | ||
import moment from 'moment'; | ||
|
||
export const generateFileNameWithTimestamp = (prefix: string = 'logs', fileType: string = 'zip') => | ||
`${prefix}-${moment.utc().format('YYYY-MM-DDTHHmmss.0SSS')}Z.${fileType}`; | ||
|
||
export const isFileNameWithTimestamp = (prefix: string = 'logs', fileType: string = 'zip') => (fileName: string) => | ||
fileName.match(RegExp(`(${prefix}-)([0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{6}.0[0-9]{3}Z)(.${fileType})`)); | ||
|
||
export const getPathSlash = (path: string) => ((path.indexOf('/') > -1) ? '/' : '\\'); | ||
|
||
export const extractFileNameFromPath = (path: string) => | ||
path.substr(path.lastIndexOf(getPathSlash(path)) + 1); |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -118,22 +118,20 @@ const messages = defineMessages({ | |
|
||
type Props = { | ||
logFiles: LogFiles, | ||
compressedLog: ?string, | ||
onCancel: Function, | ||
onSubmit: Function, | ||
onSubmitManually: Function, | ||
onDownload: Function, | ||
onGetLogs: Function, | ||
onCompressLogs: Function, | ||
onDeleteCompressedLogs: Function, | ||
isSubmitting: boolean, | ||
isCompressing: boolean, | ||
onGetLogsAndCompress: Function, | ||
isDownloading?: boolean, | ||
isSubmittingBugReport?: boolean, | ||
error: ?LocalizableError, | ||
}; | ||
|
||
type State = { | ||
showLogs: boolean, | ||
attachLogs: boolean, | ||
compressedLogsFile: ?string, | ||
}; | ||
|
||
@observer | ||
|
@@ -144,19 +142,23 @@ export default class BugReportDialog extends Component<Props, State> { | |
}; | ||
|
||
state = { | ||
showLogs: true, | ||
attachLogs: true, | ||
compressedLogsFile: null, | ||
}; | ||
|
||
componentWillMount() { | ||
this.props.onGetLogs(); | ||
this.props.onDeleteCompressedLogs(); | ||
} | ||
|
||
componentWillReceiveProps(nextProps: Object) { | ||
const commpressionFilesChanged = this.props.compressedLog !== nextProps.compressedLog; | ||
if (nextProps.compressedLog && commpressionFilesChanged && !nextProps.isDownloading) { | ||
// proceed to submit when ipc rendered successfully return compressed files | ||
this.submit(nextProps.compressedLog); | ||
const compressedLogsFileChanged = ( | ||
!this.props.compressedLogsFile && | ||
!!nextProps.compressedLogsFile | ||
); | ||
const { compressedLogsFile } = this.state; | ||
if (compressedLogsFile) return false; | ||
if (nextProps.compressedLogsFile && compressedLogsFileChanged && !nextProps.isDownloading) { | ||
this.setState({ compressedLogsFile: nextProps.compressedLogsFile }, this.submit); | ||
} | ||
} | ||
|
||
|
@@ -206,40 +208,36 @@ export default class BugReportDialog extends Component<Props, State> { | |
}, | ||
}); | ||
|
||
submit = (compressedLog: ?string) => { | ||
submit = () => { | ||
this.form.submit({ | ||
onSuccess: (form) => { | ||
const { logFiles } = this.props; | ||
const logsExist = get(logFiles, ['files'], []).length > 0; | ||
|
||
const { attachLogs, compressedLogsFile } = this.state; | ||
if (attachLogs && !compressedLogsFile) { | ||
this.props.onGetLogsAndCompress(); | ||
return false; | ||
} | ||
const { email, subject, problem } = form.values(); | ||
const data = { | ||
email, subject, problem, compressedLog | ||
email, subject, problem, compressedLogsFile | ||
}; | ||
|
||
if (this.state.showLogs && logsExist && !compressedLog) { | ||
// submit request with commpressed logs files | ||
this.props.onCompressLogs(this.props.logFiles); | ||
} else { | ||
// regular submit | ||
this.props.onSubmit(data); | ||
} | ||
this.props.onSubmit(data); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @daniloprates we shouldn't send the log files if the user has set the "attach-logs" switch to off state. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ✔︎ |
||
}, | ||
onError: () => {}, | ||
}); | ||
}; | ||
|
||
handleLogsSwitchToggle = (value: boolean) => { | ||
this.setState({ showLogs: value }); | ||
this.setState({ attachLogs: value }); | ||
}; | ||
|
||
onClose = () => !this.props.isSubmittingBugReport && this.props.onCancel(); | ||
|
||
render() { | ||
const { intl } = this.context; | ||
const { showLogs } = this.state; | ||
const { attachLogs } = this.state; | ||
const { form } = this; | ||
const { | ||
onCancel, isSubmitting, isCompressing, | ||
logFiles, error, onDownload, isDownloading, | ||
logFiles, error, onDownload, isDownloading, isSubmittingBugReport | ||
} = this.props; | ||
|
||
const submitManuallyLink = intl.formatMessage(messages.submitManuallyLink); | ||
|
@@ -250,12 +248,12 @@ export default class BugReportDialog extends Component<Props, State> { | |
|
||
const attachedLogsClasses = classnames([ | ||
styles.attachedLogs, | ||
(showLogs && logFiles) ? styles.show : null, | ||
(attachLogs && logFiles) ? styles.show : null, | ||
]); | ||
|
||
const submitButtonClasses = classnames([ | ||
'submitButton', | ||
(isSubmitting || isCompressing) ? styles.isSubmitting : null, | ||
isSubmittingBugReport ? styles.isSubmitting : null, | ||
]); | ||
|
||
const downloadButtonClasses = classnames([ | ||
|
@@ -272,8 +270,8 @@ export default class BugReportDialog extends Component<Props, State> { | |
className: submitButtonClasses, | ||
label: this.context.intl.formatMessage(messages.submitButtonLabel), | ||
primary: true, | ||
disabled: isSubmitting, | ||
onClick: this.submit.bind(this, null), | ||
disabled: isSubmittingBugReport, | ||
onClick: this.submit, | ||
}, | ||
]; | ||
|
||
|
@@ -299,8 +297,13 @@ export default class BugReportDialog extends Component<Props, State> { | |
title={intl.formatMessage(messages.title)} | ||
actions={!error ? actions : alternativeActions} | ||
closeOnOverlayClick | ||
onClose={onCancel} | ||
closeButton={<DialogCloseButton onClose={onCancel} />} | ||
onClose={this.onClose} | ||
closeButton={ | ||
<DialogCloseButton | ||
disabled={isSubmittingBugReport} | ||
onClose={this.onClose} | ||
/> | ||
} | ||
> | ||
{error ? ( | ||
<div> | ||
|
@@ -356,7 +359,7 @@ export default class BugReportDialog extends Component<Props, State> { | |
<Checkbox | ||
onChange={this.handleLogsSwitchToggle} | ||
label={intl.formatMessage(messages.logsSwitchPlaceholder)} | ||
checked={showLogs} | ||
checked={attachLogs} | ||
skin={<SimpleSwitchSkin />} | ||
/> | ||
</div> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,7 +32,6 @@ | |
|
||
button { | ||
cursor: pointer; | ||
letter-spacing: 1px; | ||
} | ||
|
||
p { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@daniloprates please add
// @flow
to the top of this file.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✔︎