mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-19 23:31:21 +02:00
Move workspace menu, better env mgmt, QoL
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import classNames from 'classnames';
|
||||
import { memo, useMemo } from 'react';
|
||||
import { memo, useCallback, useMemo } from 'react';
|
||||
import { Button } from './core/Button';
|
||||
import type { DropdownItem } from './core/Dropdown';
|
||||
import { Dropdown } from './core/Dropdown';
|
||||
@@ -9,6 +9,8 @@ import { useActiveEnvironment } from '../hooks/useActiveEnvironment';
|
||||
import { useDialog } from './DialogContext';
|
||||
import { EnvironmentEditDialog } from './EnvironmentEditDialog';
|
||||
import { useAppRoutes } from '../hooks/useAppRoutes';
|
||||
import { useCreateEnvironment } from '../hooks/useCreateEnvironment';
|
||||
import { usePrompt } from '../hooks/usePrompt';
|
||||
|
||||
type Props = {
|
||||
className?: string;
|
||||
@@ -19,36 +21,53 @@ export const EnvironmentActionsDropdown = memo(function EnvironmentActionsDropdo
|
||||
}: Props) {
|
||||
const environments = useEnvironments();
|
||||
const activeEnvironment = useActiveEnvironment();
|
||||
const createEnvironment = useCreateEnvironment();
|
||||
const dialog = useDialog();
|
||||
const prompt = usePrompt();
|
||||
const routes = useAppRoutes();
|
||||
|
||||
const showEnvironmentDialog = useCallback(() => {
|
||||
dialog.show({
|
||||
title: "Manage Environments",
|
||||
render: () => <EnvironmentEditDialog />,
|
||||
});
|
||||
}, [dialog]);
|
||||
|
||||
const items: DropdownItem[] = useMemo(
|
||||
() => [
|
||||
...environments.map(
|
||||
(e) => ({
|
||||
key: e.id,
|
||||
label: e.name,
|
||||
rightSlot: e.id === activeEnvironment?.id ? <Icon icon="check" /> : undefined,
|
||||
onSelect: async () => {
|
||||
routes.setEnvironment(e);
|
||||
},
|
||||
}),
|
||||
[activeEnvironment?.id],
|
||||
),
|
||||
{ type: 'separator', label: 'Environments' },
|
||||
{
|
||||
key: 'edit',
|
||||
label: 'Manage Environments',
|
||||
leftSlot: <Icon icon="gear" />,
|
||||
onSelect: async () => {
|
||||
dialog.show({
|
||||
title: 'Environments',
|
||||
render: () => <EnvironmentEditDialog />,
|
||||
});
|
||||
},
|
||||
},
|
||||
],
|
||||
[activeEnvironment, dialog, environments, routes],
|
||||
() =>
|
||||
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 () => {
|
||||
routes.setEnvironment(e);
|
||||
},
|
||||
}),
|
||||
[activeEnvironment?.id],
|
||||
),
|
||||
{ type: 'separator', label: 'Environments' },
|
||||
{
|
||||
key: 'edit',
|
||||
label: 'Manage Environments',
|
||||
leftSlot: <Icon icon="gear" />,
|
||||
onSelect: showEnvironmentDialog,
|
||||
},
|
||||
],
|
||||
[activeEnvironment, environments, routes, prompt, createEnvironment, showEnvironmentDialog],
|
||||
);
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user