-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
fix(editor): add default value to progress column #9637
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -180,13 +180,25 @@ export class DatabaseBlockDataSource extends DataSourceBase { | |
|
||
propertyAdd(insertToPosition: InsertToPosition, type?: string): string { | ||
this.doc.captureSync(); | ||
|
||
const metaConfig = this.propertyMetaGet( | ||
type ?? propertyPresets.multiSelectPropertyConfig.type | ||
); | ||
|
||
const result = addProperty( | ||
this._model, | ||
insertToPosition, | ||
databaseBlockAllPropertyMap[ | ||
type ?? propertyPresets.multiSelectPropertyConfig.type | ||
].create(this.newPropertyName()) | ||
metaConfig.create(this.newPropertyName()) | ||
); | ||
|
||
updateCells( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will cause a large number of update records to exist in the CRDT. It is recommended not to do this. Instead, a default value should be returned when obtaining the value. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Thank you for super fast comment! @zzj3720 I'm not sure of how to implement returning a default value when obtaining the value. Could you please provide more guidance or an example to assist me in resolving this issue? I would greatly appreciate it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. /blocksuite/affine/data-view/src/property-presets/progress/define.ts
@@ -8,16 +8,16 @@ export const progressPropertyModelConfig =
name: 'Progress',
type: () => t.number.instance(),
defaultData: () => ({}),
- cellToString: ({ value }) => value?.toString() ?? '',
+ cellToString: ({ value }) => value?.toString() ?? '0',
cellFromString: ({ value }) => {
- const num = value ? Number(value) : NaN;
+ const num = value ? Number(value) : 0;
return {
- value: isNaN(num) ? null : num,
+ value: isNaN(num) ? 0 : num,
};
},
- cellToJson: ({ value }) => value ?? null,
+ cellToJson: ({ value }) => value ?? 0,
cellFromJson: ({ value }) => {
- if (typeof value !== 'number') return undefined;
+ if (typeof value !== 'number') return 0;
return value;
},
isEmpty: () => false, How about changing all null or undefined values to return 0 like this? Although this change will internally store as null, it will work correctly when filtering. @zzj3720 |
||
this._model, | ||
result, | ||
Object.fromEntries( | ||
this.rows$.value.map(r => [r, metaConfig.config.defaultValue]) | ||
) | ||
); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it updates cells to default value whenever the property is added |
||
|
||
applyPropertyUpdate(this._model); | ||
return result; | ||
} | ||
|
@@ -306,8 +318,13 @@ export class DatabaseBlockDataSource extends DataSourceBase { | |
type: toType, | ||
data: result.property, | ||
})); | ||
const metaConfig = this.propertyMetaGet(toType); | ||
const cells: Record<string, unknown> = {}; | ||
currentCells.forEach((value, i) => { | ||
if (value == null && result.cells[i] == null) { | ||
cells[rows[i]] = metaConfig.config.defaultValue; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it updates cells to default value whenever the property is updated to other type. |
||
|
||
if (value != null || result.cells[i] != null) { | ||
cells[rows[i]] = result.cells[i]; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,4 +21,5 @@ export const progressPropertyModelConfig = | |
return value; | ||
}, | ||
isEmpty: () => false, | ||
defaultValue: 0, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The progress value always ranges from 0 to 100. When a new progress item is created, it is initially set to 0. |
||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -321,6 +321,14 @@ export class TableSingleView extends SingleViewBase<TableViewData> { | |
): string { | ||
const id = super.rowAdd(insertPosition); | ||
|
||
this.properties$.value.forEach(column => | ||
this.cellValueSet( | ||
id, | ||
column.id, | ||
this.propertyMetaGet(column.type$.value).config.defaultValue | ||
) | ||
); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It initialize the cells to default value when a row is added |
||
|
||
const filter = this.filter$.value; | ||
if (filter.conditions.length > 0) { | ||
const defaultValues = generateDefaultValues(filter, this.vars$.value); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
propertyMetaGet
method looks like thisIt returns the property configuration object corresponding the type.