Skip to content

feat: Add "Outdated" tooltip and "Update version" button in the Workspaces page #2322

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

Merged
merged 7 commits into from
Jun 15, 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
1 change: 1 addition & 0 deletions site/src/components/GlobalSnackbar/GlobalSnackbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export const GlobalSnackbar: React.FC = () => {

return (
<EnterpriseSnackbar
key={notification.msg}
open={open}
variant={variantFromMsgType(notification.msgType)}
message={
Expand Down
77 changes: 69 additions & 8 deletions site/src/components/HelpTooltip/HelpTooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,58 @@ import Popover from "@material-ui/core/Popover"
import { makeStyles } from "@material-ui/core/styles"
import HelpIcon from "@material-ui/icons/HelpOutline"
import OpenInNewIcon from "@material-ui/icons/OpenInNew"
import { useState } from "react"
import React, { createContext, useContext, useState } from "react"
import { Stack } from "../Stack/Stack"

type Icon = typeof HelpIcon

type Size = "small" | "medium"
export interface HelpTooltipProps {
// Useful to test on storybook
open?: boolean
size?: Size
}

const HelpTooltipContext = createContext<{ open: boolean; onClose: () => void } | undefined>(undefined)

const useHelpTooltip = () => {
const helpTooltipContext = useContext(HelpTooltipContext)

if (!helpTooltipContext) {
throw new Error("This hook should be used in side of the HelpTooltipContext.")
Copy link
Member

Choose a reason for hiding this comment

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

❤️

}

return helpTooltipContext
}

export const HelpTooltip: React.FC<HelpTooltipProps> = ({ children, open, size = "medium" }) => {
const styles = useStyles({ size })
const [anchorEl, setAnchorEl] = useState<HTMLButtonElement | null>(null)
open = open ?? Boolean(anchorEl)
const id = open ? "help-popover" : undefined

const onClose = () => {
setAnchorEl(null)
}
Copy link
Member

Choose a reason for hiding this comment

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

Seems like when I click to escape the tooltip, regardless of where I click, I am automatically routed to the workspace page. Sometimes I just want to close the tooltip without leaving the list. Could we suppress navigation on close?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think it is because you are clicking on a workspace row when you click outside of the tooltip.

Copy link
Member

@Kira-Pilot Kira-Pilot Jun 15, 2022

Choose a reason for hiding this comment

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

It does it even if I click somewhere else on the page. I think it is using the initial click into the tooltip to navigate.


return (
<>
<button aria-describedby={id} className={styles.button} onClick={(event) => setAnchorEl(event.currentTarget)}>
<button
aria-describedby={id}
className={styles.button}
onClick={(event) => {
event.stopPropagation()
setAnchorEl(event.currentTarget)
}}
>
<HelpIcon className={styles.icon} />
</button>
<Popover
classes={{ paper: styles.popoverPaper }}
id={id}
open={open}
anchorEl={anchorEl}
onClose={() => {
setAnchorEl(null)
}}
onClose={onClose}
anchorOrigin={{
vertical: "bottom",
horizontal: "left",
Expand All @@ -41,7 +64,7 @@ export const HelpTooltip: React.FC<HelpTooltipProps> = ({ children, open, size =
horizontal: "left",
}}
>
{children}
<HelpTooltipContext.Provider value={{ open, onClose }}>{children}</HelpTooltipContext.Provider>
</Popover>
</>
)
Expand Down Expand Up @@ -70,6 +93,25 @@ export const HelpTooltipLink: React.FC<{ href: string }> = ({ children, href })
)
}

export const HelpTooltipAction: React.FC<{ icon: Icon; onClick: () => void }> = ({ children, icon: Icon, onClick }) => {
const styles = useStyles()
const tooltip = useHelpTooltip()

return (
<button
className={styles.action}
onClick={(event) => {
event.stopPropagation()
onClick()
tooltip.onClose()
}}
>
<Icon className={styles.actionIcon} />
{children}
</button>
)
}

export const HelpTooltipLinksGroup: React.FC = ({ children }) => {
const styles = useStyles()

Expand Down Expand Up @@ -110,11 +152,12 @@ const useStyles = makeStyles((theme) => ({
padding: 0,
border: 0,
background: "transparent",
color: theme.palette.text.secondary,
color: theme.palette.text.primary,
opacity: 0.5,
cursor: "pointer",

"&:hover": {
color: theme.palette.text.primary,
opacity: 0.75,
},
},

Expand Down Expand Up @@ -156,4 +199,22 @@ const useStyles = makeStyles((theme) => ({
linksGroup: {
marginTop: theme.spacing(2),
},

action: {
display: "flex",
alignItems: "center",
background: "none",
border: 0,
color: theme.palette.primary.light,
padding: 0,
cursor: "pointer",
fontSize: 14,
},

actionIcon: {
color: "inherit",
width: 14,
height: 14,
marginRight: theme.spacing(1),
},
}))
5 changes: 3 additions & 2 deletions site/src/pages/WorkspacesPage/WorkspacesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ import { WorkspacesPageView } from "./WorkspacesPageView"
const WorkspacesPage: FC = () => {
const [workspacesState, send] = useMachine(workspacesMachine)
const [searchParams, setSearchParams] = useSearchParams()
const { workspaceRefs } = workspacesState.context

useEffect(() => {
const filter = searchParams.get("filter")
const query = filter !== null ? filter : workspaceFilterQuery.me

send({
type: "SET_FILTER",
type: "GET_WORKSPACES",
query,
})
}, [searchParams, send])
Expand All @@ -30,7 +31,7 @@ const WorkspacesPage: FC = () => {
<WorkspacesPageView
filter={workspacesState.context.filter}
loading={workspacesState.hasTag("loading")}
workspaces={workspacesState.context.workspaces}
workspaceRefs={workspaceRefs}
onFilter={(query) => {
searchParams.set("filter", query)
setSearchParams(searchParams)
Expand Down
19 changes: 15 additions & 4 deletions site/src/pages/WorkspacesPage/WorkspacesPageView.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { ComponentMeta, Story } from "@storybook/react"
import { spawn } from "xstate"
import { ProvisionerJobStatus, Workspace, WorkspaceTransition } from "../../api/typesGenerated"
import { MockWorkspace } from "../../testHelpers/entities"
import { workspaceFilterQuery } from "../../util/workspace"
import { workspaceItemMachine } from "../../xServices/workspaces/workspacesXService"
import { WorkspacesPageView, WorkspacesPageViewProps } from "./WorkspacesPageView"

export default {
Expand All @@ -14,9 +16,11 @@ const Template: Story<WorkspacesPageViewProps> = (args) => <WorkspacesPageView {
const createWorkspaceWithStatus = (
status: ProvisionerJobStatus,
transition: WorkspaceTransition = "start",
outdated = false,
): Workspace => {
return {
...MockWorkspace,
outdated,
latest_build: {
...MockWorkspace.latest_build,
transition,
Expand All @@ -41,22 +45,29 @@ const workspaces: { [key in ProvisionerJobStatus]: Workspace } = {

export const AllStates = Template.bind({})
AllStates.args = {
workspaces: [
workspaceRefs: [
...Object.values(workspaces),
createWorkspaceWithStatus("running", "stop"),
createWorkspaceWithStatus("succeeded", "stop"),
createWorkspaceWithStatus("running", "delete"),
],
].map((data) => spawn(workspaceItemMachine.withContext({ data }))),
}

export const Outdated = Template.bind({})
Outdated.args = {
workspaceRefs: [createWorkspaceWithStatus("running", "stop", true)].map((data) =>
spawn(workspaceItemMachine.withContext({ data })),
),
}

export const OwnerHasNoWorkspaces = Template.bind({})
OwnerHasNoWorkspaces.args = {
workspaces: [],
workspaceRefs: [],
filter: workspaceFilterQuery.me,
}

export const NoResults = Template.bind({})
NoResults.args = {
workspaces: [],
workspaceRefs: [],
filter: "searchtearmwithnoresults",
}
Loading