Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

refactor(web): migrate workflow featured collapsed storage (#36918)

Myshkin4512257a4f1efba
diff --git a/eslint-suppressions.json b/eslint-suppressions.json
index bbc7eb7f505..fd2418701e5 100644
--- a/eslint-suppressions.json
+++ b/eslint-suppressions.json
@@ -3413,16 +3413,6 @@
"count": 1
}
},
- "web/app/components/workflow/block-selector/featured-tools.tsx": {
- "no-restricted-properties": {
- "count": 2
- }
- },
- "web/app/components/workflow/block-selector/featured-triggers.tsx": {
- "no-restricted-properties": {
- "count": 2
- }
- },
"web/app/components/workflow/block-selector/hooks.ts": {
"react/set-state-in-effect": {
"count": 1
diff --git a/web/app/components/workflow/block-selector/featured-tools.tsx b/web/app/components/workflow/block-selector/featured-tools.tsx
index 652399edf92..82a8637cd20 100644
--- a/web/app/components/workflow/block-selector/featured-tools.tsx
+++ b/web/app/components/workflow/block-selector/featured-tools.tsx
@@ -13,8 +13,8 @@ import Loading from '@/app/components/base/loading'
import InstallFromMarketplace from '@/app/components/plugins/install-plugin/install-from-marketplace'
import Action from '@/app/components/workflow/block-selector/market-place-plugin/action'
import { useGetLanguage } from '@/context/i18n'
+import { useLocalStorage } from '@/hooks/use-local-storage'
import Link from '@/next/link'
-import { isServer } from '@/utils/client'
import { formatNumber } from '@/utils/format'
import { getMarketplaceUrl } from '@/utils/var'
import BlockIcon from '../block-icon'
@@ -55,18 +55,7 @@ const FeaturedTools = ({
const previewCardHandle = useMemo(() => createPreviewCardHandle<FeaturedToolPreviewPayload>(), [])
const [visibleCount, setVisibleCount] = useState(INITIAL_VISIBLE_COUNT)
const [visibleCountPlugins, setVisibleCountPlugins] = useState(plugins)
- const [isCollapsed, setIsCollapsed] = useState<boolean>(() => {
- if (isServer)
- return false
- const stored = window.localStorage.getItem(STORAGE_KEY)
- return stored === 'true'
- })
-
- useEffect(() => {
- if (isServer)
- return
- window.localStorage.setItem(STORAGE_KEY, String(isCollapsed))
- }, [isCollapsed])
+ const [isCollapsed, setIsCollapsed] = useLocalStorage<boolean>(STORAGE_KEY, false)
if (visibleCountPlugins !== plugins) {
setVisibleCountPlugins(plugins)
diff --git a/web/app/components/workflow/block-selector/featured-triggers.tsx b/web/app/components/workflow/block-selector/featured-triggers.tsx
index bf04efd076a..8dec59d8cc8 100644
--- a/web/app/components/workflow/block-selector/featured-triggers.tsx
+++ b/web/app/components/workflow/block-selector/featured-triggers.tsx
@@ -13,8 +13,8 @@ import Loading from '@/app/components/base/loading'
import InstallFromMarketplace from '@/app/components/plugins/install-plugin/install-from-marketplace'
import Action from '@/app/components/workflow/block-selector/market-place-plugin/action'
import { useGetLanguage } from '@/context/i18n'
+import { useLocalStorage } from '@/hooks/use-local-storage'
import Link from '@/next/link'
-import { isServer } from '@/utils/client'
import { formatNumber } from '@/utils/format'
import { getMarketplaceUrl } from '@/utils/var'
import BlockIcon from '../block-icon'
@@ -53,18 +53,7 @@ const FeaturedTriggers = ({
const triggerActionPreviewCardHandle = useMemo(() => createPreviewCardHandle<TriggerPluginActionPreviewPayload>(), [])
const [visibleCount, setVisibleCount] = useState(INITIAL_VISIBLE_COUNT)
const [visibleCountPlugins, setVisibleCountPlugins] = useState(plugins)
- const [isCollapsed, setIsCollapsed] = useState<boolean>(() => {
- if (isServer)
- return false
- const stored = window.localStorage.getItem(STORAGE_KEY)
- return stored === 'true'
- })
-
- useEffect(() => {
- if (isServer)
- return
- window.localStorage.setItem(STORAGE_KEY, String(isCollapsed))
- }, [isCollapsed])
+ const [isCollapsed, setIsCollapsed] = useLocalStorage<boolean>(STORAGE_KEY, false)
if (visibleCountPlugins !== plugins) {
setVisibleCountPlugins(plugins)