-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d4a8426
commit 7571a17
Showing
2 changed files
with
87 additions
and
12 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
64 changes: 64 additions & 0 deletions
64
client/app/pages/queries/components/QueryExecutionStatus.jsx
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,64 @@ | ||
import { includes } from "lodash"; | ||
import React from "react"; | ||
import PropTypes from "prop-types"; | ||
import Alert from "antd/lib/alert"; | ||
import Button from "antd/lib/button"; | ||
import { Timer } from "@/components/Timer"; | ||
|
||
export default function QueryExecutionStatus({ status, updatedAt, error, onCancel }) { | ||
const alertType = status === "failed" ? "error" : "info"; | ||
const showTimer = status !== "failed" && updatedAt; | ||
const canCancel = includes(["waiting", "processing"], status); | ||
let message = null; | ||
|
||
switch (status) { | ||
case "waiting": | ||
message = <React.Fragment>Query in queue…</React.Fragment>; | ||
break; | ||
case "processing": | ||
message = <React.Fragment>Executing query…</React.Fragment>; | ||
break; | ||
case "loading-result": | ||
message = <React.Fragment>Loading results…</React.Fragment>; | ||
break; | ||
case "failed": | ||
message = ( | ||
<React.Fragment> | ||
Error running query: <strong>{error}</strong> | ||
</React.Fragment> | ||
); | ||
break; | ||
// no default | ||
} | ||
|
||
return ( | ||
<Alert | ||
type={alertType} | ||
message={ | ||
<div className="d-flex align-items-center"> | ||
<div className="flex-fill"> | ||
{message}{" "} | ||
{showTimer && <Timer from={updatedAt} />} | ||
</div> | ||
<div> | ||
{canCancel && <Button type="primary" size="small" onClick={onCancel}>Cancel</Button>} | ||
</div> | ||
</div> | ||
} | ||
/> | ||
); | ||
} | ||
|
||
QueryExecutionStatus.propTypes = { | ||
status: PropTypes.string, | ||
updatedAt: PropTypes.any, | ||
error: PropTypes.string, | ||
onCancel: PropTypes.func, | ||
}; | ||
|
||
QueryExecutionStatus.defaultProps = { | ||
status: "waiting", | ||
updatedAt: null, | ||
error: null, | ||
onCancel: () => {}, | ||
}; |