-
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.
Merge pull request #1213 from Chia-Network/refactor/staging-table-act…
…ions Refactor/staging table actions
- Loading branch information
Showing
17 changed files
with
209 additions
and
44 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
47 changes: 47 additions & 0 deletions
47
src/renderer/components/blocks/modals/ConfirmDeleteStagedItemModal.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,47 @@ | ||
import React from 'react'; | ||
import { Button, Modal } from '@/components'; | ||
import { FormattedMessage } from 'react-intl'; | ||
import { useDeleteStagedItemMutation } from '@/api/cadt/v1/staging'; | ||
|
||
interface ConfirmDeleteModalProps { | ||
uuid: string; | ||
onClose: () => void; | ||
} | ||
|
||
const ConfirmDeleteStagedItemModal: React.FC<ConfirmDeleteModalProps> = ({ | ||
uuid, | ||
onClose, | ||
}: ConfirmDeleteModalProps) => { | ||
const [triggerDeleteStagedItem, { isLoading: stagedItemDeletionLoading }] = useDeleteStagedItemMutation(); | ||
const handleConfirm = async () => { | ||
await triggerDeleteStagedItem({ uuid }); | ||
onClose(); | ||
}; | ||
|
||
const handleClickClose = async () => { | ||
onClose(); | ||
}; | ||
|
||
return ( | ||
<Modal show={true} onClose={onClose}> | ||
<Modal.Header> | ||
<FormattedMessage id="confirm-delete" /> | ||
</Modal.Header> | ||
<Modal.Body> | ||
<p> | ||
<FormattedMessage id="deleting-a-staged-item-is-a-permanent-action" />. | ||
</p> | ||
</Modal.Body> | ||
<Modal.Footer> | ||
<Button color="gray" onClick={handleClickClose} disabled={stagedItemDeletionLoading}> | ||
<FormattedMessage id="cancel" /> | ||
</Button> | ||
<Button onClick={handleConfirm} isProcessing={stagedItemDeletionLoading} disabled={stagedItemDeletionLoading}> | ||
<FormattedMessage id="delete" /> | ||
</Button> | ||
</Modal.Footer> | ||
</Modal> | ||
); | ||
}; | ||
|
||
export { ConfirmDeleteStagedItemModal }; |
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
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
72 changes: 72 additions & 0 deletions
72
src/renderer/components/blocks/widgets/StagedItemActions.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,72 @@ | ||
import React, { useState } from 'react'; | ||
import { HiDotsVertical } from 'react-icons/hi'; | ||
import { Button, ConfirmDeleteStagedItemModal, Tooltip } from '@/components'; | ||
import { useWildCardUrlHash } from '@/hooks'; | ||
import { FormattedMessage } from 'react-intl'; | ||
|
||
interface ActionsProps { | ||
type: 'staged' | 'pending' | 'failed'; | ||
stagedItem: any; | ||
} | ||
|
||
const StagedItemActions: React.FC<ActionsProps> = ({ type, stagedItem }: ActionsProps) => { | ||
const [, , setEditProjectModalActive] = useWildCardUrlHash('edit-project'); | ||
const [, , setEditUnitModalActive] = useWildCardUrlHash('edit-unit'); | ||
const [showDeleteModal, setShowDeleteModal] = useState<boolean>(false); | ||
|
||
const handleClickDelete = () => { | ||
setShowDeleteModal(true); | ||
}; | ||
|
||
const handleClickEdit = () => { | ||
if (stagedItem?.table === 'Projects') { | ||
setEditProjectModalActive(true, ''); //todo: need a way to get staged data into form without using warehouseId | ||
} else { | ||
setEditUnitModalActive(true, ''); //todo: need a way to get staged data into form without using warehouseId | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
{type !== 'pending' && ( | ||
<Tooltip | ||
style="light" | ||
trigger="click" | ||
placement="right" | ||
content={ | ||
<> | ||
<Button onClick={handleClickDelete} outline> | ||
<FormattedMessage id="delete" /> | ||
</Button> | ||
{/*todo: delete the above button and encasing fragment and make this div | ||
visible when a solution to editing a staged item is complete */} | ||
<div className="hidden"> | ||
{stagedItem?.action === 'DELETE' || type === 'failed' ? ( | ||
<Button onClick={handleClickDelete} outline> | ||
<FormattedMessage id="delete" /> | ||
</Button> | ||
) : ( | ||
<Button.Group> | ||
<Button onClick={handleClickEdit} outline> | ||
<FormattedMessage id="edit" /> | ||
</Button> | ||
<Button onClick={handleClickDelete} outline> | ||
<FormattedMessage id="delete" /> | ||
</Button> | ||
</Button.Group> | ||
)} | ||
</div> | ||
</> | ||
} | ||
> | ||
<HiDotsVertical size="25" /> | ||
</Tooltip> | ||
)} | ||
{showDeleteModal && stagedItem?.uuid && ( | ||
<ConfirmDeleteStagedItemModal uuid={stagedItem.uuid} onClose={() => setShowDeleteModal(false)} /> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
export { StagedItemActions }; |
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
Oops, something went wrong.