Skip to content

Commit

Permalink
chore: fix associating new variable with feature
Browse files Browse the repository at this point in the history
  • Loading branch information
jsalaber committed Sep 6, 2024
1 parent 9b593eb commit 52a1679
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 60 deletions.
2 changes: 1 addition & 1 deletion src/commands/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export default abstract class Base extends Command {
if (error instanceof ZodError) {
this.reportZodValidationErrors(error)
} else {
this.writer.showError(error.message)
this.writer.showError(JSON.stringify(error))
}
Object.assign(error, { skipOclifErrorHandling: 1 })
throw error
Expand Down
5 changes: 1 addition & 4 deletions src/commands/features/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ import { VariableListOptions } from '../../ui/prompts/listPrompts/variablesListP
import { Flags } from '@oclif/core'
import { CreateFeatureDto, Feature } from '../../api/schemas'
import { VariationListOptions } from '../../ui/prompts/listPrompts/variationsListPrompt'
import {
getQuickConfigurations,
mergeQuickFeatureParamsWithAnswers,
} from '../../utils/features/quickCreateFeatureUtils'
import { mergeQuickFeatureParamsWithAnswers } from '../../utils/features/quickCreateFeatureUtils'
import { fetchProject } from '../../api/projects'

export default class CreateFeature extends CreateCommand {
Expand Down
20 changes: 14 additions & 6 deletions src/commands/variables/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,22 @@ export default class CreateVariable extends CreateCommand {
])

if (associateToFeature) {
const { feature } = await inquirer.prompt([featurePrompt], {
token: this.authToken,
projectKey: this.projectKey,
})
console.error('feature', feature)
const { feature: featureChoice } = await inquirer.prompt(
[featurePrompt],
{
token: this.authToken,
projectKey: this.projectKey,
},
)
// TODO: workaround for bug with undefined variable keys
const feature = await fetchFeatureByKey(
this.authToken,
this.projectKey,
featureChoice.key,
)
if (!feature) {
this.writer.showError(
`Feature with key ${feature.key} could not be found`,
`Feature with key ${featureChoice.key} could not be found`,
)
return
}
Expand Down
49 changes: 0 additions & 49 deletions src/utils/features/quickCreateFeatureUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,52 +110,3 @@ export const getQuickConfigurations =
},
}
}

// Setup targeting for all environments and turn on development only
export const setupTargetingForEnvironments = async (
authToken: string,
projectKey: string,
featureKey: string,
) => {
const environments = await fetchEnvironments(authToken, projectKey)
await Promise.all(
environments.map((environment) =>
updateFeatureConfigForEnvironment(
authToken,
projectKey,
featureKey,
environment.key,
{
targets:
environment.type !== 'development'
? []
: [
{
distribution: [
{
percentage: 1,
_variation: 'variation-on',
},
],
audience: {
name: 'All Users',
filters: {
filters: [
{
type: 'all',
},
],
operator: 'and',
},
},
},
],
status:
environment.type === 'development'
? 'active'
: 'inactive',
},
),
),
)
}

0 comments on commit 52a1679

Please sign in to comment.