mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 20:38:52 +00:00
fix: collections should be unique for workspaces (#3213)
This commit is contained in:
@@ -12,12 +12,13 @@ import { useCollectionManager } from '../use-collection-manager';
|
||||
const defaultMeta = { tags: { options: [] } };
|
||||
|
||||
test('useAllPageSetting', async () => {
|
||||
const settingHook = renderHook(() => useCollectionManager());
|
||||
const settingHook = renderHook(() => useCollectionManager('test'));
|
||||
const prevCollection = settingHook.result.current.currentCollection;
|
||||
expect(settingHook.result.current.savedCollections).toEqual([]);
|
||||
await settingHook.result.current.updateCollection({
|
||||
...settingHook.result.current.currentCollection,
|
||||
filterList: [createDefaultFilter(vars[0], defaultMeta)],
|
||||
workspaceId: 'test',
|
||||
});
|
||||
settingHook.rerender();
|
||||
const nextCollection = settingHook.result.current.currentCollection;
|
||||
|
||||
@@ -36,6 +36,7 @@ const AllPagesHead = ({
|
||||
importFile,
|
||||
getPageInfo,
|
||||
propertiesMeta,
|
||||
workspaceId,
|
||||
}: {
|
||||
isPublicWorkspace: boolean;
|
||||
sorter: ReturnType<typeof useSorter<ListData>>;
|
||||
@@ -44,6 +45,7 @@ const AllPagesHead = ({
|
||||
importFile: () => void;
|
||||
getPageInfo: GetPageInfoById;
|
||||
propertiesMeta: PropertiesMeta;
|
||||
workspaceId: string;
|
||||
}) => {
|
||||
const t = useAFFiNEI18N();
|
||||
const titleList = useMemo(
|
||||
@@ -143,6 +145,7 @@ const AllPagesHead = ({
|
||||
<TableHead>
|
||||
<TableHeadRow>{tableItem}</TableHeadRow>
|
||||
<CollectionBar
|
||||
workspaceId={workspaceId}
|
||||
columnsCount={titleList.length}
|
||||
getPageInfo={getPageInfo}
|
||||
propertiesMeta={propertiesMeta}
|
||||
@@ -153,6 +156,7 @@ const AllPagesHead = ({
|
||||
|
||||
export const PageList = ({
|
||||
isPublicWorkspace = false,
|
||||
workspaceId,
|
||||
list,
|
||||
onCreateNewPage,
|
||||
onCreateNewEdgeless,
|
||||
@@ -197,6 +201,7 @@ export const PageList = ({
|
||||
<StyledTableContainer ref={ref}>
|
||||
<Table showBorder={hasScrollTop} style={{ maxHeight: '100%' }}>
|
||||
<AllPagesHead
|
||||
workspaceId={workspaceId}
|
||||
propertiesMeta={propertiesMeta}
|
||||
isPublicWorkspace={isPublicWorkspace}
|
||||
sorter={sorter}
|
||||
|
||||
@@ -45,6 +45,7 @@ export type TrashListData = {
|
||||
|
||||
export type PageListProps = {
|
||||
isPublicWorkspace?: boolean;
|
||||
workspaceId: string;
|
||||
list: ListData[];
|
||||
fallback?: React.ReactNode;
|
||||
onCreateNewPage: () => void;
|
||||
|
||||
@@ -35,6 +35,7 @@ const defaultCollection = {
|
||||
id: NIL,
|
||||
name: 'All',
|
||||
filterList: [],
|
||||
workspaceId: 'temporary',
|
||||
};
|
||||
const collectionAtom = atomWithReset<{
|
||||
currentId: string;
|
||||
@@ -44,14 +45,15 @@ const collectionAtom = atomWithReset<{
|
||||
defaultCollection: defaultCollection,
|
||||
});
|
||||
|
||||
export const useSavedCollections = () => {
|
||||
export const useSavedCollections = (workspaceId: string) => {
|
||||
const { data: savedCollections, mutate } = useSWRImmutable<Collection[]>(
|
||||
['affine', 'page-collection'],
|
||||
['affine', 'page-collection', workspaceId],
|
||||
{
|
||||
fetcher: async () => {
|
||||
const db = await pageCollectionDBPromise;
|
||||
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,
|
||||
fallbackData: [],
|
||||
@@ -103,9 +105,9 @@ export const useSavedCollections = () => {
|
||||
};
|
||||
};
|
||||
|
||||
export const useCollectionManager = () => {
|
||||
export const useCollectionManager = (workspaceId: string) => {
|
||||
const { savedCollections, saveCollection, deleteCollection, addPage } =
|
||||
useSavedCollections();
|
||||
useSavedCollections(workspaceId);
|
||||
const [collectionData, setCollectionData] = useAtom(collectionAtom);
|
||||
|
||||
const updateCollection = useCallback(
|
||||
|
||||
@@ -22,12 +22,14 @@ export const CollectionBar = ({
|
||||
getPageInfo,
|
||||
propertiesMeta,
|
||||
columnsCount,
|
||||
workspaceId,
|
||||
}: {
|
||||
getPageInfo: GetPageInfoById;
|
||||
propertiesMeta: PropertiesMeta;
|
||||
columnsCount: number;
|
||||
workspaceId: string;
|
||||
}) => {
|
||||
const setting = useCollectionManager();
|
||||
const setting = useCollectionManager(workspaceId);
|
||||
const collection = setting.currentCollection;
|
||||
const [open, setOpen] = useState(false);
|
||||
const actions: {
|
||||
|
||||
Reference in New Issue
Block a user