mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-20 07:41:22 +02:00
Allow editing base environment
This commit is contained in:
@@ -2,7 +2,6 @@ import classNames from 'classnames';
|
|||||||
import { memo, useCallback, useMemo } from 'react';
|
import { memo, useCallback, useMemo } from 'react';
|
||||||
import { useActiveEnvironment } from '../hooks/useActiveEnvironment';
|
import { useActiveEnvironment } from '../hooks/useActiveEnvironment';
|
||||||
import { useAppRoutes } from '../hooks/useAppRoutes';
|
import { useAppRoutes } from '../hooks/useAppRoutes';
|
||||||
import { useCreateEnvironment } from '../hooks/useCreateEnvironment';
|
|
||||||
import { useEnvironments } from '../hooks/useEnvironments';
|
import { useEnvironments } from '../hooks/useEnvironments';
|
||||||
import type { ButtonProps } from './core/Button';
|
import type { ButtonProps } from './core/Button';
|
||||||
import { Button } from './core/Button';
|
import { Button } from './core/Button';
|
||||||
@@ -22,7 +21,6 @@ export const EnvironmentActionsDropdown = memo(function EnvironmentActionsDropdo
|
|||||||
}: Props) {
|
}: Props) {
|
||||||
const environments = useEnvironments();
|
const environments = useEnvironments();
|
||||||
const activeEnvironment = useActiveEnvironment();
|
const activeEnvironment = useActiveEnvironment();
|
||||||
const createEnvironment = useCreateEnvironment();
|
|
||||||
const dialog = useDialog();
|
const dialog = useDialog();
|
||||||
const routes = useAppRoutes();
|
const routes = useAppRoutes();
|
||||||
|
|
||||||
@@ -54,28 +52,15 @@ export const EnvironmentActionsDropdown = memo(function EnvironmentActionsDropdo
|
|||||||
...((environments.length > 0
|
...((environments.length > 0
|
||||||
? [{ type: 'separator', label: 'Environments' }]
|
? [{ type: 'separator', label: 'Environments' }]
|
||||||
: []) as DropdownItem[]),
|
: []) as DropdownItem[]),
|
||||||
...((environments.length > 0
|
|
||||||
? [
|
|
||||||
{
|
|
||||||
key: 'edit',
|
|
||||||
label: 'Manage Environments',
|
|
||||||
hotKeyAction: 'environmentEditor.toggle',
|
|
||||||
leftSlot: <Icon icon="box" />,
|
|
||||||
onSelect: showEnvironmentDialog,
|
|
||||||
},
|
|
||||||
]
|
|
||||||
: []) as DropdownItem[]),
|
|
||||||
{
|
{
|
||||||
key: 'new',
|
key: 'edit',
|
||||||
label: 'New Environment',
|
label: 'Manage Environments',
|
||||||
leftSlot: <Icon icon="plus" />,
|
hotKeyAction: 'environmentEditor.toggle',
|
||||||
onSelect: async () => {
|
leftSlot: <Icon icon="box" />,
|
||||||
await createEnvironment.mutateAsync();
|
onSelect: showEnvironmentDialog,
|
||||||
showEnvironmentDialog();
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
[activeEnvironment?.id, createEnvironment, environments, routes, showEnvironmentDialog],
|
[activeEnvironment?.id, environments, routes, showEnvironmentDialog],
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -89,7 +74,7 @@ export const EnvironmentActionsDropdown = memo(function EnvironmentActionsDropdo
|
|||||||
)}
|
)}
|
||||||
{...buttonProps}
|
{...buttonProps}
|
||||||
>
|
>
|
||||||
{activeEnvironment?.name ?? 'No Environment'}
|
{activeEnvironment?.name ?? 'Environment'}
|
||||||
</Button>
|
</Button>
|
||||||
</Dropdown>
|
</Dropdown>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
|
import type { ReactNode } from 'react';
|
||||||
import { useCallback, useMemo, useState } from 'react';
|
import { useCallback, useMemo, useState } from 'react';
|
||||||
import { useWindowSize } from 'react-use';
|
import { useWindowSize } from 'react-use';
|
||||||
import { useActiveWorkspace } from '../hooks/useActiveWorkspace';
|
import { useActiveWorkspace } from '../hooks/useActiveWorkspace';
|
||||||
@@ -58,13 +59,19 @@ export const EnvironmentEditDialog = function ({ initialEnvironment }: Props) {
|
|||||||
{showSidebar && (
|
{showSidebar && (
|
||||||
<aside className="grid grid-rows-[minmax(0,1fr)_auto] gap-y-0.5 h-full max-w-[250px] pr-3 border-r border-gray-100 -ml-2 pb-4">
|
<aside className="grid grid-rows-[minmax(0,1fr)_auto] gap-y-0.5 h-full max-w-[250px] pr-3 border-r border-gray-100 -ml-2 pb-4">
|
||||||
<div className="min-w-0 h-full w-full overflow-y-scroll">
|
<div className="min-w-0 h-full w-full overflow-y-scroll">
|
||||||
|
<SidebarButton
|
||||||
|
active={selectedEnvironment?.id == null}
|
||||||
|
onClick={() => setSelectedEnvironmentId(null)}
|
||||||
|
>
|
||||||
|
Global
|
||||||
|
</SidebarButton>
|
||||||
{environments.map((e) => (
|
{environments.map((e) => (
|
||||||
<SidebarButton
|
<SidebarButton
|
||||||
key={e.id}
|
key={e.id}
|
||||||
active={selectedEnvironment?.id === e.id}
|
active={selectedEnvironment?.id === e.id}
|
||||||
onClick={() => setSelectedEnvironmentId(e.id)}
|
onClick={() => setSelectedEnvironmentId(e.id)}
|
||||||
>
|
>
|
||||||
{e.name}
|
→ {e.name}
|
||||||
</SidebarButton>
|
</SidebarButton>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
@@ -79,12 +86,8 @@ export const EnvironmentEditDialog = function ({ initialEnvironment }: Props) {
|
|||||||
</Button>
|
</Button>
|
||||||
</aside>
|
</aside>
|
||||||
)}
|
)}
|
||||||
{activeWorkspace != null ? (
|
{activeWorkspace != null && (
|
||||||
<EnvironmentEditor environment={selectedEnvironment} workspace={activeWorkspace} />
|
<EnvironmentEditor environment={selectedEnvironment} workspace={activeWorkspace} />
|
||||||
) : (
|
|
||||||
<div className="flex w-full h-full items-center justify-center text-gray-400 italic">
|
|
||||||
select an environment
|
|
||||||
</div>
|
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
@@ -187,7 +190,7 @@ const EnvironmentEditor = function ({
|
|||||||
return (
|
return (
|
||||||
<VStack space={2}>
|
<VStack space={2}>
|
||||||
<HStack space={2} className="justify-between">
|
<HStack space={2} className="justify-between">
|
||||||
<h1 className="text-xl">{environment?.name ?? 'Base Environment'}</h1>
|
<h1 className="text-xl">{environment?.name ?? 'Global Environment'}</h1>
|
||||||
{items != null && (
|
{items != null && (
|
||||||
<Dropdown items={items}>
|
<Dropdown items={items}>
|
||||||
<IconButton
|
<IconButton
|
||||||
@@ -220,7 +223,7 @@ function SidebarButton({
|
|||||||
onClick,
|
onClick,
|
||||||
}: {
|
}: {
|
||||||
className?: string;
|
className?: string;
|
||||||
children: string;
|
children: ReactNode;
|
||||||
active: boolean;
|
active: boolean;
|
||||||
onClick: () => void;
|
onClick: () => void;
|
||||||
}) {
|
}) {
|
||||||
|
|||||||
Reference in New Issue
Block a user