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

Job reports improvements #2337

Merged
merged 3 commits into from
May 22, 2024
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
1 change: 0 additions & 1 deletion frontend/src/components/jobs/result/JobInfoIcon.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,4 @@ export function JobInfoIcon({ job }) {

JobInfoIcon.propTypes = {
job: PropTypes.object.isRequired,
countryInfo: PropTypes.object.isRequired,
};
16 changes: 10 additions & 6 deletions frontend/src/components/jobs/result/JobOverview.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,11 @@ export function JobOverview({
const location = useLocation();
const [UIElements, setUIElements] = useState([]);
console.debug(
`location pathname: ${location.pathname}, state: ${JSON.stringify(
location?.state,
)}`,
`location pathname: ${
location.pathname
}, state - userChanged: ${JSON.stringify(
location?.state?.userChanged,
)}, state - jobReport: #${location?.state?.jobReport.id}`,
);

useEffect(() => {
Expand Down Expand Up @@ -395,7 +397,7 @@ export function JobOverview({
`/jobs/${job.id}/${
JobResultSections.VISUALIZER
}/${encodeURIComponent(UIElements[0].name)}`,
{ state: { userChanged: true } },
{ state: { userChanged: true, jobReport: job } },
)
}
>
Expand All @@ -408,7 +410,7 @@ export function JobOverview({
onClick={() =>
navigate(
`/jobs/${job.id}/${JobResultSections.RAW}/${rawElements[0].name}`,
{ state: { userChanged: true } },
{ state: { userChanged: true, jobReport: job } },
)
}
>
Expand Down Expand Up @@ -438,7 +440,9 @@ export function JobOverview({
}/${section}/${encodeURIComponent(
componentsObject.name,
)}`,
{ state: { userChanged: true } },
{
state: { userChanged: true, jobReport: job },
},
)
}
>
Expand Down
27 changes: 15 additions & 12 deletions frontend/src/components/jobs/result/JobResult.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React, { useEffect } from "react";
import useTitle from "react-use/lib/useTitle";
import { useParams } from "react-router-dom";
import { useParams, useLocation } from "react-router-dom";

import { Loader } from "@certego/certego-ui";
import axios from "axios";
import useAxios from "axios-hooks";
import { WEBSOCKET_JOBS_URI, JOB_BASE_URI } from "../../../constants/apiURLs";
import { JobOverview } from "./JobOverview";

Expand All @@ -17,9 +17,10 @@ import { JobFinalStatuses } from "../../../constants/jobConst";
export default function JobResult() {
console.debug("JobResult rendered!");

// state
const location = useLocation();
const [initialLoading, setInitialLoading] = React.useState(true);
const [initialError, setInitialError] = React.useState("");
const [job, setJob] = React.useState(undefined);
const [job, setJob] = React.useState(location.state?.jobReport || undefined);
// this state var is used to check if we notified the user, in this way we avoid to notify more than once
const [notified, setNotified] = React.useState(false);
// this state var is used to check if the user changed page, in case he waited the result on the page we avoid the notification
Expand Down Expand Up @@ -53,7 +54,11 @@ export default function JobResult() {
`notified: ${notified}, toNotify: ${toNotify}`,
);

const getJob = () => axios.get(`${JOB_BASE_URI}/${jobId}`);
// useAxios caches the request by default
const [{ data: respData, loading, error }, refetchJob] = useAxios({
url: `${JOB_BASE_URI}/${jobId}`,
});

useEffect(() => {
/* INITIAL SETUP:
- add a focus listener:
Expand All @@ -66,12 +71,10 @@ export default function JobResult() {
setToNotify(false);
});
window.addEventListener("blur", () => setToNotify(true));
getJob()
.then((response) => setJob(response.data))
.catch((err) => setInitialError(err))
.finally((_) => setInitialLoading(false));
if (!job && respData && !loading && error == null) setJob(respData);
if (!loading) setInitialLoading(false);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
}, [loading]);

// page title
useTitle(
Expand Down Expand Up @@ -133,12 +136,12 @@ export default function JobResult() {
return (
<Loader
loading={initialLoading}
error={initialError}
error={error}
render={() => (
<JobOverview
isRunningJob={jobIsRunning}
job={job}
refetch={getJob}
refetch={refetchJob}
section={section}
subSection={subSection}
/>
Expand Down
13 changes: 9 additions & 4 deletions frontend/src/components/jobs/result/pluginReportTables.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {

import { StatusTag } from "../../common/StatusTag";
import { killPlugin, retryPlugin } from "./jobApi";
import { PluginStatuses } from "../../../constants/pluginConst";
import { PluginStatuses, PluginsTypes } from "../../../constants/pluginConst";
import { markdownToHtml } from "../../common/markdownToHtml";

const tableProps = {
Expand Down Expand Up @@ -83,12 +83,12 @@ const tableProps = {
<div className="d-inline-block col-10 offset-1">{value}</div>
<div className="col-1">
<MdInfoOutline
id={`pluginReport-infoicon__${value}`}
id={`pluginReport-infoicon__${value.replaceAll(" ", "_")}`}
className="text-secondary"
fontSize="20"
/>
<UncontrolledPopover
target={`pluginReport-infoicon__${value}`}
target={`pluginReport-infoicon__${value.replaceAll(" ", "_")}`}
placement="bottom"
trigger="hover"
popperClassName="px-2 bg-body"
Expand Down Expand Up @@ -168,7 +168,12 @@ export function PluginsReportTable({

reports.forEach((report, index) => {
pluginsStored.forEach((plugin) => {
if (plugin.name === report.name) {
if (
(report.type !== PluginsTypes.VISUALIZER &&
plugin.name === report.name) ||
(report.type === PluginsTypes.VISUALIZER &&
plugin.name === report.config)
) {
reports[index].description = plugin.description;
}
});
Expand Down
20 changes: 0 additions & 20 deletions frontend/src/stores/useJobOverviewStore.jsx

This file was deleted.

Loading