From 1238ae431829a10299d191576eeeaac2ec4d2574 Mon Sep 17 00:00:00 2001 From: Pavlos Koutoglou Date: Wed, 15 Nov 2023 16:44:07 +0100 Subject: [PATCH] Added new event to open the requested organization [INS-3300] (#6759) * Added new event to open the requested organization * Check if the organization id exist * Remove line --- packages/insomnia/src/ui/routes/organization.tsx | 9 +++++++++ packages/insomnia/src/ui/routes/root.tsx | 9 +++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/packages/insomnia/src/ui/routes/organization.tsx b/packages/insomnia/src/ui/routes/organization.tsx index 6857dfdde..ae01a621e 100644 --- a/packages/insomnia/src/ui/routes/organization.tsx +++ b/packages/insomnia/src/ui/routes/organization.tsx @@ -281,15 +281,24 @@ export interface FeatureList { export const singleOrgLoader: LoaderFunction = async ({ params }) => { const { organizationId } = params as { organizationId: string }; + + const organization = organizationsData.organizations.find(o => o.id === organizationId); + + if (!organization) { + return redirect('/organization'); + } + const fallbackFeatures = { gitSync: { enabled: false, reason: 'Insomnia API unreachable' }, orgBasicRbac: { enabled: false, reason: 'Insomnia API unreachable' }, }; + if (isScratchpadOrganizationId(organizationId)) { return { features: fallbackFeatures, }; } + try { const response = await window.main.insomniaFetch<{ features: FeatureList } | undefined>({ method: 'GET', diff --git a/packages/insomnia/src/ui/routes/root.tsx b/packages/insomnia/src/ui/routes/root.tsx index d9ca07041..9010f3a30 100644 --- a/packages/insomnia/src/ui/routes/root.tsx +++ b/packages/insomnia/src/ui/routes/root.tsx @@ -2,7 +2,7 @@ import '../css/styles.css'; import { IpcRendererEvent } from 'electron'; import React, { useEffect, useState } from 'react'; -import { LoaderFunction, Outlet, useFetcher, useParams, useRouteLoaderData } from 'react-router-dom'; +import { LoaderFunction, Outlet, useFetcher, useNavigate, useParams, useRouteLoaderData } from 'react-router-dom'; import { isDevelopment } from '../../common/constants'; import * as models from '../../models'; @@ -53,6 +53,7 @@ const Root = () => { const [importUri, setImportUri] = useState(''); const actionFetcher = useFetcher(); + const navigate = useNavigate(); useEffect(() => { return window.main.on( @@ -201,13 +202,17 @@ const Root = () => { break; } + case 'insomnia://app/open/organization': + navigate(`/organization/${params.organizationId}`); + break; + default: { console.log(`Unknown deep link: ${url}`); } } }, ); - }, [actionFetcher]); + }, [actionFetcher, navigate]); return (