mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-06 03:49:56 +08:00
fix: collections should be unique for workspaces (#3213)
This commit is contained in:
@@ -187,7 +187,6 @@ export const BlockSuitePageList: React.FC<BlockSuitePageListProps> = ({
|
|||||||
const pageList: ListData[] = list.map(pageMeta => {
|
const pageList: ListData[] = list.map(pageMeta => {
|
||||||
const page = blockSuiteWorkspace.getPage(pageMeta.id);
|
const page = blockSuiteWorkspace.getPage(pageMeta.id);
|
||||||
const preview = page ? getPagePreviewText(page) : undefined;
|
const preview = page ? getPagePreviewText(page) : undefined;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
icon: isPreferredEdgeless(pageMeta.id) ? <EdgelessIcon /> : <PageIcon />,
|
icon: isPreferredEdgeless(pageMeta.id) ? <EdgelessIcon /> : <PageIcon />,
|
||||||
pageId: pageMeta.id,
|
pageId: pageMeta.id,
|
||||||
@@ -230,6 +229,7 @@ export const BlockSuitePageList: React.FC<BlockSuitePageListProps> = ({
|
|||||||
});
|
});
|
||||||
return (
|
return (
|
||||||
<PageList
|
<PageList
|
||||||
|
workspaceId={blockSuiteWorkspace.id}
|
||||||
propertiesMeta={blockSuiteWorkspace.meta.properties}
|
propertiesMeta={blockSuiteWorkspace.meta.properties}
|
||||||
getPageInfo={getPageInfo}
|
getPageInfo={getPageInfo}
|
||||||
onCreateNewPage={createPage}
|
onCreateNewPage={createPage}
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ const CollectionRenderer = ({
|
|||||||
getPageInfo: GetPageInfoById;
|
getPageInfo: GetPageInfoById;
|
||||||
}) => {
|
}) => {
|
||||||
const [collapsed, setCollapsed] = React.useState(true);
|
const [collapsed, setCollapsed] = React.useState(true);
|
||||||
const setting = useCollectionManager();
|
const setting = useCollectionManager(workspace.id);
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const clickCollection = useCallback(() => {
|
const clickCollection = useCallback(() => {
|
||||||
router
|
router
|
||||||
@@ -255,7 +255,7 @@ const CollectionRenderer = ({
|
|||||||
};
|
};
|
||||||
export const CollectionsList = ({ currentWorkspace }: CollectionsListProps) => {
|
export const CollectionsList = ({ currentWorkspace }: CollectionsListProps) => {
|
||||||
const metas = useBlockSuitePageMeta(currentWorkspace.blockSuiteWorkspace);
|
const metas = useBlockSuitePageMeta(currentWorkspace.blockSuiteWorkspace);
|
||||||
const { savedCollections } = useSavedCollections();
|
const { savedCollections } = useSavedCollections(currentWorkspace.id);
|
||||||
const getPageInfo = useGetPageInfoById();
|
const getPageInfo = useGetPageInfoById();
|
||||||
return (
|
return (
|
||||||
<div data-testid="collections" className={styles.wrapper}>
|
<div data-testid="collections" className={styles.wrapper}>
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ export function WorkspaceHeader({
|
|||||||
currentWorkspaceId,
|
currentWorkspaceId,
|
||||||
currentEntry,
|
currentEntry,
|
||||||
}: WorkspaceHeaderProps<WorkspaceFlavour>): ReactElement {
|
}: WorkspaceHeaderProps<WorkspaceFlavour>): ReactElement {
|
||||||
const setting = useCollectionManager();
|
const setting = useCollectionManager(currentWorkspaceId);
|
||||||
const t = useAFFiNEI18N();
|
const t = useAFFiNEI18N();
|
||||||
const saveToCollection = useCallback(
|
const saveToCollection = useCallback(
|
||||||
async (collection: Collection) => {
|
async (collection: Collection) => {
|
||||||
@@ -73,6 +73,7 @@ export function WorkspaceHeader({
|
|||||||
id: uuidv4(),
|
id: uuidv4(),
|
||||||
name: '',
|
name: '',
|
||||||
filterList: setting.currentCollection.filterList,
|
filterList: setting.currentCollection.filterList,
|
||||||
|
workspaceId: currentWorkspaceId,
|
||||||
}}
|
}}
|
||||||
onConfirm={saveToCollection}
|
onConfirm={saveToCollection}
|
||||||
></SaveCollectionButton>
|
></SaveCollectionButton>
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ const WorkspaceDetail: React.FC = () => {
|
|||||||
assertExists(currentWorkspace);
|
assertExists(currentWorkspace);
|
||||||
assertExists(currentPageId);
|
assertExists(currentPageId);
|
||||||
const blockSuiteWorkspace = currentWorkspace.blockSuiteWorkspace;
|
const blockSuiteWorkspace = currentWorkspace.blockSuiteWorkspace;
|
||||||
const collectionManager = useCollectionManager();
|
const collectionManager = useCollectionManager(currentWorkspace.id);
|
||||||
const onLoad = useCallback(
|
const onLoad = useCallback(
|
||||||
(page: Page, editor: EditorContainer) => {
|
(page: Page, editor: EditorContainer) => {
|
||||||
const dispose = editor.slots.pageLinkClicked.on(({ pageId }) => {
|
const dispose = editor.slots.pageLinkClicked.on(({ pageId }) => {
|
||||||
|
|||||||
@@ -15,9 +15,9 @@ import type { NextPageWithLayout } from '../../../shared';
|
|||||||
|
|
||||||
const AllPage: NextPageWithLayout = () => {
|
const AllPage: NextPageWithLayout = () => {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const setting = useCollectionManager();
|
|
||||||
const { jumpToPage } = useRouterHelper(router);
|
const { jumpToPage } = useRouterHelper(router);
|
||||||
const [currentWorkspace] = useCurrentWorkspace();
|
const [currentWorkspace] = useCurrentWorkspace();
|
||||||
|
const setting = useCollectionManager(currentWorkspace.id);
|
||||||
const t = useAFFiNEI18N();
|
const t = useAFFiNEI18N();
|
||||||
const onClickPage = useCallback(
|
const onClickPage = useCallback(
|
||||||
(pageId: string, newTab?: boolean) => {
|
(pageId: string, newTab?: boolean) => {
|
||||||
|
|||||||
@@ -12,12 +12,13 @@ import { useCollectionManager } from '../use-collection-manager';
|
|||||||
const defaultMeta = { tags: { options: [] } };
|
const defaultMeta = { tags: { options: [] } };
|
||||||
|
|
||||||
test('useAllPageSetting', async () => {
|
test('useAllPageSetting', async () => {
|
||||||
const settingHook = renderHook(() => useCollectionManager());
|
const settingHook = renderHook(() => useCollectionManager('test'));
|
||||||
const prevCollection = settingHook.result.current.currentCollection;
|
const prevCollection = settingHook.result.current.currentCollection;
|
||||||
expect(settingHook.result.current.savedCollections).toEqual([]);
|
expect(settingHook.result.current.savedCollections).toEqual([]);
|
||||||
await settingHook.result.current.updateCollection({
|
await settingHook.result.current.updateCollection({
|
||||||
...settingHook.result.current.currentCollection,
|
...settingHook.result.current.currentCollection,
|
||||||
filterList: [createDefaultFilter(vars[0], defaultMeta)],
|
filterList: [createDefaultFilter(vars[0], defaultMeta)],
|
||||||
|
workspaceId: 'test',
|
||||||
});
|
});
|
||||||
settingHook.rerender();
|
settingHook.rerender();
|
||||||
const nextCollection = settingHook.result.current.currentCollection;
|
const nextCollection = settingHook.result.current.currentCollection;
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ const AllPagesHead = ({
|
|||||||
importFile,
|
importFile,
|
||||||
getPageInfo,
|
getPageInfo,
|
||||||
propertiesMeta,
|
propertiesMeta,
|
||||||
|
workspaceId,
|
||||||
}: {
|
}: {
|
||||||
isPublicWorkspace: boolean;
|
isPublicWorkspace: boolean;
|
||||||
sorter: ReturnType<typeof useSorter<ListData>>;
|
sorter: ReturnType<typeof useSorter<ListData>>;
|
||||||
@@ -44,6 +45,7 @@ const AllPagesHead = ({
|
|||||||
importFile: () => void;
|
importFile: () => void;
|
||||||
getPageInfo: GetPageInfoById;
|
getPageInfo: GetPageInfoById;
|
||||||
propertiesMeta: PropertiesMeta;
|
propertiesMeta: PropertiesMeta;
|
||||||
|
workspaceId: string;
|
||||||
}) => {
|
}) => {
|
||||||
const t = useAFFiNEI18N();
|
const t = useAFFiNEI18N();
|
||||||
const titleList = useMemo(
|
const titleList = useMemo(
|
||||||
@@ -143,6 +145,7 @@ const AllPagesHead = ({
|
|||||||
<TableHead>
|
<TableHead>
|
||||||
<TableHeadRow>{tableItem}</TableHeadRow>
|
<TableHeadRow>{tableItem}</TableHeadRow>
|
||||||
<CollectionBar
|
<CollectionBar
|
||||||
|
workspaceId={workspaceId}
|
||||||
columnsCount={titleList.length}
|
columnsCount={titleList.length}
|
||||||
getPageInfo={getPageInfo}
|
getPageInfo={getPageInfo}
|
||||||
propertiesMeta={propertiesMeta}
|
propertiesMeta={propertiesMeta}
|
||||||
@@ -153,6 +156,7 @@ const AllPagesHead = ({
|
|||||||
|
|
||||||
export const PageList = ({
|
export const PageList = ({
|
||||||
isPublicWorkspace = false,
|
isPublicWorkspace = false,
|
||||||
|
workspaceId,
|
||||||
list,
|
list,
|
||||||
onCreateNewPage,
|
onCreateNewPage,
|
||||||
onCreateNewEdgeless,
|
onCreateNewEdgeless,
|
||||||
@@ -197,6 +201,7 @@ export const PageList = ({
|
|||||||
<StyledTableContainer ref={ref}>
|
<StyledTableContainer ref={ref}>
|
||||||
<Table showBorder={hasScrollTop} style={{ maxHeight: '100%' }}>
|
<Table showBorder={hasScrollTop} style={{ maxHeight: '100%' }}>
|
||||||
<AllPagesHead
|
<AllPagesHead
|
||||||
|
workspaceId={workspaceId}
|
||||||
propertiesMeta={propertiesMeta}
|
propertiesMeta={propertiesMeta}
|
||||||
isPublicWorkspace={isPublicWorkspace}
|
isPublicWorkspace={isPublicWorkspace}
|
||||||
sorter={sorter}
|
sorter={sorter}
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ export type TrashListData = {
|
|||||||
|
|
||||||
export type PageListProps = {
|
export type PageListProps = {
|
||||||
isPublicWorkspace?: boolean;
|
isPublicWorkspace?: boolean;
|
||||||
|
workspaceId: string;
|
||||||
list: ListData[];
|
list: ListData[];
|
||||||
fallback?: React.ReactNode;
|
fallback?: React.ReactNode;
|
||||||
onCreateNewPage: () => void;
|
onCreateNewPage: () => void;
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ const defaultCollection = {
|
|||||||
id: NIL,
|
id: NIL,
|
||||||
name: 'All',
|
name: 'All',
|
||||||
filterList: [],
|
filterList: [],
|
||||||
|
workspaceId: 'temporary',
|
||||||
};
|
};
|
||||||
const collectionAtom = atomWithReset<{
|
const collectionAtom = atomWithReset<{
|
||||||
currentId: string;
|
currentId: string;
|
||||||
@@ -44,14 +45,15 @@ const collectionAtom = atomWithReset<{
|
|||||||
defaultCollection: defaultCollection,
|
defaultCollection: defaultCollection,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const useSavedCollections = () => {
|
export const useSavedCollections = (workspaceId: string) => {
|
||||||
const { data: savedCollections, mutate } = useSWRImmutable<Collection[]>(
|
const { data: savedCollections, mutate } = useSWRImmutable<Collection[]>(
|
||||||
['affine', 'page-collection'],
|
['affine', 'page-collection', workspaceId],
|
||||||
{
|
{
|
||||||
fetcher: async () => {
|
fetcher: async () => {
|
||||||
const db = await pageCollectionDBPromise;
|
const db = await pageCollectionDBPromise;
|
||||||
const t = db.transaction('view').objectStore('view');
|
const t = db.transaction('view').objectStore('view');
|
||||||
return await t.getAll();
|
const all = await t.getAll();
|
||||||
|
return all.filter(v => v.workspaceId === workspaceId);
|
||||||
},
|
},
|
||||||
suspense: true,
|
suspense: true,
|
||||||
fallbackData: [],
|
fallbackData: [],
|
||||||
@@ -103,9 +105,9 @@ export const useSavedCollections = () => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useCollectionManager = () => {
|
export const useCollectionManager = (workspaceId: string) => {
|
||||||
const { savedCollections, saveCollection, deleteCollection, addPage } =
|
const { savedCollections, saveCollection, deleteCollection, addPage } =
|
||||||
useSavedCollections();
|
useSavedCollections(workspaceId);
|
||||||
const [collectionData, setCollectionData] = useAtom(collectionAtom);
|
const [collectionData, setCollectionData] = useAtom(collectionAtom);
|
||||||
|
|
||||||
const updateCollection = useCallback(
|
const updateCollection = useCallback(
|
||||||
|
|||||||
@@ -22,12 +22,14 @@ export const CollectionBar = ({
|
|||||||
getPageInfo,
|
getPageInfo,
|
||||||
propertiesMeta,
|
propertiesMeta,
|
||||||
columnsCount,
|
columnsCount,
|
||||||
|
workspaceId,
|
||||||
}: {
|
}: {
|
||||||
getPageInfo: GetPageInfoById;
|
getPageInfo: GetPageInfoById;
|
||||||
propertiesMeta: PropertiesMeta;
|
propertiesMeta: PropertiesMeta;
|
||||||
columnsCount: number;
|
columnsCount: number;
|
||||||
|
workspaceId: string;
|
||||||
}) => {
|
}) => {
|
||||||
const setting = useCollectionManager();
|
const setting = useCollectionManager(workspaceId);
|
||||||
const collection = setting.currentCollection;
|
const collection = setting.currentCollection;
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
const actions: {
|
const actions: {
|
||||||
|
|||||||
Vendored
+1
@@ -29,6 +29,7 @@ export type Filter = {
|
|||||||
|
|
||||||
export type Collection = {
|
export type Collection = {
|
||||||
id: string;
|
id: string;
|
||||||
|
workspaceId: string;
|
||||||
name: string;
|
name: string;
|
||||||
pinned?: boolean;
|
pinned?: boolean;
|
||||||
filterList: Filter[];
|
filterList: Filter[];
|
||||||
|
|||||||
Reference in New Issue
Block a user