Skip to content

add single blocklist delete #18073

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

Merged
merged 4 commits into from
May 12, 2025
Merged
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
2 changes: 2 additions & 0 deletions src/Umbraco.Core/EmbeddedResources/Lang/en.xml
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@
Content.
</key>
<key alias="nestedContentDeleteAllItems">Are you sure you want to delete all items?</key>
<key alias="nestedContentDeleteItem">Are you sure you want to delete this item?</key>
<key alias="nestedContentNoContentTypes">No Content Types are configured for this property.</key>
<key alias="nestedContentAddElementType">Add Element Type</key>
<key alias="nestedContentSelectElementTypeModalTitle">Select Element Type</key>
Expand Down Expand Up @@ -331,6 +332,7 @@
<key alias="schedulePublishHelp">Select the date and time to publish and/or unpublish the content item.</key>
<key alias="createEmpty">Create new</key>
<key alias="createFromClipboard">Paste from clipboard</key>
<key alias="removeItem">Remove Item</key>
<key alias="nodeIsInTrash">This item is in the Recycle Bin</key>
<key alias="noProperties">No content can be added for this item</key>
<key alias="variantSaveNotAllowed">Save is not allowed</key>
Expand Down
2 changes: 2 additions & 0 deletions src/Umbraco.Core/EmbeddedResources/Lang/en_us.xml
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@
<![CDATA[<a href="https://docs.umbraco.com/umbraco-cms/fundamentals/data/scheduled-publishing#timezones" target="_blank" rel="noopener">What does this mean?</a>]]></key>
<key alias="nestedContentDeleteItem">Are you sure you want to delete this item?</key>
<key alias="nestedContentDeleteAllItems">Are you sure you want to delete all items?</key>
<key alias="nestedContentDeleteItem">Are you sure you want to delete this item?</key>
<key alias="nestedContentEditorNotSupported">Property %0% uses editor %1% which is not supported by Nested
Content.
</key>
Expand Down Expand Up @@ -330,6 +331,7 @@
<key alias="schedulePublishHelp">Select the date and time to publish and/or unpublish the content item.</key>
<key alias="createEmpty">Create new</key>
<key alias="createFromClipboard">Paste from clipboard</key>
<key alias="removeItem">Remove Item</key>
<key alias="nodeIsInTrash">This item is in the Recycle Bin</key>
<key alias="variantSaveNotAllowed">Save is not allowed</key>
<key alias="variantPublishNotAllowed">Publish is not allowed</key>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,59 +93,59 @@

