Skip to content

Conversation

nielslyngsoe
Copy link
Member

@nielslyngsoe nielslyngsoe commented Sep 9, 2025

Implement a few additional properties for the callArgs argument for processValue of Value Presets API.

This turned out to be necessary because neither are property value presets being created in the context of the property, and it's also being processed before the entity data is available.

This gives contextual awareness for the API, so it can react to things like the Document Type ID(unique) or the Property Alias or a few other values.

resulting in these properties being available in the 4 argument to processValue, also called callArgs:

(Example data from my own manual test)

entityType: "document"
entityTypeUnique: "b1072c96-a946-4eb2-b8cc-798feee1b453"
entityUnique: "93883faa-1ed3-4e64-b202-bcdc2cd81131"
propertyEditorSchemaAlias: "Umbraco.Slider"
propertyEditorUiAlias: "Umb.PropertyEditorUi.Slider"
variantId: UmbVariantId {culture: null, segment: null}

can be recieved using this method as your processValue:

async processValue(
		value: undefined | UmbSliderPropertyEditorUiValue,
		config: UmbPropertyEditorConfig,
		typeArgs: UmbPropertyTypePresetModelTypeModel,
		callArgs: UmbPropertyValuePresetApiCallArgs,
	): Promise<UmbSliderPropertyEditorUiValue> {
		console.log(callArgs);
}

This is implemented in a none-breaking way, but should be broken for v.17, therefore added TODOs to revisit for v.17

@Copilot Copilot AI review requested due to automatic review settings September 9, 2025 18:31
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enhances the Property Value Preset API by adding contextual awareness through additional properties in the callArgs argument. This allows the API to react to specific contextual information like Document Type ID, Property Alias, and other values.

Key changes:

  • Enhanced the UmbPropertyValuePresetApiCallArgs interface with new contextual properties
  • Updated the property value preset builder controllers to pass entity information to preset APIs
  • Modified test files to provide required entity context when calling the create method

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
types.ts Adds new interface UmbPropertyValuePresetApiCallArgsEntityBase and enhances UmbPropertyValuePresetApiCallArgs with contextual properties
property-value-preset-variant-builder.controller.ts Adds TODO comment about breaking changes for segment control
property-value-preset-variant-builder.controller.test.ts Updates test calls to include required entity context parameters
property-value-preset-builder.controller.ts Implements entity context handling, adds deprecation warnings, and constructs full callArgs
property-value-preset-builder.controller.test.ts Updates all test method calls to provide entity context
content-detail-workspace-base.ts Passes entity type, unique, and content type unique to preset builder
block-manager.context.ts Provides block-specific entity context to preset builder

@umbraco umbraco deleted a comment from Copilot AI Sep 9, 2025
@umbraco umbraco deleted a comment from Copilot AI Sep 9, 2025
@nielslyngsoe nielslyngsoe enabled auto-merge (squash) September 9, 2025 18:48
Copy link
Contributor

@AndyButland AndyButland left a comment

Choose a reason for hiding this comment

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

I've tested it out with some console.logs, and can see the expected data coming through - including all that I needed to achieve the task I was looking to implement. Should it be possible to type this arguments though other than with any?

	async processValue(
		value: undefined | UmbIntegerPropertyEditorUiValue,
		config: UmbPropertyEditorConfig,
		typeArgs: any,
		callArgs: any) {
            ...
        }

@nielslyngsoe
Copy link
Member Author

@AndyButland I see now that my example used any. So I have updated the example in this PR with the right types.

In actual implementations, they have to define the right types, making this a bit of a complex DX as the Developer would need to find those types.

@AndyButland AndyButland self-requested a review September 16, 2025 10:06
Copy link
Contributor

@AndyButland AndyButland left a comment

Choose a reason for hiding this comment

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

This looks to work as expected.

To test, I've modified UmbIntegerPropertyValuePreset as follows (just to log out the values provided):

	async processValue(
		value: undefined | UmbIntegerPropertyEditorUiValue,
		config: UmbPropertyEditorConfig,
		typeArgs: UmbPropertyTypePresetModelTypeModel,
		callArgs: UmbPropertyValuePresetApiCallArgs) {
		console.log(value);
		console.log(config);
		console.log(typeArgs);
		console.log(callArgs);
		const min = Number(config.find((x) => x.alias === 'min')?.value ?? 0);
		const minVerified = isNaN(min) ? 0 : Math.round(min);

		return value !== undefined ? value : minVerified;
	}

Then when I create a new document that has an integer property I see:

image

Which is great, as we have the information now about the property and document to be able to make decisions based on that for what the preset will be.

@nielslyngsoe nielslyngsoe merged commit 5fd01e0 into main Sep 16, 2025
26 of 27 checks passed
@nielslyngsoe nielslyngsoe deleted the v16/feature/property-value-preset-builder-caller-args branch September 16, 2025 10:07
@AndyButland
Copy link
Contributor

Docs PR is here: umbraco/UmbracoDocs#7403

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants