-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
292 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import React, { Component } from "react"; | ||
import api from "../api"; | ||
|
||
class IndexClearQueueButton extends Component { | ||
onClick() { | ||
api.post(`/queue/${this.props.ursa_id}/clear`, {}).catch((_e) => {}); | ||
} | ||
|
||
render() { | ||
return ( | ||
<span | ||
data-toggle="tooltip" | ||
title={ | ||
"This action will clear all unindexed files from this queue" | ||
} | ||
> | ||
<button | ||
className="btn btn-secondary btn-sm btn-danger my-2" | ||
onClick={() => this.onClick()} | ||
> | ||
Clear queue | ||
</button> | ||
</span> | ||
); | ||
} | ||
} | ||
|
||
export default IndexClearQueueButton; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Component } from "react"; | ||
import Select from "react-select"; | ||
|
||
class IndexMultiselect extends Component { | ||
get optionsList() { | ||
return this.props.options.map((obj) => ({ | ||
label: obj, | ||
value: obj, | ||
})); | ||
} | ||
|
||
render() { | ||
return ( | ||
<Select | ||
form="formName" | ||
name={this.props.name} | ||
options={this.optionsList} | ||
placeholder={this.props.placeholder} | ||
isMulti | ||
isSearchable | ||
onChange={this.props.onChange} | ||
/> | ||
); | ||
} | ||
} | ||
|
||
export default IndexMultiselect; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
import { Component } from "react"; | ||
import IndexMultiSelect from "./IndexMultiSelect"; | ||
import { useParams } from "react-router-dom"; | ||
import api from "../api"; | ||
import ErrorBoundary from "../components/ErrorBoundary"; | ||
import IndexProgressBar from "./IndexProgressBar"; | ||
import IndexClearQueueButton from "./IndexClearQueueButton"; | ||
|
||
// function getAvailableTaintsListFromDatasets(datasets) { | ||
// var taintList = Object.values(datasets) | ||
// .map((ds) => ds.taints) | ||
// .flat(); | ||
// return [...new Set(taintList)]; | ||
// } | ||
|
||
class IndexPageInner extends Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
filenames: [], | ||
availableNGrams: ["gram3", "text4", "wide8", "hash4"], | ||
selectedNGrams: [], | ||
availableTaints: [], | ||
selectedTaints: [], | ||
allQueuedFilesLength: 0, | ||
finishedQueuedFilesLength: 0, | ||
}; | ||
this.handleSubmit = this.handleSubmit.bind(this); | ||
this.handleTextareaInput = this.handleTextareaInput.bind(this); | ||
this.handleNGramSelect = this.handleNGramSelect.bind(this); | ||
this.handleTaintSelect = this.handleTaintSelect.bind(this); | ||
} | ||
|
||
ursa_id = this.props.params.ursa_id; | ||
|
||
componentDidMount() { | ||
api.get(`/queue/${this.props.params.ursa_id}`) | ||
// .then((response) => { | ||
// this.setState({ | ||
// allQueuedFilesLength: response.data.all_files, // NOTE: dunno whether these params will be provided at all | ||
// finishedQueuedFilesLength: response.data.finished_files | ||
// }) | ||
// }) | ||
// .catch((error) => { | ||
// this.setState({ error: error }); | ||
// }); | ||
.catch((_e) => { | ||
this.setState({ | ||
allQueuedFilesLength: 10000, | ||
finishedQueuedFilesLength: 2137, | ||
}); | ||
}); // TODO: uncomment prev then-catch clause after API implementation | ||
|
||
api.get("/backend/datasets") | ||
.then((_response) => { | ||
// this.setState({ | ||
// availableTaints: getAvailableTaintsListFromDatasets(response.data.datasets), | ||
// }); | ||
this.setState({ | ||
availableTaints: ["test_taint", "some other taint"], | ||
}); // TODO: uncomment prev set state after API implementation | ||
}) | ||
.catch((error) => { | ||
this.setState({ error: error }); | ||
}); | ||
} | ||
|
||
handleTextareaInput(e) { | ||
const splitFiles = e.target.value.split("\n").filter((file) => !!file); | ||
this.setState({ filenames: splitFiles }); | ||
} | ||
|
||
handleNGramSelect(selection) { | ||
this.setState({ selectedNGrams: selection }); | ||
} | ||
|
||
handleTaintSelect(selection) { | ||
this.setState({ selectedTaints: selection }); | ||
} | ||
|
||
handleSubmit() { | ||
// TODO: process following data accordingly to new endpoint | ||
// c_onsole.log(this.state.filenames); // list of strings | ||
// c_onsole.log(this.state.selectedNGrams); // list of {value: nGram, label: nGram} objects | ||
// c_onsole.log(this.state.selectedTaints); // list of {value: taint, label: taint} objects | ||
api.post(`/queue/${this.ursa_id}`, {}) | ||
.then((_r) => {}) | ||
.catch((_e) => {}); | ||
} | ||
|
||
render() { | ||
const fileLen = this.state.filenames.length; | ||
const percentage = this.state.allQueuedFilesLength | ||
? (this.state.finishedQueuedFilesLength * 100.0) / | ||
this.state.allQueuedFilesLength | ||
: 0; | ||
return ( | ||
<ErrorBoundary error={this.state.error}> | ||
<div className="container-fluid"> | ||
<h1 className="text-center mq-bottom">{`Index ${this.props.params.ursa_id}`}</h1> | ||
<div className="index-form-wrapper"> | ||
<textarea | ||
id="filenames-textarea" | ||
className="form-control" | ||
name="rows" | ||
placeholder="Input filenames here (each line representing one filename)" | ||
onChange={this.handleTextareaInput} | ||
/> | ||
<IndexMultiSelect | ||
placeholder="Select nGrams" | ||
options={this.state.availableNGrams} | ||
onChange={this.handleNGramSelect} | ||
/> | ||
{this.state.availableTaints.length > 0 && ( | ||
<IndexMultiSelect | ||
placeholder="Select taints" | ||
options={this.state.availableTaints} | ||
onChange={this.handleTaintSelect} | ||
/> | ||
)} | ||
<button | ||
className="btn btn-secondary btn-sm btn-success" | ||
onClick={this.handleSubmit} | ||
> | ||
{`Add to queue${ | ||
fileLen > 0 | ||
? ` (${fileLen} file${ | ||
fileLen > 1 ? "s" : "" | ||
})` | ||
: "" | ||
}`} | ||
</button> | ||
</div> | ||
{percentage ? ( | ||
<> | ||
<IndexProgressBar percentage={percentage} /> | ||
<IndexClearQueueButton | ||
ursa_id={this.props.params.ursa_id} | ||
/> | ||
</> | ||
) : ( | ||
<></> | ||
)} | ||
</div> | ||
</ErrorBoundary> | ||
); | ||
} | ||
} | ||
|
||
function IndexPage() { | ||
return <IndexPageInner params={useParams()} />; | ||
} | ||
|
||
export default IndexPage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Component } from "react"; | ||
|
||
class IndexProgressBar extends Component { | ||
render() { | ||
return ( | ||
<div className="row my-2"> | ||
<h4 className="text-center mq-bottom">Indexing progress</h4> | ||
<div className="progress my-2"> | ||
<div | ||
className="progress-bar progress-bar-striped progress-bar-animated" | ||
role="progressbar" | ||
aria-valuenow={this.props.percentage} | ||
aria-valuemin="0" | ||
aria-valuemax="100" | ||
style={{ width: `${this.props.percentage}%` }} | ||
> | ||
{`${this.props.percentage}%`} | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default IndexProgressBar; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; | ||
import { faArrowRight } from "@fortawesome/free-solid-svg-icons"; | ||
import { Link } from "react-router-dom"; | ||
|
||
const IndexLink = (props) => { | ||
return ( | ||
<div className="index-navlink"> | ||
<Link exact to={`/index-files/${props.ursaID}`}> | ||
Index using UrsaDB id.:{props.ursaID} | ||
<FontAwesomeIcon | ||
className="mx-2" | ||
icon={faArrowRight} | ||
size="xl" | ||
color="black" | ||
/> | ||
</Link> | ||
</div> | ||
); | ||
}; | ||
|
||
export default IndexLink; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters