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

Frontend refactoring: round 3 #249

Merged
merged 2 commits into from
Dec 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 1 addition & 6 deletions src/mqueryfront/src/components/ErrorBoundary.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@ class ErrorBoundary extends Component {
constructor(props) {
super(props);

let error = props.error;

if (!error) {
error = null;
}

let error = props.error ? props.error : null;
this.state = { error: error };
}

Expand Down
5 changes: 1 addition & 4 deletions src/mqueryfront/src/components/FilteringThead.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ const FilteringThead = (props) => {
let thContent;
if (props.filterData && props.filterData.valueList) {
const list = props.filterData.valueList.map((el, index) => {
let activeItem = false;
if (activeColumn && props.currentFilter.value === el)
activeItem = true;

let activeItem = activeColumn && props.currentFilter.value === el;
const itemStyle = "font-weight-" + (activeItem ? "bold" : "normal");

return (
Expand Down
49 changes: 10 additions & 39 deletions src/mqueryfront/src/components/FilteringTitle.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,17 @@ import FilterIcon from "./FilterIcon";
const FilteringTitle = (props) => {
const { title, filterValue } = props;

const icon = (
<span className="mr-1">
<FilterIcon tooltipMessage="filtered by:" />
</span>
);

if (filterValue)
return (
<div className="d-flex justify-content-between align-items-center">
<div className="flex-fill">
<div
className="text-truncate invisible"
style={{
minWidth: 50,
maxWidth: "20vw",
}}
>
{icon}
{filterValue}
</div>
</div>
<div className="flex-fill">
<h1 className="text-center">{title}</h1>
</div>

<div className="flex-fill">
<div
className="text-truncate text-right"
style={{
minWidth: 50,
maxWidth: "20vw",
}}
>
{icon}
{filterValue}
</div>
</div>
const filter = filterValue && <FilterIcon tooltipMessage="filtered by:" />;
return (
<div className="d-flex justify-content-between">
<div className="col"></div>
<h1 className="">{title}</h1>
<div className="col text-right">
{filter}
{filterValue}
</div>
);
else return <h1 className="text-center mq-bottom">{title}</h1>;
</div>
);
};

export default FilteringTitle;
10 changes: 4 additions & 6 deletions src/mqueryfront/src/components/LoadingPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faSpinner } from "@fortawesome/free-solid-svg-icons";

const LoadingPage = () => (
<div>
<h2>
<FontAwesomeIcon icon={faSpinner} spin size="lg" className="mr-2" />
Loading...
</h2>
</div>
<h2>
<FontAwesomeIcon icon={faSpinner} spin size="lg" className="mr-2" />
Loading...
</h2>
);

export default LoadingPage;
77 changes: 33 additions & 44 deletions src/mqueryfront/src/components/QueryProgressBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ import { isStatusFinished, getProgressBarClass } from "../queryUtils";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faSpinner } from "@fortawesome/free-solid-svg-icons";

const getPercentage = (partial, total) =>
total ? Math.round((partial * 100) / total) : 0;

const QueryProgressBar = (props) => {
const { job, compact, onCancel } = props;
const {
Expand All @@ -25,24 +22,18 @@ const QueryProgressBar = (props) => {
const datasetFrac = total_datasets > 0 ? datasetsDone / total_datasets : 0;
const datasetPct = Math.round(datasetFrac * 100);

const getPercentage = (files) =>
total_files ? Math.round((files * datasetFrac * 100) / total_files) : 0;

const isFinished = isStatusFinished(status);
const inProgeressPct = getPercentage(
files_in_progress * datasetFrac,
total_files
);
const erroredPct = getPercentage(files_errored * datasetFrac, total_files);
const inProgeressPct = getPercentage(files_in_progress);
const erroredPct = getPercentage(files_errored);
const processedPct =
total_files === 0 && isFinished
? 100
: getPercentage(files_processed * datasetFrac, total_files);
total_files === 0 && isFinished ? 100 : getPercentage(files_processed);

const errorString = files_errored === 1 ? "error" : "errors";
const errorTooltip = `${files_errored} ${errorString} during processing`;

const cancelButton = isFinished ? null : (
<ActionCancel onClick={onCancel} size="sm" />
);

const matches = `${files_matched} matches`;
let statusInfo = null;
if (total_datasets === 0 && status === "new") {
Expand Down Expand Up @@ -82,37 +73,35 @@ const QueryProgressBar = (props) => {
/>
)}
</div>
{
<div className={compact ? "small" : ""}>
<div class="float-left">
{statusInfo && (
<FontAwesomeIcon
icon={faSpinner}
spin
size={props.size}
className="mr-1"
/>
)}
{statusInfo || matches}
</div>
<div class="float-right">
<QueryTimer
job={job}
isFinished={isFinished}
duration={true}
countDown={true}
<div className={compact ? "small" : ""}>
<div className="float-left">
{statusInfo && (
<FontAwesomeIcon
icon={faSpinner}
spin
size={props.size}
className="mr-1"
/>
{compact || isFinished ? null : (
<ActionCancel
onClick={onCancel}
size="sm"
className="ml2"
/>
)}
</div>
<div class="clearfix"></div>
)}
{statusInfo || matches}
</div>
}
<div className="float-right">
<QueryTimer
job={job}
isFinished={isFinished}
duration={true}
countDown={true}
/>
{compact || isFinished ? null : (
<ActionCancel
onClick={onCancel}
size="sm"
className="ml2"
/>
)}
</div>
<div className="clearfix"></div>
</div>
</div>
);
};
Expand Down
Empty file.
9 changes: 0 additions & 9 deletions src/mqueryfront/src/config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1 @@
// specify where is the application backend
// if it runs on the same server with frontend then leave an empty string:
//
// export const API_URL = '/api';
//
// if not, then give some URL, e.g.:
//
// export const API_URL = 'http://my-backend.example.com";
//
export const API_URL = "/api";
2 changes: 1 addition & 1 deletion src/mqueryfront/src/config/ConfigPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ConfigPage extends Component {

componentDidMount() {
axios
.get(API_URL + "/config")
.get(`${API_URL}/config`)
.then((response) => {
this.setState({ config: response.data });
})
Expand Down
2 changes: 0 additions & 2 deletions src/mqueryfront/src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import "bootstrap/dist/css/bootstrap.min.css";
import "font-awesome/css/font-awesome.css";
//import $ from 'jquery';
//import Popper from 'popper.js';
import "bootstrap/dist/js/bootstrap.bundle.min";
import React from "react";
import ReactDOM from "react-dom";
Expand Down
7 changes: 0 additions & 7 deletions src/mqueryfront/src/query/QueryEditParseNav.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from "react";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faClone, faCode } from "@fortawesome/free-solid-svg-icons";
import PropTypes from "prop-types";

const QueryEditParseNav = (props) => {
const { onEditQuery, onParseQuery, isEditActive } = props;
Expand Down Expand Up @@ -30,10 +29,4 @@ const QueryEditParseNav = (props) => {
);
};

QueryEditParseNav.propTypes = {
isEditActive: PropTypes.bool.isRequired,
onEditQuery: PropTypes.func.isRequired,
onParseQuery: PropTypes.func.isRequired,
};

export default QueryEditParseNav;
23 changes: 0 additions & 23 deletions src/mqueryfront/src/query/QueryLayoutManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faAlignLeft } from "@fortawesome/free-solid-svg-icons";
import ErrorPage from "../components/ErrorPage";
import LoadingPage from "../components/LoadingPage";
import PropTypes from "prop-types";
import { PT_JOB, PT_MATCHES, PT_QUERYPLAN, PT_PAGINATION } from "../queryUtils";

const QueryLayoutManager = (props) => {
const {
Expand Down Expand Up @@ -96,25 +94,4 @@ const QueryLayoutManager = (props) => {
);
};

QueryLayoutManager.propTypes = {
isCollapsed: PropTypes.bool.isRequired,
onCollapsePane: PropTypes.func.isRequired,
job: PT_JOB,
matches: PT_MATCHES,
pagination: PT_PAGINATION,
onCancel: PropTypes.func.isRequired,
qhash: PropTypes.string,
queryPlan: PT_QUERYPLAN,
queryError: PropTypes.string,
onSubmitQuery: PropTypes.func.isRequired,
onEditQuery: PropTypes.func.isRequired,
onParseQuery: PropTypes.func.isRequired,
onTaintSelect: PropTypes.func.isRequired,
availableTaints: PropTypes.arrayOf(PropTypes.string).isRequired,
rawYara: PropTypes.string.isRequired,
onYaraUpdate: PropTypes.func.isRequired,
parsedError: PropTypes.arrayOf(PropTypes.string).isRequired,
selectedTaints: PropTypes.arrayOf(PropTypes.string).isRequired,
};

export default QueryLayoutManager;
14 changes: 5 additions & 9 deletions src/mqueryfront/src/query/QueryMatches.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,10 @@ const QueryMatches = (props) => {
return null;
})
.map((match, index) => {
const downloadUrl =
API_URL +
"/download?job_id=" +
encodeURIComponent(qhash) +
"&ordinal=" +
encodeURIComponent(index) +
"&file_path=" +
encodeURIComponent(match.file);
const qhashElm = encodeURIComponent(qhash);
const indexElm = encodeURIComponent(index);
const fileElm = encodeURIComponent(match.file);
const downloadUrl = `${API_URL}/download?job_id=${qhashElm}&ordinal=${indexElm}&file_path=${fileElm}`;

return (
<QueryMatchesItem
Expand All @@ -106,7 +102,7 @@ const QueryMatches = (props) => {
const filtersHead = filters.map((v) => (
<span
key={v}
className="badge badge-pill badge-secondary ml-1 mt-1 cursor-pointer"
className="badge badge-pill badge-secondary ml-1 mt-1 cursor-pointer"
onClick={() => updateFilter(v)}
>
{v}
Expand Down
18 changes: 6 additions & 12 deletions src/mqueryfront/src/query/QueryPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class QueryPage extends Component {
if (this.queryHash) {
this.fetchJob();
}
const response = await axios.get(API_URL + "/backend/datasets");
const response = await axios.get(`${API_URL}/backend/datasets`);
const datasets = response.data.datasets;

this.setState({ datasets: datasets });
Expand Down Expand Up @@ -93,7 +93,7 @@ class QueryPage extends Component {
}

async handleCancelJob() {
await axios.delete(API_URL + "/job/" + this.queryHash);
await axios.delete(`${API_URL}/job/${this.queryHash}`);
}

handlePageChange(pageNumber) {
Expand All @@ -111,7 +111,7 @@ class QueryPage extends Component {
async fetchJob() {
// Go to the job mode
// Load initial job information and start tracking results
const response = await axios.get(API_URL + "/job/" + this.queryHash);
const response = await axios.get(`${API_URL}/job/${this.queryHash}`);
this.setState(
{
...INITIAL_STATE,
Expand Down Expand Up @@ -146,13 +146,7 @@ class QueryPage extends Component {
// Loads matches from the current page
const OFFSET = (this.state.activePage - 1) * PAGE_SIZE;
const response = await axios.get(
API_URL +
"/matches/" +
this.queryHash +
"?offset=" +
OFFSET +
"&limit=" +
PAGE_SIZE
`${API_URL}/matches/${this.queryHash}?offset=${OFFSET}&limit=${PAGE_SIZE}`
);
return response ? response.data : {};
}
Expand All @@ -162,14 +156,14 @@ class QueryPage extends Component {
const taints =
this.state.selectedTaints.map((obj) => obj.value) || [];

const response = await axios.post(API_URL + "/query", {
const response = await axios.post(`${API_URL}/query`, {
raw_yara: this.state.rawYara,
method: method,
priority: priority,
taints: taints,
});
if (method === "query") {
this.props.history.push("/query/" + response.data.query_hash);
this.props.history.push(`/query/${response.data.query_hash}`);
} else if (method === "parse") {
this.setState({
queryPlan: response.data,
Expand Down
Loading