fix: address code review issues from appDetail migration

- app-info.tsx: use useInvalidateAppDetail hook instead of local queryClient call
- app-publisher.tsx: convert isAppAccessSet from useEffect+useState to useMemo
- Prune unused eslint suppressions
This commit is contained in:
yyh
2026-01-18 23:11:54 +08:00
parent 91856b09ca
commit b3acb74331
3 changed files with 10 additions and 23 deletions

View File

@ -11,7 +11,6 @@ import {
RiFileDownloadLine,
RiFileUploadLine,
} from '@remixicon/react'
import { useQueryClient } from '@tanstack/react-query'
import dynamic from 'next/dynamic'
import { useParams, useRouter } from 'next/navigation'
import * as React from 'react'
@ -26,7 +25,7 @@ import { NEED_REFRESH_APP_LIST_KEY } from '@/config'
import { useAppContext } from '@/context/app-context'
import { useProviderContext } from '@/context/provider-context'
import { copyApp, deleteApp, exportAppConfig, updateAppInfo } from '@/service/apps'
import { useAppDetail, useInvalidateAppList } from '@/service/use-apps'
import { useAppDetail, useInvalidateAppDetail, useInvalidateAppList } from '@/service/use-apps'
import { fetchWorkflowDraft } from '@/service/workflow'
import { AppModeEnum } from '@/types/app'
import { getRedirection } from '@/utils/app-redirection'
@ -65,9 +64,9 @@ const AppInfo = ({ expand, onlyShowDetail = false, openState = false, onDetailEx
const { notify } = useContext(ToastContext)
const { replace } = useRouter()
const { appId } = useParams()
const queryClient = useQueryClient()
const { onPlanInfoChanged } = useProviderContext()
const { data: appDetail } = useAppDetail(appId as string)
const invalidateAppDetail = useInvalidateAppDetail()
const invalidateAppList = useInvalidateAppList()
const [open, setOpen] = useState(openState)
const [showEditModal, setShowEditModal] = useState(false)
@ -78,10 +77,6 @@ const AppInfo = ({ expand, onlyShowDetail = false, openState = false, onDetailEx
const [secretEnvList, setSecretEnvList] = useState<EnvironmentVariable[]>([])
const [showExportWarning, setShowExportWarning] = useState(false)
const invalidateAppDetail = useCallback(() => {
queryClient.invalidateQueries({ queryKey: ['apps', 'detail', appId] })
}, [queryClient, appId])
const onEdit: CreateAppModalProps['onConfirm'] = useCallback(async ({
name,
icon_type,
@ -109,12 +104,12 @@ const AppInfo = ({ expand, onlyShowDetail = false, openState = false, onDetailEx
type: 'success',
message: t('editDone', { ns: 'app' }),
})
invalidateAppDetail()
invalidateAppDetail(appId as string)
}
catch {
notify({ type: 'error', message: t('editFailed', { ns: 'app' }) })
}
}, [appDetail, notify, invalidateAppDetail, t])
}, [appDetail, notify, invalidateAppDetail, appId, t])
const onCopy: DuplicateAppModalProps['onConfirm'] = async ({ name, icon_type, icon, icon_background }) => {
if (!appDetail)

View File

@ -144,7 +144,6 @@ const AppPublisher = ({
const [published, setPublished] = useState(false)
const [open, setOpen] = useState(false)
const [showAppAccessControl, setShowAppAccessControl] = useState(false)
const [isAppAccessSet, setIsAppAccessSet] = useState(true)
const [embeddingModalOpen, setEmbeddingModalOpen] = useState(false)
const { data: appDetail } = useAppDetail(appId as string)
@ -178,16 +177,12 @@ const AppPublisher = ({
refetch()
}, [open, appDetail, refetch, systemFeatures])
useEffect(() => {
if (appDetail && appAccessSubjects) {
if (appDetail.access_mode === AccessMode.SPECIFIC_GROUPS_MEMBERS && appAccessSubjects.groups?.length === 0 && appAccessSubjects.members?.length === 0)
setIsAppAccessSet(false)
else
setIsAppAccessSet(true)
}
else {
setIsAppAccessSet(true)
}
const isAppAccessSet = useMemo(() => {
if (!appDetail || !appAccessSubjects)
return true
if (appDetail.access_mode === AccessMode.SPECIFIC_GROUPS_MEMBERS && appAccessSubjects.groups?.length === 0 && appAccessSubjects.members?.length === 0)
return false
return true
}, [appAccessSubjects, appDetail])
const handlePublish = useCallback(async (params?: ModelAndParameter | PublishWorkflowParams) => {

View File

@ -253,9 +253,6 @@
}
},
"app/components/app/app-publisher/index.tsx": {
"react-hooks-extra/no-direct-set-state-in-use-effect": {
"count": 3
},
"ts/no-explicit-any": {
"count": 6
}