forked from fortran-lang/registry
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request fortran-lang#69 from arteevraina/reports-ui
Reports UI
- Loading branch information
Showing
8 changed files
with
188 additions
and
10 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
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,60 @@ | ||
import { useState, useEffect } from "react"; | ||
import { useDispatch, useSelector } from "react-redux"; | ||
import { Card, Container, Modal, Spinner } from "react-bootstrap"; | ||
import { | ||
fetchMalicousReports, | ||
resetData, | ||
} from "../store/actions/viewMalicousReportActions"; | ||
|
||
const ViewMalicousReports = (props) => { | ||
const accessToken = useSelector((state) => state.auth.accessToken); | ||
const reports = useSelector((state) => state.malicousReport.reports); | ||
const loading = useSelector((state) => state.malicousReport.isLoading); | ||
const dispatch = useDispatch(); | ||
|
||
useEffect(() => { | ||
if (!props.show) { | ||
return; | ||
} | ||
|
||
dispatch(fetchMalicousReports(accessToken)); | ||
}, [props.show]); | ||
|
||
const onExit = () => { | ||
dispatch(resetData()); | ||
}; | ||
|
||
return ( | ||
<Modal show={props.show} onHide={props.onHide} onExit={onExit}> | ||
<Modal.Header closeButton> | ||
<Modal.Title>View Malicious Reports</Modal.Title> | ||
</Modal.Header> | ||
<Modal.Body> | ||
{loading && ( | ||
<div className="d-flex justify-content-center"> | ||
<Spinner | ||
animation="border" | ||
role="status" | ||
style={{ alignItems: "center" }} | ||
> | ||
<span className="visually-hidden">Loading...</span> | ||
</Spinner> | ||
</div> | ||
)} | ||
{reports.map((report, index) => { | ||
return ( | ||
<Card key={index}> | ||
<Card.Body> | ||
<h5>Namespace - {report.namespace}</h5> | ||
<h6>Package - {report.package}</h6> | ||
<p style={{ textAlign: "left" }}>{report.reason}</p> | ||
</Card.Body> | ||
</Card> | ||
); | ||
})} | ||
</Modal.Body> | ||
</Modal> | ||
); | ||
}; | ||
|
||
export default ViewMalicousReports; |
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,43 @@ | ||
import axios from "axios"; | ||
|
||
export const FETCH_MALICIOUS_REPORTS = "FETCH_MALICIOUS_REPORTS"; | ||
export const FETCH_MALICIOUS_REPORTS_SUCCESS = | ||
"FETCH_MALICIOUS_REPORTS_SUCCESS"; | ||
export const FETCH_MALICIOUS_REPORTS_ERROR = "FETCH_MALICIOUS_REPORTS_ERROR"; | ||
export const RESET_DATA = "RESET_DATA"; | ||
|
||
export const fetchMalicousReports = (accessToken) => { | ||
return async (dispatch) => { | ||
dispatch({ type: FETCH_MALICIOUS_REPORTS }); | ||
try { | ||
const result = await axios({ | ||
method: "get", | ||
url: `${process.env.REACT_APP_REGISTRY_API_URL}/report/view`, | ||
headers: { | ||
Authorization: `Bearer ${accessToken}`, | ||
}, | ||
}); | ||
|
||
dispatch({ | ||
type: FETCH_MALICIOUS_REPORTS_SUCCESS, | ||
payload: { | ||
reports: result.data.reports, | ||
}, | ||
}); | ||
} catch (error) { | ||
dispatch({ | ||
type: FETCH_MALICIOUS_REPORTS_ERROR, | ||
payload: { | ||
statuscode: error.response.data.code, | ||
message: error.response.data.message, | ||
}, | ||
}); | ||
} | ||
}; | ||
}; | ||
|
||
export const resetData = () => (dispatch) => { | ||
dispatch({ | ||
type: RESET_DATA, | ||
}); | ||
}; |
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,46 @@ | ||
import { | ||
FETCH_MALICIOUS_REPORTS, | ||
FETCH_MALICIOUS_REPORTS_SUCCESS, | ||
FETCH_MALICIOUS_REPORTS_ERROR, | ||
RESET_DATA, | ||
} from "../actions/viewMalicousReportActions"; | ||
|
||
const initialState = { | ||
reports: [], | ||
isLoading: false, | ||
error: null, | ||
}; | ||
|
||
const viewMalicousReportsReducer = (state = initialState, action) => { | ||
switch (action.type) { | ||
case FETCH_MALICIOUS_REPORTS: | ||
return { | ||
...state, | ||
isLoading: true, | ||
error: null, | ||
}; | ||
case FETCH_MALICIOUS_REPORTS_SUCCESS: | ||
return { | ||
...state, | ||
reports: action.payload.reports, | ||
isLoading: false, | ||
error: null, | ||
}; | ||
case FETCH_MALICIOUS_REPORTS_ERROR: | ||
return { | ||
...state, | ||
isLoading: false, | ||
error: action.payload.message, | ||
}; | ||
case RESET_DATA: | ||
return { | ||
reports: [], | ||
isLoading: false, | ||
error: null, | ||
}; | ||
default: | ||
return state; | ||
} | ||
}; | ||
|
||
export default viewMalicousReportsReducer; |