-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding Confirm Modal and Cancel Job Utility (#347)
* Added confirm modal * Added cancel job utility * Fixed bug that led to web crash from bad URL job UUID req * Changed error message * Ran prettier and linting * Switched confirm button to be on the left of cancel button in the ConfirmModal
- Loading branch information
Showing
16 changed files
with
276 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,18 @@ | ||
import { Jobs } from '@tapis/tapis-typescript'; | ||
import { apiGenerator, errorDecoder } from 'tapis-api/utils'; | ||
|
||
export const cancel = ( | ||
jobCancelReq: Jobs.CancelJobRequest, | ||
basePath: string, | ||
jwt: string | ||
) => { | ||
const api: Jobs.JobsApi = apiGenerator<Jobs.JobsApi>( | ||
Jobs, | ||
Jobs.JobsApi, | ||
basePath, | ||
jwt | ||
); | ||
return errorDecoder<Jobs.RespCancelJob>(() => api.cancelJob(jobCancelReq)); | ||
}; | ||
|
||
export default cancel; |
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,4 @@ | ||
export { default as list } from './list'; | ||
export { default as details } from './details'; | ||
export { default as submit } from './submit'; | ||
export { default as cancel } from './cancel'; |
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
20 changes: 20 additions & 0 deletions
20
src/tapis-app/Jobs/_components/JobsToolbar/JobsToolbar.module.scss
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,20 @@ | ||
.toolbar-wrapper { | ||
padding: 0; | ||
margin: 0; | ||
margin-top: 0.5em; | ||
display: flex !important; | ||
} | ||
|
||
.toolbar-btn { | ||
height: 2rem; | ||
align-items: center; | ||
margin-left: 0.5em; | ||
font-size: 0.7em !important; | ||
border-radius: 0 !important; | ||
background-color: #f4f4f4 !important; | ||
color: #333333 !important; | ||
} | ||
|
||
.toolbar-btn:disabled { | ||
color: #999999 !important; | ||
} |
83 changes: 83 additions & 0 deletions
83
src/tapis-app/Jobs/_components/JobsToolbar/JobsToolbar.tsx
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,83 @@ | ||
import React, { useState } from 'react'; | ||
import { Button } from 'reactstrap'; | ||
import { Icon } from 'tapis-ui/_common'; | ||
import styles from './JobsToolbar.module.scss'; | ||
import { useLocation } from 'react-router-dom'; | ||
import ConfirmModal from 'tapis-ui/_common/ConfirmModal'; | ||
import { useCancel } from 'tapis-hooks/jobs'; | ||
|
||
type ToolbarButtonProps = { | ||
text: string; | ||
icon: string; | ||
onClick: () => void; | ||
disabled: boolean; | ||
}; | ||
|
||
export type ToolbarModalProps = { | ||
toggle: () => void; | ||
}; | ||
|
||
export const ToolbarButton: React.FC<ToolbarButtonProps> = ({ | ||
text, | ||
icon, | ||
onClick, | ||
disabled = true, | ||
...rest | ||
}) => { | ||
return ( | ||
<div> | ||
<Button | ||
disabled={disabled} | ||
onClick={onClick} | ||
className={styles['toolbar-btn']} | ||
{...rest} | ||
> | ||
<Icon name={icon}></Icon> | ||
<span> {text}</span> | ||
</Button> | ||
</div> | ||
); | ||
}; | ||
|
||
const JobsToolbar: React.FC<{ jobUuid: string }> = ({ jobUuid }) => { | ||
const [modal, setModal] = useState<string | undefined>(undefined); | ||
const { pathname } = useLocation(); | ||
const { isLoading, isError, isSuccess, error, cancel } = useCancel(); | ||
|
||
const toggle = () => { | ||
setModal(undefined); | ||
}; | ||
|
||
return ( | ||
<div id="file-operation-toolbar"> | ||
{pathname && ( | ||
<div className={styles['toolbar-wrapper']}> | ||
<ToolbarButton | ||
text="Cancel Job" | ||
icon="trash" | ||
disabled={false} | ||
onClick={() => setModal('ConfirmModal')} | ||
aria-label="createSystem" | ||
/> | ||
|
||
{modal === 'ConfirmModal' && ( | ||
<ConfirmModal | ||
toggle={toggle} | ||
onConfirm={() => { | ||
cancel({ jobUuid }); | ||
}} | ||
isLoading={isLoading} | ||
isError={isError} | ||
isSuccess={isSuccess} | ||
error={error} | ||
/> | ||
)} | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default JobsToolbar; | ||
|
||
// JobUuid = pathname.split("/")[2] |
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,3 @@ | ||
import JobsToolbar from './JobsToolbar'; | ||
|
||
export default JobsToolbar; |
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 +1,2 @@ | ||
export { default as JobsNav } from './JobsNav'; | ||
export { default as JobsToolbar } from './JobsToolbar'; |
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,4 @@ | ||
export { default as useList } from './useList'; | ||
export { default as useDetails } from './useDetails'; | ||
export { default as useSubmit } from './useSubmit'; | ||
export { default as useCancel } from './useCancel'; |
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,52 @@ | ||
import { useMutation, MutateOptions } from 'react-query'; | ||
import { Jobs } from '@tapis/tapis-typescript'; | ||
import { cancel } from 'tapis-api/jobs'; | ||
import { useTapisConfig } from 'tapis-hooks'; | ||
import QueryKeys from './queryKeys'; | ||
|
||
const useCancel = () => { | ||
const { basePath, accessToken } = useTapisConfig(); | ||
const jwt = accessToken?.access_token || ''; | ||
|
||
// The useMutation react-query hook is used to call operations that make server-side changes | ||
// (Other hooks would be used for data retrieval) | ||
// | ||
// In this case, move helper is called to perform the operation | ||
const { | ||
mutate, | ||
mutateAsync, | ||
isLoading, | ||
isError, | ||
isSuccess, | ||
data, | ||
error, | ||
reset, | ||
} = useMutation<Jobs.RespCancelJob, Error, Jobs.CancelJobRequest>( | ||
[QueryKeys.cancel, basePath, jwt], | ||
(jobCancelReq) => cancel(jobCancelReq, basePath, jwt) | ||
); | ||
|
||
// Return hook object with loading states and login function | ||
return { | ||
isLoading, | ||
isError, | ||
isSuccess, | ||
data, | ||
error, | ||
reset, | ||
cancel: ( | ||
jobCancelReq: Jobs.CancelJobRequest, | ||
// react-query options to allow callbacks such as onSuccess | ||
options?: MutateOptions<Jobs.RespCancelJob, Error, Jobs.CancelJobRequest> | ||
) => { | ||
// Call mutate to trigger a single post-like API operation | ||
return mutate(jobCancelReq, options); | ||
}, | ||
cancelAsync: ( | ||
jobCancelReq: Jobs.CancelJobRequest, | ||
options?: MutateOptions<Jobs.RespCancelJob, Error, Jobs.CancelJobRequest> | ||
) => mutateAsync(jobCancelReq, options), | ||
}; | ||
}; | ||
|
||
export default useCancel; |
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,62 @@ | ||
import React from 'react'; | ||
import { Button } from 'reactstrap'; | ||
import { GenericModal } from 'tapis-ui/_common'; | ||
import { SubmitWrapper } from 'tapis-ui/_wrappers'; | ||
|
||
type ConfirmModalProps = { | ||
toggle: () => void; | ||
message?: string; | ||
onConfirm: () => void; | ||
isLoading: boolean; | ||
isSuccess: boolean; | ||
isError: boolean; | ||
error: Error | null; | ||
}; | ||
|
||
const ConfirmModal: React.FC<ConfirmModalProps> = ({ | ||
toggle, | ||
message, | ||
onConfirm, | ||
isLoading, | ||
isSuccess, | ||
isError, | ||
error, | ||
}) => { | ||
return ( | ||
<GenericModal | ||
toggle={toggle} | ||
title="Confirm" | ||
body={message || 'Are you sure you want to continue?'} | ||
footer={ | ||
<SubmitWrapper | ||
className={''} | ||
isLoading={isLoading} | ||
error={error} | ||
success={isSuccess ? `Success` : ''} | ||
reverse={true} | ||
> | ||
<Button | ||
form="newsystem-form" | ||
color="primary" | ||
aria-label="Submit" | ||
type="submit" | ||
onClick={toggle} | ||
> | ||
Cancel | ||
</Button> | ||
<Button | ||
form="newsystem-form" | ||
color="primary" | ||
aria-label="Submit" | ||
type="submit" | ||
onClick={onConfirm} | ||
> | ||
Confirm | ||
</Button> | ||
</SubmitWrapper> | ||
} | ||
/> | ||
); | ||
}; | ||
|
||
export default ConfirmModal; |
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,3 @@ | ||
import ConfirmModal from './ConfirmModal'; | ||
|
||
export default ConfirmModal; |
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