-
Notifications
You must be signed in to change notification settings - Fork 76
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
fix: refresh ursadb page and add alert about successful submit #448
Changes from 1 commit
a543faa
ab5afb7
95560c3
977df9f
e9a3422
55e120b
5eda1aa
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,17 @@ | ||
import React from "react"; | ||
|
||
const IndexClearedPage = (props) => ( | ||
<div className="alert alert-danger alert-dismissible fade show"> | ||
<h2>Cleared!</h2> | ||
{props.msg} | ||
<button | ||
type="button" | ||
className="btn-close" | ||
data-bs-dismiss="alert" | ||
aria-label="Close" | ||
onClick={() => props.onClick()} | ||
/> | ||
</div> | ||
); | ||
|
||
export default IndexClearedPage; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,8 @@ import api from "../api"; | |
import ErrorBoundary from "../components/ErrorBoundary"; | ||
import IndexClearQueueButton from "./IndexClearQueueButton"; | ||
import IndexSuccessPage from "./IndexSuccessPage"; | ||
import IndexClearedPage from "./IndexClearedPage"; | ||
import Draggable from "react-draggable"; | ||
|
||
function getAvailableTaintsListFromDatasets(datasets) { | ||
var taintList = Object.values(datasets) | ||
|
@@ -26,12 +28,17 @@ class IndexPageInner extends Component { | |
oldestFile: null, | ||
newestFile: null, | ||
alertShowFileLen: false, | ||
alertShowCleared: false, | ||
modalShowClearQueue: false, | ||
}; | ||
this.handleSubmit = this.handleSubmit.bind(this); | ||
this.handleClearQueue = this.handleClearQueue.bind(this); | ||
this.handleTextareaInput = this.handleTextareaInput.bind(this); | ||
this.handleNGramSelect = this.handleNGramSelect.bind(this); | ||
this.handleTaintSelect = this.handleTaintSelect.bind(this); | ||
this.handleModalOpen = this.handleModalOpen.bind(this); | ||
this.handleAlertClose = this.handleAlertClose.bind(this); | ||
this.handleAlertClearedClose = this.handleAlertClearedClose.bind(this); | ||
this.fileOrFiles = this.fileOrFiles.bind(this); | ||
} | ||
|
||
|
@@ -111,12 +118,92 @@ class IndexPageInner extends Component { | |
}); | ||
} | ||
|
||
handleClearQueue() { | ||
// TODO: include modal before handling closing | ||
api.delete(`/queue/${this.ursa_id}`) | ||
.then((response) => { | ||
this.setState({ | ||
modalShowClearQueue: false, | ||
}); | ||
if (response.data.status == "ok") { | ||
this.setState({ | ||
alertShowCleared: true, | ||
}); | ||
} // NOTE: this will not throw error on 'ursa_id not found' status | ||
}) | ||
.catch((error) => this.setState({ error: error })); | ||
} | ||
|
||
handleAlertClose() { | ||
this.setState({ alertShowFileLen: false }); | ||
} | ||
|
||
handleModalOpen() { | ||
this.setState({ modalShowClearQueue: true }); | ||
} | ||
|
||
handleAlertClearedClose() { | ||
this.setState({ alertShowCleared: false }); | ||
} | ||
|
||
render() { | ||
const fileLen = this.state.filenames.length; | ||
|
||
const clearQueueModal = ( | ||
<Draggable handle=".modal-header"> | ||
<div className="modal-container-index-page"> | ||
<div | ||
className="modal modal-block" | ||
style={{ | ||
display: this.state.modalShowClearQueue | ||
? "block" | ||
: "none", | ||
}} | ||
> | ||
<div className="modal-dialog modal-xl"> | ||
<div className="modal-content"> | ||
<div className="modal-header d-flex justify-content-between"> | ||
<h6 className="modal-title">{`Clear queue alert`}</h6> | ||
<button | ||
type="button" | ||
className="btn-close" | ||
onClick={() => | ||
this.setState({ | ||
modalShowClearQueue: false, | ||
}) | ||
} | ||
/> | ||
</div> | ||
<div className="modal-body"> | ||
<div> | ||
Are you sure you want to clear queue at | ||
UrsaDB: {this.ursa_id}? | ||
</div> | ||
<div className="d-flex justify-content-evenly"> | ||
<IndexClearQueueButton | ||
msg="Yes, clear queue" | ||
ursa_id={this.props.params.ursa_id} | ||
onClick={this.handleClearQueue} | ||
/> | ||
<button | ||
className="btn btn-secondary btn-sm my-2" | ||
onClick={() => | ||
this.setState({ | ||
modalShowClearQueue: false, | ||
}) | ||
} | ||
> | ||
Cancel | ||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</Draggable> | ||
); | ||
|
||
return ( | ||
<ErrorBoundary error={this.state.error}> | ||
<div className="container-fluid"> | ||
|
@@ -131,6 +218,16 @@ class IndexPageInner extends Component { | |
onClick={this.handleAlertClose} | ||
/> | ||
)} | ||
{this.state.alertShowCleared && ( | ||
<IndexClearedPage | ||
msg={`Successfully cleared ${ | ||
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.
I think the variable here should be 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. I'm not sure if I understand - this alert won't show if 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. step one: add 1 file You're right that my comment was wrong, I think that the issue is that 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. Yes, I mistakenly used the same variable used to store sent files to also show amount of cleared files. Unfortunately I think the best way to handle this issue was to simplify cleared queue alert not to use any numbers, since it's non-obvious how many files are currently in queue after submitting some amount (and later if queued files would happen to change status server-side whilst page would not update). |
||
this.state.alertShowFileLen | ||
} ${this.fileOrFiles( | ||
this.state.alertShowFileLen | ||
)} from queue ${this.ursa_id}!`} | ||
onClick={this.handleAlertClearedClose} | ||
/> | ||
)} | ||
<div className="index-form-wrapper"> | ||
<textarea | ||
id="filenames-textarea" | ||
|
@@ -175,8 +272,11 @@ class IndexPageInner extends Component { | |
<div className="my-2">{`Oldest file in the queue: ${this.state.oldestFile}`}</div> | ||
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. 🤔 missed that previously |
||
)} | ||
<IndexClearQueueButton | ||
msg="Clear queue" | ||
ursa_id={this.props.params.ursa_id} | ||
onClick={this.handleModalOpen} | ||
/> | ||
{this.state.modalShowClearQueue && clearQueueModal} | ||
</div> | ||
</ErrorBoundary> | ||
); | ||
|
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.
isn't
z-index: auto
the default value? Unless there's some inheritance going on here.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.
Leftover from modal styling 😁 Will clear this.