From b9fa52aea8686f8095878e7f210c2d937b533c63 Mon Sep 17 00:00:00 2001 From: aaronvg Date: Mon, 14 Oct 2024 11:48:58 -0700 Subject: [PATCH] Popup settings dialog when no env vars set (#1033) > [!IMPORTANT] > Automatically show settings dialog if no environment variables are set, with UI adjustments in `SettingsDialog.tsx`. > > - **Behavior**: > - Automatically shows settings dialog if no environment variables are set using `requiredAndSetCountAtom` in `SettingsDialog.tsx`. > - **Atoms**: > - Adds `requiredAndSetCountAtom` to count set environment variables in `SettingsDialog.tsx`. > - **UI Adjustments**: > - Adjusts flexbox properties in `EnvvarInput` and `SettingsDialog` components for better alignment. > - Updates tooltip message logic in `ShowSettingsButton` for unset environment variables. > > This description was created by [Ellipsis](https://www.ellipsis.dev?ref=BoundaryML%2Fbaml&utm_source=github&utm_medium=referral) for d6cbef865da04b3fab7676138903429565da2c19. It will automatically update as commits are pushed. --- .../src/shared/SettingsDialog.tsx | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) 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 = (