diff --git a/typescript/playground-common/src/shared/SettingsDialog.tsx b/typescript/playground-common/src/shared/SettingsDialog.tsx index 7eec05bb1..f2a952c97 100644 --- a/typescript/playground-common/src/shared/SettingsDialog.tsx +++ b/typescript/playground-common/src/shared/SettingsDialog.tsx @@ -112,12 +112,19 @@ const requiredButUnsetAtom = atom((get) => { ) }) +const requiredAndSetCountAtom = atom((get) => { + const envvars = get(envvarsAtom) + return get(runtimeRequiredEnvVarsAtom).filter((k) => + envvars.some(({ key, value }) => k === key && value && value.length > 0), + ).length +}) + type EnvVar = { key: string; value: string; type: 'baml' | 'tracing' | 'user' | 'config'; index: number | null } const EnvvarInput: React.FC<{ envvar: EnvVar }> = ({ envvar }) => { const [showEnvvarValues] = useAtom(showEnvvarValuesAtom) const setEnvKeyValue = useSetAtom(envKeyValuesAtom) return ( -
+
= ({ envvar }) => { export const ShowSettingsButton: React.FC<{ iconClassName: string }> = ({ iconClassName }) => { const setShowSettings = useSetAtom(showSettingsAtom) const requiredButUnset = useAtomValue(requiredButUnsetAtom) + const requiredAndSetCount = useAtomValue(requiredAndSetCountAtom) const requiredButUnsetCount = requiredButUnset.length if ((window as any).next?.version) { // dont run in nextjs return null } + useEffect(() => { + if (requiredAndSetCount === 0) { + // no env vars have been set at all pop up the dialog + setShowSettings(true) + } + }, [requiredAndSetCount]) + const button = (