Some fixes around environments

This commit is contained in:
Gregory Schier
2024-12-21 11:04:49 -08:00
parent c1d5881167
commit 61d094d9fd
20 changed files with 95 additions and 46 deletions

View File

@@ -1,4 +1,4 @@
import { getRouteApi, useSearch } from '@tanstack/react-router';
import { useNavigate, useSearch } from '@tanstack/react-router';
import { useCallback } from 'react';
import { useEnvironments } from './useEnvironments';
@@ -11,17 +11,15 @@ export function useActiveEnvironment() {
export const QUERY_ENVIRONMENT_ID = 'environment_id';
const routeApi = getRouteApi('/workspaces/$workspaceId/');
function useActiveEnvironmentId() {
// NOTE: This query param is accessed from Rust side, so do not change
const { environmentId: id } = useSearch({ strict: false });
const navigate = routeApi.useNavigate();
const { environment_id: id} = useSearch({ strict: false });
const navigate = useNavigate({ from: '/workspaces/$workspaceId' });
const setId = useCallback(
(environment_id: string | null) =>
(environmentId: string | null) =>
navigate({
search: (prev) => ({ ...prev, environment_id: environment_id ?? undefined }),
search: (prev) => ({ ...prev, environment_id: environmentId ?? undefined }),
}),
[navigate],
);