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

Allow to select parent work packages for editing in tables

Oliver Güntherfa82943f9df3
diff --git a/frontend/src/app/shared/components/fields/edit/field-types/select-edit-field/select-edit-field.component.ts b/frontend/src/app/shared/components/fields/edit/field-types/select-edit-field/select-edit-field.component.ts
index e600ccca3d3..3ab3c53cda1 100644
--- a/frontend/src/app/shared/components/fields/edit/field-types/select-edit-field/select-edit-field.component.ts
+++ b/frontend/src/app/shared/components/fields/edit/field-types/select-edit-field/select-edit-field.component.ts
@@ -192,7 +192,7 @@ export class SelectEditFieldComponent extends EditFieldComponent implements OnIn
return this.fetchAllowedValueQuery(query);
}
- protected fetchAllowedValueQuery(query?:string) {
+ protected fetchAllowedValueQuery(query?:string):Promise<CollectionResource> {
return this.schema.allowedValues.$link.$fetch(this.allowedValuesFilter(query)) as Promise<CollectionResource>;
}
diff --git a/frontend/src/app/shared/components/fields/edit/field-types/work-package-edit-field.component.ts b/frontend/src/app/shared/components/fields/edit/field-types/work-package-edit-field.component.ts
index cfd48a9333a..8c0cae75427 100644
--- a/frontend/src/app/shared/components/fields/edit/field-types/work-package-edit-field.component.ts
+++ b/frontend/src/app/shared/components/fields/edit/field-types/work-package-edit-field.component.ts
@@ -35,6 +35,7 @@ import {
import { take } from 'rxjs/operators';
import { ApiV3FilterBuilder } from 'core-app/shared/helpers/api-v3/api-v3-filter-builder';
import { SelectEditFieldComponent } from './select-edit-field/select-edit-field.component';
+import { CollectionResource } from 'core-app/features/hal/resources/collection-resource';
@Component({
templateUrl: './work-package-edit-field.component.html',
@@ -64,6 +65,15 @@ export class WorkPackageEditFieldComponent extends SelectEditFieldComponent {
return this.requests.input$;
}
+ protected fetchAllowedValueQuery(query?:string):Promise<CollectionResource> {
+ if (this.name === 'parent') {
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
+ return this.schema.allowedValues.$link.$fetch({ query }) as Promise<CollectionResource>;
+ }
+
+ return super.fetchAllowedValueQuery(query);
+ }
+
protected allowedValuesFilter(query?:string):{} {
let filterParams = super.allowedValuesFilter(query);
diff --git a/lib/api/v3/utilities/path_helper.rb b/lib/api/v3/utilities/path_helper.rb
index 499ec95eac2..0c6e6e923ac 100644
--- a/lib/api/v3/utilities/path_helper.rb
+++ b/lib/api/v3/utilities/path_helper.rb
@@ -484,8 +484,9 @@ module API
"#{work_package_relations(work_package_id)}/#{id}"
end
- def self.work_package_available_relation_candidates(id)
- "#{work_package(id)}/available_relation_candidates"
+ def self.work_package_available_relation_candidates(id, type: nil)
+ query = "?type=#{type}" if type
+ "#{work_package(id)}/available_relation_candidates#{query}"
end
def self.work_package_revisions(id)
diff --git a/lib/api/v3/work_packages/schema/work_package_schema_representer.rb b/lib/api/v3/work_packages/schema/work_package_schema_representer.rb
index 3ea32630e3f..6d2670a895b 100644
--- a/lib/api/v3/work_packages/schema/work_package_schema_representer.rb
+++ b/lib/api/v3/work_packages/schema/work_package_schema_representer.rb
@@ -211,17 +211,16 @@ module API
end
}
- # TODO:
- # * create an available_work_package_parent resource
- # One can use a relatable filter with the 'parent' operator. Will however need to also
- # work without a value which is currently not supported.
- # * turn :parent into a schema_with_allowed_link
-
- schema :parent,
- type: 'WorkPackage',
- location: :link,
- required: false,
- writable: true
+ schema_with_allowed_link :parent,
+ type: 'WorkPackage',
+ required: false,
+ writable: true,
+ href_callback: ->(*) {
+ work_package = represented.work_package
+ if work_package&.persisted?
+ api_v3_paths.work_package_available_relation_candidates(represented.id, type: :parent)
+ end
+ }
schema_with_allowed_link :assignee,
type: 'User',
diff --git a/spec/features/work_packages/table/hierarchy/parent_column_spec.rb b/spec/features/work_packages/table/hierarchy/parent_column_spec.rb
index 10fe08bf240..7cda7b75c7d 100644
--- a/spec/features/work_packages/table/hierarchy/parent_column_spec.rb
+++ b/spec/features/work_packages/table/hierarchy/parent_column_spec.rb
@@ -4,8 +4,9 @@ describe 'Work Package table parent column', js: true do
let(:user) { create :admin }
let!(:parent) { create(:work_package, project:) }
let!(:child) { create(:work_package, project:, parent:) }
+ let!(:other_wp) { create(:work_package, project:) }
let!(:query) do
- query = build(:query, user:, project:)
+ query = build(:query, user:, project:)
query.column_names = ['subject', 'parent']
query.filters.clear
query.show_hierarchies = false
@@ -34,4 +35,17 @@ describe 'Work Package table parent column', js: true do
expect(page).to have_selector('td.parent', text: "##{parent.id}")
end
end
+
+ it 'can edit the parent work package (Regression #43647)' do
+ wp_table.visit_query query
+ wp_table.expect_work_package_listed(parent, child)
+
+ parent_field = wp_table.edit_field(child, :parent)
+ parent_field.update other_wp.subject
+
+ wp_table.expect_and_dismiss_toaster message: 'Successful update.'
+
+ child.reload
+ expect(child.parent).to eq other_wp
+ end
end
diff --git a/spec/lib/api/v3/work_packages/schema/work_package_schema_representer_spec.rb b/spec/lib/api/v3/work_packages/schema/work_package_schema_representer_spec.rb
index d1e3548918f..97579914527 100644
--- a/spec/lib/api/v3/work_packages/schema/work_package_schema_representer_spec.rb
+++ b/spec/lib/api/v3/work_packages/schema/work_package_schema_representer_spec.rb
@@ -797,6 +797,25 @@ describe ::API::V3::WorkPackages::Schema::WorkPackageSchemaRepresenter do
let(:writable) { true }
let(:location) { '_links' }
end
+
+ it_behaves_like 'links to allowed values via collection link' do
+ let(:path) { 'parent' }
+ let(:href) { api_v3_paths.work_package_available_relation_candidates(work_package.id, type: :parent) }
+ end
+
+ context 'when creating' do
+ let(:work_package) do
+ build(:work_package, project:) do |wp|
+ allow(wp)
+ .to receive(:available_custom_fields)
+ .and_return(available_custom_fields)
+ end
+ end
+
+ it_behaves_like 'does not link to allowed values' do
+ let(:path) { 'parent' }
+ end
+ end
end
describe 'type' do
diff --git a/spec/support/edit_fields/edit_field.rb b/spec/support/edit_fields/edit_field.rb
index e08449864d2..82e9cb5aeed 100644
--- a/spec/support/edit_fields/edit_field.rb
+++ b/spec/support/edit_fields/edit_field.rb
@@ -248,7 +248,7 @@ class EditField
'version-autocompleter'
when :assignee, :responsible, :user
'op-user-autocompleter'
- when :priority, :status, :type, :category, :workPackage
+ when :priority, :status, :type, :category, :workPackage, :parent
'create-autocompleter'
when :project
'op-autocompleter'