-
Notifications
You must be signed in to change notification settings - Fork 3.4k
[COMMS-916] Read cost report version filter and group-by from target_versions #24432
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
Draft
akabiru
wants to merge
9
commits into
dev
Choose a base branch
from
implementation/comms-916-adjust-cost-reports-to-read-from-target_versions
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
829cc91
Read cost report version filter and group-by from target_versions
akabiru c180ad3
Guard target-version join against polymorphic entity collisions
akabiru 6038740
Pin intentional multi-value over-count in cost report specs
akabiru c89d659
Gate cost report version filter/group-by on multiple-versions flag
akabiru f326962
Fix 'is not' version filter to exclude the whole work package
akabiru 93757d5
Clarify primary-version comments as lowest version id
akabiru dbad763
Cover flag-off version-filter negation on the primary join
akabiru 3643997
Add chip multi-select to the cost report versions filter
akabiru 4e5c883
Drop blank version filter values before id coercion
akabiru File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
modules/reporting/app/models/cost_query/work_package_target_version_join.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| #-- copyright | ||
| # OpenProject is an open source project management software. | ||
| # Copyright (C) the OpenProject GmbH | ||
| # | ||
| # This program is free software; you can redistribute it and/or | ||
| # modify it under the terms of the GNU General Public License version 3. | ||
| # | ||
| # OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: | ||
| # Copyright (C) 2006-2013 Jean-Philippe Lang | ||
| # Copyright (C) 2010-2013 the ChiliProject Team | ||
| # | ||
| # This program is free software; you can redistribute it and/or | ||
| # modify it under the terms of the GNU General Public License | ||
| # as published by the Free Software Foundation; either version 2 | ||
| # of the License, or (at your option) any later version. | ||
| # | ||
| # This program is distributed in the hope that it will be useful, | ||
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| # GNU General Public License for more details. | ||
| # | ||
| # You should have received a copy of the GNU General Public License | ||
| # along with this program; if not, write to the Free Software | ||
| # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
| # | ||
| # See COPYRIGHT and LICENSE files for more details. | ||
| #++ | ||
|
|
||
| module CostQuery::WorkPackageTargetVersionJoin | ||
| # Reaches a work package's target versions from the reporting entries. | ||
| # | ||
| # entries.entity_id is polymorphic (a time entry can point at a Meeting whose | ||
| # id collides with a work package's), so the entity_type guard lives in the ON | ||
| # clause: it keeps LEFT semantics for the group-by (non-work-package entries | ||
| # stay, grouped under "no version") instead of dropping them via WHERE. | ||
| # | ||
| # With multiple target versions on, the join is one-to-many: a work package | ||
| # with several target versions is reported under each of them. With the | ||
| # feature off a work package is single-version, so the join is narrowed to the | ||
| # primary target version (the lowest version id, matching target_versions.first) | ||
| # and stays one-to-one. | ||
|
akabiru marked this conversation as resolved.
|
||
| JOIN_ALL = <<~SQL.squish | ||
| LEFT OUTER JOIN work_package_versions | ||
| ON work_package_versions.work_package_id = entries.entity_id | ||
| AND entries.entity_type = 'WorkPackage' | ||
| AND work_package_versions.kind = 'target' | ||
| SQL | ||
|
|
||
| JOIN_PRIMARY = <<~SQL.squish | ||
| #{JOIN_ALL} | ||
| AND work_package_versions.version_id = ( | ||
| SELECT MIN(primary_target.version_id) | ||
| FROM work_package_versions primary_target | ||
| WHERE primary_target.work_package_id = entries.entity_id | ||
| AND primary_target.kind = 'target' | ||
| ) | ||
| SQL | ||
|
akabiru marked this conversation as resolved.
|
||
|
|
||
| # Read at report-build time so a feature-flag change takes effect without a | ||
| # restart. The filter and group-by must resolve to the exact same string so | ||
| # the engine collapses them into a single join. | ||
| def self.sql | ||
| Setting::WorkPackageMultipleVersions.active? ? JOIN_ALL : JOIN_PRIMARY | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| #-- copyright | ||
| # OpenProject is an open source project management software. | ||
| # Copyright (C) the OpenProject GmbH | ||
| # | ||
| # This program is free software; you can redistribute it and/or | ||
| # modify it under the terms of the GNU General Public License version 3. | ||
| # | ||
| # OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: | ||
| # Copyright (C) 2006-2013 Jean-Philippe Lang | ||
| # Copyright (C) 2010-2013 the ChiliProject Team | ||
| # | ||
| # This program is free software; you can redistribute it and/or | ||
| # modify it under the terms of the GNU General Public License | ||
| # as published by the Free Software Foundation; either version 2 | ||
| # of the License, or (at your option) any later version. | ||
| # | ||
| # This program is distributed in the hope that it will be useful, | ||
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| # GNU General Public License for more details. | ||
| # | ||
| # You should have received a copy of the GNU General Public License | ||
| # along with this program; if not, write to the Free Software | ||
| # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
| # | ||
| # See COPYRIGHT and LICENSE files for more details. | ||
| #++ | ||
|
|
||
| class Widget::Filters::Version < Widget::Filters::Base | ||
| include AngularHelper | ||
|
|
||
| def render | ||
| write(content_tag(:div, id: "#{filter_class.underscore_name}_arg_1", class: "advanced-filters--filter-value") do | ||
| label = html_label | ||
|
|
||
| box = angular_component_tag "opce-autocompleter", | ||
| inputs: { | ||
| filters: [], | ||
| InputName: "values[#{filter_class.underscore_name}]", | ||
| hiddenFieldAction: "change->reporting--page#selectValueChanged", | ||
| multiple: true, | ||
| items: available_versions, | ||
| bindLabel: "name", | ||
| bindValue: "id", | ||
| model: selected_version_ids | ||
| }, | ||
| id: "#{filter_class.underscore_name}_select_1", | ||
| class: "filter-value advanced-filters--ng-select" | ||
|
|
||
| content_tag(:span, class: "inline-label") do | ||
| label + box | ||
| end | ||
| end) | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def html_label | ||
| label_tag "#{filter_class.underscore_name}_arg_1_val", | ||
| "#{h(filter_class.label)} #{I18n.t(:label_filter_value)}", | ||
| class: "sr-only" | ||
| end | ||
|
|
||
| # The whole set of selectable versions, project-qualified so identically named | ||
| # versions in different projects stay distinguishable. The list is small, so we | ||
| # hand it to the autocompleter up front and let it filter client-side. | ||
| def available_versions | ||
| filter_class.available_values.map { |label, id| { id:, name: label } } | ||
| end | ||
|
akabiru marked this conversation as resolved.
|
||
|
|
||
| def selected_version_ids | ||
| expand_comma_separated_values! | ||
|
|
||
| filter.values.compact_blank.map(&:to_i) | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| #-- copyright | ||
| # OpenProject is an open source project management software. | ||
| # Copyright (C) the OpenProject GmbH | ||
| # | ||
| # This program is free software; you can redistribute it and/or | ||
| # modify it under the terms of the GNU General Public License version 3. | ||
| # | ||
| # OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: | ||
| # Copyright (C) 2006-2013 Jean-Philippe Lang | ||
| # Copyright (C) 2010-2013 the ChiliProject Team | ||
| # | ||
| # This program is free software; you can redistribute it and/or | ||
| # modify it under the terms of the GNU General Public License | ||
| # as published by the Free Software Foundation; either version 2 | ||
| # of the License, or (at your option) any later version. | ||
| # | ||
| # This program is distributed in the hope that it will be useful, | ||
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| # GNU General Public License for more details. | ||
| # | ||
| # You should have received a copy of the GNU General Public License | ||
| # along with this program; if not, write to the Free Software | ||
| # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
| # | ||
| # See COPYRIGHT and LICENSE files for more details. | ||
| #++ | ||
|
|
||
| require_relative "../../../spec_helper" | ||
|
|
||
| RSpec.describe Widget::Filters::Version do | ||
| let(:admin) { create(:admin) } | ||
| let(:project) { create(:project, name: "Demo project") } | ||
| let(:version) { create(:version, project:, name: "2.0.0") } | ||
|
|
||
| let(:filter) do | ||
| CostQuery::Filter::VersionId.new.tap { |f| f.values = [version.id.to_s] } | ||
| end | ||
| let(:widget) { described_class.new(filter) } | ||
|
|
||
| before { login_as(admin) } | ||
|
|
||
| describe "#available_versions" do | ||
| subject(:items) { widget.send(:available_versions) } | ||
|
|
||
| it "offers every version with a project-qualified label the autocompleter can filter" do | ||
| expect(items).to include(id: version.id, name: "Demo project - 2.0.0") | ||
| end | ||
| end | ||
|
|
||
| describe "#selected_version_ids" do | ||
| subject(:ids) { widget.send(:selected_version_ids) } | ||
|
|
||
| it "maps the filter values to integer ids the autocompleter matches against its items" do | ||
| expect(ids).to eq([version.id]) | ||
| end | ||
|
|
||
| context "when a blank value slips in" do | ||
| let(:filter) do | ||
| CostQuery::Filter::VersionId.new.tap { |f| f.values = [version.id.to_s, ""] } | ||
| end | ||
|
|
||
| it "drops it instead of coercing it to a spurious id 0" do | ||
| expect(ids).to eq([version.id]) | ||
| end | ||
| end | ||
| end | ||
| end |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.