mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-27 11:51:13 +01:00
Fix deleting selected environment
This commit is contained in:
@@ -32,10 +32,13 @@ export const EnvironmentEditDialog = function ({ initialEnvironment }: Props) {
|
|||||||
const { baseEnvironment, subEnvironments, allEnvironments } = useEnvironments();
|
const { baseEnvironment, subEnvironments, allEnvironments } = useEnvironments();
|
||||||
|
|
||||||
const [selectedEnvironmentId, setSelectedEnvironmentId] = useState<string | null>(
|
const [selectedEnvironmentId, setSelectedEnvironmentId] = useState<string | null>(
|
||||||
initialEnvironment?.id ?? baseEnvironment?.id ?? null,
|
initialEnvironment?.id ?? null,
|
||||||
);
|
);
|
||||||
|
|
||||||
const selectedEnvironment = allEnvironments.find((e) => e.id === selectedEnvironmentId);
|
const selectedEnvironment =
|
||||||
|
selectedEnvironmentId != null
|
||||||
|
? allEnvironments.find((e) => e.id === selectedEnvironmentId)
|
||||||
|
: baseEnvironment;
|
||||||
|
|
||||||
const handleCreateEnvironment = async () => {
|
const handleCreateEnvironment = async () => {
|
||||||
if (baseEnvironment == null) return;
|
if (baseEnvironment == null) return;
|
||||||
@@ -55,7 +58,7 @@ export const EnvironmentEditDialog = function ({ initialEnvironment }: Props) {
|
|||||||
<div className="min-w-0 h-full overflow-y-auto pt-1">
|
<div className="min-w-0 h-full overflow-y-auto pt-1">
|
||||||
<SidebarButton
|
<SidebarButton
|
||||||
active={selectedEnvironment?.id == baseEnvironment?.id}
|
active={selectedEnvironment?.id == baseEnvironment?.id}
|
||||||
onClick={() => setSelectedEnvironmentId(baseEnvironment?.id ?? null)}
|
onClick={() => setSelectedEnvironmentId(null)}
|
||||||
environment={null}
|
environment={null}
|
||||||
rightSlot={
|
rightSlot={
|
||||||
<IconButton
|
<IconButton
|
||||||
@@ -82,6 +85,11 @@ export const EnvironmentEditDialog = function ({ initialEnvironment }: Props) {
|
|||||||
active={selectedEnvironment?.id === e.id}
|
active={selectedEnvironment?.id === e.id}
|
||||||
environment={e}
|
environment={e}
|
||||||
onClick={() => setSelectedEnvironmentId(e.id)}
|
onClick={() => setSelectedEnvironmentId(e.id)}
|
||||||
|
onDelete={() => {
|
||||||
|
if (e.id === selectedEnvironmentId) {
|
||||||
|
setSelectedEnvironmentId(null);
|
||||||
|
}
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
{e.name}
|
{e.name}
|
||||||
</SidebarButton>
|
</SidebarButton>
|
||||||
@@ -90,11 +98,7 @@ export const EnvironmentEditDialog = function ({ initialEnvironment }: Props) {
|
|||||||
</aside>
|
</aside>
|
||||||
)}
|
)}
|
||||||
secondSlot={() =>
|
secondSlot={() =>
|
||||||
selectedEnvironmentId == null ? (
|
selectedEnvironment == null ? (
|
||||||
<div className="p-3 mt-10">
|
|
||||||
<Banner color="danger">No selected environment</Banner>
|
|
||||||
</div>
|
|
||||||
) : selectedEnvironment == null ? (
|
|
||||||
<div className="p-3 mt-10">
|
<div className="p-3 mt-10">
|
||||||
<Banner color="danger">
|
<Banner color="danger">
|
||||||
Failed to find selected environment <InlineCode>{selectedEnvironmentId}</InlineCode>
|
Failed to find selected environment <InlineCode>{selectedEnvironmentId}</InlineCode>
|
||||||
@@ -198,6 +202,7 @@ function SidebarButton({
|
|||||||
className,
|
className,
|
||||||
active,
|
active,
|
||||||
onClick,
|
onClick,
|
||||||
|
onDelete,
|
||||||
rightSlot,
|
rightSlot,
|
||||||
environment,
|
environment,
|
||||||
}: {
|
}: {
|
||||||
@@ -205,6 +210,7 @@ function SidebarButton({
|
|||||||
children: ReactNode;
|
children: ReactNode;
|
||||||
active: boolean;
|
active: boolean;
|
||||||
onClick: () => void;
|
onClick: () => void;
|
||||||
|
onDelete?: () => void;
|
||||||
rightSlot?: ReactNode;
|
rightSlot?: ReactNode;
|
||||||
environment: Environment | null;
|
environment: Environment | null;
|
||||||
}) {
|
}) {
|
||||||
@@ -275,7 +281,11 @@ function SidebarButton({
|
|||||||
color: 'danger',
|
color: 'danger',
|
||||||
label: 'Delete',
|
label: 'Delete',
|
||||||
leftSlot: <Icon icon="trash" size="sm" />,
|
leftSlot: <Icon icon="trash" size="sm" />,
|
||||||
onSelect: () => deleteEnvironment.mutate(),
|
onSelect: () => {
|
||||||
|
deleteEnvironment.mutate(undefined, {
|
||||||
|
onSuccess: onDelete,
|
||||||
|
});
|
||||||
|
},
|
||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in New Issue
Block a user