diff --git a/invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/JobSearchResultItemLayout.js b/invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/JobSearchResultItemLayout.js index b487daa..618ef17 100644 --- a/invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/JobSearchResultItemLayout.js +++ b/invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/JobSearchResultItemLayout.js @@ -6,6 +6,7 @@ * under the terms of the MIT License; see LICENSE file for more details. */ +import { NotificationContext } from "@js/invenio_administration"; import { BoolFormatter } from "@js/invenio_administration"; import { i18next } from "@translations/invenio_app_rdm/i18next"; import PropTypes from "prop-types"; @@ -18,6 +19,18 @@ import { http } from "react-invenio-forms"; import { StatusFormatter } from "./StatusFormatter"; class SearchResultItemComponent extends Component { + static contextType = NotificationContext; + + onError = (e) => { + const { addNotification } = this.context; + addNotification({ + title: i18next.t("Error"), + content: e.message, + type: "error", + }); + console.error(e); + }; + render() { const { result } = this.props; @@ -105,7 +118,7 @@ class SearchResultItemComponent extends Component { Run now - {/* */} + {/* */} ); diff --git a/invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/RunButton.js b/invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/RunButton.js index 1fd4ea6..587e49b 100644 --- a/invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/RunButton.js +++ b/invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/RunButton.js @@ -6,7 +6,8 @@ import { i18next } from "@translations/invenio_app_rdm/i18next"; import PropTypes from "prop-types"; -import React from "react"; +import React, { useState } from "react"; +import { http } from "react-invenio-forms"; import { Button, Dropdown, @@ -14,12 +15,24 @@ import { Form, FormInput, } from "semantic-ui-react"; -import { http } from "react-invenio-forms"; -export const RunButton = ({ jobId, config }) => { +export const RunButton = ({ jobId, config, onError }) => { + const [loading, setLoading] = useState(false); + + const handleClick = async () => { + setLoading(true); + try { + await http.post("/api/jobs/" + jobId + "/runs"); + setLoading(false); + } catch (error) { + setLoading(false); + onError(error); + } + }; + return ( { { - http.post("/api/jobs/" + jobId + "/runs"); - }} + onClick={handleClick} + loading={loading} /> @@ -55,6 +67,7 @@ export const RunButton = ({ jobId, config }) => { RunButton.propTypes = { jobId: PropTypes.string.isRequired, config: PropTypes.object, + onError: PropTypes.func.isRequired, }; RunButton.defaultProps = { diff --git a/invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/RunsSearchResultItemLayout.js b/invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/RunsSearchResultItemLayout.js index e9b69ca..207081f 100644 --- a/invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/RunsSearchResultItemLayout.js +++ b/invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/RunsSearchResultItemLayout.js @@ -6,6 +6,7 @@ * under the terms of the MIT License; see LICENSE file for more details. */ +import { NotificationContext } from "@js/invenio_administration"; import { i18next } from "@translations/invenio_app_rdm/i18next"; import PropTypes from "prop-types"; import React, { Component } from "react"; @@ -16,21 +17,21 @@ import { StatusFormatter } from "./StatusFormatter"; import { StopButton } from "./StopButton"; class SearchResultItemComponent extends Component { - // constructor(props) { - // super(props); - // this.state = { - // error: "", - // }; - // } + static contextType = NotificationContext; + + onError = (e) => { + const { addNotification } = this.context; + addNotification({ + title: i18next.t("Status ") + e.status, + content: `${e.message}`, + type: "error", + }); + console.error(e); + }; render() { const { result } = this.props; - // const handleError = (errorMessage) => { - // console.error(errorMessage); - // this.setState({ error: errorMessage }); - // }; - return ( - {result.title} + {result.message} {result.started_by ? ( {result.status === "RUNNING" || result.status === "QUEUED" ? ( - + ) : ( "" )} diff --git a/invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/StatusFormatter.js b/invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/StatusFormatter.js index 61edc76..8ff5648 100644 --- a/invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/StatusFormatter.js +++ b/invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/StatusFormatter.js @@ -45,7 +45,7 @@ export const StatusFormatter = ({ status }) => { diff --git a/invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/StopButton.js b/invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/StopButton.js index a213782..8eb3574 100644 --- a/invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/StopButton.js +++ b/invenio_jobs/assets/semantic-ui/js/invenio_jobs/administration/search/StopButton.js @@ -4,24 +4,25 @@ // Invenio RDM Records is free software; you can redistribute it and/or modify it // under the terms of the MIT License; see LICENSE file for more details. -import React, { useState } from "react"; -import { Icon, Button } from "semantic-ui-react"; import { i18next } from "@translations/invenio_app_rdm/i18next"; -import { http } from "react-invenio-forms"; import PropTypes from "prop-types"; +import React, { useState } from "react"; +import { http } from "react-invenio-forms"; +import { Button, Icon } from "semantic-ui-react"; -export const StopButton = ({ stopURL }) => { +export const StopButton = ({ stopURL, onError }) => { const [loading, setLoading] = useState(false); const handleClick = async () => { setLoading(true); - try { - await http.post(stopURL); - setLoading(false); - } catch (error) { - setLoading(false); - // onError(error.response.data.message); - } + await http.post(stopURL).catch((error) => { + if (error.response) { + onError(error.response.data); + } else { + onError(error); + } + }); + setLoading(false); }; return ( @@ -42,4 +43,5 @@ export const StopButton = ({ stopURL }) => { StopButton.propTypes = { stopURL: PropTypes.string.isRequired, + onError: PropTypes.func.isRequired, }; diff --git a/invenio_jobs/templates/semantic-ui/invenio_jobs/system/jobs/jobs-details.html b/invenio_jobs/templates/semantic-ui/invenio_jobs/system/jobs/jobs-details.html index 7e04481..5d36538 100644 --- a/invenio_jobs/templates/semantic-ui/invenio_jobs/system/jobs/jobs-details.html +++ b/invenio_jobs/templates/semantic-ui/invenio_jobs/system/jobs/jobs-details.html @@ -15,12 +15,12 @@ {{ go_back() }} - + - {{ title or name }} - + {{ title or name }} + - + {% block admin_page_content %}