-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add JobOverview and modals to query interface
- Loading branch information
1 parent
dd19233
commit 031fe8c
Showing
18 changed files
with
826 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
|
||
import ReactCodeMirror from '@uiw/react-codemirror' | ||
import { EditorView } from '@codemirror/view' | ||
import { sql } from '@codemirror/lang-sql' | ||
|
||
const CodeMirrorDisplay = ({ value }) => { | ||
// check https://www.npmjs.com/package/@uiw/react-codemirror#Props for props | ||
|
||
return ( | ||
<ReactCodeMirror | ||
className="codemirror" | ||
value={value} | ||
extensions={[sql(), EditorView.lineWrapping]} | ||
editable={false} | ||
basicSetup={{ | ||
lineNumbers: false, | ||
foldGutter: false, | ||
highlightActiveLine: false, | ||
}} | ||
/> | ||
) | ||
} | ||
|
||
CodeMirrorDisplay.propTypes = { | ||
value: PropTypes.string | ||
} | ||
|
||
export default CodeMirrorDisplay |
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,5 @@ | ||
import { useReducer } from 'react' | ||
|
||
export const useToggle = (initialValue = false) => { | ||
return useReducer((value) => (!value), initialValue) | ||
} |
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,18 @@ | ||
import { useRef } from 'react' | ||
import { Modal } from 'bootstrap' | ||
|
||
export const useModal = () => { | ||
const ref = useRef() | ||
|
||
const showModal = () => { | ||
const modal = new Modal(ref.current, {}) | ||
modal.show() | ||
} | ||
|
||
const hideModal = () => { | ||
const modal = Modal.getInstance(ref.current) | ||
modal.hide() | ||
} | ||
|
||
return [ref, showModal, hideModal] | ||
} |
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 |
---|---|---|
@@ -1,3 +1,8 @@ | ||
h1 { | ||
margin-top: 60px; | ||
} | ||
.modal-body { | ||
:last-child { | ||
margin-bottom: 0; | ||
} | ||
} |
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
64 changes: 64 additions & 0 deletions
64
daiquiri/query/assets/js/query/components/JobAbortModal.js
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 React, { useEffect } from 'react' | ||
import PropTypes from 'prop-types' | ||
|
||
import { useModal } from '../../../../../core/assets/js/hooks/modal' | ||
|
||
import { useAbortJobMutation } from '../hooks/query' | ||
|
||
const JobAbortModal = ({ job, show, toggle }) => { | ||
const [ref, showModal, hideModal] = useModal() | ||
|
||
useEffect(() => { | ||
if (show) { | ||
showModal() | ||
} | ||
}, [show]) | ||
|
||
const mutation = useAbortJobMutation() | ||
|
||
const handleSubmit = () => { | ||
mutation.mutate({job, onSuccess: handleClose}) | ||
} | ||
|
||
const handleClose = () => { | ||
hideModal() | ||
toggle() | ||
} | ||
|
||
return ( | ||
<div ref={ref} className="modal" tabIndex="-1"> | ||
<div className="modal-dialog modal-lg"> | ||
<div className="modal-content"> | ||
<div className="modal-header"> | ||
<h5 className="modal-title">{gettext('Archive job')}</h5> | ||
<button type="button" className="btn-close" onClick={handleClose}></button> | ||
</div> | ||
<div className="modal-body"> | ||
<p dangerouslySetInnerHTML={{ | ||
__html: interpolate(gettext('You are about to abort the job <code>%s</code>.'), [job.id]) | ||
}} /> | ||
<p className="text-danger"> | ||
{gettext('This action cannot be undone!')} | ||
</p> | ||
</div> | ||
<div className="modal-footer"> | ||
<button type="button" className="btn btn-sm btn-secondary" onClick={handleClose}> | ||
{gettext('Close')} | ||
</button> | ||
<button type="button" className="btn btn-sm btn-danger" onClick={handleSubmit}> | ||
{gettext('Abort')} | ||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
JobAbortModal.propTypes = { | ||
job: PropTypes.object.isRequired, | ||
show: PropTypes.bool.isRequired, | ||
toggle: PropTypes.func.isRequired | ||
} | ||
|
||
export default JobAbortModal |
64 changes: 64 additions & 0 deletions
64
daiquiri/query/assets/js/query/components/JobArchiveModal.js
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 React, { useEffect } from 'react' | ||
import PropTypes from 'prop-types' | ||
|
||
import { useModal } from '../../../../../core/assets/js/hooks/modal' | ||
|
||
import { useArchiveJobMutation } from '../hooks/query' | ||
|
||
const JobArchiveModal = ({ job, show, toggle }) => { | ||
const [ref, showModal, hideModal] = useModal() | ||
|
||
useEffect(() => { | ||
if (show) { | ||
showModal() | ||
} | ||
}, [show]) | ||
|
||
const mutation = useArchiveJobMutation() | ||
|
||
const handleSubmit = () => { | ||
mutation.mutate({job, onSuccess: handleClose}) | ||
} | ||
|
||
const handleClose = () => { | ||
hideModal() | ||
toggle() | ||
} | ||
|
||
return ( | ||
<div ref={ref} className="modal" tabIndex="-1"> | ||
<div className="modal-dialog modal-lg"> | ||
<div className="modal-content"> | ||
<div className="modal-header"> | ||
<h5 className="modal-title">{gettext('Archive job')}</h5> | ||
<button type="button" className="btn-close" onClick={handleClose}></button> | ||
</div> | ||
<div className="modal-body"> | ||
<p dangerouslySetInnerHTML={{ | ||
__html: interpolate(gettext('You are about to archive the job <code>%s</code>.'), [job.id]) | ||
}} /> | ||
<p className="text-danger"> | ||
{gettext('This action cannot be undone!')} | ||
</p> | ||
</div> | ||
<div className="modal-footer"> | ||
<button type="button" className="btn btn-sm btn-secondary" onClick={handleClose}> | ||
{gettext('Close')} | ||
</button> | ||
<button type="button" className="btn btn-sm btn-danger" onClick={handleSubmit}> | ||
{gettext('Archive')} | ||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
JobArchiveModal.propTypes = { | ||
job: PropTypes.object.isRequired, | ||
show: PropTypes.bool.isRequired, | ||
toggle: PropTypes.func.isRequired | ||
} | ||
|
||
export default JobArchiveModal |
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,12 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
|
||
const JobDownload = ({ job }) => { | ||
return <pre>Download {job.id}</pre> | ||
} | ||
|
||
JobDownload.propTypes = { | ||
job: PropTypes.object.isRequired | ||
} | ||
|
||
export default JobDownload |
Oops, something went wrong.