Skip to content

Commit 4265df6

Browse files
committed
fix: resolve race condition in environment creation modal
Prevents tab from resetting to 'default' when creating first environment. Previously, CreateEnvironment modal would call onClose() which set tab to 'default', causing a brief flash back to DefaultTab before EnvironmentList appeared. Now only resets tab if no environments were created.
1 parent a5d9300 commit 4265df6

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

  • packages/bruno-app/src/components/Environments/EnvironmentSettings

packages/bruno-app/src/components/Environments/EnvironmentSettings/index.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,24 @@ const EnvironmentSettings = ({ collection, onClose }) => {
4747
const { environments } = collection;
4848
const [selectedEnvironment, setSelectedEnvironment] = useState(null);
4949
const [tab, setTab] = useState('default');
50+
51+
// Handler for closing create/import modals
52+
const handleCreateOrImportClose = () => {
53+
// Only reset tab if there are still no environments
54+
// If an environment was created, the component will re-render to show EnvironmentList
55+
if (!environments || !environments.length) {
56+
setTab('default');
57+
}
58+
};
59+
5060
if (!environments || !environments.length) {
5161
return (
5262
<StyledWrapper>
5363
<Modal size="md" title="Environments" handleCancel={onClose} hideCancel={true} hideFooter={true}>
5464
{tab === 'create' ? (
55-
<CreateEnvironment collection={collection} onClose={() => setTab('default')} />
65+
<CreateEnvironment collection={collection} onClose={handleCreateOrImportClose} />
5666
) : tab === 'import' ? (
57-
<ImportEnvironment collection={collection} onClose={() => setTab('default')} />
67+
<ImportEnvironment collection={collection} onClose={handleCreateOrImportClose} />
5868
) : (
5969
<DefaultTab setTab={setTab} />
6070
)}

0 commit comments

Comments
 (0)