-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(graph): add task graph tooltips (nrwl#13262)
- Loading branch information
1 parent
5045206
commit ec85e1b
Showing
18 changed files
with
247 additions
and
82 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 |
---|---|---|
@@ -1,19 +1,24 @@ | ||
import '../src/styles.scss'; | ||
|
||
import React from 'react'; | ||
import { MemoryRouter } from 'react-router-dom'; | ||
|
||
export const decorators = [ | ||
(Story, context) => { | ||
return ( | ||
<div className="bg-white text-slate-500 dark:bg-slate-900 dark:text-slate-400"> | ||
{context.title.startsWith('Project Graph') ? ( | ||
<div className="flex justify-center"> | ||
<div className="relative flex h-full w-72 flex-col overflow-y-scroll pb-10 shadow-lg ring-1 ring-slate-900/10 ring-opacity-10 transition-all dark:ring-slate-300/10"> | ||
<Story /> | ||
<MemoryRouter initialEntries={['/']}> | ||
<div className="bg-white text-slate-500 dark:bg-slate-900 dark:text-slate-400"> | ||
{context.title.startsWith('Project Graph') ? ( | ||
<div className="flex justify-center"> | ||
<div className="relative flex h-full w-72 flex-col overflow-y-scroll pb-10 shadow-lg ring-1 ring-slate-900/10 ring-opacity-10 transition-all dark:ring-slate-300/10"> | ||
<Story /> | ||
</div> | ||
</div> | ||
</div> | ||
) : ( | ||
<Story /> | ||
)} | ||
</div> | ||
) : ( | ||
<Story /> | ||
)} | ||
</div> | ||
</MemoryRouter> | ||
); | ||
}, | ||
]; |
19 changes: 19 additions & 0 deletions
19
graph/client/src/app/ui-components/link-with-current-search-params.tsx
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,19 @@ | ||
import { Link, LinkProps, useSearchParams, To } from 'react-router-dom'; | ||
import React from 'react'; | ||
|
||
type LinkWithSearchParamsProps = LinkProps & | ||
React.RefAttributes<HTMLAnchorElement>; | ||
|
||
function LinkWithSearchParams(props: LinkWithSearchParamsProps) { | ||
const [searchParams] = useSearchParams(); | ||
|
||
let to: To; | ||
if (typeof props.to === 'object') { | ||
to = { ...props.to, search: searchParams.toString() }; | ||
} else if (typeof props.to === 'string') { | ||
to = { pathname: props.to, search: searchParams.toString() }; | ||
} | ||
return <Link {...props} to={to} />; | ||
} | ||
|
||
export default LinkWithSearchParams; |
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
27 changes: 27 additions & 0 deletions
27
graph/client/src/app/ui-tooltips/task-node-tooltip.stories.tsx
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,27 @@ | ||
import type { ComponentStory, ComponentMeta } from '@storybook/react'; | ||
import { TaskNodeTooltip } from './task-node-tooltip'; | ||
import Tippy from '@tippyjs/react'; | ||
|
||
const Story: ComponentMeta<typeof TaskNodeTooltip> = { | ||
component: TaskNodeTooltip, | ||
title: 'Tooltips/TaskNodeTooltip', | ||
}; | ||
export default Story; | ||
|
||
const Template: ComponentStory<typeof TaskNodeTooltip> = (args) => ( | ||
<Tippy | ||
content={<TaskNodeTooltip {...args} />} | ||
visible={true} | ||
theme="nx" | ||
interactive={true} | ||
maxWidth="none" | ||
> | ||
<p></p> | ||
</Tippy> | ||
); | ||
|
||
export const Primary = Template.bind({}); | ||
Primary.args = { | ||
id: 'my-lib:build', | ||
executor: '@nrwl/webpack:webpack', | ||
}; |
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,31 @@ | ||
import Tag from '../ui-components/tag'; | ||
import { Link, useParams } from 'react-router-dom'; | ||
import { TooltipLinkButton } from './tooltip-button'; | ||
import { getEnvironmentConfig } from '../hooks/use-environment-config'; | ||
|
||
export interface TaskNodeTooltipProps { | ||
id: string; | ||
executor: string; | ||
} | ||
|
||
export function TaskNodeTooltip({ id, executor }: TaskNodeTooltipProps) { | ||
const params = useParams(); | ||
const selectedWorkspaceId = params['selectedProjectId']; | ||
|
||
const to = selectedWorkspaceId | ||
? `/${selectedWorkspaceId}/tasks/${id}` | ||
: `/tasks/${id}`; | ||
return ( | ||
<div> | ||
<h4> | ||
<Tag className="mr-3">{executor}</Tag> | ||
{id} | ||
</h4> | ||
<div className="mt-2 flex"> | ||
<TooltipLinkButton to={to}>Focus</TooltipLinkButton> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
export default TaskNodeTooltip; |
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,36 @@ | ||
/* eslint-disable-next-line */ | ||
import { Link, LinkProps } from 'react-router-dom'; | ||
import { HTMLAttributes } from 'react'; | ||
import LinkWithSearchParams from '../ui-components/link-with-current-search-params'; | ||
|
||
const sharedClasses = | ||
'inline-flex items-center rounded-md border border-slate-300 bg-slate-50 py-2 px-4 mt-2 mr-2 text-slate-500 hover:bg-slate-100 dark:border-slate-600 dark:bg-slate-800 dark:text-slate-300 hover:dark:bg-slate-700'; | ||
|
||
export function TooltipButton({ | ||
className, | ||
children, | ||
...rest | ||
}: HTMLAttributes<HTMLButtonElement>) { | ||
return ( | ||
<button className={`${sharedClasses} ${className}`} {...rest}> | ||
{children} | ||
</button> | ||
); | ||
} | ||
|
||
export function TooltipLinkButton({ | ||
to, | ||
className, | ||
children, | ||
...rest | ||
}: LinkProps) { | ||
return ( | ||
<LinkWithSearchParams | ||
className={`${sharedClasses} ${className}`} | ||
to={to} | ||
{...rest} | ||
> | ||
{children} | ||
</LinkWithSearchParams> | ||
); | ||
} |
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
Oops, something went wrong.