Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

[33592] Add an empty group to ensure the user can remove all groups

Oliver Güntheraba899626232
diff --git a/frontend/src/app/modules/admin/types/type-form-configuration.component.ts b/frontend/src/app/modules/admin/types/type-form-configuration.component.ts
index 0363f0d906b..58848916442 100644
--- a/frontend/src/app/modules/admin/types/type-form-configuration.component.ts
+++ b/frontend/src/app/modules/admin/types/type-form-configuration.component.ts
@@ -30,6 +30,7 @@ export interface TypeGroup {
}
export const adminTypeFormConfigurationSelector = 'admin-type-form-configuration';
+export const emptyTypeGroup = '__empty';
@Component({
selector: adminTypeFormConfigurationSelector,
@@ -125,7 +126,9 @@ export class TypeFormConfigurationComponent extends UntilDestroyedMixin implemen
});
// Get attribute id
- this.groups = JSON.parse(this.element.dataset.activeGroups!);
+ this.groups = JSON
+ .parse(this.element.dataset.activeGroups!)
+ .filter((group:TypeGroup) => group?.key !== emptyTypeGroup);
this.inactives = JSON.parse(this.element.dataset.inactiveAttributes!);
// Setup autoscroll
@@ -222,9 +225,23 @@ export class TypeFormConfigurationComponent extends UntilDestroyedMixin implemen
this.inactives = [...newValue].sort((a, b) => a.translation.localeCompare(b.translation));
}
+ // We maintain an empty group
+ // that gets hidden in the frontend in case the user
+ // decides to remove all groups
+ // This was necessary since the "default" is actually an empty array of groups
+ private get emptyGroup():TypeGroup {
+ return { type: 'attribute', key: emptyTypeGroup, name: 'empty', attributes: [] };
+ }
+
private updateHiddenFields() {
const hiddenField = this.form.find('.admin-type-form--hidden-field');
- hiddenField.val(JSON.stringify(this.groups));
+ if (this.groups.length === 0) {
+ // Ensure we're adding an empty group if deliberately removing
+ // all values.
+ hiddenField.val(JSON.stringify([this.emptyGroup]));
+ } else {
+ hiddenField.val(JSON.stringify(this.groups));
+ }
}
}
diff --git a/spec/features/types/form_configuration_spec.rb b/spec/features/types/form_configuration_spec.rb
index d8c56ce9e00..bffe7fd6d17 100644
--- a/spec/features/types/form_configuration_spec.rb
+++ b/spec/features/types/form_configuration_spec.rb
@@ -86,6 +86,40 @@ describe 'form configuration', type: :feature, js: true do
form.expect_attribute(key: :assignee)
end
+ it 'can remove all groups to be left with an invisible one (Regression #33592)' do
+ form.remove_group 'Details'
+ form.remove_group 'Estimates and Time'
+ form.remove_group 'People'
+ form.remove_group 'Costs'
+
+ # Save configuration
+ form.save_changes
+ expect(page).to have_selector('.flash.notice', text: 'Successful update.', wait: 10)
+
+ form.expect_empty
+
+ # Test the actual type backend
+ type.reload
+ expect(type.attribute_groups.count).to eq 1
+ expect(type.attribute_groups.first.key).to eq :__empty
+ expect(type.attribute_groups.first.attributes).to be_empty
+
+ # Visit work package with that type
+ wp_page.visit!
+ wp_page.ensure_page_loaded
+
+ wp_page.expect_hidden_field(:version)
+ wp_page.expect_hidden_field(:assignee)
+ wp_page.expect_hidden_field(:responsible)
+ wp_page.expect_hidden_field(:priority)
+ wp_page.expect_hidden_field(:date)
+ wp_page.expect_hidden_field(:category)
+ wp_page.expect_hidden_field(:done_ratio)
+
+ groups = page.all('.attributes-group--header-text').map(&:text)
+ expect(groups).to eq %w[DESCRIPTION FILES]
+ end
+
it 'allows modification of the form configuration' do
#
# Test default set of groups
diff --git a/spec/support/components/admin/type_configuration_form.rb b/spec/support/components/admin/type_configuration_form.rb
index a20bac201c3..87ad78f8d7b 100644
--- a/spec/support/components/admin/type_configuration_form.rb
+++ b/spec/support/components/admin/type_configuration_form.rb
@@ -58,6 +58,10 @@ module Components
page.find '#type-form-conf-inactive-group .attributes'
end
+ def expect_empty
+ expect(page).to have_no_selector('#draggable-groups .group-head')
+ end
+
def find_group(name)
head = page.find('.group-head', text: name.upcase)
@@ -194,6 +198,14 @@ module Components
expect(page).to have_selector('.group-edit-handler', text: to.upcase)
end
+ def remove_group(name)
+ container = find('.group-head', text: name.upcase)
+
+ container.find('.delete-group').click
+
+ expect(page).to have_no_selector('.group-head', text: name.upcase)
+ end
+
def expect_no_attribute(attribute, group)
expect(find_group(group)).not_to have_selector("#{attribute_selector(attribute)}")
end