Skip to content

Commit

Permalink
JS: Add stop button
Browse files Browse the repository at this point in the history
  • Loading branch information
carlinmack committed May 30, 2024
1 parent f3cf1fb commit f5fefa7
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import PropTypes from "prop-types";
import React, { Component } from "react";
import { UserListItemCompact, toRelativeTime } from "react-invenio-forms";
import { withState } from "react-searchkit";
import { Popup, Table, Button, Icon } from "semantic-ui-react";
import { Button, Icon, Popup, Table } from "semantic-ui-react";
// import { RunButton } from "./RunButton";
import { StatusFormatter } from "./StatusFormatter";
import { http } from "react-invenio-forms";
import { StatusFormatter } from "./StatusFormatter";

class SearchResultItemComponent extends Component {
render() {
Expand Down Expand Up @@ -103,7 +103,7 @@ class SearchResultItemComponent extends Component {
}}
>
<Icon name="play" />
Run
Run now
</Button>
{/* <RunButton jobId={result.id} config={result.default_args ?? {}} /> */}
</Table.Cell>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,24 @@ import { UserListItemCompact, toRelativeTime } from "react-invenio-forms";
import { withState } from "react-searchkit";
import { Table } from "semantic-ui-react";
import { StatusFormatter } from "./StatusFormatter";
import { SystemRunActions } from "./SystemRunActions";
import { StopButton } from "./StopButton";

class SearchResultItemComponent extends Component {
// constructor(props) {
// super(props);
// this.state = {
// error: "",
// };
// }

render() {
const { result } = this.props;

// const handleError = (errorMessage) => {
// console.error(errorMessage);
// this.setState({ error: errorMessage });
// };

return (
<Table.Row>
<Table.Cell
Expand Down Expand Up @@ -72,7 +84,7 @@ class SearchResultItemComponent extends Component {
)}
<Table.Cell collapsing>
{result.status === "RUNNING" || result.status === "QUEUED" ? (
<SystemRunActions result={result} />
<StopButton stopURL={result.links.stop} />
) : (
""
)}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// This file is part of InvenioRDM
// Copyright (C) 2024 CERN
//
// 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";

export const StopButton = ({ stopURL }) => {
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);
}
};

return (
<Button
fluid
className="error outline"
size="medium"
onClick={handleClick}
loading={loading}
icon
labelPosition="left"
>
<Icon name="stop" />
{i18next.t("Stop")}
</Button>
);
};

StopButton.propTypes = {
stopURL: PropTypes.string.isRequired,
};

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// This file is part of Invenio
// Copyright (C) 2024 CERN.
//
// Invenio RDM 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 { http } from "react-invenio-forms";
import React from "react";

import { ErrorMessage } from "@js/invenio_administration";

export const stopRun = async (url) => {
try {
await http.post(url);
} catch (error) {
console.error(error);
return (
<ErrorMessage
{...error}
id="error"
header="hello"
content="errormessage"
/>
);
}
};
1 change: 0 additions & 1 deletion invenio_jobs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ def last_run(self):
return self.runs.order_by(Run.created.desc()).first()



class RunStatusEnum(enum.Enum):
"""Enumeration of a run's possible states."""

Expand Down

0 comments on commit f5fefa7

Please sign in to comment.