-
Notifications
You must be signed in to change notification settings - Fork 197
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
283f32a
commit a767ad9
Showing
6 changed files
with
130 additions
and
7 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,5 @@ | ||
--- | ||
'@hyperdx/app': minor | ||
--- | ||
|
||
feat: Add dashboard delete confirmations and duplicate chart button |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import * as React from 'react'; | ||
import { atom, useAtomValue, useSetAtom } from 'jotai'; | ||
import Modal from 'react-bootstrap/Modal'; | ||
import Button from 'react-bootstrap/Button'; | ||
|
||
type ConfirmAtom = { | ||
message: string; | ||
confirmLabel?: string; | ||
onConfirm: () => void; | ||
onClose?: () => void; | ||
} | null; | ||
|
||
const confirmAtom = atom<ConfirmAtom>(null); | ||
|
||
export const useConfirm = () => { | ||
const setConfirm = useSetAtom(confirmAtom); | ||
|
||
return React.useCallback( | ||
async (message: string, confirmLabel?: string): Promise<boolean> => { | ||
return new Promise(resolve => { | ||
setConfirm({ | ||
message, | ||
confirmLabel, | ||
onConfirm: () => { | ||
resolve(true); | ||
setConfirm(null); | ||
}, | ||
onClose: () => { | ||
resolve(false); | ||
setConfirm(null); | ||
}, | ||
}); | ||
}); | ||
}, | ||
[setConfirm], | ||
); | ||
}; | ||
|
||
export const useConfirmModal = () => { | ||
const confirm = useAtomValue(confirmAtom); | ||
const setConfirm = useSetAtom(confirmAtom); | ||
|
||
const handleClose = React.useCallback(() => { | ||
confirm?.onClose?.(); | ||
setConfirm(null); | ||
}, [confirm, setConfirm]); | ||
|
||
return confirm ? ( | ||
<Modal show onHide={handleClose}> | ||
<Modal.Body className="bg-hdx-dark"> | ||
{confirm.message} | ||
<div className="mt-3 d-flex justify-content-end gap-2"> | ||
<Button variant="secondary" onClick={handleClose} size="sm"> | ||
Cancel | ||
</Button> | ||
<Button variant="success" onClick={confirm.onConfirm} size="sm"> | ||
{confirm.confirmLabel || 'OK'} | ||
</Button> | ||
</div> | ||
</Modal.Body> | ||
</Modal> | ||
) : null; | ||
}; |
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