Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
fix(IR-2799): fix remove type from flagName to decouple flags from th…
Browse files Browse the repository at this point in the history
…e engine
  • Loading branch information
kattsushi committed Jun 27, 2024
1 parent 40c4cc2 commit 267c001
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,29 @@ import React, { forwardRef, useEffect } from 'react'
import { useTranslation } from 'react-i18next'
import { HiMinus, HiPlusSmall } from 'react-icons/hi2'

import {
FeatureFlag,
FeatureFlagSettingType,
featureFlagSettingPath
} from '@etherealengine/common/src/schema.type.module'
import { FeatureFlagSettingType, featureFlagSettingPath } from '@etherealengine/common/src/schema.type.module'
import { useFind } from '@etherealengine/spatial/src/common/functions/FeathersHooks'
import Accordion from '@etherealengine/ui/src/primitives/tailwind/Accordion'
import { useHookstate } from '@hookstate/core'

const defaultProps = ['id', 'flagName', 'flagValue', 'createdAt', 'updatedAt']

const defaultTypes = [
'ir.client.menu.social',
'ir.client.menu.emote',
'ir.client.menu.avaturn',
'ir.client.menu.readyPlayerMe'
] as const

type FeatureFlag = (typeof defaultTypes)[number]

const FeaturesTab = forwardRef(({ open }: { open: boolean }, ref: React.MutableRefObject<HTMLDivElement>) => {
const { t } = useTranslation()
const displayedFeatures = useHookstate<FeatureFlagSettingType[]>([])

const featureFlagSettings = useFind(featureFlagSettingPath)

useEffect(() => {
const defaultTypes = [
'ir.client.menu.social',
'ir.client.menu.emote',
'ir.client.menu.avaturn',
'ir.client.menu.readyPlayerMe'
]

if (featureFlagSettings.status === 'success') {
const missingTypes = defaultTypes.filter(
(type) =>
Expand Down
14 changes: 2 additions & 12 deletions packages/common/src/schemas/setting/feature-flag-setting.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,9 @@ Ethereal Engine. All Rights Reserved.

// For more information about this file see https://dove.feathersjs.com/guides/cli/service.schemas.html
import type { Static } from '@feathersjs/typebox'
import { getValidator, querySyntax, StringEnum, Type } from '@feathersjs/typebox'
import { getValidator, querySyntax, Type } from '@feathersjs/typebox'
import { dataValidator, queryValidator } from '../validators'

export type FeatureFlag = FeatureFlagSettingType['flagName']

export const featureFlagSettingPath = 'feature-flag-setting'

export const featureFlagSettingMethods = ['find', 'get', 'create', 'patch', 'remove'] as const
Expand All @@ -40,15 +38,7 @@ export const featureFlagSettingSchema = Type.Object(
id: Type.String({
format: 'uuid'
}),
flagName: StringEnum([
'ir.client.menu.social',
'ir.client.menu.emote',
'ir.client.menu.avaturn',
'ir.client.menu.readyPlayerMe',
'ir.mt.menu.myDomains',
'ir.mt.project.storage',
'ir.mt.project.version'
]),
flagName: Type.String(),
flagValue: Type.Boolean(),
createdAt: Type.String({ format: 'date-time' }),
updatedAt: Type.String({ format: 'date-time' })
Expand Down
10 changes: 5 additions & 5 deletions packages/engine/src/FeatureFlagsState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,21 @@ All portions of the code written by the Ethereal Engine team are Copyright © 20
Ethereal Engine. All Rights Reserved.
*/

import { FeatureFlag, featureFlagSettingPath } from '@etherealengine/common/src/schema.type.module'
import { featureFlagSettingPath } from '@etherealengine/common/src/schema.type.module'
import { defineState, getMutableState, useHookstate } from '@etherealengine/hyperflux/functions/StateFunctions'
import { useFind } from '@etherealengine/spatial/src/common/functions/FeathersHooks'
import { useEffect } from 'react'

export const FeatureFlagsState = defineState({
name: 'ee.engine.FeatureFlagsState',
initial: {} as Record<FeatureFlag, boolean>,
enabled(flagName: FeatureFlag) {
initial: {} as Record<string, boolean>,
enabled<FlagName extends string>(flagName: FlagName) {
const state = getMutableState(FeatureFlagsState)[flagName].value
return typeof state === 'boolean' ? state : true
},
useEnabled(flagName: FeatureFlag) {
useEnabled<FlagName extends string>(flagName: FlagName) {
const state = useHookstate(getMutableState(FeatureFlagsState)[flagName]).value
return typeof state === 'boolean' ? state : typeof state === 'number' && state === 0 ? false : true
return typeof state === 'boolean' ? state : true
},
reactor: () => {
const featureFlagQuery = useFind(featureFlagSettingPath)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ export const featureFlagSettingResolver = resolve<FeatureFlagSettingType, HookCo
updatedAt: virtual(async (featureFlagSettings) => fromDateTimeSql(featureFlagSettings.updatedAt))
})

export const featureFlagSettingExternalResolver = resolve<FeatureFlagSettingType, HookContext>({})
export const featureFlagSettingExternalResolver = resolve<FeatureFlagSettingType, HookContext>({
flagValue: async (_, setting) => !!setting.flagValue
})

export const featureFlagSettingDataResolver = resolve<FeatureFlagSettingType, HookContext>({
id: async () => {
Expand Down

0 comments on commit 267c001

Please sign in to comment.