Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ public DecimalConfigurationEditor()
Key = "min"
});

Fields.Add(new ConfigurationField(new DecimalValidator())
Comment thread
nielslyngsoe marked this conversation as resolved.
{
Key = "defaultValue",
});

Fields.Add(new ConfigurationField(new DecimalValidator())
{
Key = "step",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ export const manifests: Array<UmbExtensionManifest> = [
propertyEditorUiAlias: 'Umb.PropertyEditorUi.Decimal',
config: [{ alias: 'step', value: '0.000001' }],
},
{
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps move this so it comes after the step setting? Seems like min and max (and arguably step) should go together as they are part of the same process of considering what valid values are.

alias: 'defaultValue',
Comment thread
nielslyngsoe marked this conversation as resolved.
label: 'Default value',
description: 'Enter the default value to use when a new property is created',
propertyEditorUiAlias: 'Umb.PropertyEditorUi.Decimal',
config: [{ alias: 'step', value: '0.000001' }],
},
{
alias: 'max',
label: 'Maximum',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,26 @@
implements UmbPropertyValuePreset<UmbDecimalPropertyEditorUiValue, UmbPropertyEditorConfig>
{
async processValue(value: undefined | UmbDecimalPropertyEditorUiValue, config: UmbPropertyEditorConfig) {
const min = Number(config.find((x) => x.alias === 'min')?.value ?? 0);
const minVerified = isNaN(min) ? 0 : min;
const defaultValue = this.#parseConfiguredNumber(config, 'defaultValue');
if (defaultValue !== undefined) {
return value !== undefined ? value : defaultValue;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I note you can configure a default value that's outside of the min and max and therefore will be immediately invalid. We could look to clamp it, so if they default is lower than the min it'll use the min and if greater than the max it'll use the max. But I'm not sure it's necessary. When it comes to data type configuration validation we don't currently enforce that these settings are internally correct, and rely on the developer to get it right for their editors.

So no action here I feel, just noting.

}

return value !== undefined ? value : minVerified;
const min = this.#parseConfiguredNumber(config, 'min') ?? 0;
return value !== undefined ? value : min;
}

destroy(): void {}

#parseConfiguredNumber(config: UmbPropertyEditorConfig, alias: string): number | undefined {
const rawValue = config.find((x) => x.alias === alias)?.value;
if (rawValue === undefined || rawValue === null || rawValue === '') {

Check warning on line 22 in src/Umbraco.Web.UI.Client/src/packages/property-editors/number/decimal-property-value-preset.ts

View check run for this annotation

CodeScene Delta Analysis / CodeScene Code Health Review (main)

❌ New issue: Complex Conditional

UmbDecimalPropertyValuePreset.parseConfiguredNumber has 1 complex conditionals with 2 branches, threshold = 2. A complex conditional is an expression inside a branch (e.g. if, for, while) which consists of multiple, logical operators such as AND/OR. The more logical operators in an expression, the more severe the code smell.
return undefined;
}

const parsedValue = Number(rawValue);
return Number.isFinite(parsedValue) ? parsedValue : undefined;
}
}

export { UmbDecimalPropertyValuePreset as api };
Loading