Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a tooltip w/ full expiration date #15253

Merged
merged 3 commits into from
Dec 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions components/dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
"react-datepicker": "^4.8.0",
"react-dom": "^17.0.1",
"react-intl-tel-input": "^8.2.0",
"react-popper": "^2.3.0",
"react-portal": "^4.2.2",
"react-router-dom": "^5.2.0",
"xterm": "^4.11.0",
"xterm-addon-fit": "^0.5.0"
Expand All @@ -38,6 +40,7 @@
"@types/node": "^16.11.0",
"@types/react": "^17.0.0",
"@types/react-dom": "^17.0.3",
"@types/react-portal": "^4.0.4",
"@types/react-router": "^5.1.13",
"@types/react-router-dom": "^5.1.7",
"@types/uuid": "^8.3.1",
Expand Down
28 changes: 23 additions & 5 deletions components/dashboard/src/components/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,48 @@
* See License-AGPL.txt in the project root for license information.
*/

import { useState } from "react";
import { ReactNode, useEffect, useState } from "react";
import { Portal } from "react-portal";
import { usePopper } from "react-popper";

export interface TooltipProps {
children: React.ReactChild[] | React.ReactChild;
children: ReactNode;
content: string;
allowWrap?: boolean;
}

function Tooltip(props: TooltipProps) {
const [expanded, setExpanded] = useState(false);
const [triggerEl, setTriggerEl] = useState<HTMLElement | null>(null);
const [tooltipEl, setTooltipEl] = useState<HTMLElement | null>(null);

// this calculates the positioning for our tooltip
const { styles, attributes, update } = usePopper(triggerEl, tooltipEl, {
placement: "top",
});

// If the tooltip contents change, force a recalc on positioning
useEffect(() => {
update && update();
}, [update, props.content]);

return (
<div onMouseLeave={() => setExpanded(false)} onMouseEnter={() => setExpanded(true)} className="relative">
<div>{props.children}</div>
<div ref={setTriggerEl}>{props.children}</div>
{expanded ? (
<Portal>
<div
style={{ top: "-0.5rem", left: "50%", transform: "translate(-50%, -100%)" }}
ref={setTooltipEl}
style={styles.popper}
className={
`max-w-md mt-2 z-50 py-1 px-2 bg-gray-900 text-gray-100 text-sm absolute flex flex-col border border-gray-200 dark:border-gray-800 rounded-md truncated ` +
`max-w-md z-50 py-1 px-2 bg-gray-900 text-gray-100 text-sm absolute flex flex-col border border-gray-200 dark:border-gray-800 rounded-md truncated ` +
(props.allowWrap ? "whitespace-normal" : "whitespace-nowrap")
}
{...attributes.popper}
>
{props.content}
</div>
</Portal>
) : null}
</div>
);
Expand Down
10 changes: 7 additions & 3 deletions components/dashboard/src/settings/TokenEntry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { PersonalAccessToken } from "@gitpod/public-api/lib/gitpod/experimental/
import dayjs from "dayjs";
import { ContextMenuEntry } from "../components/ContextMenu";
import { ItemFieldContextMenu } from "../components/ItemsList";
import Tooltip from "../components/Tooltip";
import { ReactComponent as ExclamationIcon } from "../images/exclamation.svg";
import { AllPermissions } from "./PersonalAccessTokens";

Expand All @@ -19,6 +20,7 @@ interface TokenEntryProps {
function TokenEntry(props: TokenEntryProps) {
const expirationDay = dayjs(props.token.expirationTime!.toDate());
const expired = expirationDay.isBefore(dayjs());
const expirationDateString = expirationDay.format("MMM D, YYYY, hh:mm A");

const getScopes = () => {
if (!props.token.scopes) {
Expand All @@ -33,7 +35,6 @@ function TokenEntry(props: TokenEntryProps) {
};

return (
<>
<div className="rounded-xl whitespace-nowrap flex space-x-2 py-4 px-4 w-full justify-between hover:bg-gray-100 dark:hover:bg-gray-800 focus:bg-gitpod-kumquat-light group">
<div className="flex items-center pr-3 w-4/12">
<span className="truncate">{props.token.name || ""}</span>
Expand All @@ -44,14 +45,17 @@ function TokenEntry(props: TokenEntryProps) {
<div className="flex items-center w-3/12 text-gray-400">
<span className={"flex items-center gap-1 truncate" + (expired ? " text-orange-600" : "")}>
<span>{expirationDay.format("MMM D, YYYY")}</span>
{expired && <ExclamationIcon fill="#D97706" className="h-4 w-4" />}
{expired && (
<Tooltip content={expirationDateString}>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only real change in this block, but I removed the unnecessary fragment wrapper (<></>).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, thanks for the pointer! 👍 (FYI, to review changes with big indentation changes, I like to ignore whitespaces by appending ?w=1 at the end of the diff URL -- for example https://github.com/gitpod-io/gitpod/pull/15253/files?w=1 )

<ExclamationIcon fill="#D97706" className="h-4 w-4" />
</Tooltip>
)}
</span>
</div>
<div className="flex items-center justify-end w-1/12">
<ItemFieldContextMenu menuEntries={props.menuEntries} />
</div>
</div>
</>
);
}

Expand Down
18 changes: 16 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3188,6 +3188,13 @@
dependencies:
"@types/react" "*"

"@types/react-portal@^4.0.4":
version "4.0.4"
resolved "https://registry.yarnpkg.com/@types/react-portal/-/react-portal-4.0.4.tgz#1c0e5a248f6e18a66f981139c13b6e796f4a92b6"
integrity sha512-ecVWngYHeSymq5XdrQOXRpIb9ay5SM4Stm/ur6+wc0Z+r05gafZ5SuMRbXKYsj4exNJa+4CTKK6J7qcTKm9K5g==
dependencies:
"@types/react" "*"

"@types/react-router-dom@^5.1.7":
version "5.3.2"
resolved "https://registry.npmjs.org/@types/react-router-dom/-/react-router-dom-5.3.2.tgz"
Expand Down Expand Up @@ -14572,7 +14579,7 @@ prompts@^2.0.1:
kleur "^3.0.3"
sisteransi "^1.0.5"

prop-types@^15.5.4, prop-types@^15.6.1:
prop-types@^15.5.4, prop-types@^15.5.8, prop-types@^15.6.1:
version "15.8.1"
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.8.1.tgz#67d87bf1a694f48435cf332c24af10214a3140b5"
integrity sha512-oj87CgZICdulUohogVAR7AjlC0327U4el4L6eAvOqCeudMDVU0NThNaV+b9Df4dXgSP1gXMTnPdhfe/2qDH5cg==
Expand Down Expand Up @@ -15039,14 +15046,21 @@ react-onclickoutside@^6.12.0:
resolved "https://registry.yarnpkg.com/react-onclickoutside/-/react-onclickoutside-6.12.2.tgz#8e6cf80c7d17a79f2c908399918158a7b02dda01"
integrity sha512-NMXGa223OnsrGVp5dJHkuKxQ4czdLmXSp5jSV9OqiCky9LOpPATn3vLldc+q5fK3gKbEHvr7J1u0yhBh/xYkpA==

react-popper@^2.2.5:
react-popper@^2.2.5, react-popper@^2.3.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/react-popper/-/react-popper-2.3.0.tgz#17891c620e1320dce318bad9fede46a5f71c70ba"
integrity sha512-e1hj8lL3uM+sgSR4Lxzn5h1GxBlpa4CQz0XLF8kx4MDrDRWY0Ena4c97PUeSX9i5W3UAfDP0z0FXCTQkoXUl3Q==
dependencies:
react-fast-compare "^3.0.1"
warning "^4.0.2"

react-portal@^4.2.2:
version "4.2.2"
resolved "https://registry.yarnpkg.com/react-portal/-/react-portal-4.2.2.tgz#bff1e024147d6041ba8c530ffc99d4c8248f49fa"
integrity sha512-vS18idTmevQxyQpnde0Td6ZcUlv+pD8GTyR42n3CHUQq9OHi1C4jDE4ZWEbEsrbrLRhSECYiao58cvocwMtP7Q==
dependencies:
prop-types "^15.5.8"

react-refresh@^0.8.3:
version "0.8.3"
resolved "https://registry.npmjs.org/react-refresh/-/react-refresh-0.8.3.tgz"
Expand Down