Skip to content

Commit

Permalink
remove super admins from always being on preview stream (#5247)
Browse files Browse the repository at this point in the history
* remove super admins from always being on preview stream

* code clean up
  • Loading branch information
lcampbell2 committed Apr 22, 2024
1 parent f8d5297 commit e730e50
Showing 1 changed file with 5 additions and 20 deletions.
25 changes: 5 additions & 20 deletions frontend/src/app/ABTestWrapper.js
@@ -1,30 +1,20 @@
import React from 'react'
import { any, string } from 'prop-types'
import { useUserVar } from '../utilities/userState'
import { IS_USER_SUPER_ADMIN } from '../graphql/queries'
import { useQuery } from '@apollo/client'

const isInsiderUser = ({ isUserSuperAdmin, insideUser }) => {
return insideUser || isUserSuperAdmin
}

export function ABTestVariant({ children }) {
return <>{children}</>
}

export function ABTestWrapper({ children, insiderVariantName = 'B' }) {
const { data } = useQuery(IS_USER_SUPER_ADMIN)
const { currentUser } = useUserVar()
const {
currentUser: { insideUser },
} = useUserVar()
let childIndex = 0

// only one variant
if (!children.length) {
if (
isInsiderUser({
isUserSuperAdmin: data?.isUserSuperAdmin || false,
insideUser: currentUser?.insideUser || false,
})
) {
if (insideUser) {
if (children.props.name === insiderVariantName) return <>{children}</>
else return <></>
} else {
Expand All @@ -33,12 +23,7 @@ export function ABTestWrapper({ children, insiderVariantName = 'B' }) {
}
}
// A + B variants
if (
isInsiderUser({
isUserSuperAdmin: data?.isUserSuperAdmin || false,
insideUser: currentUser?.insideUser || false,
})
) {
if (insideUser) {
childIndex = children.findIndex((variant) => variant.props.name === insiderVariantName)
} else {
childIndex = children.findIndex((variant) => variant.props.name !== insiderVariantName)
Expand Down

0 comments on commit e730e50

Please sign in to comment.