-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Noble Mittal <[email protected]>
- Loading branch information
1 parent
c74db2b
commit ff6ac08
Showing
7 changed files
with
224 additions
and
3 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
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
87 changes: 87 additions & 0 deletions
87
web/vtadmin/src/components/routes/transactions/TransactionAction.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,87 @@ | ||
import React from 'react'; | ||
import { Icon, Icons } from '../../Icon'; | ||
import Dialog from '../../dialog/Dialog'; | ||
import { UseMutationResult } from 'react-query'; | ||
|
||
interface TransactionActionProps { | ||
isOpen: boolean; | ||
mutation: UseMutationResult<any, any, any>; | ||
title: string; | ||
confirmText: string; | ||
successText: string; | ||
errorText: string; | ||
loadingText: string; | ||
description?: string; | ||
body?: JSX.Element; | ||
refetchTransactions: Function; | ||
closeDialog: () => void; | ||
} | ||
|
||
const TransactionAction: React.FC<TransactionActionProps> = ({ | ||
isOpen, | ||
closeDialog, | ||
mutation, | ||
title, | ||
confirmText, | ||
description, | ||
successText, | ||
loadingText, | ||
errorText, | ||
refetchTransactions, | ||
body, | ||
}) => { | ||
const onCloseDialog = () => { | ||
setTimeout(mutation.reset, 500); | ||
closeDialog(); | ||
}; | ||
|
||
const hasRun = mutation.data || mutation.error; | ||
const onConfirm = () => { | ||
mutation.mutate( | ||
{}, | ||
{ | ||
onSuccess: () => { | ||
refetchTransactions(); | ||
}, | ||
} | ||
); | ||
}; | ||
return ( | ||
<Dialog | ||
isOpen={isOpen} | ||
confirmText={hasRun ? 'Close' : confirmText} | ||
cancelText="Cancel" | ||
onConfirm={hasRun ? onCloseDialog : onConfirm} | ||
loadingText={loadingText} | ||
loading={mutation.isLoading} | ||
onCancel={onCloseDialog} | ||
onClose={onCloseDialog} | ||
hideCancel={hasRun} | ||
title={hasRun ? undefined : title} | ||
description={hasRun ? undefined : description} | ||
> | ||
<div className="w-full"> | ||
{!hasRun && body} | ||
{mutation.data && !mutation.error && ( | ||
<div className="w-full flex flex-col justify-center items-center"> | ||
<span className="flex h-12 w-12 relative items-center justify-center"> | ||
<Icon className="fill-current text-green-500" icon={Icons.checkSuccess} /> | ||
</span> | ||
<div className="text-lg mt-3 font-bold text-center">{successText}</div> | ||
</div> | ||
)} | ||
{mutation.error && ( | ||
<div className="w-full flex flex-col justify-center items-center"> | ||
<span className="flex h-12 w-12 relative items-center justify-center"> | ||
<Icon className="fill-current text-red-500" icon={Icons.alertFail} /> | ||
</span> | ||
<div className="text-lg mt-3 font-bold text-center">{errorText}</div> | ||
<div className="text-sm">{mutation.error.message}</div> | ||
</div> | ||
)} | ||
</div> | ||
</Dialog> | ||
); | ||
}; | ||
|
||
export default TransactionAction; |
45 changes: 45 additions & 0 deletions
45
web/vtadmin/src/components/routes/transactions/TransactionActions.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,45 @@ | ||
import React, { useState } from 'react'; | ||
import Dropdown from '../../dropdown/Dropdown'; | ||
import MenuItem from '../../dropdown/MenuItem'; | ||
import { Icons } from '../../Icon'; | ||
import TransactionAction from './TransactionAction'; | ||
import { useConcludeTransaction } from '../../../hooks/api'; | ||
|
||
interface TransactionActionsProps { | ||
refetchTransactions: Function; | ||
clusterID: string; | ||
dtid: string; | ||
} | ||
|
||
const TransactionActions: React.FC<TransactionActionsProps> = ({ refetchTransactions, clusterID, dtid }) => { | ||
const [currentDialog, setCurrentDialog] = useState<string>(''); | ||
const closeDialog = () => setCurrentDialog(''); | ||
|
||
const concludeTransactionMutation = useConcludeTransaction({ clusterID, dtid }); | ||
|
||
return ( | ||
<div className="w-min inline-block"> | ||
<Dropdown dropdownButton={Icons.info}> | ||
<MenuItem onClick={() => setCurrentDialog('Conclude Transaction')}>Conclude Transaction</MenuItem> | ||
</Dropdown> | ||
<TransactionAction | ||
title="Conclude Transaction" | ||
confirmText="Conclude" | ||
loadingText="Concluding" | ||
mutation={concludeTransactionMutation} | ||
successText="Concluded transaction" | ||
errorText={`Error occured while concluding the transaction (ID: ${dtid})`} | ||
closeDialog={closeDialog} | ||
isOpen={currentDialog === 'Conclude Transaction'} | ||
refetchTransactions={refetchTransactions} | ||
body={ | ||
<div className="text-sm mt-3"> | ||
Conclude the transaction with id: <span className="font-mono bg-gray-300">{dtid}</span>. | ||
</div> | ||
} | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
export default TransactionActions; |
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