Skip to content

Commit 5c3794a

Browse files
authored
fix: make playground env var reveal toggle visibility on the correct row (#1816)
Fixes #1815. ... I knew this code was iffy when I merged it, but it wasn't buggy until I merged #1806. That's my lesson on vibe coding. <!-- ELLIPSIS_HIDDEN --> ---- > [!IMPORTANT] > Fixes environment variable visibility toggle in `EnvironmentVariablesPanel` by using `key` instead of `index`, and updates storybook text. > > - **Behavior**: > - Fixes visibility toggle in `EnvironmentVariablesPanel` by using `key` instead of `index` for `toggleVisibility`, `updateEnvVar`, and `deleteEnvVar` functions. > - Removes animation delay based on index in `env-vars.tsx`. > - **Storybook**: > - Updates heading text from `JSON.stringify(useAtomValue(envVarsAtom))` to `envVars` in `EnvVars.stories.tsx`. > - Removes comments about default required environment variables in `EnvVars.stories.tsx`. > > <sup>This description was created by </sup>[<img alt="Ellipsis" src="https://img.shields.io/badge/Ellipsis-blue?color=175173">](https://www.ellipsis.dev?ref=BoundaryML%2Fbaml&utm_source=github&utm_medium=referral)<sup> for 300e92e. It will automatically update as commits are pushed.</sup> <!-- ELLIPSIS_HIDDEN -->
1 parent 430e428 commit 5c3794a

2 files changed

Lines changed: 12 additions & 18 deletions

File tree

  • typescript

typescript/playground-common/src/shared/baml-project-panel/playground-panel/side-bar/env-vars.tsx

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -140,25 +140,22 @@ export const EnvironmentVariablesPanel: React.FC = () => {
140140
const { toast } = useToast()
141141

142142
// Toggle visibility of an environment variable
143-
const toggleVisibility = (index: number) => {
144-
const envVar = envVars[index]
143+
const toggleVisibility = (key: string) => {
145144
setVisibility((prev) => ({
146145
...prev,
147-
[envVar.key]: !envVar.hidden,
146+
[key]: !prev[key],
148147
}))
149148
}
150149

151150
// Update an environment variable immediately
152-
const updateEnvVar = (index: number, value: string) => {
153-
const envVar = envVars[index]
151+
const updateEnvVar = (key: string, value: string) => {
154152
const newVars = { ...currentEnvVars }
155-
newVars[envVar.key] = value
153+
newVars[key] = value
156154
setEnvVars(newVars)
157155
}
158156

159157
// Delete an environment variable
160-
const deleteEnvVar = (index: number) => {
161-
const { key } = envVars[index]
158+
const deleteEnvVar = (key: string) => {
162159
const newVars = { ...currentEnvVars }
163160
delete newVars[key]
164161
setEnvVars(newVars)
@@ -259,11 +256,11 @@ export const EnvironmentVariablesPanel: React.FC = () => {
259256
<tbody>
260257
{envVars
261258
.filter(({ key }) => key !== 'BOUNDARY_PROXY_URL')
262-
.map((env, index) => (
259+
.map((env) => (
263260
<motion.tr
264261
initial={{ opacity: 0, y: 2 }}
265262
animate={{ opacity: 1, y: 0 }}
266-
transition={{ delay: index * 0.001, duration: 0.05 }}
263+
transition={{ duration: 0.05 }}
267264
key={env.key}
268265
className='relative hover:bg-accent/50 rounded-md'
269266
>
@@ -280,7 +277,7 @@ export const EnvironmentVariablesPanel: React.FC = () => {
280277
<Input
281278
type={env.hidden ? 'password' : 'text'}
282279
value={typeof env.value === 'string' ? escapeValue(env.value) : ''}
283-
onChange={(e) => updateEnvVar(index, unescapeValue(e.target.value))}
280+
onChange={(e) => updateEnvVar(env.key, unescapeValue(e.target.value))}
284281
className='h-6 text-xs font-mono placeholder:font-sans min-w-32'
285282
placeholder={env.required && !env.value ? '<unset>' : undefined}
286283
autoComplete='off'
@@ -302,7 +299,7 @@ export const EnvironmentVariablesPanel: React.FC = () => {
302299
variant='ghost'
303300
size='sm'
304301
className='p-0.5 w-5 h-5'
305-
onClick={() => toggleVisibility(index)}
302+
onClick={() => toggleVisibility(env.key)}
306303
>
307304
{env.hidden ? (
308305
<EyeOff className='w-4 h-4 text-muted-foreground hover:text-primary' />
@@ -323,7 +320,7 @@ export const EnvironmentVariablesPanel: React.FC = () => {
323320
variant='ghost'
324321
size='sm'
325322
className='p-0.5 w-5 h-5'
326-
onClick={() => deleteEnvVar(index)}
323+
onClick={() => deleteEnvVar(env.key)}
327324
>
328325
<Trash2 className='w-4 h-4 text-muted-foreground hover:text-destructive' />
329326
</Button>
@@ -340,7 +337,7 @@ export const EnvironmentVariablesPanel: React.FC = () => {
340337
<motion.tr
341338
initial={{ opacity: 0, y: 2 }}
342339
animate={{ opacity: 1, y: 0 }}
343-
transition={{ delay: envVars.length * 0.001, duration: 0.05 }}
340+
transition={{ duration: 0.05 }}
344341
className='rounded-md'
345342
>
346343
<td className='pl-2 pr-0.5 py-0.5'>

typescript/vscode-ext/packages/web-panel/src/stories/EnvVars.stories.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const WrappedEnvVars: React.FC = () => {
3232
<div className='flex gap-8 items-start'>
3333
<EnvironmentVariablesPanel />
3434
<div className='p-4 bg-[#1e1e1e] rounded-lg min-w-[300px]'>
35-
<h3 className='mb-2 text-sm font-mono'>JSON.stringify(useAtomValue(envVarsAtom))</h3>
35+
<h3 className='mb-2 text-sm font-mono'>envVars</h3>
3636
<pre className='text-xs'>{JSON.stringify(envVars, null, 2)}</pre>
3737
</div>
3838
</div>
@@ -68,7 +68,6 @@ export const NoRequiredEnvVarsAreSet = {
6868
],
6969
}
7070

71-
// ANTHROPIC_API_KEY and OPENAI_API_KEY are required by default
7271
export const SomeRequiredEnvVarsAreSet = {
7372
decorators: [
7473
(Story: React.FC) => (
@@ -91,7 +90,6 @@ export const SomeRequiredEnvVarsAreSet = {
9190
],
9291
}
9392

94-
// ANTHROPIC_API_KEY and OPENAI_API_KEY are required by default
9593
export const AllRequiredEnvVarsAreSet = {
9694
decorators: [
9795
(Story: React.FC) => (
@@ -124,7 +122,6 @@ export const EnvVarContainsNewlines = {
124122
],
125123
}
126124

127-
// ANTHROPIC_API_KEY and OPENAI_API_KEY are required by default
128125
export const TableWith100EnvVars = {
129126
decorators: [
130127
(Story: React.FC) => (

0 commit comments

Comments
 (0)