Recursive Insomnia import!

This commit is contained in:
Gregory Schier
2023-11-05 13:33:23 -08:00
parent 33d1a84ecd
commit f7a4ea9735
21 changed files with 1354 additions and 159 deletions

View File

@@ -1,15 +1,14 @@
import classNames from 'classnames';
import { memo, useCallback, useMemo } from 'react';
import { useActiveEnvironment } from '../hooks/useActiveEnvironment';
import { useAppRoutes } from '../hooks/useAppRoutes';
import { useEnvironments } from '../hooks/useEnvironments';
import { Button } from './core/Button';
import type { DropdownItem } from './core/Dropdown';
import { Dropdown } from './core/Dropdown';
import { Icon } from './core/Icon';
import { useEnvironments } from '../hooks/useEnvironments';
import { useActiveEnvironment } from '../hooks/useActiveEnvironment';
import { useDialog } from './DialogContext';
import { EnvironmentEditDialog } from './EnvironmentEditDialog';
import { useAppRoutes } from '../hooks/useAppRoutes';
import { useCreateEnvironment } from '../hooks/useCreateEnvironment';
type Props = {
className?: string;
@@ -20,7 +19,6 @@ export const EnvironmentActionsDropdown = memo(function EnvironmentActionsDropdo
}: Props) {
const environments = useEnvironments();
const activeEnvironment = useActiveEnvironment();
const createEnvironment = useCreateEnvironment();
const dialog = useDialog();
const routes = useAppRoutes();
@@ -32,44 +30,33 @@ export const EnvironmentActionsDropdown = memo(function EnvironmentActionsDropdo
}, [dialog, activeEnvironment]);
const items: DropdownItem[] = useMemo(
() =>
environments.length === 0
? [
{
key: 'create',
label: 'Create Environment',
leftSlot: <Icon icon="plusCircle" />,
onSelect: async () => {
await createEnvironment.mutateAsync();
showEnvironmentDialog();
},
},
]
: [
...environments.map(
(e) => ({
key: e.id,
label: e.name,
rightSlot: e.id === activeEnvironment?.id ? <Icon icon="check" /> : undefined,
onSelect: async () => {
if (e.id !== activeEnvironment?.id) {
routes.setEnvironment(e);
} else {
routes.setEnvironment(null);
}
},
}),
[activeEnvironment?.id],
),
{ type: 'separator', label: 'Environments' },
{
key: 'edit',
label: 'Manage Environments',
leftSlot: <Icon icon="gear" />,
onSelect: showEnvironmentDialog,
},
],
[activeEnvironment, environments, routes, createEnvironment, showEnvironmentDialog],
() => [
...environments.map(
(e) => ({
key: e.id,
label: e.name,
rightSlot: e.id === activeEnvironment?.id ? <Icon icon="check" /> : undefined,
onSelect: async () => {
if (e.id !== activeEnvironment?.id) {
routes.setEnvironment(e);
} else {
routes.setEnvironment(null);
}
},
}),
[activeEnvironment?.id],
),
...((environments.length > 0
? [{ type: 'separator', label: 'Environments' }]
: []) as DropdownItem[]),
{
key: 'edit',
label: 'Manage Environments',
leftSlot: <Icon icon="gear" />,
onSelect: showEnvironmentDialog,
},
],
[activeEnvironment, environments, routes, showEnvironmentDialog],
);
return (

View File

@@ -1,18 +1,18 @@
import { invoke } from '@tauri-apps/api';
import { useCallback, useRef } from 'react';
import { open } from '@tauri-apps/api/dialog';
import { useCallback, useRef } from 'react';
import { useAppRoutes } from '../hooks/useAppRoutes';
import { useDeleteRequest } from '../hooks/useDeleteRequest';
import { useDuplicateRequest } from '../hooks/useDuplicateRequest';
import { useListenToTauriEvent } from '../hooks/useListenToTauriEvent';
import { useTheme } from '../hooks/useTheme';
import type { Environment, Folder, HttpRequest, Workspace } from '../lib/models';
import { pluralize } from '../lib/pluralize';
import type { DropdownItem, DropdownProps, DropdownRef } from './core/Dropdown';
import { Dropdown } from './core/Dropdown';
import { HotKey } from './core/HotKey';
import { Icon } from './core/Icon';
import { useListenToTauriEvent } from '../hooks/useListenToTauriEvent';
import { useAppRoutes } from '../hooks/useAppRoutes';
import type { Environment, HttpRequest, Workspace } from '../lib/models';
import { useDialog } from './DialogContext';
import { pluralize } from '../lib/pluralize';
interface Props {
requestId: string | null;
@@ -50,10 +50,10 @@ export function RequestActionsDropdown({ requestId, children }: Props) {
const imported: {
workspaces: Workspace[];
environments: Environment[];
folders: Folder[];
requests: HttpRequest[];
} = await invoke('import_data', {
filePaths: selected,
workspaceId: null,
});
const importedWorkspace = imported.workspaces[0];
@@ -62,7 +62,7 @@ export function RequestActionsDropdown({ requestId, children }: Props) {
description: 'Imported the following:',
size: 'dynamic',
render: () => {
const { workspaces, environments, requests } = imported;
const { workspaces, environments, folders, requests } = imported;
return (
<div>
<ul className="list-disc pl-6">
@@ -72,6 +72,9 @@ export function RequestActionsDropdown({ requestId, children }: Props) {
<li>
{environments.length} {pluralize('Environment', environments.length)}
</li>
<li>
{folders.length} {pluralize('Folder', folders.length)}
</li>
<li>
{requests.length} {pluralize('Request', requests.length)}
</li>

View File

@@ -403,7 +403,6 @@ function SidebarItems({
>
{tree.children.map((child, i) => (
<Fragment key={child.item.id}>
{hoveredIndex === i && hoveredTree?.item.id === tree.item.id && <DropMarker />}
{hoveredIndex === i && hoveredTree?.item.id === tree.item.id && <DropMarker />}
<DraggableSidebarItem
selected={selectedId === child.item.id}