Avoid reading some variables directly from window (#12280)

GitOrigin-RevId: 93af19498470fd7903db9d55d7468f0298097cc4
This commit is contained in:
Alf Eaton 2023-03-24 12:09:14 +00:00 committed by Copybot
parent 9c78422efa
commit 4c9c0641b2
2 changed files with 9 additions and 4 deletions

View file

@ -11,6 +11,8 @@ import useBrowserWindow from '../hooks/use-browser-window'
import { useIdeContext } from './ide-context'
import { useProjectContext } from './project-context'
import { useDetachContext } from './detach-context'
import getMeta from '../../utils/meta'
import { useUserContext } from './user-context'
export const EditorContext = createContext()
@ -47,7 +49,7 @@ EditorContext.Provider.propTypes = {
export function EditorProvider({ children, settings }) {
const ide = useIdeContext()
const { id: userId } = useUserContext()
const { role } = useDetachContext()
const { owner, features } = useProjectContext({
@ -170,8 +172,8 @@ export function EditorProvider({ children, settings }) {
loading,
renameProject,
permissionsLevel,
isProjectOwner: owner?._id === window.user.id,
isRestrictedTokenMember: window.isRestrictedTokenMember,
isProjectOwner: owner?._id === userId,
isRestrictedTokenMember: getMeta('ol-isRestrictedTokenMember'),
showSymbolPalette,
toggleSymbolPalette,
insertSymbol,
@ -185,10 +187,11 @@ export function EditorProvider({ children, settings }) {
[
cobranding,
features?.compileGroup,
owner,
userId,
loading,
renameProject,
permissionsLevel,
owner?._id,
showSymbolPalette,
toggleSymbolPalette,
insertSymbol,

View file

@ -268,6 +268,8 @@ describe('<ShareProjectModal/>', function () {
})
it('only shows read-only token link to restricted token members', async function () {
window.metaAttributesCache.set('ol-isRestrictedTokenMember', true)
renderWithEditorContext(<ShareProjectModal {...modalProps} />, {
isRestrictedTokenMember: true,
scope: { project: { ...project, publicAccesLevel: 'tokenBased' } },