Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
handleSubmit() {
const { submitState, setSubmitState, update, id } = this.props;
if(submitState == SUBMITSTATES.SUBMITTING) {
return;
}
setSubmitState(SUBMITSTATES.SUBMITTING);
const backupConfig = object.clone(this.props.backupConfig);
for(const key in backupConfig) {
if(input.isEmpty(backupConfig[key])) {
delete backupConfig[key];
continue;
}
if(key == "duration" || key == "interval") {
backupConfig[key] = time.convertToMilliseconds(backupConfig[key]);
}
}
if(!update) {
//create a new backup
backups.newBackupConfig(backupConfig)
.then(response => {
this.submitErr = response.data.message;
// redirect to the main page
hashHistory.push('/');
})
search() {
let filteredDBs = this.copyDBs;
const { startTime, endTime } = this.timeFilters;
if(!input.isEmpty(startTime)) {
try {
filteredDBs = filteredDBs.filter(db => {
return startTime.isSameOrBefore(new Date(db.createdTime))
})
}catch (e) {console.error(e)}
}
if(!input.isEmpty(endTime)) {
try {
filteredDBs = filteredDBs.filter(db => {
return endTime.isSameOrAfter(new Date(db.createdTime));
})
}catch (e) {}
}
this.filteredDBs = filteredDBs;
this.forceUpdate();
}
search() {
let filteredDBs = this.copyDBs;
const { startTime, endTime } = this.timeFilters;
if(!input.isEmpty(startTime)) {
try {
filteredDBs = filteredDBs.filter(db => {
return startTime.isSameOrBefore(new Date(db.createdTime))
})
}catch (e) {console.error(e)}
}
if(!input.isEmpty(endTime)) {
try {
filteredDBs = filteredDBs.filter(db => {
return endTime.isSameOrAfter(new Date(db.createdTime));
})
}catch (e) {}
}
this.filteredDBs = filteredDBs;
getValue(key) {
const { backupConfig } = this.props;
let value = backupConfig[key];
if(!input.isEmpty(value) && (key == "duration" || key == "interval")) {
let displayValue = "";
if(key == "duration" || key == "interval") {
for(const k in value) {
displayValue += `${ value[k] } ${ k } `;
}
}
value = displayValue;
}
if(!input.isEmpty(value) && (key == "startTime")) {
value = new Date(value).toLocaleString();
}
onSearchClick(event) {
event.preventDefault();
const queryString = this.input.value;
if(input.isEmpty(queryString)) {
this.filteredData = this.data;
this.queryStringError = null;
}else {
try {
const query = JSON.parse(queryString);
this.filteredData = sift(query, this.data);
this.queryStringError = null;
} catch (e) {
this.queryStringError = e.message;
}
}
this.input.blur();
if(this.queryStringError) {
this.forceUpdate();
}else {
if(key == "duration" || key == "interval") {
for(const k in value) {
displayValue += `${ value[k] } ${ k } `;
}
}
value = displayValue;
}
if(!input.isEmpty(value) && (key == "startTime")) {
value = new Date(value).toLocaleString();
}
if(key == "collections" && !input.isEmpty(value)) {
let displayValue = "";
for(const i in value) {
displayValue += value[i] + (i !== value.length - 1? " ": "");
}
value = displayValue;
}
return value;
}
const { backupConfig } = this.props;
let value = backupConfig[key];
if(!input.isEmpty(value) && (key == "duration" || key == "interval")) {
let displayValue = "";
if(key == "duration" || key == "interval") {
for(const k in value) {
displayValue += `${ value[k] } ${ k } `;
}
}
value = displayValue;
}
if(!input.isEmpty(value) && (key == "startTime")) {
value = new Date(value).toLocaleString();
}
if(key == "collections" && !input.isEmpty(value)) {
let displayValue = "";
for(const i in value) {
displayValue += value[i] + (i !== value.length - 1? " ": "");
}
value = displayValue;
}
return value;
}
handleKeyPress(name, event) {
const code = event.which;
if(code !== 13) {
return;
}
const username = this.inputs['name'].value;
const password = this.inputs['password'].value;
if(input.isEmpty(username)) {
this.inputs['name'].focus();
return;
}
if(input.isEmpty(password)) {
this.inputs['password'].focus();
return;
}
this.handleSubmit.call(this);
}