-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Quickfix: fix 'getState' error after insomnia update (#8)
* Quickfix: fix 'getState' error after insomnia update * lint fixes --------- Co-authored-by: Loïc Damet <loic.damet.e@thalesdigital.io> Co-authored-by: Nick Rimmer <NickRimmer@users.noreply.github.com>
- Loading branch information
1 parent
dbb2afc
commit 3487970
Showing
2 changed files
with
26 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,30 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
|
||
import { BaseDoc } from './insomnia.types' | ||
|
||
let store: any = null | ||
let router: any = null | ||
|
||
export const getStore = (): any => { | ||
if (!store) { | ||
const getRouter = (): any => { | ||
if (!router) { | ||
const root = document.querySelector('#root') as Record<string, any> | ||
const parameter = Object.getOwnPropertyNames(root).findLast(x => x.startsWith('__reactContainer')) as string | ||
store = root[parameter].memoizedState.element.props.store | ||
if (!root) { | ||
return | ||
} | ||
const parameter = Object.getOwnPropertyNames(root).findLast((x) => x.startsWith('__reactContainer')) | ||
router = root[parameter as string]?.memoizedState?.element?.props?.router | ||
} | ||
|
||
return store | ||
return router | ||
} | ||
|
||
export const getState = (): any => { | ||
const store = getStore() | ||
return store.getState() | ||
export const getState = () => { | ||
const router = getRouter() | ||
return router?.state | ||
} | ||
|
||
export const getActiveWorkspace = (): BaseDoc => { | ||
export const getActiveWorkspaceId = (): string => { | ||
const state = getState() | ||
const workspaceId = state.global.activeWorkspaceId | ||
const workspace = state.entities.workspaces[workspaceId] | ||
return workspace | ||
return state?.loaderData[':workspaceId'].activeWorkspace._id | ||
} | ||
|
||
export const getActiveEnvironment = (): BaseDoc | null => { | ||
export const getActiveEnvironmentId = (): string => { | ||
const state = getState() | ||
const activeWorkspaceId = getActiveWorkspace()._id | ||
const activeWorkspaceMeta = (Object.values(state.entities.workspaceMetas) as any[]).find(x => x.parentId === activeWorkspaceId) as BaseDoc | ||
const activeEnvironmentId = activeWorkspaceMeta.activeEnvironmentId | ||
const activeEnvironment = state.entities.environments[activeEnvironmentId] ?? null as (BaseDoc | null) | ||
|
||
return activeEnvironment | ||
return state?.loaderData[':workspaceId'].activeEnvironment._id | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters