Add archived label for inventories and item in item card relationships and modal [SCI-9122] (#6884)

This commit is contained in:
wandji 2024-01-10 17:23:15 +01:00 committed by GitHub
parent 3b97571777
commit e31448c8e7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 19 additions and 10 deletions

View file

@ -90,8 +90,8 @@ class RepositoryRowConnectionsController < ApplicationController
.page(params[:page] || 1)
.per(Constants::SEARCH_LIMIT)
render json: {
data: repositories.select(:id, :name)
.map { |repository| { id: repository.id, name: repository.name } },
data: repositories.select(:id, :name, :archived)
.map { |repository| { id: repository.id, name: repository.name_with_label } },
next_page: repositories.next_page
}
end
@ -103,8 +103,9 @@ class RepositoryRowConnectionsController < ApplicationController
.page(params[:page] || 1)
.per(Constants::SEARCH_LIMIT)
render json: {
data: repository_rows.select(:id, :name)
.map { |repository| { id: repository.id, name: repository.name } },
data: repository_rows.select(:id, :name, :archived, :repository_id)
.preload(:repository)
.map { |row| { id: row.id, name: row.name_with_label } },
next_page: repository_rows.next_page
}
end

View file

@ -50,9 +50,9 @@ module ArchivableModel
def name_with_label
raise NotImplementedError, "Archivable model must implement the '.archived_branch?' method!" unless respond_to?(:archived_branch?)
return "#{I18n.t('labels.archived')} #{parent&.name || name}" if archived_branch?
return "#{I18n.t('labels.archived')} #{name || parent&.name}" if archived_branch?
parent&.name || name
name || parent&.name
end
protected

View file

@ -275,6 +275,10 @@ class Repository < RepositoryBase
.destroy_all
end
def archived_branch?
archived?
end
private
def sync_name_with_snapshots

View file

@ -192,4 +192,8 @@ class RepositoryRow < ApplicationRecord
def relationship_count
parent_connections.size + child_connections.size
end
def archived_branch?
archived?
end
end

View file

@ -55,9 +55,9 @@ json.relationships do
json.array! @repository_row.parent_repository_rows.preload(:repository).each do |parent|
json.id parent.id
json.code parent.code
json.name parent.name
json.name parent.name_with_label
json.path repository_repository_row_path(parent.repository, parent)
json.repository_name parent.repository.name
json.repository_name parent.repository.name_with_label
json.repository_path repository_path(parent.repository)
json.unlink_path repository_repository_row_repository_row_connection_path(parent.repository,
parent,
@ -69,9 +69,9 @@ json.relationships do
json.array! @repository_row.child_repository_rows.preload(:repository).each do |child|
json.id child.id
json.code child.code
json.name child.name
json.name child.name_with_label
json.path repository_repository_row_path(child.repository, child)
json.repository_name child.repository.name
json.repository_name child.repository.name_with_label
json.repository_path repository_path(child.repository)
json.unlink_path repository_repository_row_repository_row_connection_path(child.repository,
child,