From 9b9dde0ae9ae511fdc14b5616095e180891fbe23 Mon Sep 17 00:00:00 2001 From: Sam Chau Date: Wed, 15 Jan 2025 09:01:07 +1030 Subject: [PATCH] feat: implement PushButton component with tooltip for unpushed files in OutgoingChanges --- .../settings/git/status/OutgoingChanges.jsx | 84 ++++++++++++------- 1 file changed, 56 insertions(+), 28 deletions(-) diff --git a/frontend/src/components/settings/git/status/OutgoingChanges.jsx b/frontend/src/components/settings/git/status/OutgoingChanges.jsx index 6d05e6d..3be0ee8 100644 --- a/frontend/src/components/settings/git/status/OutgoingChanges.jsx +++ b/frontend/src/components/settings/git/status/OutgoingChanges.jsx @@ -1,4 +1,5 @@ -import React from 'react'; +import React, {useRef, useState, useEffect} from 'react'; +import ReactDOM from 'react-dom'; import { ArrowUpFromLine, Plus, @@ -38,6 +39,56 @@ const OutgoingChanges = ({ const totalOutgoingChanges = changes.length; const totalUnpushedCommits = unpushedFiles?.length || 0; + const PushButton = () => { + const [showTooltip, setShowTooltip] = useState(false); + const buttonRef = useRef(null); + + return ( + <> +
setShowTooltip(true)} + onMouseLeave={() => setShowTooltip(false)}> + } + className='bg-gray-700' + /> +
+ {showTooltip && + buttonRef.current && + ReactDOM.createPortal( +
+ {unpushedFiles?.length > 0 && ( +
+ {unpushedFiles.map((file, index) => ( +
+ • {file.type}: {file.name} +
+ ))} +
+ )} +
, + document.body + )} + + ); + }; // If we only have committed changes waiting to be pushed if (totalOutgoingChanges === 0 && hasUnpushedCommits) { console.log('Unpushed Files:', unpushedFiles); @@ -52,6 +103,9 @@ const OutgoingChanges = ({ /> Ready to Push ({totalUnpushedCommits}) +
+ +
@@ -113,33 +167,7 @@ const OutgoingChanges = ({ className='bg-gray-700' disabledTooltip={getButtonTooltips.revert()} /> - {hasUnpushedCommits && ( - } - tooltip={ -
-
Push Changes
- {unpushedFiles?.length > 0 && ( -
- {unpushedFiles.map( - (file, index) => ( -
- • {file.type}:{' '} - {file.name} -
- ) - )} -
- )} -
- } - className='bg-gray-700' - disabledTooltip='No changes to push' - /> - )} +
{changes.length > 0 && (