From fce61d8db91626ffd97326626312cbe858f488ff Mon Sep 17 00:00:00 2001 From: Rohan Lahori <64496391+rohanlahori@users.noreply.github.com> Date: Mon, 11 Nov 2024 11:27:33 +0530 Subject: [PATCH] open in new tab fix workspace modal (#2595) --- .../_components/OrganizationManager/List.jsx | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/frontend/src/_components/OrganizationManager/List.jsx b/frontend/src/_components/OrganizationManager/List.jsx index 8ac54710bb..9229d4079b 100644 --- a/frontend/src/_components/OrganizationManager/List.jsx +++ b/frontend/src/_components/OrganizationManager/List.jsx @@ -1,4 +1,4 @@ -import React, { useEffect, useState } from 'react'; +import React, { useEffect, useState, useRef } from 'react'; import { authenticationService } from '@/_services'; import { CustomSelect } from './CustomSelect'; import { getAvatar, decodeEntities } from '@/_helpers/utils'; @@ -29,14 +29,21 @@ export const OrganizationList = function () { fetchOrganizations(); // eslint-disable-next-line react-hooks/exhaustive-deps }, []); - - const switchOrganization = (id) => { + const newTabRef = useRef(false); + const switchOrganization = (id, newTab = false) => { + newTabRef.current = newTab; const organization = organizationList.find((org) => org.id === id); if (![id, organization.slug].includes(getWorkspaceIdOrSlugFromURL())) { const newPath = appendWorkspaceId(organization.slug || id, location.pathname, true); - window.open(newPath, '_blank'); + newTab ? window.open(newPath, '_blank') : (window.location = newPath); } }; + const handleOnChange = (id) => { + if (!newTabRef.current) { + switchOrganization(id, false); + } + newTabRef.current = false; + }; const options = organizationList .map((org) => ({ @@ -81,7 +88,7 @@ export const OrganizationList = function () {
switchOrganization(org.id)} + onClick={() => switchOrganization(org.id, true)} >
@@ -103,7 +110,7 @@ export const OrganizationList = function () { isLoading={isGettingOrganizations} options={options} value={current_organization_id} - onChange={(id) => switchOrganization(id)} + onChange={handleOnChange} className={`tj-org-select ${darkMode && 'dark-theme'}`} />