diff --git a/app/components/log_summary_component.html.erb b/app/components/log_summary_component.html.erb new file mode 100644 index 000000000..612f920bd --- /dev/null +++ b/app/components/log_summary_component.html.erb @@ -0,0 +1,67 @@ +
+
+
+
+

+ <%= govuk_link_to case_log_path(log) do %> + Log <%= log.id %> + <% end %> +

+ <% if log.tenancycode? or log.propcode? %> + + <% end %> +
+ + <% if log.needstype? or log.startdate? %> +

+ <% if log.needstype? %> + <%= log.is_general_needs? ? "General needs" : "Supported housing" %>
+ <% end %> + <% if log.startdate? %> + Tenancy starts + <% end %> +

+ <% end %> + + <% if current_user.support? %> + <% if log.owning_organisation or log.managing_organisation %> + + <% end %> + <% end %> +
+ + +
+
diff --git a/app/components/log_summary_component.rb b/app/components/log_summary_component.rb new file mode 100644 index 000000000..bbd504e5d --- /dev/null +++ b/app/components/log_summary_component.rb @@ -0,0 +1,13 @@ +class LogSummaryComponent < ViewComponent::Base + attr_reader :current_user, :log + + def initialize(current_user:, log:) + @current_user = current_user + @log = log + super + end + + def log_status + helpers.status_tag(log.status) + end +end diff --git a/app/components/search_result_caption_component.html.erb b/app/components/search_result_caption_component.html.erb index f16cc485e..f2a553828 100644 --- a/app/components/search_result_caption_component.html.erb +++ b/app/components/search_result_caption_component.html.erb @@ -1,7 +1,7 @@ - - <% if searched.present? %> - <%= count %> <%= item_label %> found matching ‘<%= searched %>’ of <%= total_count %> total <%= item %>. <%= govuk_link_to("Clear search", path) %> - <% else %> - <%= count %> total <%= item %>. - <% end %> + + <% if searched.present? %> + <%= count %> <%= item_label %> found matching ‘<%= searched %>’ of <%= total_count %> total <%= item %>. <%= govuk_link_to("Clear search", path) %> + <% else %> + <%= count %> total <%= item %> + <% end %> diff --git a/app/frontend/styles/_log.scss b/app/frontend/styles/_log.scss new file mode 100644 index 000000000..f24f92a3f --- /dev/null +++ b/app/frontend/styles/_log.scss @@ -0,0 +1,23 @@ +.app-log-summary { + border-top: 1px solid $govuk-border-colour; + padding-top: govuk-spacing(3); +} + +.app-log-summary__header { + align-items: baseline; + display: flex; +} + +.app-log-summary__title { + margin: 0 govuk-spacing(3) govuk-spacing(2) 0; +} + +@include govuk-media-query(tablet) { + .app-log-summary__footer { + text-align: right; + } + + .app-log-summary__footer--actor { + display: block; + } +} diff --git a/app/frontend/styles/_metadata.scss b/app/frontend/styles/_metadata.scss new file mode 100644 index 000000000..7dc18d9b7 --- /dev/null +++ b/app/frontend/styles/_metadata.scss @@ -0,0 +1,23 @@ +.app-metadata { + @include govuk-font($size: 16, $tabular: true); + color: $govuk-secondary-text-colour; + margin-top: 0; + + &--inline { + display: flex; + gap: govuk-spacing(3); + margin: 0; + } + + &__item { + display: flex; + } + + &__term { + margin-right: govuk-spacing(1); + } + + &__definition { + margin-left: 0; + } +} diff --git a/app/frontend/styles/application.scss b/app/frontend/styles/application.scss index 4b26044d1..e862aec23 100644 --- a/app/frontend/styles/application.scss +++ b/app/frontend/styles/application.scss @@ -30,6 +30,8 @@ $govuk-breakpoints: ( @import "filter-layout"; @import "header"; @import "input"; +@import "log"; +@import "metadata"; @import "related-navigation"; @import "section-skip-link"; @import "table-group"; diff --git a/app/views/case_logs/_log_list.html.erb b/app/views/case_logs/_log_list.html.erb index 43a0bc701..6dab48bbc 100644 --- a/app/views/case_logs/_log_list.html.erb +++ b/app/views/case_logs/_log_list.html.erb @@ -1,68 +1,8 @@ -
- <%= govuk_table do |table| %> - <%= table.caption(classes: %w[govuk-!-font-size-19 govuk-!-font-weight-regular], id: title.dasherize) do |caption| %> - <%= render(SearchResultCaptionComponent.new(searched:, count: pagy.count, item_label:, total_count:, item: "logs", path: request.path)) %> - <%= govuk_link_to "Download (CSV)", "#{request.path}.csv", type: "text/csv" %> - <% end %> - <%= table.head do |head| %> - <%= head.row do |row| %> - <% row.cell(header: true, text: "Log", html_attributes: { - scope: "col", - }) %> - <% row.cell(header: true, text: "Tenant", html_attributes: { - scope: "col", - }) %> - <% row.cell(header: true, text: "Property", html_attributes: { - scope: "col", - }) %> - <% row.cell(header: true, text: "Tenancy starts", html_attributes: { - scope: "col", - }) %> - <% row.cell(header: true, text: "Log created", html_attributes: { - scope: "col", - }) %> - <% row.cell(header: true, text: "Log status", html_attributes: { - scope: "col", - }) %> - <% if current_user.support? %> - <% row.cell(header: true, text: "Owning organisation", html_attributes: { - scope: "col", - }) %> - <% row.cell(header: true, text: "Managing organisation", html_attributes: { - scope: "col", - }) %> - <% end %> - <% end %> - <% end %> - <%= table.body do |body| %> - <% case_logs.map do |log| %> - <%= body.row do |row| %> - <% row.cell(header: true, html_attributes: { - scope: "row", - }) do %> - <%= govuk_link_to case_log_path(log) do %> - Log <%= log.id %> - <% end %> - <% end %> - <% row.cell( - text: log.tenancycode? ? log.tenancycode : "–", - classes: "app-!-font-tabular", - ) %> - <% row.cell( - text: log.propcode? ? log.propcode : "–", - classes: "app-!-font-tabular", - ) %> - <% row.cell(text: log.startdate.present? ? log.startdate.to_formatted_s(:govuk_date) : "–") %> - <% row.cell(text: log.created_at.to_formatted_s(:govuk_date)) %> - <% row.cell do %> - <%= status_tag(log.status) %> - <% end %> - <% if current_user.support? %> - <% row.cell(text: log.owning_organisation&.name) %> - <% row.cell(text: log.managing_organisation&.name) %> - <% end %> - <% end %> - <% end %> - <% end %> - <% end %> -
+

+ <%= render(SearchResultCaptionComponent.new(searched:, count: pagy.count, item_label:, total_count:, item: "logs", path: request.path)) %> + <%= govuk_link_to "Download (CSV)", "#{request.path}.csv", type: "text/csv" %> +

+ +<% case_logs.map do |log| %> + <%= render(LogSummaryComponent.new(current_user:, log:)) %> +<% end %> diff --git a/spec/components/log_summary_component_spec.rb b/spec/components/log_summary_component_spec.rb new file mode 100644 index 000000000..c7f452d68 --- /dev/null +++ b/spec/components/log_summary_component_spec.rb @@ -0,0 +1,33 @@ +require "rails_helper" + +RSpec.describe LogSummaryComponent, type: :component do + let(:support_user) { FactoryBot.create(:user, :support) } + let(:coordinator_user) { FactoryBot.create(:user) } + let!(:log) { FactoryBot.create(:case_log, needstype: 1, startdate: Time.utc(2022, 1, 1)) } + + context "when rendering log for a support user" do + it "show the log summary with organisational relationships" do + result = render_inline(described_class.new(current_user: support_user, log:)) + + expect(result).to have_link(log.id.to_s) + expect(result).to have_text(log.tenancycode) + expect(result).to have_text(log.propcode) + expect(result).to have_text(log.propcode) + expect(result).to have_text("General needs") + expect(result).to have_text("Tenancy starts 1 January 2022") + expect(result).to have_text("Created 8 February 2022") + expect(result).to have_text("by Danny Rojas") + expect(result).to have_content("Owned by\n DLUHC") + expect(result).to have_content("Managed by\n DLUHC") + end + end + + context "when rendering log for a data coordinator user" do + it "show the log summary" do + result = render_inline(described_class.new(current_user: coordinator_user, log:)) + + expect(result).not_to have_content("Owned by\n DLUHC") + expect(result).not_to have_content("Managed by\n DLUHC") + end + end +end diff --git a/spec/components/search_result_caption_component_spec.rb b/spec/components/search_result_caption_component_spec.rb index a317e562e..ed4934633 100644 --- a/spec/components/search_result_caption_component_spec.rb +++ b/spec/components/search_result_caption_component_spec.rb @@ -10,7 +10,7 @@ RSpec.describe SearchResultCaptionComponent, type: :component do it "renders table caption including the search results and total" do result = render_inline(described_class.new(searched:, count:, item_label:, total_count:, item:, path:)) - expect(result.to_html).to eq(" \n #{count} #{item_label} found matching ‘#{searched}’ of #{total_count} total #{item}. Clear search\n\n") + expect(result.to_html).to eq("\n #{count} #{item_label} found matching ‘#{searched}’ of #{total_count} total #{item}. Clear search\n\n") end context "when no search results are found" do @@ -19,7 +19,7 @@ RSpec.describe SearchResultCaptionComponent, type: :component do it "renders table caption with total count only" do result = render_inline(described_class.new(searched:, count:, item_label:, total_count:, item:, path:)) - expect(result.to_html).to eq(" \n #{count} total #{item}.\n\n") + expect(result.to_html).to eq("\n #{count} total #{item}\n\n") end end end diff --git a/spec/requests/case_logs_controller_spec.rb b/spec/requests/case_logs_controller_spec.rb index eef4744d4..30007fc4d 100644 --- a/spec/requests/case_logs_controller_spec.rb +++ b/spec/requests/case_logs_controller_spec.rb @@ -172,10 +172,10 @@ RSpec.describe CaseLogsController, type: :request do sign_in user end - it "does have organisation columns" do + it "does have organisation values" do get "/logs", headers: headers, params: {} - expect(page).to have_content("Owning organisation") - expect(page).to have_content("Managing organisation") + expect(page).to have_content("Owned by") + expect(page).to have_content("Managed by") end it "shows case logs for all organisations" do @@ -449,7 +449,7 @@ RSpec.describe CaseLogsController, type: :request do end it "shows a table of logs" do - expect(CGI.unescape_html(response.body)).to match(//) + expect(CGI.unescape_html(response.body)).to match(/
/) expect(CGI.unescape_html(response.body)).to match(/logs/) end diff --git a/spec/requests/organisations_controller_spec.rb b/spec/requests/organisations_controller_spec.rb index e17f140f5..0498209f9 100644 --- a/spec/requests/organisations_controller_spec.rb +++ b/spec/requests/organisations_controller_spec.rb @@ -892,7 +892,7 @@ RSpec.describe OrganisationsController, type: :request do end it "shows the total organisations count" do - expect(CGI.unescape_html(response.body)).to match("#{total_organisations_count} total organisations.") + expect(CGI.unescape_html(response.body)).to match("#{total_organisations_count} total organisations") end it "has pagination links" do diff --git a/spec/requests/schemes_controller_spec.rb b/spec/requests/schemes_controller_spec.rb index 2e853a922..47ba637e3 100644 --- a/spec/requests/schemes_controller_spec.rb +++ b/spec/requests/schemes_controller_spec.rb @@ -90,7 +90,7 @@ RSpec.describe SchemesController, type: :request do end it "shows the total organisations count" do - expect(CGI.unescape_html(response.body)).to match("#{schemes.count} total schemes.") + expect(CGI.unescape_html(response.body)).to match("#{schemes.count} total schemes") end context "when params scheme_id is present" do @@ -113,7 +113,7 @@ RSpec.describe SchemesController, type: :request do end it "shows the total schemes count" do - expect(CGI.unescape_html(response.body)).to match("#{total_schemes_count} total schemes.") + expect(CGI.unescape_html(response.body)).to match("#{total_schemes_count} total schemes") end it "shows which schemes are being shown on the current page" do @@ -138,7 +138,7 @@ RSpec.describe SchemesController, type: :request do end it "shows the total schemes count" do - expect(CGI.unescape_html(response.body)).to match("#{total_schemes_count} total schemes.") + expect(CGI.unescape_html(response.body)).to match("#{total_schemes_count} total schemes") end it "has pagination links" do