diff --git a/packages/insomnia/src/main.development.ts b/packages/insomnia/src/main.development.ts
index 3f7e6c8a2..5ab01b3cb 100644
--- a/packages/insomnia/src/main.development.ts
+++ b/packages/insomnia/src/main.development.ts
@@ -6,7 +6,7 @@ import installExtension, { REACT_DEVELOPER_TOOLS } from 'electron-devtools-insta
import path from 'path';
import { userDataFolder } from '../config/config.json';
-import { changelogUrl, getAppVersion, isDevelopment, isMac } from './common/constants';
+import { changelogUrl, getAppVersion, getProductName, isDevelopment, isMac } from './common/constants';
import { database } from './common/database';
import log, { initializeLogging } from './common/log';
import { registerInsomniaStreamProtocol } from './main/api.protocol';
@@ -219,6 +219,21 @@ const _launchApp = async () => {
async function _createModelInstances() {
await models.stats.get();
await models.settings.getOrCreate();
+ try {
+ const scratchpadProject = await models.project.getById(models.project.SCRATCHPAD_PROJECT_ID);
+ const scratchPad = await models.workspace.getById(models.workspace.SCRATCHPAD_WORKSPACE_ID);
+ if (!scratchpadProject) {
+ console.log('Initializing Scratch Pad Project');
+ await models.project.create({ _id: models.project.SCRATCHPAD_PROJECT_ID, name: getProductName(), remoteId: null, parentId: models.organization.SCRATCHPAD_ORGANIZATION_ID });
+ }
+
+ if (!scratchPad) {
+ console.log('Initializing Scratch Pad');
+ await models.workspace.create({ _id: models.workspace.SCRATCHPAD_WORKSPACE_ID, name: 'Scratch Pad', parentId: models.project.SCRATCHPAD_PROJECT_ID, scope: 'collection' });
+ }
+ } catch (err) {
+ console.warn('Failed to create default project. It probably already exists', err);
+ }
}
async function _trackStats() {
diff --git a/packages/insomnia/src/ui/index.tsx b/packages/insomnia/src/ui/index.tsx
index d708fc7e2..3c3e17acd 100644
--- a/packages/insomnia/src/ui/index.tsx
+++ b/packages/insomnia/src/ui/index.tsx
@@ -99,9 +99,9 @@ function getInitialEntry() {
return '/auth/login';
}
- return '/scratchpad';
+ return '/organization/org_scratchpad/project/proj_scratchpad/workspace/wrk_scratchpad/debug';
} catch (e) {
- return '/scratchpad';
+ return '/organization/org_scratchpad/project/proj_scratchpad/workspace/wrk_scratchpad/debug';
}
}
@@ -117,10 +117,6 @@ const router = createMemoryRouter(
loader: async (...args) => (await import('./routes/root')).loader(...args),
errorElement: ,
children: [
- {
- path: '/scratchpad',
- loader: async (...args) => (await import('./routes/scratchpad')).loader(...args),
- },
{
path: 'onboarding/*',
element: ,
@@ -903,7 +899,7 @@ const router = createMemoryRouter(
);
// Store the last location in local storage
-router.subscribe(({ location }) => {
+router.subscribe(({ location, navigation }) => {
const match = matchPath(
{
path: '/organization/:organizationId',
@@ -911,8 +907,18 @@ router.subscribe(({ location }) => {
},
location.pathname
);
+ const nextRoute = navigation.location?.pathname;
+ const currentRoute = location.pathname;
+ // Use navigation send tracking events on page change
+ const bothHaveValueButNotEqual = nextRoute && currentRoute && nextRoute !== currentRoute;
+ if (bothHaveValueButNotEqual) {
+ // transforms /organization/:org_* to /organization/:org_id
+ const routeWithoutUUID = nextRoute.replace(/_[a-f0-9]{32}/g, '_id');
+ // console.log('Tracking page view', { name: routeWithoutUUID });
+ window.main.trackPageView({ name: routeWithoutUUID });
+ }
- match?.params.organizationId && localStorage.setItem(`locationHistoryEntry:${match?.params.organizationId}`, location.pathname);
+ match?.params.organizationId && localStorage.setItem(`locationHistoryEntry:${match?.params.organizationId}`, currentRoute);
});
async function renderApp() {
diff --git a/packages/insomnia/src/ui/routes/auth.login.tsx b/packages/insomnia/src/ui/routes/auth.login.tsx
index bb9df487a..5d6a03d38 100644
--- a/packages/insomnia/src/ui/routes/auth.login.tsx
+++ b/packages/insomnia/src/ui/routes/auth.login.tsx
@@ -171,7 +171,7 @@ const Login = () => {
@@ -214,7 +214,7 @@ const Login = () => {
You can use Insomnia without an account and without connecting to the cloud by using the local Scratch Pad.
diff --git a/packages/insomnia/src/ui/routes/project.tsx b/packages/insomnia/src/ui/routes/project.tsx
index b8cb734b7..97f8839b5 100644
--- a/packages/insomnia/src/ui/routes/project.tsx
+++ b/packages/insomnia/src/ui/routes/project.tsx
@@ -179,6 +179,7 @@ export const indexLoader: LoaderFunction = async ({ params }) => {
const { organizationId } = params;
invariant(organizationId, 'Organization ID is required');
+ // When org icon is clicked this ensures we remember the last visited page
const prevOrganizationLocation = localStorage.getItem(
`locationHistoryEntry:${organizationId}`
);
diff --git a/packages/insomnia/src/ui/routes/scratchpad.tsx b/packages/insomnia/src/ui/routes/scratchpad.tsx
deleted file mode 100644
index 2e9710c95..000000000
--- a/packages/insomnia/src/ui/routes/scratchpad.tsx
+++ /dev/null
@@ -1,23 +0,0 @@
-import { LoaderFunction, redirect } from 'react-router-dom';
-
-import { getProductName } from '../../common/constants';
-import * as models from '../../models';
-
-export const loader: LoaderFunction = async () => {
- try {
- const scratchpadProject = await models.project.getById(models.project.SCRATCHPAD_PROJECT_ID);
- const scratchPad = await models.workspace.getById(models.workspace.SCRATCHPAD_WORKSPACE_ID);
- if (!scratchpadProject) {
- console.log('Initializing Scratch Pad Project');
- await models.project.create({ _id: models.project.SCRATCHPAD_PROJECT_ID, name: getProductName(), remoteId: null, parentId: models.organization.SCRATCHPAD_ORGANIZATION_ID });
- }
-
- if (!scratchPad) {
- console.log('Initializing Scratch Pad');
- await models.workspace.create({ _id: models.workspace.SCRATCHPAD_WORKSPACE_ID, name: 'Scratch Pad', parentId: models.project.SCRATCHPAD_PROJECT_ID, scope: 'collection' });
- }
- } catch (err) {
- console.warn('Failed to create default project. It probably already exists', err);
- }
- return redirect(`/organization/${models.organization.SCRATCHPAD_ORGANIZATION_ID}/project/${models.project.SCRATCHPAD_PROJECT_ID}/workspace/${models.workspace.SCRATCHPAD_WORKSPACE_ID}/debug`);
-};