Skip to content

Commit

Permalink
fix: add field action to show hide extra experiment data
Browse files Browse the repository at this point in the history
  • Loading branch information
jjburbridge committed Nov 20, 2024
1 parent 2f1b67f commit 810e913
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/components/VariantPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const VariantPreview = (props: PreviewProps) => {
// "title":coalesce(select(title.experimentValue == $experiment && defined(title.variants[variantId == $variant][0]) => title.variants[variantId == $variant][0].value, null), title.default),

// exp stored agaisnt variant
// "title":coalesce(title.variants[experimentId == $experiment && variantId == $variant][0].value, title.default),
// "title":coalesce(title.variants[experimentId == $experiment && variantId == $variant][0].value, title.default, title),

// exp and var stored as _key
// "title":coalesce(title.variants[_key == $experiment+':'+$variant][0].value, title.default),
Expand Down
18 changes: 14 additions & 4 deletions src/fieldExperiments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {ExperimentInput} from './components/ExperimentInput'
import {VariantPreview} from './components/VariantPreview'
import {ExperimentType, FieldPluginConfig} from './types'
import {flattenSchemaType} from './utils/flattenSchemaType'
import {Experimentfield} from './components/ExperimentField'

const createFieldType = ({
field,
Expand All @@ -28,6 +29,9 @@ const createFieldType = ({
return defineType({
name: `experiment${usedName}`,
type: 'object',
components: {
field: Experimentfield,
},
fields: [
typeof field === `string`
? // Define a simple field if all we have is the name as a string
Expand All @@ -40,13 +44,21 @@ const createFieldType = ({
...field,
name: 'default',
},
defineField({
name: 'active',
type: 'boolean',
hidden: true,
}),
defineField({
title: 'Experiment',
name: 'experimentId',
type: 'string',
components: {
input: ExperimentInput,
},
hidden: ({parent}) => {
return !parent?.active
},
}),
defineField({
name: 'variants',
Expand Down Expand Up @@ -148,11 +160,9 @@ export const fieldLevelExperiments = definePlugin<FieldPluginConfig>((config) =>
const flatFieldTypeNames = flattenSchemaType(props.schemaType).map(
(field) => field.type.name,
)
const hasInternationalizedArray = flatFieldTypeNames.some((name) =>
name.startsWith('experiment'),
)
const hasExperiment = flatFieldTypeNames.some((name) => name.startsWith('experiment'))

if (!hasInternationalizedArray) {
if (!hasExperiment) {
return props.renderDefault(props)
}
const providerProps = {...props, experimentFieldPluginConfig: pluginConfig}
Expand Down

0 comments on commit 810e913

Please sign in to comment.