Skip to content

Commit 9968398

Browse files
committed
feat(marketplace): add batch plugin selection
1 parent 3d0e23c commit 9968398

10 files changed

Lines changed: 331 additions & 50 deletions

File tree

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import { Box, Button, Checkbox, Flex } from '@chakra-ui/react';
2+
import { useTranslation } from 'next-i18next';
3+
import MyTooltip from '../../../common/MyTooltip';
4+
5+
type BatchOperationBarProps = {
6+
selectedCount: number;
7+
isAllSelected: boolean;
8+
isIndeterminate?: boolean;
9+
actionLabel: string;
10+
onToggleSelectAll: () => void;
11+
onAction: () => void | Promise<void>;
12+
isActionLoading?: boolean;
13+
isActionDisabled?: boolean;
14+
};
15+
16+
/**
17+
* 插件市场卡片批量选择后的固定操作栏。
18+
* 只负责呈现选择计数、全选入口和当前页面注入的批量动作。
19+
*/
20+
const BatchOperationBar = ({
21+
selectedCount,
22+
isAllSelected,
23+
isIndeterminate,
24+
actionLabel,
25+
onToggleSelectAll,
26+
onAction,
27+
isActionLoading,
28+
isActionDisabled
29+
}: BatchOperationBarProps) => {
30+
const { t } = useTranslation();
31+
32+
return (
33+
<Flex
34+
position={'absolute'}
35+
left={0}
36+
right={0}
37+
bottom={0}
38+
zIndex={20}
39+
h={'64px'}
40+
px={8}
41+
alignItems={'center'}
42+
gap={6}
43+
borderTop={'1px solid'}
44+
borderColor={'myGray.200'}
45+
bg={'rgba(255,255,255,0.96)'}
46+
backdropFilter={'blur(8px)'}
47+
boxShadow={'0 -4px 12px rgba(19, 51, 107, 0.06)'}
48+
>
49+
<Flex alignItems={'center'} gap={2}>
50+
<MyTooltip label={t('common:Select_all')}>
51+
<Checkbox
52+
size={'lg'}
53+
isChecked={isAllSelected}
54+
isIndeterminate={isIndeterminate}
55+
onChange={onToggleSelectAll}
56+
/>
57+
</MyTooltip>
58+
<Box fontSize={'sm'} color={'myGray.700'}>
59+
{t('common:select_count_num', { num: selectedCount })}
60+
</Box>
61+
</Flex>
62+
<Button
63+
size={'sm'}
64+
variant={'primary'}
65+
isLoading={isActionLoading}
66+
isDisabled={isActionDisabled}
67+
onClick={onAction}
68+
>
69+
{actionLabel}
70+
</Button>
71+
</Flex>
72+
);
73+
};
74+
75+
export default BatchOperationBar;

packages/web/components/core/plugin/tool/ToolCard.tsx

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Box, Button, Flex, HStack } from '@chakra-ui/react';
1+
import { Box, Button, Checkbox, Flex, HStack } from '@chakra-ui/react';
22
import Avatar from '../../../common/Avatar';
33
import MyBox from '../../../common/MyBox';
44
import React, { useMemo, useRef, useState, useEffect } from 'react';
@@ -46,7 +46,10 @@ const ToolCard = ({
4646
onUpdate,
4747
onClickCard,
4848
showActionButton = true,
49-
variant = 'default'
49+
variant = 'default',
50+
showSelectCheckbox = false,
51+
isSelected = false,
52+
onToggleSelect
5053
}: {
5154
item: ToolCardItemType;
5255
systemTitle?: string;
@@ -59,6 +62,9 @@ const ToolCard = ({
5962
onClickCard?: () => void;
6063
showActionButton?: boolean;
6164
variant?: 'default' | 'marketplace';
65+
showSelectCheckbox?: boolean;
66+
isSelected?: boolean;
67+
onToggleSelect?: () => void;
6268
}) => {
6369
const { t, i18n } = useTranslation();
6470
const tagsContainerRef = useRef<HTMLDivElement>(null);
@@ -143,6 +149,8 @@ const ToolCard = ({
143149
}
144150
}, [isMarketplaceVariant, item.installed, item.status, mode, t]);
145151

152+
const hasSelectCheckbox = !!onToggleSelect;
153+
146154
return (
147155
<MyBox
148156
key={item.id}
@@ -192,16 +200,57 @@ const ToolCard = ({
192200
: {}),
193201
'& .download-count': {
194202
display: 'none'
195-
}
203+
},
204+
...(hasSelectCheckbox
205+
? {
206+
'& .tool-card-select-checkbox': {
207+
display: 'flex'
208+
}
209+
}
210+
: {})
196211
}}
197212
>
213+
{hasSelectCheckbox && (
214+
<Flex
215+
className="tool-card-select-checkbox"
216+
position={'absolute'}
217+
top={isMarketplaceVariant ? '17px' : 4}
218+
right={isMarketplaceVariant ? '17px' : 4}
219+
zIndex={2}
220+
display={showSelectCheckbox || isSelected ? 'flex' : 'none'}
221+
alignItems={'center'}
222+
justifyContent={'center'}
223+
bg={'white'}
224+
borderRadius={'4px'}
225+
onClick={(e) => {
226+
e.stopPropagation();
227+
}}
228+
>
229+
<Checkbox
230+
isChecked={isSelected}
231+
onChange={(e) => {
232+
e.stopPropagation();
233+
onToggleSelect?.();
234+
}}
235+
/>
236+
</Flex>
237+
)}
238+
198239
{/* Update badge in top-right corner */}
199240
{item.update && mode === 'admin' && !item.isDebug && (
200241
<Flex
201242
alignItems="center"
202243
position={'absolute'}
203244
top={isMarketplaceVariant ? '17px' : 4}
204-
right={isMarketplaceVariant ? '17px' : 4}
245+
right={
246+
hasSelectCheckbox
247+
? isMarketplaceVariant
248+
? '45px'
249+
: 12
250+
: isMarketplaceVariant
251+
? '17px'
252+
: 4
253+
}
205254
px={2}
206255
py={0.5}
207256
bg={'rgb(255, 247, 237)'}

packages/web/i18n/en/app.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,8 @@
401401
"toolkit_add_resource": "Add resources",
402402
"toolkit_basic_config": "Basic Configuration",
403403
"toolkit_basic_info": "Basic Info",
404+
"toolkit_batch_install": "Batch Install",
405+
"toolkit_batch_install_update": "Batch Install/Update",
404406
"toolkit_batch_update": "Batch Update",
405407
"toolkit_call_points_label": "Call Points",
406408
"toolkit_community": "Community",

packages/web/i18n/zh-CN/app.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,8 @@
401401
"toolkit_add_resource": "添加插件",
402402
"toolkit_basic_config": "基础配置",
403403
"toolkit_basic_info": "基础信息",
404+
"toolkit_batch_install": "批量安装",
405+
"toolkit_batch_install_update": "批量安装/更新",
404406
"toolkit_batch_update": "批量更新",
405407
"toolkit_call_points_label": "调用积分",
406408
"toolkit_community": "社区",

packages/web/i18n/zh-Hant/app.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,8 @@
391391
"toolkit_add_resource": "添加資源",
392392
"toolkit_basic_config": "基礎配置",
393393
"toolkit_basic_info": "基礎資訊",
394+
"toolkit_batch_install": "批次安裝",
395+
"toolkit_batch_install_update": "批次安裝/更新",
394396
"toolkit_batch_update": "批次更新",
395397
"toolkit_call_points_label": "調用積分",
396398
"toolkit_community": "社區",

0 commit comments

Comments
 (0)