Skip to content
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

V13: fix 16663 #16866

Merged
merged 4 commits into from
Aug 13, 2024
Merged
Changes from all 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
@@ -0,0 +1,95 @@
/**
* @ngdoc service
* @name umbraco.services.rte-block-clipboard-service
*
* Handles clipboard resolvers for Block of RTE properties.
*
*/
(function () {
'use strict';



/**
* When performing a runtime copy of Block Editors entries, we copy the ElementType Data Model and inner IDs are kept identical, to ensure new IDs are changed on paste we need to provide a resolver for the ClipboardService.
*/
angular.module('umbraco').run(['clipboardService', 'udiService', function (clipboardService, udiService) {

function replaceUdi(obj, key, dataObject, markup) {
var udi = obj[key];
var newUdi = udiService.create("element");
obj[key] = newUdi;
dataObject.forEach((data) => {
if (data.udi === udi) {
data.udi = newUdi;
}
});
// make a attribute name of the key, by kebab casing it:
var attrName = key.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
// replace the udi in the markup as well.
var regex = new RegExp('data-'+attrName+'="'+udi+'"', "g");
markup = markup.replace(regex, 'data-'+attrName+'="'+newUdi+'"');
return markup;
}
function replaceUdisOfObject(obj, propValue, markup) {
for (var k in obj) {
if(k === "contentUdi") {
markup = replaceUdi(obj, k, propValue.contentData, markup);
} else if(k === "settingsUdi") {
markup = replaceUdi(obj, k, propValue.settingsData, markup);
} else {
// lets crawl through all properties of layout to make sure get captured all `contentUdi` and `settingsUdi` properties.
var propType = typeof obj[k];
if(propType != null && (propType === "object" || propType === "array")) {

Check warning on line 43 in src/Umbraco.Web.UI.Client/src/views/propertyeditors/rte/blocks/umb-rte-block-clipboard.component.js

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (v13/dev)

❌ New issue: Complex Conditional

replaceUdisOfObject 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.
markup = replaceUdisOfObject(obj[k], propValue, markup);
}
}
}
return markup
}

Check warning on line 49 in src/Umbraco.Web.UI.Client/src/views/propertyeditors/rte/blocks/umb-rte-block-clipboard.component.js

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (v13/dev)

❌ New issue: Bumpy Road Ahead

replaceUdisOfObject has 2 blocks with nested conditional logic. Any nesting of 2 or deeper is considered. Threshold is one single, nested block per function. The Bumpy Road code smell is a function that contains multiple chunks of nested conditional logic. The deeper the nesting and the more bumps, the lower the code health.


function rawRteBlockResolver(propertyValue, propPasteResolverMethod) {
if (propertyValue != null && typeof propertyValue === "object") {

// object property of 'blocks' holds the data for the Block Editor.
var value = propertyValue.blocks;

// we got an object, and it has these three props then we are most likely dealing with a Block Editor.
if ((value.layout !== undefined && value.contentData !== undefined && value.settingsData !== undefined)) {

Check warning on line 59 in src/Umbraco.Web.UI.Client/src/views/propertyeditors/rte/blocks/umb-rte-block-clipboard.component.js

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (v13/dev)

❌ New issue: Complex Conditional

rawRteBlockResolver 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.

// replaceUdisOfObject replaces udis of the value object(by instance reference), but also returns the updated markup (as we cant update the reference of a string).
propertyValue.markup = replaceUdisOfObject(value.layout, value, propertyValue.markup);

// run resolvers for inner properties of this Blocks content data.
if(value.contentData.length > 0) {
value.contentData.forEach((item) => {
for (var k in item) {
propPasteResolverMethod(item[k], clipboardService.TYPES.RAW);
}
});
}
// run resolvers for inner properties of this Blocks settings data.
if(value.settingsData.length > 0) {
value.settingsData.forEach((item) => {
for (var k in item) {
propPasteResolverMethod(item[k], clipboardService.TYPES.RAW);
}
});
}

}
}
}

Check warning on line 83 in src/Umbraco.Web.UI.Client/src/views/propertyeditors/rte/blocks/umb-rte-block-clipboard.component.js

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (v13/dev)

❌ New issue: Complex Method

rawRteBlockResolver has a cyclomatic complexity of 10, threshold = 9. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.

Check warning on line 83 in src/Umbraco.Web.UI.Client/src/views/propertyeditors/rte/blocks/umb-rte-block-clipboard.component.js

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (v13/dev)

❌ New issue: Bumpy Road Ahead

rawRteBlockResolver has 2 blocks with nested conditional logic. Any nesting of 2 or deeper is considered. Threshold is one single, nested block per function. The Bumpy Road code smell is a function that contains multiple chunks of nested conditional logic. The deeper the nesting and the more bumps, the lower the code health.

Check warning on line 83 in src/Umbraco.Web.UI.Client/src/views/propertyeditors/rte/blocks/umb-rte-block-clipboard.component.js

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (v13/dev)

❌ New issue: Deep, Nested Complexity

rawRteBlockResolver has a nested complexity depth of 4, threshold = 4. This function contains deeply nested logic such as if statements and/or loops. The deeper the nesting, the lower the code health.

function elementTypeBlockResolver(obj, propPasteResolverMethod) {
// we could filter for specific Property Editor Aliases, but as the Block Editor structure can be used by many Property Editor we do not in this code know a good way to detect that this is a Block Editor and will therefor leave it to the value structure to determin this.
rawRteBlockResolver(obj.value, propPasteResolverMethod);
}

clipboardService.registerPastePropertyResolver(elementTypeBlockResolver, clipboardService.TYPES.ELEMENT_TYPE);
clipboardService.registerPastePropertyResolver(rawRteBlockResolver, clipboardService.TYPES.RAW);

}]);

})();
Loading