-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add duplicate chart button * Add confirm modal for delete chart and delete dashboard actions `docker compose -f docker-compose.dev.yml up -d --no-deps --build app` after pulling this branch https://github.com/hyperdxio/hyperdx/assets/149748269/68f8facc-9d8f-4ebf-9dc2-937d65dbc89f
- Loading branch information
1 parent
283f32a
commit fe41b15
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