mirror of
https://github.com/AppFlowy-IO/AppFlowy-Web.git
synced 2026-03-13 10:00:26 +08:00
chore: fix key
This commit is contained in:
@@ -48,7 +48,7 @@ import { createSelectOptionCell } from '@/application/database-yjs/fields/select
|
||||
import { createDateTimeField, createTextField } from '@/application/database-yjs/fields/text/utils';
|
||||
import { dateFilterFillData, filterFillData, getDefaultFilterCondition } from '@/application/database-yjs/filter';
|
||||
import { getOptionsFromRow, initialDatabaseRow } from '@/application/database-yjs/row';
|
||||
import { generateRowMeta, getMetaIdMap, getMetaJSON, getRowDocumentId } from '@/application/database-yjs/row_meta';
|
||||
import { generateRowMeta, getMetaIdMap, getMetaJSON, getRowKey } from '@/application/database-yjs/row_meta';
|
||||
import { useBoardLayoutSettings, useCalendarLayoutSetting, useDatabaseViewLayout, useFieldSelector, useFieldType } from '@/application/database-yjs/selector';
|
||||
import { executeOperations } from '@/application/slate-yjs/utils/yjs';
|
||||
import {
|
||||
@@ -1222,9 +1222,8 @@ export function useNewRowDispatch() {
|
||||
}
|
||||
|
||||
const rowId = uuidv4();
|
||||
const documentId = getRowDocumentId(rowId);
|
||||
|
||||
const rowDoc = await createRow(documentId);
|
||||
const rowKey = getRowKey(guid, rowId);
|
||||
const rowDoc = await createRow(rowKey);
|
||||
let shouldOpenRowModal = false;
|
||||
|
||||
rowDoc.transact(() => {
|
||||
@@ -1505,8 +1504,8 @@ export function useDuplicateRowDispatch() {
|
||||
[RowMetaKey.CoverId]: cover ? JSON.stringify(cover) : null,
|
||||
});
|
||||
|
||||
const documentId = getRowDocumentId(rowId);
|
||||
const rowDoc = await createRow(documentId);
|
||||
const rowKey = getRowKey(guid, rowId);
|
||||
const rowDoc = await createRow(rowKey);
|
||||
|
||||
rowDoc.transact(() => {
|
||||
initialDatabaseRow(rowId, database.get(YjsDatabaseKey.id), rowDoc);
|
||||
|
||||
@@ -34,17 +34,8 @@ export function generateRowMeta(rowId: string, data: Record<string, string | boo
|
||||
|
||||
export const metaIdMapFromRowIdMap = new Map<string, Map<RowMetaKey, string>>();
|
||||
|
||||
/**
|
||||
* Generate row document ID from row ID using UUID v5
|
||||
* This matches the Rust implementation:
|
||||
* pub fn database_row_document_id_from_row_id(row_id: &RowId) -> RowId {
|
||||
* Uuid::new_v5(row_id, RowMetaKey::DocumentId.as_str().as_bytes())
|
||||
* }
|
||||
*/
|
||||
export function getRowDocumentId(rowId: string): string {
|
||||
const parser = metaIdFromRowId(rowId);
|
||||
|
||||
return parser(RowMetaKey.DocumentId);
|
||||
export function getRowKey(guid: string, rowId: string): string {
|
||||
return `${guid}_rows_${rowId}`;
|
||||
}
|
||||
|
||||
export function getMetaIdMap(rowId: string) {
|
||||
@@ -80,9 +71,9 @@ export function getMetaJSON(rowId: string, meta: Y.Map<unknown>) {
|
||||
try {
|
||||
cover = metaJson[coverKey]
|
||||
? (JSON.parse(metaJson[coverKey]) as {
|
||||
data: string;
|
||||
cover_type: RowCoverType;
|
||||
})
|
||||
data: string;
|
||||
cover_type: RowCoverType;
|
||||
})
|
||||
: null;
|
||||
} catch (e) {
|
||||
// do nothing
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { getRowKey } from '@/application/database-yjs/row_meta';
|
||||
import { closeCollabDB, db, openCollabDB } from '@/application/db';
|
||||
import { getRowDocumentId } from '@/application/database-yjs/row_meta';
|
||||
import { Fetcher, StrategyType } from '@/application/services/js-services/cache/types';
|
||||
import {
|
||||
DatabaseId,
|
||||
@@ -275,7 +275,7 @@ async function updateRows(collab: YDoc, rows: Record<RowId, number[]>) {
|
||||
const bulkData = [];
|
||||
|
||||
for (const [key, value] of Object.entries(rows)) {
|
||||
const rowKey = getRowDocumentId(key);
|
||||
const rowKey = getRowKey(collab.guid, key);
|
||||
const doc = await createRowDoc(rowKey);
|
||||
|
||||
const dbRow = await db.rows.get(key);
|
||||
|
||||
@@ -1,29 +1,29 @@
|
||||
import { useCallback, useRef } from 'react';
|
||||
import { PromptDatabaseConfiguration } from '@/components/chat';
|
||||
import { useCallback, useRef } from 'react';
|
||||
|
||||
import { FieldType } from '@/application/database-yjs';
|
||||
import { getCellDataText } from '@/application/database-yjs/cell.parse';
|
||||
import { getRowKey } from '@/application/database-yjs/row_meta';
|
||||
import {
|
||||
DatabasePrompt,
|
||||
DatabasePromptField,
|
||||
DatabasePromptRow,
|
||||
GenerateAISummaryRowPayload,
|
||||
GenerateAITranslateRowPayload,
|
||||
YDoc,
|
||||
YDatabase,
|
||||
YjsEditorKey,
|
||||
YDoc,
|
||||
YjsDatabaseKey,
|
||||
YjsEditorKey,
|
||||
} from '@/application/types';
|
||||
import { FieldType } from '@/application/database-yjs';
|
||||
import { getCellDataText } from '@/application/database-yjs/cell.parse';
|
||||
import { getRowDocumentId } from '@/application/database-yjs/row_meta';
|
||||
import { useAuthInternal } from '../contexts/AuthInternalContext';
|
||||
|
||||
// Hook for managing database-related operations
|
||||
export function useDatabaseOperations(
|
||||
loadView?: (id: string, isSubDocument?: boolean, loadAwareness?: boolean) => Promise<YDoc | null>,
|
||||
loadView?: (id: string, isSubDocument?: boolean, loadAwareness?: boolean) => Promise<YDoc | null>,
|
||||
createRowDoc?: (rowKey: string) => Promise<YDoc>
|
||||
) {
|
||||
const { service, currentWorkspaceId } = useAuthInternal();
|
||||
|
||||
|
||||
const rowDocsRef = useRef<Map<string, DatabasePromptRow>>(new Map());
|
||||
|
||||
// Generate AI summary for row
|
||||
@@ -80,7 +80,7 @@ export function useDatabaseOperations(
|
||||
|
||||
if (!createRowDoc) return;
|
||||
|
||||
const rowKey = getRowDocumentId(row.id);
|
||||
const rowKey = getRowKey(doc?.guid || '', row.id);
|
||||
const rowDoc = await createRowDoc(rowKey);
|
||||
|
||||
const rowSharedRoot = rowDoc?.getMap(YjsEditorKey.data_section);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { debounce } from 'lodash-es';
|
||||
import { useCallback, useEffect, useMemo, useState } from 'react';
|
||||
|
||||
import { getRowDocumentId } from '@/application/database-yjs/row_meta';
|
||||
import { getRowKey } from '@/application/database-yjs/row_meta';
|
||||
import {
|
||||
AppendBreadcrumb,
|
||||
CreateFolderViewPayload,
|
||||
@@ -80,7 +80,7 @@ function Database(props: Database2Props) {
|
||||
return;
|
||||
}
|
||||
|
||||
const rowKey = getRowDocumentId(id);
|
||||
const rowKey = getRowKey(doc.guid, id);
|
||||
const rowDoc = await createRowDoc(rowKey);
|
||||
|
||||
return { id, rowDoc };
|
||||
@@ -177,7 +177,7 @@ function Database(props: Database2Props) {
|
||||
setOpenModalViewId(viewId);
|
||||
setOpenModalRowDatabaseDoc(viewDoc);
|
||||
|
||||
const rowDoc = await createRowDoc?.(getRowDocumentId(rowId));
|
||||
const rowDoc = await createRowDoc?.(getRowKey(viewDoc.guid, rowId));
|
||||
|
||||
if (!rowDoc) {
|
||||
throw new Error('Row document not found');
|
||||
|
||||
@@ -3,7 +3,7 @@ import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { getPrimaryFieldId, useDatabaseContext } from '@/application/database-yjs';
|
||||
import { parseYDatabaseCellToCell } from '@/application/database-yjs/cell.parse';
|
||||
import { getRowDocumentId } from '@/application/database-yjs/row_meta';
|
||||
import { getRowKey } from '@/application/database-yjs/row_meta';
|
||||
import { View, YDatabase, YDatabaseRow, YDoc, YjsDatabaseKey, YjsEditorKey } from '@/application/types';
|
||||
import { ReactComponent as MinusIcon } from '@/assets/icons/minus.svg';
|
||||
import { ReactComponent as PlusIcon } from '@/assets/icons/plus.svg';
|
||||
@@ -140,7 +140,7 @@ function RelationCellMenuContent({
|
||||
continue;
|
||||
}
|
||||
|
||||
const rowKey = getRowDocumentId(rowId);
|
||||
const rowKey = getRowKey(guid, rowId);
|
||||
const rowDoc = await createRowDoc(rowKey);
|
||||
|
||||
rowDocsRef.current.set(rowId, rowDoc);
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
useDatabaseIdFromField,
|
||||
} from '@/application/database-yjs';
|
||||
import { RelationCell, RelationCellData } from '@/application/database-yjs/cell.type';
|
||||
import { getRowDocumentId } from '@/application/database-yjs/row_meta';
|
||||
import { getRowKey } from '@/application/database-yjs/row_meta';
|
||||
import { YDoc, YjsEditorKey } from '@/application/types';
|
||||
import { notify } from '@/components/_shared/notify';
|
||||
import { RelationPrimaryValue } from '@/components/database/components/cell/relation/RelationPrimaryValue';
|
||||
@@ -69,7 +69,7 @@ function RelationItems({
|
||||
const rows: Record<string, YDoc> = {};
|
||||
|
||||
for (const rowId of rowIds) {
|
||||
const rowDoc = await createRowDoc(getRowDocumentId(rowId));
|
||||
const rowDoc = await createRowDoc(getRowKey(docGuid, rowId));
|
||||
|
||||
rows[rowId] = rowDoc;
|
||||
}
|
||||
@@ -161,9 +161,8 @@ function RelationItems({
|
||||
notify.error(e.message);
|
||||
}
|
||||
}}
|
||||
className={`min-w-fit overflow-hidden text-text-primary underline ${
|
||||
relatedViewId ? 'cursor-pointer hover:text-text-action' : ''
|
||||
}`}
|
||||
className={`min-w-fit overflow-hidden text-text-primary underline ${relatedViewId ? 'cursor-pointer hover:text-text-action' : ''
|
||||
}`}
|
||||
>
|
||||
<RelationPrimaryValue fieldId={relatedFieldId} rowDoc={rowDoc} />
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user