From 39d23ccf67e247c695caf597e176dd66261394e4 Mon Sep 17 00:00:00 2001 From: Zac Spitzer Date: Tue, 16 Apr 2024 12:58:18 +0200 Subject: [PATCH 1/5] DATAAPI-29 add dataApiRenderEmptyValues property https://github.com/pixl8/preside-ext-data-api/issues/81 --- README.md | 3 +++ services/DataApiConfigurationService.cfc | 13 +++++++------ services/DataApiService.cfc | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 4d814cc..e762e01 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,7 @@ Object properties support the following _optional_ annotations: * `dataApiFormat`: For the documentation. The format for the property, e.g. 'Email address'. * `dataApiEnabled`: Whether or not this property should be included in the API * `dataApiUpsertEnabled`: Whether or not this property should be included in the POST/PUT operations. +* `dataApiRenderEmptyValues`: Whether to force always calling a custom render when the value being processed is empty or null ## Custom renderers @@ -72,6 +73,8 @@ If you specify a non-default renderer for an object property, it will be rendere property name="my_prop" dataApiAlias="myProp" dataApiRenderer="myCustomRenderer"; ``` +By default for performance reasons, empty/null values are skipped, to force always calling the custom renderer, set the following property `dataApiRenderEmptyValues=true`. + To implement this, you will need a corresponding _viewlet_ at `renderers.content.myCustomRenderer.dataapi` **or** `renderers.content.myCustomRenderer.default` (a renderer _context_ of `dataapi` will be used and the system will fallback to the default renderer if that context is not implemented). For example: diff --git a/services/DataApiConfigurationService.cfc b/services/DataApiConfigurationService.cfc index 595d57c..1c5e6b4 100755 --- a/services/DataApiConfigurationService.cfc +++ b/services/DataApiConfigurationService.cfc @@ -199,12 +199,13 @@ component { for( var field in props ) { fieldSettings[ field ] = { - alias = props[ field ][ "dataApiAlias#namespace#" ] ?: field - , renderer = props[ field ][ "dataApiRenderer#namespace#" ] ?: _getDefaultRendererForField( props[ field ] ?: {} ) - , type = props[ field ][ "dataApiType#namespace#" ] ?: "" - , format = props[ field ][ "dataApiFormat#namespace#" ] ?: "" - , derivative = props[ field ][ "dataApiDerivative#namespace#" ] ?: "" - , name = field + alias = props[ field ][ "dataApiAlias#namespace#" ] ?: field + , renderer = props[ field ][ "dataApiRenderer#namespace#" ] ?: _getDefaultRendererForField( props[ field ] ?: {} ) + , renderEmptyValues = props[ field ][ "dataApiRenderEmptyValues#namespace#" ] ?: false + , type = props[ field ][ "dataApiType#namespace#" ] ?: "" + , format = props[ field ][ "dataApiFormat#namespace#" ] ?: "" + , derivative = props[ field ][ "dataApiDerivative#namespace#" ] ?: "" + , name = field }; } diff --git a/services/DataApiService.cfc b/services/DataApiService.cfc index c6eb002..908d5eb 100644 --- a/services/DataApiService.cfc +++ b/services/DataApiService.cfc @@ -336,7 +336,7 @@ component { return $isFeatureEnabled( "dataApiUseNullForStrings" ) ? NullValue() : ""; } - if ( !Len( arguments.value ?: "" ) ) { + if ( !Len( arguments.value ?: "" ) && !arguments.fieldSettings.renderEmptyValues ) { return $isFeatureEnabled( "dataApiUseNullForStrings" ) ? NullValue() : ""; } From 401349f5b8a0b574ae4b0f458328461fff5d9aca Mon Sep 17 00:00:00 2001 From: Dominic Watson Date: Tue, 16 Apr 2024 12:07:26 +0100 Subject: [PATCH 2/5] [twgit] Init feature 'feature-DATAAPI-29_allow-empty-values-to-be-passed-to-a-field-renderer'. From 09a59b0b2c7f4b4f5b93b2de1b6f5dfd22fdd7ca Mon Sep 17 00:00:00 2001 From: Dominic Watson Date: Tue, 16 Apr 2024 12:09:00 +0100 Subject: [PATCH 3/5] DATAAPI-29 alignment + a little extra defensiveness --- services/DataApiConfigurationService.cfc | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/services/DataApiConfigurationService.cfc b/services/DataApiConfigurationService.cfc index 1c5e6b4..eab3be1 100755 --- a/services/DataApiConfigurationService.cfc +++ b/services/DataApiConfigurationService.cfc @@ -199,14 +199,16 @@ component { for( var field in props ) { fieldSettings[ field ] = { - alias = props[ field ][ "dataApiAlias#namespace#" ] ?: field - , renderer = props[ field ][ "dataApiRenderer#namespace#" ] ?: _getDefaultRendererForField( props[ field ] ?: {} ) - , renderEmptyValues = props[ field ][ "dataApiRenderEmptyValues#namespace#" ] ?: false - , type = props[ field ][ "dataApiType#namespace#" ] ?: "" - , format = props[ field ][ "dataApiFormat#namespace#" ] ?: "" - , derivative = props[ field ][ "dataApiDerivative#namespace#" ] ?: "" + alias = props[ field ][ "dataApiAlias#namespace#" ] ?: field + , renderer = props[ field ][ "dataApiRenderer#namespace#" ] ?: _getDefaultRendererForField( props[ field ] ?: {} ) + , renderEmptyValues = props[ field ][ "dataApiRenderEmptyValues#namespace#" ] ?: false + , type = props[ field ][ "dataApiType#namespace#" ] ?: "" + , format = props[ field ][ "dataApiFormat#namespace#" ] ?: "" + , derivative = props[ field ][ "dataApiDerivative#namespace#" ] ?: "" , name = field }; + + fieldSettings[ field ].renderEmptyValues = IsBoolean( fieldSettings[ field ].renderEmptyValues ) && fieldSettings[ field ].renderEmptyValues; } return fieldSettings; From 18cffa6d7b4d8afad64e240bf314bffcf22fde52 Mon Sep 17 00:00:00 2001 From: Dominic Watson Date: Tue, 16 Apr 2024 12:53:11 +0100 Subject: [PATCH 4/5] [twgit] Init hotfix 'hotfix-3.5.10'. From dcb4abe4b7084241a1c6ad0af4653687cc83351d Mon Sep 17 00:00:00 2001 From: Dominic Watson Date: Tue, 16 Apr 2024 12:55:11 +0100 Subject: [PATCH 5/5] changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 81f56c3..d5808b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## v3.5.10 + +* Add flag option to allow renderers to process empty values (fix for certain implementations with changes made in 3.5.5) + ## v3.5.9 * [DATAAPI-27](https://projects.pixl8.london/browse/DATAAPI-27) - Function count does not exist in the object