diff --git a/app/admin/bank_assessment_indicators.rb b/app/admin/bank_assessment_indicators.rb index ab2e48b99..484fd74ce 100644 --- a/app/admin/bank_assessment_indicators.rb +++ b/app/admin/bank_assessment_indicators.rb @@ -12,7 +12,7 @@ data_export_sidebar 'BankAssessmentIndicators', display_name: 'Indicators' - permit_params :number, :indicator_type, :text, :comment, :disable_bubbles_at_chart + permit_params :number, :indicator_type, :text, :comment, :is_placeholder show do attributes_table do @@ -21,7 +21,7 @@ row :indicator_type row :text row :comment - row :disable_bubbles_at_chart + row :is_placeholder row :created_at row :updated_at end @@ -37,7 +37,7 @@ f.input :number f.input :text f.input :comment - f.input :disable_bubbles_at_chart + f.input :is_placeholder end f.actions diff --git a/app/javascript/components/tpi/charts/average-bank-score/Chart.js b/app/javascript/components/tpi/charts/average-bank-score/Chart.js index dca43e0ba..b874e933b 100644 --- a/app/javascript/components/tpi/charts/average-bank-score/Chart.js +++ b/app/javascript/components/tpi/charts/average-bank-score/Chart.js @@ -10,10 +10,10 @@ import { getOptions } from './options'; import { useChartData } from '../hooks'; import { useDeviceInfo } from 'components/Responsive'; -function AverageBankScore({ dataUrl }) { +function AverageBankScore({ dataUrl, disabled_areas }) { const { data, error, loading } = useChartData(dataUrl); const { isMobile } = useDeviceInfo(); - const options = getOptions(data, isMobile); + const options = getOptions(data, isMobile, disabled_areas); const noData = !loading && data && data.length === 0; return ( @@ -38,8 +38,13 @@ function AverageBankScore({ dataUrl }) { ); } +AverageBankScore.defaultProps = { + disabled_areas: [] +}; + AverageBankScore.propTypes = { - dataUrl: PropTypes.string.isRequired + dataUrl: PropTypes.string.isRequired, + disabled_areas: PropTypes.arrayOf(PropTypes.string) }; export default AverageBankScore; diff --git a/app/javascript/components/tpi/charts/average-bank-score/options.js b/app/javascript/components/tpi/charts/average-bank-score/options.js index 0a65462f9..91309ac2e 100644 --- a/app/javascript/components/tpi/charts/average-bank-score/options.js +++ b/app/javascript/components/tpi/charts/average-bank-score/options.js @@ -2,7 +2,7 @@ import merge from 'lodash/merge'; import defaultOptions from '../default-options'; -export function getOptions(data, isMobile) { +export function getOptions(data, isMobile, disabled_areas) { return merge({}, defaultOptions, { chart: { type: 'bar' @@ -61,7 +61,7 @@ export function getOptions(data, isMobile) { dataLabels: { enabled: true, formatter() { - return `${Number(this.y).toFixed(1)}%`; + return (disabled_areas.includes(this.x)) ? 'N/A' : `${Number(this.y).toFixed(1)}%`; } }, states: { diff --git a/app/services/csv_export/user/bank_assessments.rb b/app/services/csv_export/user/bank_assessments.rb index 1fbe5f1a8..55f51d09e 100644 --- a/app/services/csv_export/user/bank_assessments.rb +++ b/app/services/csv_export/user/bank_assessments.rb @@ -32,6 +32,8 @@ def call assessment.bank.sedol&.tr(',', ';')&.tr(' ', ''), assessment.assessment_date, results_columns.map do |column| + next 'N/A' if column.is_placeholder + all_results[[assessment.id, column.type, column.number]]&.first&.decorate&.value end, assessment.bank.latest_information&.squish @@ -54,12 +56,13 @@ def all_results def results_columns @results_columns ||= begin - indicators = indicator_areas.map { |area| [area, child_indicators[area.number]] }.flatten + indicators = indicator_areas.values.flatten.map { |area| [area, child_indicators[area.number]] }.flatten indicators.map do |indicator| OpenStruct.new( type: indicator.indicator_type, number: indicator.number, - column_name: "#{indicator.indicator_type.humanize} #{indicator.number}" + column_name: "#{indicator.indicator_type.humanize} #{indicator.number}", + is_placeholder: indicator_areas[indicator.number.split('.').first]&.first&.is_placeholder ) end end @@ -69,6 +72,7 @@ def indicator_areas @indicator_areas ||= BankAssessmentIndicator .where(indicator_type: 'area') .order('length(number), number') + .group_by(&:number) end def child_indicators diff --git a/app/views/tpi/banks/_assessment.html.erb b/app/views/tpi/banks/_assessment.html.erb index 3478d49dd..bd7facbfd 100644 --- a/app/views/tpi/banks/_assessment.html.erb +++ b/app/views/tpi/banks/_assessment.html.erb @@ -53,7 +53,11 @@ <% if area.percentage < 5 %>
- <%= number_with_precision(area.percentage, precision: 1, strip_insignificant_zeros: true) %>% + <% if area.indicator.is_placeholder %> + N/A + <% else %> + <%= number_with_precision(area.percentage, precision: 1, strip_insignificant_zeros: true) %>% + <% end %>
<% end %> @@ -83,12 +87,12 @@
- <%= render "indicators", assessment: assessment, indicators: assessment.child_indicators(sub_area, "indicator") %> + <%= render "indicators", assessment: assessment, area: area, indicators: assessment.child_indicators(sub_area, "indicator") %>
<% end %> <% else %> - <%= render "indicators", assessment: assessment, indicators: assessment.child_indicators(area, "indicator") %> + <%= render "indicators", assessment: assessment, area: area, indicators: assessment.child_indicators(area, "indicator") %> <% end %> diff --git a/app/views/tpi/banks/_index_charts.html.erb b/app/views/tpi/banks/_index_charts.html.erb index 01e159c6a..0c012d4a6 100644 --- a/app/views/tpi/banks/_index_charts.html.erb +++ b/app/views/tpi/banks/_index_charts.html.erb @@ -1,9 +1,12 @@ -<%= react_component('charts/average-bank-score', { dataUrl: average_bank_score_chart_data_tpi_banks_path }) %> +<%= react_component('charts/average-bank-score', { + dataUrl: average_bank_score_chart_data_tpi_banks_path, + disabled_areas: BankAssessmentIndicator.area.where(is_placeholder: true).map { |area| "#{area.number}. #{area.text}" } +}) %> <%= react_component('charts/bank-bubble/Chart', { results: @results, - disabled_bubbles_areas: BankAssessmentIndicator.area.where(disable_bubbles_at_chart: true).pluck(:text) + disabled_bubbles_areas: BankAssessmentIndicator.area.where(is_placeholder: true).pluck(:text) }) %> <%= react_component('charts/bank-bubble/CompaniesAccordion', { results: @results, - disabled_bubbles_areas: BankAssessmentIndicator.area.where(disable_bubbles_at_chart: true).pluck(:text) + disabled_bubbles_areas: BankAssessmentIndicator.area.where(is_placeholder: true).pluck(:text) }) %> diff --git a/app/views/tpi/banks/_indicators.html.erb b/app/views/tpi/banks/_indicators.html.erb index 4501145b3..f5c3899b8 100644 --- a/app/views/tpi/banks/_indicators.html.erb +++ b/app/views/tpi/banks/_indicators.html.erb @@ -6,7 +6,11 @@
- <%= number_with_precision(indicator.percentage, precision: 1, strip_insignificant_zeros: true) %>% + <% if area.indicator.is_placeholder %> + N/A + <% else %> + <%= number_with_precision(indicator.percentage, precision: 1, strip_insignificant_zeros: true) %>% + <% end %>
diff --git a/db/migrate/20230927112905_rename_disable_bubbles_at_chart_to_is_placeholder.rb b/db/migrate/20230927112905_rename_disable_bubbles_at_chart_to_is_placeholder.rb new file mode 100644 index 000000000..e68890a43 --- /dev/null +++ b/db/migrate/20230927112905_rename_disable_bubbles_at_chart_to_is_placeholder.rb @@ -0,0 +1,5 @@ +class RenameDisableBubblesAtChartToIsPlaceholder < ActiveRecord::Migration[6.1] + def change + rename_column :bank_assessment_indicators, :disable_bubbles_at_chart, :is_placeholder + end +end diff --git a/db/structure.sql b/db/structure.sql index 842b46f40..7ab6ee9dc 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -322,7 +322,7 @@ CREATE TABLE public.bank_assessment_indicators ( created_at timestamp(6) without time zone NOT NULL, updated_at timestamp(6) without time zone NOT NULL, comment text, - disable_bubbles_at_chart boolean DEFAULT false + is_placeholder boolean DEFAULT false ); @@ -3734,6 +3734,7 @@ INSERT INTO "schema_migrations" (version) VALUES ('20230622093001'), ('20230712074753'), ('20230713121501'), -('20230926075145'); +('20230926075145'), +('20230927112905'); diff --git a/db/test-dump.psql b/db/test-dump.psql index 2f95720a4..eb6ba7d62 100644 Binary files a/db/test-dump.psql and b/db/test-dump.psql differ