function ButtonGroupDirective() {

function controller($scope, localizationService) {
$scope.toggleStyle = null;
$scope.blockElement = false;

var buttonStyle = $scope.buttonStyle;
if (buttonStyle) {
// Make it possible to pass in multiple styles
if (buttonStyle.startsWith("[") && buttonStyle.endsWith("]")) {
// when using an attr it will always be a string so we need to remove square brackets and turn it into and array
var withoutBrackets = buttonStyle.replace(/[\[\]']+/g, '');
// split array by , + make sure to catch whitespaces
var array = withoutBrackets.split(/\s?,\s?/g);

Utilities.forEach(array, item => {
if (item === "block") {
$scope.blockElement = true;
} else {
$scope.toggleStyle = ($scope.toggleStyle ? $scope.toggleStyle + " " : "") + "btn-" + item;
}
});
} else {
if (buttonStyle === "block") {
$scope.blockElement = true;
} else {
$scope.toggleStyle = "btn-" + buttonStyle;
}
}
}

// As the <localize /> directive doesn't support Angular expressions as fallback, we instead listen for changes
// to the label key of the default button, and if detected, we update the button label with the localized value
// received from the localization service
$scope.$watch("defaultButton.labelKey", function () {
if (!$scope.defaultButton.labelKey) return;
if (!$scope.defaultButton?.labelKey) return;
localizationService.localize($scope.defaultButton.labelKey).then(value => {
if (value && value.indexOf("[") === 0) return;
$scope.defaultButton.label = value;
});
});

// In a similar way, we must listen for changes to the sub buttons (or their label keys), and if detected, update
// the label with the localized value received from the localization service
$scope.$watch("defaultButton.subButtons", function () {
if (!Array.isArray($scope.subButtons)) return;
$scope.subButtons.forEach(function (sub) {
if (!sub.labelKey) return;
localizationService.localize(sub.labelKey).then(value => {
if (value && value.indexOf("[") === 0) return;
sub.label = value;
});
});
}, true);

Check warning on line 148 in src/Umbraco.Web.UI.Client/src/common/directives/components/buttons/umbbuttongroup.directive.js

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (contrib)

❌ New issue: Complex Method

ButtonGroupDirective.controller has a cyclomatic complexity of 15, 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.
}

function link(scope) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(function () {

Check notice on line 1 in src/Umbraco.Web.UI.Client/src/views/propertyeditors/blocklist/umbBlockListPropertyEditor.component.js

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (contrib)

✅ Getting better: Overall Code Complexity

The mean cyclomatic complexity decreases from 4.94 to 4.81, threshold = 4. This file has many conditional statements (e.g. if, for, while) across its implementation, leading to lower code health. Avoid adding more conditionals.
"use strict";


Expand Down Expand Up @@ -37,6 +37,9 @@
let copyAllBlocksAction = null;
let deleteAllBlocksAction = null;
let pasteSingleBlockAction = null;
let resetSingleBlock = null;

let scopeOfExistence = null;

var inlineEditing = false;
var liveEditing = true;
Expand Down Expand Up @@ -124,64 +127,73 @@
vm.listWrapperStyles['max-width'] = vm.model.config.maxPropertyWidth;
}

// We need to ensure that the property model value is an object, this is needed for modelObject to recive a reference and keep that updated.
// We need to ensure that the property model value is an object, this is needed for modelObject to receive a reference and keep that updated.
if (typeof vm.model.value !== 'object' || vm.model.value === null) {// testing if we have null or undefined value or if the value is set to another type than Object.
vm.model.value = {};
}

var scopeOfExistence = $scope;
scopeOfExistence = $scope;
if (vm.umbVariantContentEditors && vm.umbVariantContentEditors.getScope) {
scopeOfExistence = vm.umbVariantContentEditors.getScope();
} else if(vm.umbElementEditorContent && vm.umbElementEditorContent.getScope) {
scopeOfExistence = vm.umbElementEditorContent.getScope();
}

vm.sortableOptions = {
axis: "y",
containment: "parent",
cursor: "grabbing",
handle: ".blockelement__draggable-element",
cancel: "input,textarea,select,option",
classes: ".blockelement--dragging",
distance: 5,
tolerance: "pointer",
scroll: true,
disabled: vm.readonly || vm.singleBlockMode,
update: function (ev, ui) {
setDirty();
}
};

copyAllBlocksAction = {
labelKey: "clipboard_labelForCopyAllEntries",
labelTokens: [vm.model.label],
icon: "icon-documents",
method: requestCopyAllBlocks,
isDisabled: true,
useLegacyIcon: false
};

deleteAllBlocksAction = {
labelKey: "clipboard_labelForRemoveAllEntries",
labelTokens: [],
icon: "icon-trash",
method: requestDeleteAllBlocks,
isDisabled: true,
useLegacyIcon: false
};

pasteSingleBlockAction = {
labelKey: "content_createFromClipboard",
labelTokens: [],
icon: "icon-paste-in",
method: requestShowClipboard,
isDisabled: false,
useLegacyIcon: false
};

resetSingleBlock = {
labelKey: "content_removeItem",
labelTokens: [],
icon: "icon-trash",
method: requestResetSingleBlock,
isDisabled: false,
useLegacyIcon: false
};

var propertyActions = [copyAllBlocksAction, deleteAllBlocksAction];

var propertyActionsForSingleBlockMode = [pasteSingleBlockAction];
var propertyActionsForSingleBlockMode = [pasteSingleBlockAction, resetSingleBlock];

Check notice on line 196 in src/Umbraco.Web.UI.Client/src/views/propertyeditors/blocklist/umbBlockListPropertyEditor.component.js

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (contrib)

ℹ Getting worse: Complex Method

BlockListController.onInit already has high cyclomatic complexity, and now it increases in Lines of Code from 82 to 90. 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.

if (vm.umbProperty) {
if (vm.singleBlockMode) {
Expand Down Expand Up @@ -844,6 +856,24 @@
});
}

function requestResetSingleBlock() {
localizationService.localizeMany(["content_nestedContentDeleteItem", "general_delete"]).then(function (data) {
overlayService.confirmDelete({
title: data[1],
content: data[0],
close: function () {
overlayService.close();
},
submit: function () {
deleteAllBlocks();
modelObject = blockEditorService.createModelObject(vm.model.value, vm.model.editor, vm.model.config.blocks, scopeOfExistence, $scope);
modelObject.load().then(onLoaded);
overlayService.close();
}
});
});
}

function openSettingsForBlock(block, blockIndex, parentForm) {
editBlock(block, true, blockIndex, parentForm);
}
Expand Down
Loading