feat(untracked-data): Display a warning when there are untracked data in the app (#6927)

* show a warning when there are untracked data in the app

* update copy
This commit is contained in:
James Gatz 2023-12-18 20:51:27 +01:00 committed by GitHub
parent 45ee1a14a4
commit de3934bd60
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 6 deletions

View File

@ -16,7 +16,7 @@ import { SegmentEvent } from '../../analytics';
import { useOrganizationLoaderData } from '../../routes/organization';
import { ProjectLoaderData } from '../../routes/project';
import { useRootLoaderData } from '../../routes/root';
import { LoaderData } from '../../routes/untracked-projects';
import { UntrackedProjectsLoaderData } from '../../routes/untracked-projects';
import { WorkspaceLoaderData } from '../../routes/workspace';
import { Dropdown, DropdownItem, DropdownSection, ItemContent } from '../base/dropdown';
import { Icon } from '../icon';
@ -236,7 +236,7 @@ export const ImportExport: FC<Props> = ({ hideSettingsModal }) => {
const organizationData = useOrganizationLoaderData();
const organizations = organizationData?.organizations || [];
const untrackedProjectsFetcher = useFetcher<LoaderData>();
const untrackedProjectsFetcher = useFetcher<UntrackedProjectsLoaderData>();
useEffect(() => {
const isIdleAndUninitialized = untrackedProjectsFetcher.state === 'idle' && !untrackedProjectsFetcher.data;

View File

@ -44,13 +44,14 @@ import { GitHubStarsButton } from '../components/github-stars-button';
import { Hotkey } from '../components/hotkey';
import { Icon } from '../components/icon';
import { InsomniaAILogo } from '../components/insomnia-icon';
import { showAlert } from '../components/modals';
import { showSettingsModal } from '../components/modals/settings-modal';
import { showAlert, showModal } from '../components/modals';
import { SettingsModal, showSettingsModal } from '../components/modals/settings-modal';
import { OrganizationAvatar } from '../components/organization-avatar';
import { PresentUsers } from '../components/present-users';
import { Toast } from '../components/toast';
import { InsomniaEventStreamProvider } from '../context/app/insomnia-event-stream-context';
import { useRootLoaderData } from './root';
import { UntrackedProjectsLoaderData } from './untracked-projects';
import { WorkspaceLoaderData } from './workspace';
export interface OrganizationsResponse {
@ -396,7 +397,7 @@ const OrganizationRoute = () => {
workspaceData?.activeWorkspace &&
isScratchpad(workspaceData.activeWorkspace);
const isScratchPadBannerVisible = !isScratchPadBannerDismissed && isScratchpadWorkspace;
const untrackedProjectsFetcher = useFetcher<UntrackedProjectsLoaderData>();
const { organizationId, projectId, workspaceId } = useParams() as {
organizationId: string;
projectId?: string;
@ -404,6 +405,17 @@ const OrganizationRoute = () => {
};
const [status, setStatus] = useState<'online' | 'offline'>('online');
useEffect(() => {
const isIdleAndUninitialized = untrackedProjectsFetcher.state === 'idle' && !untrackedProjectsFetcher.data;
if (isIdleAndUninitialized) {
untrackedProjectsFetcher.load('/untracked-projects');
}
}, [untrackedProjectsFetcher, organizationId]);
const untrackedProjects = untrackedProjectsFetcher.data?.untrackedProjects || [];
const untrackedWorkspaces = untrackedProjectsFetcher.data?.untrackedWorkspaces || [];
const hasUntrackedData = untrackedProjects.length > 0 || untrackedWorkspaces.length > 0;
useEffect(() => {
const handleOnline = () => setStatus('online');
const handleOffline = () => setStatus('offline');
@ -697,6 +709,14 @@ const OrganizationRoute = () => {
/>
</Tooltip>
</TooltipTrigger>
{hasUntrackedData ? <div>
<Button
className="px-4 py-1 h-full flex items-center justify-center gap-2 aria-pressed:bg-[--hl-sm] text-[--color-warning] text-xs hover:bg-[--hl-xs] focus:ring-inset ring-1 ring-transparent focus:ring-[--hl-md] transition-all"
onPress={() => showModal(SettingsModal, { tab: 'data' })}
>
<Icon icon="exclamation-circle" /> You have untracked data in your computer
</Button>
</div> : null}
</div>
<div className='flex items-center gap-2 divide divide-y-[--hl-sm]'>
<TooltipTrigger>

View File

@ -6,7 +6,7 @@ import { Project } from '../../models/project';
import { Workspace } from '../../models/workspace';
import { organizationsData } from './organization';
export interface LoaderData {
export interface UntrackedProjectsLoaderData {
untrackedProjects: (Project & { workspacesCount: number })[];
untrackedWorkspaces: Workspace[];
}