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

feat(graph): add spinner on the projects page #22149

Merged
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
32 changes: 22 additions & 10 deletions graph/client/src/app/shell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@ import {
import classNames from 'classnames';
import { DebuggerPanel } from './ui-components/debugger-panel';
import { getGraphService } from './machines/graph.service';
import { Outlet, useNavigate, useParams } from 'react-router-dom';
import {
Outlet,
useNavigate,
useNavigation,
useParams,
} from 'react-router-dom';
import { getSystemTheme, Theme, ThemePanel } from '@nx/graph/ui-theme';
import { Dropdown } from '@nx/graph/ui-components';
import { Dropdown, Spinner } from '@nx/graph/ui-components';
import { useCurrentPath } from './hooks/use-current-path';
import { ExperimentalFeature } from './ui-components/experimental-feature';
import { RankdirPanel } from './feature-projects/panels/rankdir-panel';
Expand Down Expand Up @@ -36,8 +41,9 @@ export function Shell(): JSX.Element {
}

const navigate = useNavigate();
const { state: navigationState } = useNavigation();
const currentPath = useCurrentPath();
const { selectedWorkspaceId, selectedTaskId } = useParams();
const { selectedWorkspaceId } = useParams();
const currentRoute = currentPath.currentPath;

const topLevelRoute = currentRoute.startsWith('/tasks')
Expand Down Expand Up @@ -165,17 +171,23 @@ export function Shell(): JSX.Element {
></DebuggerPanel>
) : null}

{!nodesVisible ? (
{!nodesVisible || navigationState === 'loading' ? (
<div
data-cy="no-tasks-selected"
className="flex h-full w-full items-center justify-center text-slate-700 dark:text-slate-400"
>
<ArrowLeftCircleIcon className="mr-4 h-6 w-6" />
<h4>
Please select a{' '}
{currentRoute.startsWith('/tasks') ? 'task' : 'project'} in the
sidebar.
</h4>
{navigationState === 'loading' ? (
<Spinner></Spinner>
) : (
<>
<ArrowLeftCircleIcon className="mr-4 h-6 w-6" />
<h4>
Please select a{' '}
{currentRoute.startsWith('/tasks') ? 'task' : 'project'} in
the sidebar.
</h4>
</>
)}
</div>
) : null}

Expand Down
1 change: 1 addition & 0 deletions graph/ui-components/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './lib/debounced-text-input';
export * from './lib/tag';
export * from './lib/dropdown';
export * from './lib/spinner';
16 changes: 16 additions & 0 deletions graph/ui-components/src/lib/spinner.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { Meta, StoryObj } from '@storybook/react';
import { Spinner } from './spinner';

const meta: Meta<typeof Spinner> = {
component: Spinner,
title: 'Shared/Spinner',
};

export default meta;
type Story = StoryObj<typeof Spinner>;

export const Primary: Story = {
args: {
className: '',
},
};
31 changes: 31 additions & 0 deletions graph/ui-components/src/lib/spinner.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Spinner component from https://tailwindcss.com/docs/animation#spin
*/

import React from 'react';

export type SpinnerProps = React.SVGProps<SVGSVGElement>;

export function Spinner({ className, ...rest }: SpinnerProps) {
return (
<svg
className={`${className} animate-spin h-8 w-8`}
viewBox="0 0 24 24"
{...rest}
>
<circle
className="opacity-10"
cx="12"
cy="12"
r="10"
stroke="currentColor"
stroke-width="4"
></circle>
<path
className="opacity-90"
fill="currentColor"
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
></path>
</svg>
);
}