chore: fix update issues (#31)

This commit is contained in:
Kilu.He
2025-08-13 10:20:14 +08:00
committed by GitHub
parent b487e4eb1a
commit 5d45e0ccf7
25 changed files with 442 additions and 165 deletions

View File

@@ -18,6 +18,7 @@ import {
getDateFormat,
getTimeFormat,
getTypeOptions,
parseRelationTypeOption,
parseSelectOptionTypeOptions,
SelectOption,
TimeFormat,
@@ -290,6 +291,30 @@ export function useFieldSelector(fieldId: string) {
};
}
export function useDatabaseIdFromField(fieldId: string) {
const database = useDatabase();
const field = database?.get(YjsDatabaseKey.fields)?.get(fieldId);
const [databaseId, setDatabaseId] = useState<string | null>(null);
useEffect(() => {
if (!field) return;
const observerEvent = () => {
setDatabaseId(parseRelationTypeOption(field)?.database_id);
};
observerEvent();
field.observe(observerEvent);
return () => {
field.unobserve(observerEvent);
};
}, [database, field, fieldId]);
return databaseId;
}
export function useFiltersSelector() {
const database = useDatabase();
const viewId = useDatabaseViewId();
@@ -725,11 +750,14 @@ export function useRowOrdersSelector() {
sorts?.observeDeep(throttleChange);
filters?.observeDeep(throttleChange);
fields?.observeDeep(throttleChange);
Object.values(rows || {}).forEach((rowDoc) => {
const rowSharedRoot = rowDoc.getMap(YjsEditorKey.data_section);
const databaseRow = rowSharedRoot.get(YjsEditorKey.database_row) as YDatabaseRow;
const debouncedConditionsChange = debounce(onConditionsChange, 150);
databaseRow?.get(YjsDatabaseKey.cells)?.observeDeep(throttleChange);
const observerRowsEvent = () => {
debouncedConditionsChange();
};
Object.values(rows || {}).forEach((row) => {
row.getMap(YjsEditorKey.data_section).observeDeep(observerRowsEvent);
});
return () => {
@@ -737,12 +765,8 @@ export function useRowOrdersSelector() {
sorts?.unobserveDeep(throttleChange);
filters?.unobserveDeep(throttleChange);
fields?.unobserveDeep(throttleChange);
Object.values(rows || {}).forEach((rowDoc) => {
const rowSharedRoot = rowDoc.getMap(YjsEditorKey.data_section);
const databaseRow = rowSharedRoot.get(YjsEditorKey.database_row) as YDatabaseRow;
databaseRow?.get(YjsDatabaseKey.cells)?.unobserveDeep(throttleChange);
Object.values(rows || {}).forEach((row) => {
row.getMap(YjsEditorKey.data_section).unobserveDeep(observerRowsEvent);
});
};
}, [onConditionsChange, view, fields, filters, sorts, rows]);