mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-18 02:26:21 +08:00
fix(editor): remove the fixation of created-by and created-time (#12260)
close: BS-3474, BS-3153 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Enhanced property addition to support specifying both type and name for new properties across databases and views. - Added context menu for selecting property type when adding new columns in table headers. - Introduced `addToGroup` functions to various group-by configurations for consistent grouping behavior. - **Bug Fixes** - Improved grouping logic to treat empty arrays as ungrouped in multi-member group configurations. - Refined grouping behavior to respect explicit group addition settings. - Ensured grouping operations only occur when both group key and row ID are present. - **Tests** - Updated test expectations to align with revised default column naming conventions. - Adjusted test utilities to accommodate the updated property addition method. - Improved typing simulation in column type selection for more reliable test execution. - **Improvements** - Introduced a new root component rendering on the share page to enhance UI integration. - Refined default property naming logic for clearer and more consistent column titles. - Simplified created-time and created-by property configurations for better maintainability. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -56,10 +56,12 @@ type SpacialProperty = {
|
||||
valueSet: (rowId: string, propertyId: string, value: unknown) => void;
|
||||
valueGet: (rowId: string, propertyId: string) => unknown;
|
||||
};
|
||||
|
||||
export class DatabaseBlockDataSource extends DataSourceBase {
|
||||
override get parentProvider() {
|
||||
return this._model.store.provider;
|
||||
}
|
||||
|
||||
spacialProperties: Record<string, SpacialProperty> = {
|
||||
'created-time': {
|
||||
valueSet: () => {},
|
||||
@@ -101,11 +103,17 @@ export class DatabaseBlockDataSource extends DataSourceBase {
|
||||
},
|
||||
},
|
||||
};
|
||||
isSpacialProperty(propertyId: string): boolean {
|
||||
return this.spacialProperties[propertyId] !== undefined;
|
||||
|
||||
isSpacialProperty(propertyType: string): boolean {
|
||||
return this.spacialProperties[propertyType] !== undefined;
|
||||
}
|
||||
spacialValueGet(rowId: string, propertyId: string): unknown {
|
||||
return this.spacialProperties[propertyId]?.valueGet(rowId, propertyId);
|
||||
|
||||
spacialValueGet(
|
||||
rowId: string,
|
||||
propertyId: string,
|
||||
propertyType: string
|
||||
): unknown {
|
||||
return this.spacialProperties[propertyType]?.valueGet(rowId, propertyId);
|
||||
}
|
||||
|
||||
static externalProperties = signal<PropertyMetaConfig[]>([]);
|
||||
@@ -213,16 +221,20 @@ export class DatabaseBlockDataSource extends DataSourceBase {
|
||||
return this._model.children[this._model.childMap.value.get(rowId) ?? -1];
|
||||
}
|
||||
|
||||
private newPropertyName() {
|
||||
private newPropertyName(prefix = 'Column'): string {
|
||||
let i = 1;
|
||||
while (
|
||||
this._model.props.columns$.value.some(
|
||||
column => column.name === `Column ${i}`
|
||||
)
|
||||
) {
|
||||
const hasSameName = (name: string) => {
|
||||
return this._model.props.columns$.value.some(
|
||||
column => column.name === name
|
||||
);
|
||||
};
|
||||
while (true) {
|
||||
let name = i === 1 ? prefix : `${prefix} ${i}`;
|
||||
if (!hasSameName(name)) {
|
||||
return name;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
return `Column ${i}`;
|
||||
}
|
||||
|
||||
cellValueChange(rowId: string, propertyId: string, value: unknown): void {
|
||||
@@ -257,14 +269,14 @@ export class DatabaseBlockDataSource extends DataSourceBase {
|
||||
|
||||
cellValueGet(rowId: string, propertyId: string): unknown {
|
||||
if (this.isSpacialProperty(propertyId)) {
|
||||
return this.spacialValueGet(rowId, propertyId);
|
||||
return this.spacialValueGet(rowId, propertyId, propertyId);
|
||||
}
|
||||
const type = this.propertyTypeGet(propertyId);
|
||||
if (!type) {
|
||||
return;
|
||||
}
|
||||
if (type === 'title') {
|
||||
return this.spacialValueGet(rowId, 'title');
|
||||
if (this.isSpacialProperty(type)) {
|
||||
return this.spacialValueGet(rowId, propertyId, type);
|
||||
}
|
||||
const meta = this.propertyMetaGet(type);
|
||||
if (!meta) {
|
||||
@@ -283,9 +295,13 @@ export class DatabaseBlockDataSource extends DataSourceBase {
|
||||
|
||||
propertyAdd(
|
||||
insertToPosition: InsertToPosition,
|
||||
type?: string
|
||||
ops?: {
|
||||
type?: string;
|
||||
name?: string;
|
||||
}
|
||||
): string | undefined {
|
||||
this.doc.captureSync();
|
||||
const { type, name } = ops ?? {};
|
||||
const property = this.propertyMetaGet(
|
||||
type ?? propertyPresets.multiSelectPropertyConfig.type
|
||||
);
|
||||
@@ -295,7 +311,7 @@ export class DatabaseBlockDataSource extends DataSourceBase {
|
||||
const result = addProperty(
|
||||
this._model,
|
||||
insertToPosition,
|
||||
property.create(this.newPropertyName())
|
||||
property.create(this.newPropertyName(name))
|
||||
);
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user