From b682591c7a7318eb0bad5040b5497c3ee7a32ca1 Mon Sep 17 00:00:00 2001 From: lmlm Date: Tue, 2 Jun 2026 18:28:50 +0800 Subject: [PATCH] refactor(web): migrate question classifier label hint storage (#36932) Co-authored-by: lmlm <7487674+popsiclelmlm@users.noreply.github.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> --- eslint-suppressions.json | 5 ----- .../components/class-list.tsx | 21 ++++--------------- 2 files changed, 4 insertions(+), 22 deletions(-) diff --git a/eslint-suppressions.json b/eslint-suppressions.json index 3d4323a096..100e36e2f0 100644 --- a/eslint-suppressions.json +++ b/eslint-suppressions.json @@ -4397,11 +4397,6 @@ "count": 9 } }, - "web/app/components/workflow/nodes/question-classifier/components/class-list.tsx": { - "no-restricted-properties": { - "count": 2 - } - }, "web/app/components/workflow/nodes/question-classifier/use-single-run-form-params.ts": { "ts/no-explicit-any": { "count": 8 diff --git a/web/app/components/workflow/nodes/question-classifier/components/class-list.tsx b/web/app/components/workflow/nodes/question-classifier/components/class-list.tsx index bb6341ae5f..ef7764a106 100644 --- a/web/app/components/workflow/nodes/question-classifier/components/class-list.tsx +++ b/web/app/components/workflow/nodes/question-classifier/components/class-list.tsx @@ -11,6 +11,7 @@ import { useCallback, useEffect, useRef, useState } from 'react' import { useTranslation } from 'react-i18next' import { ReactSortable } from 'react-sortablejs' import { ArrowDownRoundFill } from '@/app/components/base/icons/src/vender/solid/general' +import { useLocalStorage } from '@/hooks/use-local-storage' import { useEdgesInteractions } from '../../../hooks' import AddButton from '../../_base/components/add-button' import Item from './class-item' @@ -42,17 +43,8 @@ const ClassList: FC = ({ const [shouldScrollToEnd, setShouldScrollToEnd] = useState(false) const prevListLength = useRef(list.length) const [collapsed, setCollapsed] = useState(false) - const [isRenameHintDismissed, setIsRenameHintDismissed] = useState(() => { - if (typeof window === 'undefined') - return true - - try { - return window.localStorage.getItem(INLINE_LABEL_HINT_STORAGE_KEY) === 'true' - } - catch { - return false - } - }) + const [storedRenameHintDismissed, setIsRenameHintDismissed] = useLocalStorage(INLINE_LABEL_HINT_STORAGE_KEY) + const isRenameHintDismissed = storedRenameHintDismissed ?? false const handleClassChange = useCallback((index: number) => { return (value: Topic) => { @@ -104,12 +96,7 @@ const ClassList: FC = ({ return setIsRenameHintDismissed(true) - try { - window.localStorage.setItem(INLINE_LABEL_HINT_STORAGE_KEY, 'true') - } - catch { - } - }, [isRenameHintDismissed]) + }, [isRenameHintDismissed, setIsRenameHintDismissed]) const shouldShowRenameHint = !readonly && !isRenameHintDismissed && list.some((item, index) => { return isDefaultClassLabel(item.label, index + 1, t)