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 %>