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

[55123] Fixed empty project attribute mapping list unlink response

Andreas Pfohl1bc11f42350e
diff --git a/app/components/projects/table_component.html.erb b/app/components/projects/table_component.html.erb
index 1b95df7fbb5..5c50618759d 100644
--- a/app/components/projects/table_component.html.erb
+++ b/app/components/projects/table_component.html.erb
@@ -26,43 +26,45 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
See COPYRIGHT and LICENSE files for more details.
++#%>
-<div class="project-list-page--table">
- <div class="generic-table--flex-container">
- <div class="generic-table--container <%= container_class %>">
- <div class="generic-table--results-container">
- <table class="generic-table" <%= table_id ? "id=\"#{table_id}\"".html_safe : '' %>>
- <colgroup>
- <% columns.each do |column| %>
- <col <%= "opHighlightCol" unless column.attribute == :hierarchy %> >
- <% end %>
- <col>
- </colgroup>
- <thead class="-sticky">
- <tr>
- <% columns.each do |column| %>
- <% if column.attribute == :hierarchy %>
- <th id="project-table--hierarchy-header">
- <div class="generic-table--sort-header-outer generic-table--sort-header-outer_no-highlighting">
- <div class="generic-table--sort-header"
- data-controller="params-from-query"
- data-application-target="dynamic"
- data-params-from-query-all-anchors-value="true"
- data-params-from-query-allowed-value='["query_id", "per_page", "filters", "columns"]'>
- <%= content_tag :a,
- helpers.op_icon("icon-hierarchy"),
- href: href_only_when_not_sort_lft,
- class: "spot-link #{deactivate_class_on_lft_sort}",
- title: t(:label_sort_by, value: %("#{t(:label_project_hierarchy)}")) %>
+
+<%= component_wrapper(tag: "div", data: { turbo: true }) do %>
+ <div class="project-list-page--table">
+ <div class="generic-table--flex-container">
+ <div class="generic-table--container <%= container_class %>">
+ <div class="generic-table--results-container">
+ <table class="generic-table" <%= table_id ? "id=\"#{table_id}\"".html_safe : '' %>>
+ <colgroup>
+ <% columns.each do |column| %>
+ <col <%= "opHighlightCol" unless column.attribute == :hierarchy %> >
+ <% end %>
+ <col>
+ </colgroup>
+ <thead class="-sticky">
+ <tr>
+ <% columns.each do |column| %>
+ <% if column.attribute == :hierarchy %>
+ <th id="project-table--hierarchy-header">
+ <div class="generic-table--sort-header-outer generic-table--sort-header-outer_no-highlighting">
+ <div class="generic-table--sort-header"
+ data-controller="params-from-query"
+ data-application-target="dynamic"
+ data-params-from-query-all-anchors-value="true"
+ data-params-from-query-allowed-value='["query_id", "per_page", "filters", "columns"]'>
+ <%= content_tag :a,
+ helpers.op_icon("icon-hierarchy"),
+ href: href_only_when_not_sort_lft,
+ class: "spot-link #{deactivate_class_on_lft_sort}",
+ title: t(:label_sort_by, value: %("#{t(:label_project_hierarchy)}")) %>
+ </div>
</div>
- </div>
- </th>
- <% elsif sortable_column?(column) %>
- <%= build_sort_header column.attribute,
- order_options(column) %>
- <% else %>
- <th>
- <div class="generic-table--sort-header-outer">
- <div class="generic-table--sort-header">
+ </th>
+ <% elsif sortable_column?(column) %>
+ <%= build_sort_header column.attribute,
+ order_options(column) %>
+ <% else %>
+ <th>
+ <div class="generic-table--sort-header-outer">
+ <div class="generic-table--sort-header">
<span>
<% if column.attribute == :favored %>
<%= render(Primer::Beta::Octicon.new(icon: "star-fill", color: :subtle, ml: 2, "aria-label": I18n.t(:label_favorite))) %>
@@ -70,41 +72,42 @@ See COPYRIGHT and LICENSE files for more details.
<%= column.caption %>
<% end %>
</span>
+ </div>
</div>
- </div>
- </th>
+ </th>
+ <% end %>
<% end %>
- <% end %>
- <th>
- <div class="generic-table--empty-header">
- </div>
- </th>
- </tr>
- </thead>
- <tbody>
- <% if rows.empty? %>
- <tr class="generic-table--empty-row">
- <td colspan="<%= headers.length + 1 %>"><%= empty_row_message %></td>
+ <th>
+ <div class="generic-table--empty-header">
+ </div>
+ </th>
</tr>
+ </thead>
+ <tbody>
+ <% if rows.empty? %>
+ <tr class="generic-table--empty-row">
+ <td colspan="<%= headers.length + 1 %>"><%= empty_row_message %></td>
+ </tr>
+ <% end %>
+ <%= render_collection rows %>
+ </tbody>
+ </table>
+ <% if inline_create_link && show_inline_create %>
+ <div class="wp-inline-create-button">
+ <%= inline_create_link %>
+ </div>
<% end %>
- <%= render_collection rows %>
- </tbody>
- </table>
- <% if inline_create_link && show_inline_create %>
- <div class="wp-inline-create-button">
- <%= inline_create_link %>
- </div>
- <% end %>
+ </div>
</div>
</div>
</div>
-</div>
-<% if paginated? %>
- <div data-controller="params-from-query"
- data-application-target="dynamic"
- data-params-from-query-all-anchors-value="true"
- data-params-from-query-allowed-value='["query_id", "columns"]'>
- <%= helpers.pagination_links_full model, { blocked_url_params: [:query_id, :columns] } %>
- </div>
+ <% if paginated? %>
+ <div data-controller="params-from-query"
+ data-application-target="dynamic"
+ data-params-from-query-all-anchors-value="true"
+ data-params-from-query-allowed-value='["query_id", "columns"]'>
+ <%= helpers.pagination_links_full model, { blocked_url_params: [:query_id, :columns] } %>
+ </div>
+ <% end %>
<% end %>
diff --git a/app/components/projects/table_component.rb b/app/components/projects/table_component.rb
index 048288c7e55..50b9c017d43 100644
--- a/app/components/projects/table_component.rb
+++ b/app/components/projects/table_component.rb
@@ -30,6 +30,8 @@
module Projects
class TableComponent < ::TableComponent
+ include OpTurbo::Streamable
+
options :params # We read collapsed state from params
options :current_user # adds this option to those of the base class
options :query
@@ -64,10 +66,11 @@ module Projects
# We don't return the project row
# but the [project, level] array from the helper
def rows
- @rows ||= begin
- projects_enumerator = ->(model) { to_enum(:projects_with_levels_order_sensitive, model).to_a } # rubocop:disable Lint/ToEnumArguments
- instance_exec(model, &projects_enumerator)
- end
+ @rows ||=
+ begin
+ projects_enumerator = ->(model) { to_enum(:projects_with_levels_order_sensitive, model).to_a }
+ instance_exec(model, &projects_enumerator)
+ end
end
def initialize_sorted_model
@@ -112,14 +115,15 @@ module Projects
end
def columns
- @columns ||= begin
- columns = query.selects.reject { |select| select.is_a?(Queries::Selects::NotExistingSelect) }
+ @columns ||=
+ begin
+ columns = query.selects.reject { |select| select.is_a?(Queries::Selects::NotExistingSelect) }
- index = columns.index { |column| column.attribute == :name }
- columns.insert(index, Queries::Projects::Selects::Default.new(:hierarchy)) if index
+ index = columns.index { |column| column.attribute == :name }
+ columns.insert(index, Queries::Projects::Selects::Default.new(:hierarchy)) if index
- columns
- end
+ columns
+ end
end
def projects(query)
diff --git a/app/controllers/admin/settings/project_custom_fields_controller.rb b/app/controllers/admin/settings/project_custom_fields_controller.rb
index ebc5e337468..387be7f2c76 100644
--- a/app/controllers/admin/settings/project_custom_fields_controller.rb
+++ b/app/controllers/admin/settings/project_custom_fields_controller.rb
@@ -40,6 +40,7 @@ module Admin::Settings
only: %i(show edit project_mappings unlink update destroy delete_option reorder_alphabetical move drop)
before_action :prepare_custom_option_position, only: %i(update create)
before_action :find_custom_option, only: :delete_option
+ before_action :project_custom_field_mappings_query, only: %i[project_mappings unlink]
# rubocop:enable Rails/LexicallyScopedActionFilter
def show_local_breadcrumb
@@ -77,15 +78,10 @@ module Admin::Settings
project = Project.find(permitted_params.project_custom_field_project_mapping[:project_id])
project_custom_field_mapping = @custom_field.project_custom_field_project_mappings.find_by(project:)
delete_service = ProjectCustomFieldProjectMappings::DeleteService
- .new(user: current_user, model: project_custom_field_mapping)
- .call
+ .new(user: current_user, model: project_custom_field_mapping)
+ .call
- delete_service.on_success do
- remove_via_turbo_stream(
- component: Settings::ProjectCustomFields::ProjectCustomFieldMapping::RowComponent
- .new(row: [project, 0], table: nil)
- )
- end
+ delete_service.on_success { render_unlink_response(project:) }
respond_to_with_turbo_streams(status: delete_service.success? ? :ok : :unprocessable_entity)
end
@@ -129,6 +125,32 @@ module Admin::Settings
private
+ def render_unlink_response(project:)
+ if @custom_field.project_custom_field_project_mappings.empty?
+ update_via_turbo_stream(
+ component: Settings::ProjectCustomFields::ProjectCustomFieldMapping::TableComponent.new(
+ query: @project_custom_field_mappings_query,
+ params: { custom_field: @custom_field }
+ ),
+ status: :ok
+ )
+ else
+ remove_via_turbo_stream(
+ component: Settings::ProjectCustomFields::ProjectCustomFieldMapping::RowComponent
+ .new(row: [project, 0], table: nil)
+ )
+ end
+ end
+
+ def project_custom_field_mappings_query
+ @project_custom_field_mappings_query = Queries::Projects::ProjectQuery.new(
+ name: "project-custom-field-mappings-#{@custom_field.id}"
+ ) do |query|
+ query.where(:available_project_attributes, "=", [@custom_field.id])
+ query.select(:name)
+ end
+ end
+
def set_sections
@project_custom_field_sections = ProjectCustomFieldSection
.includes(custom_fields: :project_custom_field_project_mappings)