Skip to content
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

Merged
merged 7 commits into from
Mar 20, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: add modal and clear alert to index page
mickol34 committed Feb 28, 2025
commit 95560c32bdb5e8e88d97b01ffd82cee9454707d1
8 changes: 8 additions & 0 deletions src/mqueryfront/src/App.css
Original file line number Diff line number Diff line change
@@ -95,6 +95,14 @@
right: 5vw;
}

.modal-container-index-page {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
z-index: auto;
Copy link
Member

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.

Copy link
Collaborator Author

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.

}

.modal-block {
position: relative;
block-size: "fit-content";
8 changes: 2 additions & 6 deletions src/mqueryfront/src/indexFiles/IndexClearQueueButton.js
Original file line number Diff line number Diff line change
@@ -2,10 +2,6 @@ import React, { Component } from "react";
import api from "../api";

class IndexClearQueueButton extends Component {
onClick() {
api.delete(`/queue/${this.props.ursa_id}`);
}

render() {
return (
<span
@@ -14,9 +10,9 @@ class IndexClearQueueButton extends Component {
>
<button
className="btn btn-secondary btn-sm btn-danger my-2"
onClick={() => this.onClick()}
onClick={() => this.props.onClick()}
>
Clear queue
{this.props.msg}
</button>
</span>
);
17 changes: 17 additions & 0 deletions src/mqueryfront/src/indexFiles/IndexClearedPage.js
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;
100 changes: 100 additions & 0 deletions src/mqueryfront/src/indexFiles/IndexPage.js
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 ${
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully cleared false file from queue default!

I think the variable here should be alertShowCleared?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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 alertShowCleared is false (this variable is boolean). Variable alertShowFileLen stores amount of submitted files and this is the value we want to return in feedback. Is something not presenting correctly on your version?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

step one: add 1 file
image
step two: add 2 files
image
now there are three files in the queue (verify by select * from queuedfile;)
step three: clear queue
this should clear three fules, but the result is either:
image
or
image
depending on if the previous banner was closed. Also in the latter situation, I can now add one file again, and get:
image
so I believe there is some variable confusion here 🦆

You're right that my comment was wrong, I think that the issue is that handleClearQueue doesn't set FileLen? But I leave this to you, anyway something's wrong I belive

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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>
Copy link
Member

Choose a reason for hiding this comment

The 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>
);