From 96ff86a62711ee4380c47665b053ae2bd775b9fc Mon Sep 17 00:00:00 2001 From: NFish Date: Wed, 30 Apr 2025 16:34:56 +0800 Subject: [PATCH 1/2] fix: console page show error if click app card --- .../app/(appDetailLayout)/[appId]/layout-main.tsx | 13 +++---------- .../workflow-header/features-trigger.tsx | 14 +++----------- web/types/feature.ts | 2 -- 3 files changed, 6 insertions(+), 23 deletions(-) diff --git a/web/app/(commonLayout)/app/(appDetailLayout)/[appId]/layout-main.tsx b/web/app/(commonLayout)/app/(appDetailLayout)/[appId]/layout-main.tsx index 1434a81b55..0a2c764d89 100644 --- a/web/app/(commonLayout)/app/(appDetailLayout)/[appId]/layout-main.tsx +++ b/web/app/(commonLayout)/app/(appDetailLayout)/[appId]/layout-main.tsx @@ -15,14 +15,13 @@ import { } from '@remixicon/react' import { useTranslation } from 'react-i18next' import { useShallow } from 'zustand/react/shallow' -import { useContextSelector } from 'use-context-selector' import s from './style.module.css' import cn from '@/utils/classnames' import { useStore } from '@/app/components/app/store' import AppSideBar from '@/app/components/app-sidebar' import type { NavIcon } from '@/app/components/app-sidebar/navLink' -import { fetchAppDetail, fetchAppSSO } from '@/service/apps' -import AppContext, { useAppContext } from '@/context/app-context' +import { fetchAppDetail } from '@/service/apps' +import { useAppContext } from '@/context/app-context' import Loading from '@/app/components/base/loading' import useBreakpoints, { MediaType } from '@/hooks/use-breakpoints' import type { App } from '@/types/app' @@ -56,7 +55,6 @@ const AppDetailLayout: FC = (props) => { icon: NavIcon selectedIcon: NavIcon }>>([]) - const systemFeatures = useContextSelector(AppContext, state => state.systemFeatures) const getNavigations = useCallback((appId: string, isCurrentWorkspaceEditor: boolean, mode: string) => { const navs = [ @@ -142,14 +140,9 @@ const AppDetailLayout: FC = (props) => { else { setAppDetail({ ...res, enable_sso: false }) setNavigation(getNavigations(appId, isCurrentWorkspaceEditor, res.mode)) - if (systemFeatures.enable_web_sso_switch_component && canIEditApp) { - fetchAppSSO({ appId }).then((ssoRes) => { - setAppDetail({ ...res, enable_sso: ssoRes.enabled }) - }) - } } // eslint-disable-next-line react-hooks/exhaustive-deps - }, [appDetailRes, isCurrentWorkspaceEditor, isLoadingAppDetail, isLoadingCurrentWorkspace, systemFeatures.enable_web_sso_switch_component]) + }, [appDetailRes, isCurrentWorkspaceEditor, isLoadingAppDetail, isLoadingCurrentWorkspace]) useUnmount(() => { setAppDetail() diff --git a/web/app/components/workflow-app/components/workflow-header/features-trigger.tsx b/web/app/components/workflow-app/components/workflow-header/features-trigger.tsx index da64409090..f183dd9545 100644 --- a/web/app/components/workflow-app/components/workflow-header/features-trigger.tsx +++ b/web/app/components/workflow-app/components/workflow-header/features-trigger.tsx @@ -26,9 +26,8 @@ import type { StartNodeType } from '@/app/components/workflow/nodes/start/types' import { useToastContext } from '@/app/components/base/toast' import { usePublishWorkflow, useResetWorkflowVersionHistory } from '@/service/use-workflow' import type { PublishWorkflowParams } from '@/types/workflow' -import { fetchAppDetail, fetchAppSSO } from '@/service/apps' +import { fetchAppDetail } from '@/service/apps' import { useStore as useAppStore } from '@/app/components/app/store' -import { useSelector as useAppSelector } from '@/context/app-context' const FeaturesTrigger = () => { const { t } = useTranslation() @@ -36,7 +35,6 @@ const FeaturesTrigger = () => { const appDetail = useAppStore(s => s.appDetail) const appID = appDetail?.id const setAppDetail = useAppStore(s => s.setAppDetail) - const systemFeatures = useAppSelector(state => state.systemFeatures) const { nodesReadOnly, getNodesReadOnly, @@ -85,18 +83,12 @@ const FeaturesTrigger = () => { const updateAppDetail = useCallback(async () => { try { const res = await fetchAppDetail({ url: '/apps', id: appID! }) - if (systemFeatures.enable_web_sso_switch_component) { - const ssoRes = await fetchAppSSO({ appId: appID! }) - setAppDetail({ ...res, enable_sso: ssoRes.enabled }) - } - else { - setAppDetail({ ...res }) - } + setAppDetail({ ...res }) } catch (error) { console.error(error) } - }, [appID, setAppDetail, systemFeatures.enable_web_sso_switch_component]) + }, [appID, setAppDetail]) const { mutateAsync: publishWorkflow } = usePublishWorkflow(appID!) const onPublish = useCallback(async (params?: PublishWorkflowParams) => { if (await handleCheckBeforePublish()) { diff --git a/web/types/feature.ts b/web/types/feature.ts index cc75f999b3..cc945754b1 100644 --- a/web/types/feature.ts +++ b/web/types/feature.ts @@ -23,7 +23,6 @@ export type SystemFeatures = { sso_enforced_for_signin_protocol: SSOProtocol | '' sso_enforced_for_web: boolean sso_enforced_for_web_protocol: SSOProtocol | '' - enable_web_sso_switch_component: boolean enable_marketplace: boolean enable_email_code_login: boolean enable_email_password_login: boolean @@ -55,7 +54,6 @@ export const defaultSystemFeatures: SystemFeatures = { sso_enforced_for_signin_protocol: '', sso_enforced_for_web: false, sso_enforced_for_web_protocol: '', - enable_web_sso_switch_component: false, enable_marketplace: false, enable_email_code_login: false, enable_email_password_login: false, From 6de5172a7d1b39bed9c81fbd4630c3ab7c9fb1a3 Mon Sep 17 00:00:00 2001 From: NFish Date: Wed, 30 Apr 2025 16:41:38 +0800 Subject: [PATCH 2/2] fix: import systemFeatures from useGlobalPublicStore --- .../header/account-setting/model-provider-page/index.tsx | 4 ++-- web/app/components/plugins/plugin-page/context.tsx | 4 ++-- web/app/components/plugins/plugin-page/empty/index.tsx | 4 ++-- web/app/components/plugins/plugin-page/index.tsx | 4 ++-- .../plugins/plugin-page/install-plugin-dropdown.tsx | 4 ++-- web/app/components/plugins/plugin-page/use-permission.ts | 4 ++-- web/app/components/workflow/block-selector/all-tools.tsx | 4 ++-- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/web/app/components/header/account-setting/model-provider-page/index.tsx b/web/app/components/header/account-setting/model-provider-page/index.tsx index 7c4e2eac3c..4aa98daf66 100644 --- a/web/app/components/header/account-setting/model-provider-page/index.tsx +++ b/web/app/components/header/account-setting/model-provider-page/index.tsx @@ -23,7 +23,7 @@ import { import InstallFromMarketplace from './install-from-marketplace' import { useProviderContext } from '@/context/provider-context' import cn from '@/utils/classnames' -import { useSelector as useAppContextSelector } from '@/context/app-context' +import { useGlobalPublicStore } from '@/context/global-public-context' type Props = { searchText: string @@ -40,7 +40,7 @@ const ModelProviderPage = ({ searchText }: Props) => { const { data: speech2textDefaultModel } = useDefaultModel(ModelTypeEnum.speech2text) const { data: ttsDefaultModel } = useDefaultModel(ModelTypeEnum.tts) const { modelProviders: providers } = useProviderContext() - const { enable_marketplace } = useAppContextSelector(s => s.systemFeatures) + const { enable_marketplace } = useGlobalPublicStore(s => s.systemFeatures) const defaultModelNotConfigured = !textGenerationDefaultModel && !embeddingsDefaultModel && !speech2textDefaultModel && !rerankDefaultModel && !ttsDefaultModel const [configuredProviders, notConfiguredProviders] = useMemo(() => { const configuredProviders: ModelProvider[] = [] diff --git a/web/app/components/plugins/plugin-page/context.tsx b/web/app/components/plugins/plugin-page/context.tsx index ae1ad7d053..52efbb263e 100644 --- a/web/app/components/plugins/plugin-page/context.tsx +++ b/web/app/components/plugins/plugin-page/context.tsx @@ -10,11 +10,11 @@ import { createContext, useContextSelector, } from 'use-context-selector' -import { useSelector as useAppContextSelector } from '@/context/app-context' import type { FilterState } from './filter-management' import { useTabSearchParams } from '@/hooks/use-tab-searchparams' import { noop } from 'lodash-es' import { PLUGIN_PAGE_TABS_MAP, usePluginPageTabs } from '../hooks' +import { useGlobalPublicStore } from '@/context/global-public-context' export type PluginPageContextValue = { containerRef: React.RefObject @@ -61,7 +61,7 @@ export const PluginPageContextProvider = ({ }) const [currentPluginID, setCurrentPluginID] = useState() - const { enable_marketplace } = useAppContextSelector(s => s.systemFeatures) + const { enable_marketplace } = useGlobalPublicStore(s => s.systemFeatures) const tabs = usePluginPageTabs() const options = useMemo(() => { return enable_marketplace ? tabs : tabs.filter(tab => tab.value !== PLUGIN_PAGE_TABS_MAP.marketplace) diff --git a/web/app/components/plugins/plugin-page/empty/index.tsx b/web/app/components/plugins/plugin-page/empty/index.tsx index 7fee823c02..e07c0761bb 100644 --- a/web/app/components/plugins/plugin-page/empty/index.tsx +++ b/web/app/components/plugins/plugin-page/empty/index.tsx @@ -6,19 +6,19 @@ import InstallFromGitHub from '@/app/components/plugins/install-plugin/install-f import InstallFromLocalPackage from '@/app/components/plugins/install-plugin/install-from-local-package' import { usePluginPageContext } from '../context' import { Group } from '@/app/components/base/icons/src/vender/other' -import { useSelector as useAppContextSelector } from '@/context/app-context' import Line from '../../marketplace/empty/line' import { useInstalledPluginList } from '@/service/use-plugins' import { useTranslation } from 'react-i18next' import { SUPPORT_INSTALL_LOCAL_FILE_EXTENSIONS } from '@/config' import { noop } from 'lodash-es' +import { useGlobalPublicStore } from '@/context/global-public-context' const Empty = () => { const { t } = useTranslation() const fileInputRef = useRef(null) const [selectedAction, setSelectedAction] = useState(null) const [selectedFile, setSelectedFile] = useState(null) - const { enable_marketplace } = useAppContextSelector(s => s.systemFeatures) + const { enable_marketplace } = useGlobalPublicStore(s => s.systemFeatures) const setActiveTab = usePluginPageContext(v => v.setActiveTab) const handleFileChange = (event: React.ChangeEvent) => { diff --git a/web/app/components/plugins/plugin-page/index.tsx b/web/app/components/plugins/plugin-page/index.tsx index a4bc7a6e6c..6acc081dc1 100644 --- a/web/app/components/plugins/plugin-page/index.tsx +++ b/web/app/components/plugins/plugin-page/index.tsx @@ -25,7 +25,6 @@ import TabSlider from '@/app/components/base/tab-slider' import Tooltip from '@/app/components/base/tooltip' import cn from '@/utils/classnames' import PermissionSetModal from '@/app/components/plugins/permission-setting-modal/modal' -import { useSelector as useAppContextSelector } from '@/context/app-context' import InstallFromMarketplace from '../install-plugin/install-from-marketplace' import { useRouter, @@ -42,6 +41,7 @@ import I18n from '@/context/i18n' import { noop } from 'lodash-es' import { PLUGIN_TYPE_SEARCH_MAP } from '../marketplace/plugin-type-switch' import { PLUGIN_PAGE_TABS_MAP } from '../hooks' +import { useGlobalPublicStore } from '@/context/global-public-context' const PACKAGE_IDS_KEY = 'package-ids' const BUNDLE_INFO_KEY = 'bundle-info' @@ -136,7 +136,7 @@ const PluginPage = ({ const options = usePluginPageContext(v => v.options) const activeTab = usePluginPageContext(v => v.activeTab) const setActiveTab = usePluginPageContext(v => v.setActiveTab) - const { enable_marketplace } = useAppContextSelector(s => s.systemFeatures) + const { enable_marketplace } = useGlobalPublicStore(s => s.systemFeatures) const isPluginsTab = useMemo(() => activeTab === PLUGIN_PAGE_TABS_MAP.plugins, [activeTab]) const isExploringMarketplace = useMemo(() => { diff --git a/web/app/components/plugins/plugin-page/install-plugin-dropdown.tsx b/web/app/components/plugins/plugin-page/install-plugin-dropdown.tsx index 875cbd0ab2..abe4f9cb6a 100644 --- a/web/app/components/plugins/plugin-page/install-plugin-dropdown.tsx +++ b/web/app/components/plugins/plugin-page/install-plugin-dropdown.tsx @@ -14,10 +14,10 @@ import { PortalToFollowElemContent, PortalToFollowElemTrigger, } from '@/app/components/base/portal-to-follow-elem' -import { useSelector as useAppContextSelector } from '@/context/app-context' import { useTranslation } from 'react-i18next' import { SUPPORT_INSTALL_LOCAL_FILE_EXTENSIONS } from '@/config' import { noop } from 'lodash-es' +import { useGlobalPublicStore } from '@/context/global-public-context' type Props = { onSwitchToMarketplaceTab: () => void @@ -30,7 +30,7 @@ const InstallPluginDropdown = ({ const [isMenuOpen, setIsMenuOpen] = useState(false) const [selectedAction, setSelectedAction] = useState(null) const [selectedFile, setSelectedFile] = useState(null) - const { enable_marketplace } = useAppContextSelector(s => s.systemFeatures) + const { enable_marketplace } = useGlobalPublicStore(s => s.systemFeatures) const handleFileChange = (event: React.ChangeEvent) => { const file = event.target.files?.[0] diff --git a/web/app/components/plugins/plugin-page/use-permission.ts b/web/app/components/plugins/plugin-page/use-permission.ts index 93c96a8926..918813fb44 100644 --- a/web/app/components/plugins/plugin-page/use-permission.ts +++ b/web/app/components/plugins/plugin-page/use-permission.ts @@ -3,8 +3,8 @@ import { useAppContext } from '@/context/app-context' import Toast from '../../base/toast' import { useTranslation } from 'react-i18next' import { useInvalidatePermissions, useMutationPermissions, usePermissions } from '@/service/use-plugins' -import { useSelector as useAppContextSelector } from '@/context/app-context' import { useMemo } from 'react' +import { useGlobalPublicStore } from '@/context/global-public-context' const hasPermission = (permission: PermissionType | undefined, isAdmin: boolean) => { if (!permission) @@ -46,7 +46,7 @@ const usePermission = () => { } export const useCanInstallPluginFromMarketplace = () => { - const { enable_marketplace } = useAppContextSelector(s => s.systemFeatures) + const { enable_marketplace } = useGlobalPublicStore(s => s.systemFeatures) const { canManagement } = usePermission() const canInstallPluginFromMarketplace = useMemo(() => { diff --git a/web/app/components/workflow/block-selector/all-tools.tsx b/web/app/components/workflow/block-selector/all-tools.tsx index 3ad0a41d54..36831aee3c 100644 --- a/web/app/components/workflow/block-selector/all-tools.tsx +++ b/web/app/components/workflow/block-selector/all-tools.tsx @@ -21,7 +21,7 @@ import ActionButton from '../../base/action-button' import { RiAddLine } from '@remixicon/react' import { PluginType } from '../../plugins/types' import { useMarketplacePlugins } from '../../plugins/marketplace/hooks' -import { useSelector as useAppContextSelector } from '@/context/app-context' +import { useGlobalPublicStore } from '@/context/global-public-context' type AllToolsProps = { className?: string @@ -87,7 +87,7 @@ const AllTools = ({ plugins: notInstalledPlugins = [], } = useMarketplacePlugins() - const { enable_marketplace } = useAppContextSelector(s => s.systemFeatures) + const { enable_marketplace } = useGlobalPublicStore(s => s.systemFeatures) useEffect(() => { if (enable_marketplace) return