From 90240cb6dbef5422113677ca779a1f683b484679 Mon Sep 17 00:00:00 2001 From: Harry Date: Sun, 12 Oct 2025 23:56:27 +0800 Subject: [PATCH] refactor(subscription): optimize subscription count handling in list view - Replaced direct length checks on subscriptions with a computed subscriptionCount variable for improved readability and performance. - Updated the CreateSubscriptionButton to conditionally render based on the new subscriptionCount variable, enhancing clarity in the component logic. - Adjusted className logic for the button to account for multiple supported methods, ensuring better user experience. --- .../subscription-list/create/index.tsx | 2 +- .../plugin-detail-panel/subscription-list/list-view.tsx | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/web/app/components/plugins/plugin-detail-panel/subscription-list/create/index.tsx b/web/app/components/plugins/plugin-detail-panel/subscription-list/create/index.tsx index 81b76539ab..814905cc3b 100644 --- a/web/app/components/plugins/plugin-detail-panel/subscription-list/create/index.tsx +++ b/web/app/components/plugins/plugin-detail-panel/subscription-list/create/index.tsx @@ -146,7 +146,7 @@ export const CreateSubscriptionButton = ({ buttonType = CreateButtonType.FULL_BU triggerPopupSameWidth: buttonType === CreateButtonType.FULL_BUTTON, }} triggerProps={{ - className: cn('h-8 bg-transparent px-0 hover:bg-transparent', methodType !== DEFAULT_METHOD && 'pointer-events-none', buttonType === CreateButtonType.FULL_BUTTON && 'grow'), + className: cn('h-8 bg-transparent px-0 hover:bg-transparent', methodType !== DEFAULT_METHOD && supportedMethods.length > 1 && 'pointer-events-none', buttonType === CreateButtonType.FULL_BUTTON && 'grow'), }} popupProps={{ wrapperClassName: 'z-[1000]', diff --git a/web/app/components/plugins/plugin-detail-panel/subscription-list/list-view.tsx b/web/app/components/plugins/plugin-detail-panel/subscription-list/list-view.tsx index 5ca2e2bb36..dc26a2a97e 100644 --- a/web/app/components/plugins/plugin-detail-panel/subscription-list/list-view.tsx +++ b/web/app/components/plugins/plugin-detail-panel/subscription-list/list-view.tsx @@ -29,24 +29,25 @@ export const SubscriptionListView: React.FC = ({ ) } + const subscriptionCount = subscriptions?.length || 0 return (
- {subscriptions?.length && ( + {subscriptionCount > 0 && (
- {t('pluginTrigger.subscription.listNum', { num: subscriptions?.length || 0 })} + {t('pluginTrigger.subscription.listNum', { num: subscriptionCount })}
)} 0 ? CreateButtonType.ICON_BUTTON : CreateButtonType.FULL_BUTTON} />
- {subscriptions?.length && ( + {subscriptionCount > 0 && (
{subscriptions?.map(subscription => (