-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
fix(editor): add default value to progress column #9637
base: canary
Are you sure you want to change the base?
fix(editor): add default value to progress column #9637
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. |
); | ||
|
||
updateCells( |
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.
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 comment
The 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.
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 comment
The 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
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.
Leave any comment please! 🙏
All feedback, positive or negative, is welcome!
|
||
const metaConfig = this.propertyMetaGet( | ||
type ?? propertyPresets.multiSelectPropertyConfig.type | ||
); |
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 this
propertyMetaGet(type: string): PropertyMetaConfig {
return databaseBlockAllPropertyMap[type];
}
It returns the property configuration object corresponding the type.
Object.fromEntries( | ||
this.rows$.value.map(r => [r, metaConfig.config.defaultValue]) | ||
) | ||
); |
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.
it updates cells to default value whenever the property is added
@@ -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 comment
The 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.
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 comment
The 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.
column.id, | ||
this.propertyMetaGet(column.type$.value).config.defaultValue | ||
) | ||
); |
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.
It initialize the cells to default value when a row is added
Fixes #9624
What's the issue?
2025-01-11.2.57.36.mov
What's the root cause?
New rows are initialized to null by default, resulting in empty values.
What's changed?
2025-01-11.3.12.19.mov
defaultValue
field within thePropertyConfig
typedefaultValue
with zero atprogressPropertyModelConfig