From 72ff6d3a58fc5dfe50cfedb1d54356c0d5594f5a Mon Sep 17 00:00:00 2001 From: Mike Fortman Date: Tue, 30 Jul 2024 16:19:05 -0500 Subject: [PATCH] feat: create Frontend feature flags (#3029) * Add UI feature flag config * [autofix.ci] apply automated fixes * hide general settings if there is nothing to show * make sure to handle !autoLogin case * [autofix.ci] apply automated fixes * missed commit * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: anovazzi1 --- src/frontend/feature-config.json | 6 +++ .../src/components/chatComponent/index.tsx | 53 ++++++++++--------- .../src/components/headerComponent/index.tsx | 48 +++++++++++------ src/frontend/src/pages/SettingsPage/index.tsx | 28 ++++++++-- .../SettingsPage/pages/GeneralPage/index.tsx | 17 +++--- src/frontend/src/routes.tsx | 24 ++++++++- src/frontend/src/stores/storeStore.ts | 5 +- 7 files changed, 127 insertions(+), 54 deletions(-) create mode 100644 src/frontend/feature-config.json diff --git a/src/frontend/feature-config.json b/src/frontend/feature-config.json new file mode 100644 index 00000000000..0100b3ffbee --- /dev/null +++ b/src/frontend/feature-config.json @@ -0,0 +1,6 @@ +{ + "ENABLE_DARK_MODE": true, + "ENABLE_API": true, + "ENABLE_LANGFLOW_STORE": true, + "ENABLE_PROFILE_ICONS": true +} \ No newline at end of file diff --git a/src/frontend/src/components/chatComponent/index.tsx b/src/frontend/src/components/chatComponent/index.tsx index fd2c7a0802b..cf4ea95e241 100644 --- a/src/frontend/src/components/chatComponent/index.tsx +++ b/src/frontend/src/components/chatComponent/index.tsx @@ -1,3 +1,4 @@ +import FeatureFlags from "@/../feature-config.json"; import { Transition } from "@headlessui/react"; import { useMemo, useRef, useState } from "react"; import { useHotkeys } from "react-hotkeys-hook"; @@ -140,30 +141,34 @@ export default function FlowToolbar(): JSX.Element {
-
- {currentFlow && currentFlow.data && ( - -
- - API -
-
- )} -
-
- -
+ {FeatureFlags.ENABLE_API && ( + <> +
+ {currentFlow && currentFlow.data && ( + +
+ + API +
+
+ )} +
+
+ +
+ + )}
- + {FeatureFlags.ENABLE_DARK_MODE && ( + + )}
{notificationCenter && ( @@ -216,10 +225,17 @@ export default function Header(): JSX.Element { data-testid="user-profile-settings" className="shrink-0" > - + {FeatureFlags.ENABLE_PROFILE_ICONS ? ( + + ) : ( + + )} diff --git a/src/frontend/src/pages/SettingsPage/index.tsx b/src/frontend/src/pages/SettingsPage/index.tsx index 2e8f49cfc46..bb08417d4d6 100644 --- a/src/frontend/src/pages/SettingsPage/index.tsx +++ b/src/frontend/src/pages/SettingsPage/index.tsx @@ -1,3 +1,6 @@ +import FeatureFlags from "@/../feature-config.json"; +import useAuthStore from "@/stores/authStore"; +import { useStoreStore } from "@/stores/storeStore"; import { useEffect } from "react"; import { Outlet } from "react-router-dom"; import ForwardedIconComponent from "../../components/genericIconComponent"; @@ -10,12 +13,26 @@ export default function SettingsPage(): JSX.Element { const setCurrentFlowId = useFlowsManagerStore( (state) => state.setCurrentFlowId, ); + + const autoLogin = useAuthStore((state) => state.autoLogin); + const hasStore = useStoreStore((state) => state.hasStore); + + // Hides the General settings if there is nothing to show + const showGeneralSettings = + FeatureFlags.ENABLE_PROFILE_ICONS || hasStore || !autoLogin; + useEffect(() => { setCurrentFlowId(""); }, [pathname]); - const sidebarNavItems = [ - { + const sidebarNavItems: { + href?: string; + title: string; + icon: React.ReactNode; + }[] = []; + + if (showGeneralSettings) { + sidebarNavItems.push({ title: "General", href: "/settings/general", icon: ( @@ -24,7 +41,10 @@ export default function SettingsPage(): JSX.Element { className="w-4 flex-shrink-0 justify-start stroke-[1.5]" /> ), - }, + }); + } + + sidebarNavItems.push( { title: "Global Variables", href: "/settings/global-variables", @@ -65,7 +85,7 @@ export default function SettingsPage(): JSX.Element { /> ), }, - ]; + ); return ( {
- + {FeatureFlags.ENABLE_PROFILE_ICONS && ( + + )} {!autoLogin && ( import("./pages/StorePage")); const ViewPage = lazy(() => import("./pages/ViewPage")); const Router = () => { + const autoLogin = useAuthStore((state) => state.autoLogin); + const hasStore = useStoreStore((state) => state.hasStore); + + // Hides the General settings if there is nothing to show + const showGeneralSettings = + FeatureFlags.ENABLE_PROFILE_ICONS || hasStore || !autoLogin; + return ( { } > - } /> + + } + /> } /> } /> - } /> + {showGeneralSettings && ( + } /> + )} } /> } /> diff --git a/src/frontend/src/stores/storeStore.ts b/src/frontend/src/stores/storeStore.ts index f27af5e69fe..aadc40141cd 100644 --- a/src/frontend/src/stores/storeStore.ts +++ b/src/frontend/src/stores/storeStore.ts @@ -1,3 +1,4 @@ +import FeatureFlags from "@/../feature-config.json"; import { create } from "zustand"; import { checkHasApiKey, checkHasStore } from "../controllers/API"; import { StoreStoreType } from "../types/zustand/store"; @@ -9,7 +10,9 @@ export const useStoreStore = create((set) => ({ loadingApiKey: true, checkHasStore: () => { checkHasStore().then((res) => { - set({ hasStore: res?.enabled ?? false }); + set({ + hasStore: FeatureFlags.ENABLE_LANGFLOW_STORE && (res?.enabled ?? false), + }); }); }, updateValidApiKey: (validApiKey) => set(() => ({ validApiKey: validApiKey })),