mirror of
https://github.com/Kong/insomnia.git
synced 2026-05-07 14:33:20 -04:00
fix: persist environment tab data when switching between tabs (#9138)
* fix: persist environment tab data when switching between tabs Signed-off-by: “niladrix719” <niladrix719@gmail.com> * Update packages/insomnia/src/routes/organization.$organizationId.project.$projectId.workspace.$workspaceId.environment.tsx Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * fix: use memo wrap dependence --------- Signed-off-by: “niladrix719” <niladrix719@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Curry Yang <163384738+CurryYangxx@users.noreply.github.com> Co-authored-by: Curry Yang <1019yanglu@gmail.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import type { IconName, IconProp } from '@fortawesome/fontawesome-svg-core';
|
||||
import React, { Fragment, useEffect, useRef, useState } from 'react';
|
||||
import React, { Fragment, useEffect, useMemo, useRef, useState } from 'react';
|
||||
import {
|
||||
Breadcrumb,
|
||||
Breadcrumbs,
|
||||
@@ -88,7 +88,16 @@ const Component = ({ loaderData, params }: Route.ComponentProps) => {
|
||||
const isUsingInsomniaCloudSync = Boolean(isRemoteProject(activeProject) && !activeWorkspaceMeta?.gitRepositoryId);
|
||||
const isUsingGitSync = Boolean(features.gitSync.enabled && activeWorkspaceMeta?.gitRepositoryId);
|
||||
|
||||
const allEnvironment = [baseEnvironment, ...subEnvironments];
|
||||
const allEnvironment = useMemo(() => {
|
||||
return [baseEnvironment, ...subEnvironments];
|
||||
}, [baseEnvironment, subEnvironments]);
|
||||
|
||||
// Keep selectedEnvironmentId in sync when navigating between different environment workspaces/tabs.
|
||||
useEffect(() => {
|
||||
if (!allEnvironment.find(env => env._id === selectedEnvironmentId)) {
|
||||
setSelectedEnvironmentId(activeEnvironment._id);
|
||||
}
|
||||
}, [selectedEnvironmentId, activeEnvironment._id, allEnvironment]);
|
||||
const selectedEnvironment = allEnvironment.find(env => env._id === selectedEnvironmentId);
|
||||
// Do not allowed to switch to json environment if contains secret item
|
||||
const allowSwitchEnvironment = !selectedEnvironment?.kvPairData?.some(
|
||||
|
||||
Reference in New Issue
Block a user