Skip to content

Commit

Permalink
Merge pull request #9997 from alphagov/content-modelling/949-change-n…
Browse files Browse the repository at this point in the history
…ame-to-title

content modelling/949 change name to title
  • Loading branch information
Harriethw authored Mar 3, 2025
2 parents 99da9e9 + 2e25e55 commit a2e1777
Show file tree
Hide file tree
Showing 38 changed files with 213 additions and 137 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class ChangeObjectNameColumnToObjectTitle < ActiveRecord::Migration[8.0]
def up
rename_column :content_block_versions, :updated_embedded_object_name, :updated_embedded_object_title
end

def down
rename_column :content_block_versions, :updated_embedded_object_title, :updated_embedded_object_name
end
end
4 changes: 2 additions & 2 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[8.0].define(version: 2025_02_26_161012) do
ActiveRecord::Schema[8.0].define(version: 2025_02_28_111735) do
create_table "assets", charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t|
t.string "asset_manager_id", null: false
t.string "variant", null: false
Expand Down Expand Up @@ -249,7 +249,7 @@
t.text "state"
t.json "field_diffs"
t.string "updated_embedded_object_type"
t.string "updated_embedded_object_name"
t.string "updated_embedded_object_title"
t.index ["item_id"], name: "index_content_block_versions_on_item_id"
t.index ["item_type"], name: "index_content_block_versions_on_item_type"
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ def rows
end

def caption
content_block_edition.details.dig(subschema_id, object_id, "name") || object_id.underscore.humanize
content_block_edition.details.dig(subschema_id, object_id, "title") || object_id.underscore.humanize
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def updated_subschema_id
end

def new_subschema_item_details
version.field_diffs.dig("details", updated_subschema_id, version.updated_embedded_object_name).map do |field_name, diff|
version.field_diffs.dig("details", updated_subschema_id, version.updated_embedded_object_title).map do |field_name, diff|
[field_name.humanize, diff.new_value]
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
class ContentBlockManager::ContentBlock::Document::Show::EmbeddedObjects::SummaryCardComponent < ViewComponent::Base
def initialize(content_block_edition:, object_type:, object_name:)
def initialize(content_block_edition:, object_type:, object_title:)
@content_block_edition = content_block_edition
@object_type = object_type
@object_name = object_name
@object_title = object_title
end

private

attr_reader :content_block_edition, :object_type, :object_name
attr_reader :content_block_edition, :object_type, :object_title

def title
"#{object_type.titleize.singularize} details"
Expand All @@ -23,6 +23,6 @@ def rows
end

def object
content_block_edition.details.dig(object_type, object_name)
content_block_edition.details.dig(object_type, object_title)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<%= render ContentBlockManager::Shared::EmbeddedObjects::SummaryCardComponent.new(
content_block_edition:,
object_type:,
object_name: key,
object_title: key,
) %>
<% end %>
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
class ContentBlockManager::ContentBlockEdition::Details::EmbeddedObjects::FormComponent < ContentBlockManager::ContentBlockEdition::Details::FormComponent
def initialize(content_block_edition:, schema:, object_name:, params:)
def initialize(content_block_edition:, schema:, object_title:, params:)
@content_block_edition = content_block_edition
@schema = schema
@object_name = object_name
@object_title = object_title
@params = params || {}
end

private

attr_reader :content_block_edition, :schema, :object_name, :params
attr_reader :content_block_edition, :schema, :object_title, :params

def component_args(field)
{
content_block_edition:,
label: field.humanize,
field: [object_name, field],
id_suffix: "#{object_name}_#{field}",
field: [object_title, field],
id_suffix: "#{object_title}_#{field}",
value: params[field],
}
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
class ContentBlockManager::Shared::EmbeddedObjects::SummaryCardComponent < ViewComponent::Base
def initialize(content_block_edition:, object_type:, object_name:, is_editable: false, redirect_url: nil)
def initialize(content_block_edition:, object_type:, object_title:, is_editable: false, redirect_url: nil)
@content_block_edition = content_block_edition
@object_type = object_type
@object_name = object_name
@object_title = object_title
@is_editable = is_editable
@redirect_url = redirect_url
end

private

attr_reader :content_block_edition, :object_type, :object_name, :is_editable, :redirect_url
attr_reader :content_block_edition, :object_type, :object_title, :is_editable, :redirect_url

