Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

fix: resource problem (#11519)

René Wangad7961f9befb
diff --git a/src/app/[variants]/(main)/resource/features/DndContextWrapper.tsx b/src/app/[variants]/(main)/resource/features/DndContextWrapper.tsx
index fd713ff3d90..2571f280e36 100644
--- a/src/app/[variants]/(main)/resource/features/DndContextWrapper.tsx
+++ b/src/app/[variants]/(main)/resource/features/DndContextWrapper.tsx
@@ -193,14 +193,16 @@ export const DndContextWrapper = memo<PropsWithChildren>(({ children }) => {
document.addEventListener('dragstart', handleDragStart);
document.addEventListener('drag', handleDrag);
- document.addEventListener('drop', handleDrop);
+ // Use capture phase so drops still work even if some UI stops propagation
+ // (e.g., header dropdowns / menus).
+ document.addEventListener('drop', handleDrop, true);
document.addEventListener('dragover', handleDragOver);
document.addEventListener('dragend', handleDragEnd);
return () => {
document.removeEventListener('dragstart', handleDragStart);
document.removeEventListener('drag', handleDrag);
- document.removeEventListener('drop', handleDrop);
+ document.removeEventListener('drop', handleDrop, true);
document.removeEventListener('dragover', handleDragOver);
document.removeEventListener('dragend', handleDragEnd);
};
diff --git a/src/app/[variants]/(main)/resource/library/_layout/Header/LibraryHead.tsx b/src/app/[variants]/(main)/resource/library/_layout/Header/LibraryHead.tsx
index a410cce6420..3ee2002f581 100644
--- a/src/app/[variants]/(main)/resource/library/_layout/Header/LibraryHead.tsx
+++ b/src/app/[variants]/(main)/resource/library/_layout/Header/LibraryHead.tsx
@@ -1,8 +1,16 @@
'use client';
-import { Center, type DropdownItem, DropdownMenu, Flexbox, Skeleton, Text } from '@lobehub/ui';
+import {
+ ActionIcon,
+ Block,
+ Center,
+ type DropdownItem,
+ DropdownMenu,
+ Skeleton,
+ Text,
+} from '@lobehub/ui';
import { createStaticStyles, cx } from 'antd-style';
-import { ChevronsUpDown } from 'lucide-react';
+import { ChevronsUpDownIcon } from 'lucide-react';
import { type DragEvent, memo, useCallback, useMemo, useState } from 'react';
import { useNavigate } from 'react-router-dom';
@@ -12,15 +20,6 @@ import RepoIcon from '@/components/LibIcon';
import { knowledgeBaseSelectors, useKnowledgeBaseStore } from '@/store/library';
const styles = createStaticStyles(({ css, cssVar }) => ({
- clickableHeader: css`
- cursor: pointer;
- border-radius: ${cssVar.borderRadius}px;
- transition: all 0.2s;
-
- &:hover {
- background-color: ${cssVar.colorFillTertiary};
- }
- `,
dropZoneActive: css`
color: ${cssVar.colorBgElevated} !important;
background-color: ${cssVar.colorText} !important;
@@ -29,14 +28,6 @@ const styles = createStaticStyles(({ css, cssVar }) => ({
color: ${cssVar.colorBgElevated} !important;
}
`,
- icon: css`
- color: ${cssVar.colorTextSecondary};
- transition: all 0.2s;
-
- &:hover {
- color: ${cssVar.colorText};
- }
- `,
menuIcon: css`
color: ${cssVar.colorTextTertiary};
`,
@@ -101,43 +92,47 @@ const Head = memo<{ id: string }>(({ id }) => {
}, [libraries, handleLibrarySwitch, id, styles.menuIcon]);
return (
- <Flexbox
+ <Block
align={'center'}
- className={cx(styles.clickableHeader, isDropZoneActive && styles.dropZoneActive)}
+ className={cx(isDropZoneActive && styles.dropZoneActive)}
+ clickable
data-drop-target-id="root"
data-is-folder="true"
data-root-drop="true"
gap={8}
horizontal
+ onClick={handleClick}
onDragLeave={handleDragLeave}
onDragOver={handleDragOver}
onDrop={handleDrop}
- paddingBlock={6}
- paddingInline={'12px 14px'}
+ padding={2}
+ style={{ minWidth: 32, overflow: 'hidden' }}
+ variant={'borderless'}
>
- <Center style={{ minWidth: 24 }} width={24}>
- <RepoIcon />
+ <Center style={{ minWidth: 32 }} width={32}>
+ <RepoIcon size={18} />
</Center>
{!name ? (
<Skeleton active paragraph={false} title={{ style: { marginBottom: 0 }, width: 80 }} />
) : (
- <Flexbox align={'center'} flex={1} gap={4} horizontal onClick={handleClick}>
- <Text ellipsis strong style={{ flex: 1, fontSize: 16 }}>
- {name}
- </Text>
- </Flexbox>
+ <Text ellipsis style={{ flex: 1 }} weight={500}>
+ {name}
+ </Text>
)}
{name && (
<DropdownMenu items={menuItems} placement="bottomRight">
- <ChevronsUpDown
- className={styles.icon}
+ <ActionIcon
+ icon={ChevronsUpDownIcon}
onClick={(e) => e.stopPropagation()}
- size={16}
- style={{ cursor: 'pointer', flex: 'none' }}
+ size={{
+ blockSize: 28,
+ size: 16,
+ }}
+ style={{ width: 24 }}
/>
</DropdownMenu>
)}
- </Flexbox>
+ </Block>
);
});
diff --git a/src/app/[variants]/(main)/resource/library/_layout/Header/index.tsx b/src/app/[variants]/(main)/resource/library/_layout/Header/index.tsx
index 00e3446185b..09c336883fc 100644
--- a/src/app/[variants]/(main)/resource/library/_layout/Header/index.tsx
+++ b/src/app/[variants]/(main)/resource/library/_layout/Header/index.tsx
@@ -12,17 +12,15 @@ const Header = memo(() => {
const { id } = useParams<{ id: string }>();
const { t } = useTranslation('common');
return (
- <>
- <SideBarHeaderLayout
- breadcrumb={[
- {
- href: '/resource',
- title: t('tab.resource'),
- },
- ]}
- />
- <LibraryHead id={id || ''} />
- </>
+ <SideBarHeaderLayout
+ breadcrumb={[
+ {
+ href: '/resource',
+ title: t('tab.resource'),
+ },
+ ]}
+ left={<LibraryHead id={id || ''} />}
+ />
);
});
diff --git a/src/features/ResourceManager/components/Explorer/Header/index.tsx b/src/features/ResourceManager/components/Explorer/Header/index.tsx
index 2fe2610a2ac..c988b940245 100644
--- a/src/features/ResourceManager/components/Explorer/Header/index.tsx
+++ b/src/features/ResourceManager/components/Explorer/Header/index.tsx
@@ -1,8 +1,9 @@
'use client';
import { ActionIcon, Flexbox } from '@lobehub/ui';
+import { App } from 'antd';
import { cssVar } from 'antd-style';
-import { SearchIcon } from 'lucide-react';
+import { BookMinusIcon, FileBoxIcon, SearchIcon, Trash2Icon } from 'lucide-react';
import { memo } from 'react';
import { useTranslation } from 'react-i18next';
@@ -18,7 +19,8 @@ import ViewSwitcher from '../ToolBar/ViewSwitcher';
import Breadcrumb from './Breadcrumb';
const Header = memo(() => {
- const { t } = useTranslation('file');
+ const { t } = useTranslation(['components', 'common', 'file', 'knowledgeBase']);
+ const { modal, message } = App.useApp();
// Get state and actions from store
const [libraryId, category, onActionClick, selectFileIds] = useResourceManagerStore((s) => [
@@ -29,8 +31,59 @@ const Header = memo(() => {
]);
const toggleCommandMenu = useGlobalStore((s) => s.toggleCommandMenu);
+ const selectCount = selectFileIds.length;
+ const isMultiSelected = selectCount > 1;
+
// If no libraryId, show category name or "Resource" for All
- const leftContent = !libraryId ? (
+ const leftContent = isMultiSelected ? (
+ <Flexbox align={'center'} gap={8} horizontal style={{ marginLeft: 0 }}>
+ {libraryId ? (
+ <ActionIcon
+ icon={BookMinusIcon}
+ onClick={() => {
+ modal.confirm({
+ okButtonProps: {
+ danger: true,
+ },
+ onOk: async () => {
+ await onActionClick('removeFromKnowledgeBase');
+ message.success(t('FileManager.actions.removeFromKnowledgeBaseSuccess'));
+ },
+ title: t('FileManager.actions.confirmRemoveFromKnowledgeBase', {
+ count: selectCount,
+ }),
+ });
+ }}
+ title={t('FileManager.actions.removeFromKnowledgeBase')}
+ />
+ ) : null}
+
+ <ActionIcon
+ icon={FileBoxIcon}
+ onClick={async () => {
+ await onActionClick('batchChunking');
+ }}
+ title={t('FileManager.actions.batchChunking')}
+ />
+
+ <ActionIcon
+ icon={Trash2Icon}
+ onClick={() => {
+ modal.confirm({
+ okButtonProps: {
+ danger: true,
+ },
+ onOk: async () => {
+ await onActionClick('delete');
+ message.success(t('FileManager.actions.deleteSuccess'));
+ },
+ title: t('FileManager.actions.confirmDeleteMultiFiles', { count: selectCount }),
+ });
+ }}
+ title={t('delete', { ns: 'common' })}
+ />
+ </Flexbox>
+ ) : !libraryId ? (
<Flexbox style={{ marginLeft: 8 }}>
{category === FilesTabs.All
? t('resource', { defaultValue: 'Resource' })
@@ -49,7 +102,7 @@ const Header = memo(() => {
<>
<ActionIcon icon={SearchIcon} onClick={() => toggleCommandMenu(true)} />
<SortDropdown />
- <BatchActionsDropdown onActionClick={onActionClick} selectCount={selectFileIds.length} />
+ <BatchActionsDropdown onActionClick={onActionClick} selectCount={selectCount} />
<ViewSwitcher />
<Flexbox style={{ marginLeft: 8 }}>
<AddButton />
diff --git a/src/features/ResourceManager/components/Explorer/ListView/ListItem/index.tsx b/src/features/ResourceManager/components/Explorer/ListView/ListItem/index.tsx
index 409cc6c6aba..dfee049575f 100644
--- a/src/features/ResourceManager/components/Explorer/ListView/ListItem/index.tsx
+++ b/src/features/ResourceManager/components/Explorer/ListView/ListItem/index.tsx
@@ -48,12 +48,13 @@ const styles = createStaticStyles(({ css }) => {
`,
dragOver: css`
- color: ${cssVar.colorBgElevated} !important;
- background-color: ${cssVar.colorText} !important;
-
- * {
- color: ${cssVar.colorBgElevated} !important;
+ &,
+ &:hover {
+ background: ${cssVar.colorPrimaryBg};
}
+
+ outline: 1px dashed ${cssVar.colorPrimaryBorder};
+ outline-offset: -2px;
`,
dragging: css`
@@ -510,6 +511,7 @@ const FileListItem = memo<FileListItemProps>(
e.stopPropagation();
}}
onPointerDown={(e) => e.stopPropagation()}
+ paddingInline={8}
>
{!isFolder &&
!isPage &&
diff --git a/src/features/ResourceManager/components/Explorer/ListView/index.tsx b/src/features/ResourceManager/components/Explorer/ListView/index.tsx
index 4ea7fbd119a..ec4aacc89de 100644
--- a/src/features/ResourceManager/components/Explorer/ListView/index.tsx
+++ b/src/features/ResourceManager/components/Explorer/ListView/index.tsx
@@ -34,7 +34,7 @@ const styles = createStaticStyles(({ css }) => ({
`,
dropZoneActive: css`
background: ${cssVar.colorPrimaryBg};
- outline: 2px dashed ${cssVar.colorPrimary};
+ outline: 1px dashed ${cssVar.colorPrimaryBorder};
outline-offset: -4px;
`,
header: css`
@@ -330,9 +330,15 @@ const ListView = memo(function ListView() {
// Memoize footer component to show skeleton loaders when loading more
const Footer = useCallback(() => {
- if (!isLoadingMore || !fileListHasMore) return null;
- return <ListViewSkeleton columnWidths={columnWidths} />;
- }, [isLoadingMore, fileListHasMore, columnWidths]);
+ if (isLoadingMore && fileListHasMore) return <ListViewSkeleton columnWidths={columnWidths} />;
+
+ // Leave some padding at the end when there are no more pages,
+ // so users can clearly feel they've reached the end of the list.
+ if (fileListHasMore === false && dataLength > 0)
+ return <div aria-hidden style={{ height: 96 }} />;
+
+ return null;
+ }, [columnWidths, dataLength, fileListHasMore, isLoadingMore]);
if (showSkeleton) return <ListViewSkeleton columnWidths={columnWidths} />;
@@ -369,7 +375,12 @@ const ListView = memo(function ListView() {
width: columnWidths.name,
}}
>
- {t('FileManager.title.title')}
+ {selectFileIds.length > 0
+ ? t('FileManager.total.selectedCount', {
+ count: selectFileIds.length,
+ ns: 'components',
+ })
+ : t('FileManager.title.title')}
<ColumnResizeHandle
column="name"
currentWidth={columnWidths.name}
diff --git a/src/features/ResourceManager/components/LibraryHierarchy/styles.ts b/src/features/ResourceManager/components/LibraryHierarchy/styles.ts
index 0b1faa6065f..38f77897045 100644
--- a/src/features/ResourceManager/components/LibraryHierarchy/styles.ts
+++ b/src/features/ResourceManager/components/LibraryHierarchy/styles.ts
@@ -6,12 +6,13 @@ export const styles = createStaticStyles(({ css, cssVar }) => ({
opacity: 0.5;
`,
fileItemDragOver: css`
- color: ${cssVar.colorBgElevated} !important;
- background-color: ${cssVar.colorText} !important;
-
- * {
- color: ${cssVar.colorBgElevated} !important;
+ &,
+ &:hover {
+ background: ${cssVar.colorPrimaryBg};
}
+
+ outline: 1px dashed ${cssVar.colorPrimaryBorder};
+ outline-offset: -2px;
`,
treeItem: css`
cursor: pointer;
diff --git a/src/store/file/slices/resource/action.ts b/src/store/file/slices/resource/action.ts
index 9792b8c4c50..69cc3360054 100644
--- a/src/store/file/slices/resource/action.ts
+++ b/src/store/file/slices/resource/action.ts
@@ -239,9 +239,11 @@ export const createResourceSlice: StateCreator<
'deleteResource/optimistic',
);
- // 2. Enqueue sync (background)
+ // 2. Enqueue sync and await completion.
+ // Important: if callers revalidate the list immediately, doing so before the server-side
+ // deletion finishes can re-introduce the item from a still-stale query response.
const syncEngine = getSyncEngine();
- syncEngine.enqueue({
+ await syncEngine.enqueue({
id: `sync-${id}-${Date.now()}`,
payload: {},
resourceId: id,