def title
"#{object_type.titleize.singularize} details"
Expand All @@ -34,7 +34,7 @@ def rows
def embed_code_row(key)
{
key: "Embed code",
value: content_block_edition.document.embed_code_for_field("#{object_type}/#{object_name}/#{key}"),
value: content_block_edition.document.embed_code_for_field("#{object_type}/#{object_title}/#{key}"),
data: {
"embed-code-row": "true",
},
Expand All @@ -53,13 +53,13 @@ def copy_embed_code(key)
unless is_editable
{
module: "copy-embed-code",
"embed-code": content_block_edition.document.embed_code_for_field("#{object_type}/#{object_name}/#{key}"),
"embed-code": content_block_edition.document.embed_code_for_field("#{object_type}/#{object_title}/#{key}"),
}
end
end

def object
content_block_edition.details.dig(object_type, object_name)
content_block_edition.details.dig(object_type, object_title)
end

def summary_card_actions
Expand All @@ -70,7 +70,7 @@ def summary_card_actions
href: helpers.content_block_manager.edit_embedded_object_content_block_manager_content_block_edition_path(
content_block_edition,
object_type:,
object_name:,
object_title:,
redirect_url:,
),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def create
redirect_to content_block_manager.review_embedded_object_content_block_manager_content_block_edition_path(
@content_block_edition,
object_type: @subschema.block_type,
object_name: @content_block_edition.key_for_object(@params),
object_title: @content_block_edition.key_for_object(@params),
)
rescue ActiveRecord::RecordInvalid
render :new
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ def create

def edit
@redirect_url = params[:redirect_url]
@object_name = params[:object_name]
@object = @content_block_edition.details.dig(params[:object_type], params[:object_name])
@object_title = params[:object_title]
@object = @content_block_edition.details.dig(params[:object_type], params[:object_title])

render "admin/errors/not_found", status: :not_found unless @object
end

def update
@object = object_params(@subschema).dig(:details, @subschema.block_type)
@content_block_edition.update_object_with_details(params[:object_type], params[:object_name], @object)
@content_block_edition.update_object_with_details(params[:object_type], params[:object_title], @object)
@content_block_edition.save!

if params[:redirect_url].present?
Expand All @@ -37,17 +37,17 @@ def update
redirect_to content_block_manager.review_embedded_object_content_block_manager_content_block_edition_path(
@content_block_edition,
object_type: @subschema.block_type,
object_name: params[:object_name],
object_title: params[:object_title],
)
end
rescue ActiveRecord::RecordInvalid
@redirect_url = params[:redirect_url]
@object_name = params[:object_name]
@object_title = params[:object_title]
render :edit
end

def review
@object_name = params[:object_name]
@object_title = params[:object_title]
end

def publish
Expand All @@ -56,11 +56,11 @@ def publish
redirect_path = content_block_manager.review_embedded_object_content_block_manager_content_block_edition_path(
@content_block_edition,
object_type: @subschema.block_type,
object_name: params[:object_name],
object_title: params[:object_title],
)
else
@content_block_edition.updated_embedded_object_type = @subschema.block_type
@content_block_edition.updated_embedded_object_name = params[:object_name]
@content_block_edition.updated_embedded_object_title = params[:object_title]
ContentBlockManager::PublishEditionService.new.call(@content_block_edition)
flash[:notice] = "#{@subschema.name.singularize} created"
redirect_path = content_block_manager.content_block_manager_content_block_document_path(@content_block_edition.document)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ def add_object_to_details(object_type, body)
details[object_type][key] = body.to_h
end

def update_object_with_details(object_type, object_name, body)
details[object_type][object_name] = body.to_h
def update_object_with_details(object_type, object_title, body)
details[object_type][object_title] = body.to_h
end

def key_for_object(object)
object["name"]&.parameterize.presence || SecureRandom.alphanumeric.downcase
object["title"]&.parameterize.presence || SecureRandom.alphanumeric.downcase
end

def has_entries_for_subschema_id?(subschema_id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def self.acting_as(actor)
after_update :record_update
end

attr_accessor :updated_embedded_object_type, :updated_embedded_object_name
attr_accessor :updated_embedded_object_type, :updated_embedded_object_title

private

Expand All @@ -37,7 +37,7 @@ def record_update
user:, state:,
field_diffs: generate_diff,
updated_embedded_object_type:,
updated_embedded_object_name:
updated_embedded_object_title:
)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def field_diffs
end

def is_embedded_update?
updated_embedded_object_type && updated_embedded_object_name
updated_embedded_object_type && updated_embedded_object_title
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
render ContentBlockManager::ContentBlockEdition::Details::EmbeddedObjects::FormComponent.new(
content_block_edition: @content_block_edition,
schema: @subschema,
object_name: @subschema.block_type,
object_title: @subschema.block_type,
params: @params,
)
%>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
url: content_block_manager.embedded_object_content_block_manager_content_block_edition_path(
@content_block_edition,
object_type: @subschema.block_type,
object_name: @object_name,
object_title: @object_title,
), method: :put) do |form| %>
<%= form.hidden_field :redirect_url, value: @redirect_url %>
<%= render partial: "content_block_manager/content_block/editions/embedded_objects/shared/form", locals: { form: } %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
href: content_block_manager.edit_embedded_object_content_block_manager_content_block_edition_path(
@content_block_edition,
object_type: @subschema.block_type,
object_name: @object_name,
object_title: @object_title,
),
} %>
<% end %>
Expand All @@ -23,7 +23,7 @@
<%= render ContentBlockManager::Shared::EmbeddedObjects::SummaryCardComponent.new(
content_block_edition: @content_block_edition,
object_type: @subschema.block_type,
object_name: @object_name,
object_title: @object_title,
is_editable: true,
) %>
</div>
Expand All @@ -35,7 +35,7 @@
url: content_block_manager.publish_embedded_object_content_block_manager_content_block_edition_path(
@content_block_edition,
object_type: @subschema.block_type,
object_name: @object_name,
object_title: @object_title,
),
id: "review",
method: :post,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
render ContentBlockManager::ContentBlockEdition::Details::EmbeddedObjects::FormComponent.new(
content_block_edition: @content_block_edition,
schema: @subschema,
object_name: @subschema.block_type,
object_title: @subschema.block_type,
params: @object,
)
%>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<%= render ContentBlockManager::Shared::EmbeddedObjects::SummaryCardComponent.new(
content_block_edition: @content_block_edition,
object_type: @subschema.block_type,
object_name: k,
object_title: k,
is_editable: true,
redirect_url: request.fullpath,
) %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<%= render ContentBlockManager::Shared::EmbeddedObjects::SummaryCardComponent.new(
content_block_edition: @content_block_edition,
object_type: subschema.id,
object_name: k,
object_title: k,
is_editable: true,
redirect_url: content_block_manager.content_block_manager_content_block_workflow_path(@content_block_edition, step: "#{Workflow::Step::SUBSCHEMA_PREFIX}#{subschema.id}"),
) %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ schemas:
embeddable_fields:
- amount
field_order:
- name
- title
- amount
- frequency
- description
8 changes: 4 additions & 4 deletions lib/engines/content_block_manager/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
end
get "embedded-objects/:object_type/new", to: "editions/embedded_objects#new", as: :new_embedded_object
post "embedded-objects/:object_type", to: "editions/embedded_objects#create", as: :create_embedded_object
get "embedded-objects/:object_type/:object_name/edit", to: "editions/embedded_objects#edit", as: :edit_embedded_object
put "embedded-objects/:object_type/:object_name", to: "editions/embedded_objects#update", as: :embedded_object
get "embedded-objects/:object_type/:object_name/review", to: "editions/embedded_objects#review", as: :review_embedded_object
post "embedded-objects/:object_type/:object_name/publish", to: "editions/embedded_objects#publish", as: :publish_embedded_object
get "embedded-objects/:object_type/:object_title/edit", to: "editions/embedded_objects#edit", as: :edit_embedded_object
put "embedded-objects/:object_type/:object_title", to: "editions/embedded_objects#update", as: :embedded_object
get "embedded-objects/:object_type/:object_title/review", to: "editions/embedded_objects#review", as: :review_embedded_object
post "embedded-objects/:object_type/:object_title/publish", to: "editions/embedded_objects#publish", as: :publish_embedded_object
get :preview, to: "editions/host_content#preview", path: "host-content/:host_content_id/preview", as: :host_content_preview
end
end
Expand Down
Loading

0 comments on commit a2e1777

Please sign in to comment.